MainWindowViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. using Device;
  4. using EEMSMain.Data;
  5. using GeneralData;
  6. using GlobalData;
  7. using UICommon.CommonContainer;
  8. using UICommon.DataType;
  9. namespace EEMSMain.ViewModels;
  10. public partial class MainWindowViewModel : ObservableObject
  11. {
  12. public MainWindowViewModel(ICommonContainer commonContainer, ContainerManager containerManager, DeviceCollection deviceCollection)
  13. {
  14. this._commonContainer = commonContainer;
  15. this.ContainerManager = containerManager;
  16. this._deviceCollection = deviceCollection;
  17. containerManager.Containers.CollectionChanged += Containers_CollectionChanged;
  18. //deviceCollection.RawDevices.CollectionChanged += RawDevices_CollectionChanged;
  19. this.FakeData();
  20. }
  21. //private void RawDevices_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  22. //{
  23. // if (e.NewItems is null)
  24. // return;
  25. // foreach (object item in e.NewItems)
  26. // {
  27. // if (item is KeyValuePair<Guid, DeviceInfo_VM> devicePair)
  28. // {
  29. // }
  30. // }
  31. //}
  32. private void Containers_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  33. {
  34. if (sender is not ObservableDictionary<int, ContainerInfo> t)
  35. return;
  36. ContainerInfo? containerInfo = t.Values.FirstOrDefault(x => x.IsDefault);
  37. if (containerInfo is null)
  38. return;
  39. this.Open(containerInfo);
  40. }
  41. private readonly ICommonContainer _commonContainer;
  42. public ContainerManager ContainerManager { get; }
  43. private readonly DeviceCollection _deviceCollection;
  44. void FakeData()
  45. {
  46. _deviceCollection.Devices ??= [];
  47. _deviceCollection.Devices[DeviceModel.JetKepler] = [];
  48. for (int i = 1; i <= 6; i++)
  49. {
  50. DeviceInfo_VM device = new()
  51. {
  52. DeviceModel = DeviceModel.JetKepler,
  53. DeviceSubModel = KeplerSubModel.JetKepler_2200A.ToString(),
  54. DeviceName = $"Device {i}",
  55. Position = $"position-{i}",
  56. SoftwareVersion = "1.0.0.0",
  57. Guid = Guid.NewGuid(),
  58. };
  59. _deviceCollection.Devices[DeviceModel.JetKepler].Add(device);
  60. //_deviceCollection.RawDevices.Add(device.Guid.Value, device);
  61. }
  62. _deviceCollection.Devices[DeviceModel.Proxima] = [];
  63. for (int i = 1; i <= 3; i++)
  64. {
  65. DeviceInfo_VM device = new()
  66. {
  67. DeviceModel = DeviceModel.Proxima,
  68. DeviceSubModel = ProximaSubModel.Proxima_ELK.ToString(),
  69. DeviceName = $"Device {i}",
  70. Position = $"position-{i}",
  71. SoftwareVersion = "1.0.0.0",
  72. Guid = Guid.NewGuid(),
  73. };
  74. _deviceCollection.Devices[DeviceModel.Proxima].Add(device);
  75. //_deviceCollection.RawDevices.Add(device.Guid.Value, device);
  76. }
  77. }
  78. [ObservableProperty]
  79. private string? _CurrentModule;
  80. [RelayCommand]
  81. private void Open(ContainerInfo para)
  82. {
  83. try
  84. {
  85. _commonContainer.RequestNavigation(para.ModuleName);
  86. this.CurrentModule = para.Name;
  87. }
  88. catch
  89. {
  90. }
  91. }
  92. }