You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.7 KiB

using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Controls;
using SparkClient.Model.Helper;
using SparkClient.Model.Services;
using SparkClient.ViewModel.Configuration;
using SparkClient.ViewModel.Grading;
using MessageBox = System.Windows.MessageBox;
namespace SparkClient.ViewModel.BaseWindow;
public class HomeWindowVM : BaseViewModel
{
private SOCClientService _socClientService;
public ICommand ShowHelperPageCommand { get; }
public ICommand ShowConfigPageCommand { get; }
public ICommand ShowDiamondSelPageCommand { get; }
public HomeWindowVM()
{
ShowHelperPageCommand = new RelayCommand(ShowHelperPage);
ShowConfigPageCommand = new RelayCommand(ShowConfigPage);
ShowDiamondSelPageCommand = new RelayCommand(ShowDiamlondSelPage);
// 初始化SOC客户端服务,传入SOC端的地址和认证Token
_socClientService = new SOCClientService("http://localhost:5000/api/SoC", "your_basic_auth_token");
}
public void ShowHelperPage(object parameter)
{
BaseControlVM vm = new BaseControlVM(new HelperPageVM(), MultilingualHelper.getString("Help"));
WindowManager.mainViewModel.Content = vm;
WindowManager.openContent.Add(vm);
}
public void ShowConfigPage(object parameter)
{
ConfigMenuPageVM vm = new ConfigMenuPageVM();
WindowManager.mainViewModel.Content = vm;
WindowManager.openContent.Add(vm);
}
public async void ShowDiamlondSelPage(object parameter)
{
try
{
// string savePath = @"..\..\..\Resource\SOCImages";
// string result = await _socClientService.ProcessImageCollectionAsync(100, savePath);
//
// ShowMessage(result);
//
// if (result == "成功")
// {
// BaseControlVM vm = new BaseControlVM(new GradingResultVM(null), MultilingualHelper.getString("DetectionResult"));
// WindowManager.mainViewModel.Content = vm;
// WindowManager.openContent.Add(vm);
// }
BaseControlVM vm = new BaseControlVM(new GradingResultVM(null), MultilingualHelper.getString("DetectionResult"));
WindowManager.mainViewModel.Content = vm;
WindowManager.openContent.Add(vm);
}
catch (Exception e)
{
// 记录日志
LogError(e);
ShowMessage("错误: " + e.Message);
}
}
private void ShowMessage(string message)
{
MessageBox.Show(message);
}
private void LogError(Exception e)
{
// 实现日志记录逻辑,例如写入文件或数据库
Console.WriteLine($"Error: {e.Message}\n{e.StackTrace}");
}
}