ConfigFileManagerViewModel.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. namespace ConfigFileManager.ViewModels;
  2. public partial class ConfigFileManagerViewModel : ObservableObject
  3. {
  4. public ConfigFileManagerViewModel(DeviceCollection deviceCollection, IDialogService dialogService)
  5. {
  6. _DialogService = dialogService;
  7. deviceCollection.DeviceList.CollectionChanged += DeviceList_CollectionChanged;
  8. this.DeviceList_CollectionChanged(deviceCollection.DeviceList, null);
  9. }
  10. private void DeviceList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs? e)
  11. {
  12. if (sender is not ObservableDictionary<Guid, DeviceInfo_VM> deviceList)
  13. return;
  14. this.Devices.Clear();
  15. foreach (DeviceInfo_VM device in deviceList.Values)
  16. {
  17. this.Devices[device.DeviceModel] ??= [];
  18. this.Devices[device.DeviceModel].Add(device);
  19. }
  20. }
  21. private readonly IDialogService _DialogService;
  22. [ObservableProperty]
  23. private ObservableDictionary<DeviceModel, ObservableCollection<DeviceInfo_VM>> _Devices = [];
  24. [RelayCommand]
  25. private void Migrate(DeviceInfo_VM deviceInfo)
  26. {
  27. IDialogParameters para = new DialogParameters()
  28. {
  29. {"Device",deviceInfo }
  30. };
  31. this._DialogService.ShowDialog("Migrate", para);
  32. }
  33. [RelayCommand]
  34. private async Task Update(DeviceInfo_VM deviceInfo)
  35. {
  36. deviceInfo.ConfigUpdating = true;
  37. await Task.Delay(5000);
  38. deviceInfo.ConfigUpdating = false;
  39. deviceInfo.UpdateTime = DateTime.Now;
  40. }
  41. [RelayCommand]
  42. private void CheckRecipe(DeviceInfo_VM deviceInfo)
  43. {
  44. IDialogParameters para = new DialogParameters()
  45. {
  46. {"Device",deviceInfo }
  47. };
  48. this._DialogService.ShowDialog("Recipe", para);
  49. }
  50. [RelayCommand]
  51. private void CheckConfig(DeviceInfo_VM deviceInfo)
  52. {
  53. IDialogParameters para = new DialogParameters()
  54. {
  55. {"Device",deviceInfo }
  56. };
  57. this._DialogService.ShowDialog("Config", para);
  58. }
  59. }