MigrateViewModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. namespace ConfigFileManager.ViewModels.Dialog;
  2. internal partial class MigrateViewModel : ObservableObject, IDialogAware
  3. {
  4. public MigrateViewModel(DeviceCollection deviceCollection)
  5. {
  6. this.Sources = [];
  7. this.Running = Visibility.Collapsed;
  8. this.Progress = 0;
  9. foreach (DeviceInfo_VM deviceInfos in deviceCollection.DeviceList.Values.OrderBy(t=>t.DeviceModel))
  10. this.Sources.Add(deviceInfos);
  11. }
  12. [ObservableProperty]
  13. private string? _Title;
  14. [ObservableProperty]
  15. private ObservableCollection<DeviceInfo_VM> _Sources;
  16. [ObservableProperty]
  17. private DeviceInfo_VM? _Source;
  18. public DialogCloseListener RequestClose { get; set; }
  19. public bool CanCloseDialog()
  20. {
  21. return true;
  22. }
  23. public void OnDialogClosed()
  24. {
  25. }
  26. public void OnDialogOpened(IDialogParameters parameters)
  27. {
  28. this.Title = "文件迁移";
  29. if (!parameters.TryGetValue("Device", out DeviceInfo_VM? deviceInfo) || deviceInfo is null)
  30. {
  31. MessageBox.Show("Config Device Error");
  32. this.RequestClose.Invoke();
  33. return;
  34. }
  35. this.Sources.Remove(deviceInfo);
  36. this.Source = deviceInfo;
  37. }
  38. [ObservableProperty]
  39. private Visibility _Running;
  40. [ObservableProperty]
  41. private int _progress;
  42. [RelayCommand]
  43. private async Task Migrate(DeviceInfo_VM device)
  44. {
  45. if (this.Source is null)
  46. return;
  47. if (Source.SoftwareVersion != device.SoftwareVersion)
  48. MessageBox.Show($"{this.Source.DeviceName} 与 {device.DeviceName} 间存在软件版本差异,请确认无误后再进行迁移!", "配置迁移", MessageBoxButton.OK, MessageBoxImage.Warning);
  49. MessageBoxResult result = MessageBox.Show($"确认将 {this.Source.DeviceName} Config文件迁移至 {device.DeviceName}?", "配置迁移", MessageBoxButton.YesNo, MessageBoxImage.Question);
  50. if (result != MessageBoxResult.Yes)
  51. return;
  52. this.Running = Visibility.Visible;
  53. this.Progress = 0;
  54. for (int i = 1; i <= 10; i++)
  55. {
  56. await Task.Delay(500);
  57. this.Progress = 10 * i;
  58. }
  59. MessageBox.Show($"配置及Recipe文件迁移成功", "配置迁移", MessageBoxButton.OK, MessageBoxImage.Question);
  60. this.Running = Visibility.Collapsed;
  61. }
  62. [RelayCommand]
  63. private async Task MigrateRecipe(DeviceInfo_VM device)
  64. {
  65. if (this.Source is null)
  66. return;
  67. if (Source.SoftwareVersion != device.SoftwareVersion)
  68. MessageBox.Show($"{this.Source.DeviceName} 与 {device.DeviceName} 间存在软件版本差异,请确认无误后再进行迁移!", "配置迁移", MessageBoxButton.OK, MessageBoxImage.Warning);
  69. MessageBoxResult result = MessageBox.Show($"确认将 {this.Source.DeviceName} Recipe文件迁移至 {device.DeviceName}?", "配置迁移", MessageBoxButton.YesNo, MessageBoxImage.Question);
  70. if (result != MessageBoxResult.Yes)
  71. return;
  72. this.Running = Visibility.Visible;
  73. this.Progress = 0;
  74. for (int i = 1; i <= 10; i++)
  75. {
  76. await Task.Delay(500);
  77. this.Progress = 10 * i;
  78. }
  79. MessageBox.Show($"配置及Recipe文件迁移成功", "配置迁移", MessageBoxButton.OK, MessageBoxImage.Question);
  80. this.Running = Visibility.Collapsed;
  81. }
  82. [RelayCommand]
  83. private void Close()
  84. {
  85. this.RequestClose.Invoke();
  86. }
  87. }