diff --git a/ViewModel/BaseWindow/HomeWindowVM.cs b/ViewModel/BaseWindow/HomeWindowVM.cs index a29e27e..0faa33d 100644 --- a/ViewModel/BaseWindow/HomeWindowVM.cs +++ b/ViewModel/BaseWindow/HomeWindowVM.cs @@ -1,15 +1,20 @@ -using System.Windows; +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; } @@ -20,6 +25,9 @@ public class HomeWindowVM : BaseViewModel 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) @@ -36,10 +44,43 @@ public class HomeWindowVM : BaseViewModel WindowManager.openContent.Add(vm); } - public void ShowDiamlondSelPage(object parameter) + public async void ShowDiamlondSelPage(object parameter) { - BaseControlVM vm = new BaseControlVM(new GradingResultVM(null), MultilingualHelper.getString("DetectionResult")); - WindowManager.mainViewModel.Content = vm; - WindowManager.openContent.Add(vm); + 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}"); } + + } \ No newline at end of file