MainWindowViewModel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. namespace EEMSMain.ViewModels;
  3. public partial class MainWindowViewModel : ObservableObject
  4. {
  5. public MainWindowViewModel(ICommonContainer commonContainer, ContainerManager containerManager, DeviceCollection deviceCollection)
  6. {
  7. this._commonContainer = commonContainer;
  8. this.ContainerManager = containerManager;
  9. this._deviceCollection = deviceCollection;
  10. containerManager.Containers.CollectionChanged += Containers_CollectionChanged;
  11. this.FakeData();
  12. }
  13. private void Containers_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  14. {
  15. if (sender is not ObservableDictionary<int, ContainerInfo> t)
  16. return;
  17. ContainerInfo? containerInfo = t.Values.FirstOrDefault(x => x.IsDefault);
  18. if (containerInfo is null)
  19. return;
  20. this.Open(containerInfo);
  21. }
  22. private readonly ICommonContainer _commonContainer;
  23. public ContainerManager ContainerManager { get; }
  24. private readonly DeviceCollection _deviceCollection;
  25. void FakeData()
  26. {
  27. Random r = new();
  28. for (int i = 1; i <= 6; i++)
  29. {
  30. Guid guid = Guid.NewGuid();
  31. DeviceInfo_VM device = new()
  32. {
  33. DeviceModel = DeviceModel.JetKepler,
  34. DeviceSubModel = KeplerSubModel.JetKepler_2200A.ToString(),
  35. DeviceName = $"Device {i}",
  36. Position = $"position-{i}",
  37. SoftwareVersion = "1.0.0.0",
  38. IP = $"192.168.250.{i}",
  39. Port = 50002,
  40. UpdateTime = DateTime.Now,
  41. Guid = guid,
  42. IsConnected = Convert.ToBoolean(r.Next(0, 2))
  43. };
  44. RecipeInfo_VM recipe = new()
  45. {
  46. DeviceId = guid,
  47. CurrentStepName = "Step 1",
  48. NextStepName = "Step 2",
  49. CurrentStepTotalTime = r.Next(50, 100),
  50. CurrentStepRemainTime = r.Next(0, 50),
  51. TotalTime = r.Next(200, 400),
  52. TotalRemainTime = r.Next(100, 200),
  53. };
  54. //recipe.RecipeInfo["PJobID"] = "TestPJob";
  55. //recipe.RecipeInfo["CJboID"] = "TestCJob";
  56. //recipe.RecipeInfo["RecipeType"] = (RecipeType)r.Next(0, 8);
  57. DeviceData_VM deviceData = new()
  58. {
  59. DeviceId = guid,
  60. DeviceModel = DeviceModel.JetKepler,
  61. DeviceStatus = ((DeviceStatus)r.Next(0, 12)).ToString(),
  62. RecipeInfo = recipe,
  63. Alarms = []
  64. };
  65. deviceData.OtherInfo.Add("子型号", KeplerSubModel.JetKepler_2200A);
  66. //deviceData.OtherInfo["PMC Mode"] = PMCMode.Running.ToString();
  67. if (r.Next(1, 4) > 1)
  68. {
  69. for (int j = 0; j < r.Next(1, 5); j++)
  70. {
  71. Alarm_VM alarm = new()
  72. {
  73. DeviceId = guid,
  74. AlarmCode = r.Next(10000, 90000).ToString(),
  75. AlarmTime = DateTime.Now,
  76. AlarmName = $"Test Alarm {j}"
  77. };
  78. deviceData.Alarms.Add(alarm);
  79. }
  80. }
  81. _deviceCollection.DeviceDataList.Add(guid, deviceData);
  82. _deviceCollection.DeviceList.Add(guid, device);
  83. }
  84. for (int i = 1; i <= 3; i++)
  85. {
  86. Guid guid = Guid.NewGuid();
  87. DeviceInfo_VM device = new()
  88. {
  89. DeviceModel = DeviceModel.Proxima,
  90. DeviceSubModel = ProximaSubModel.Proxima_ELK.ToString(),
  91. DeviceName = $"Device {i}",
  92. Position = $"position-{i}",
  93. SoftwareVersion = "1.0.0.0",
  94. IP = $"192.168.250.{i}",
  95. Port = 50002,
  96. UpdateTime = DateTime.Now,
  97. Guid = guid,
  98. IsConnected = Convert.ToBoolean(r.Next(0, 2))
  99. };
  100. RecipeInfo_VM recipe = new()
  101. {
  102. DeviceId = guid,
  103. CurrentStepName = "Step 1",
  104. NextStepName = "Step 2",
  105. CurrentStepTotalTime = r.Next(50, 100),
  106. CurrentStepRemainTime = r.Next(0, 50),
  107. TotalTime = r.Next(200, 400),
  108. TotalRemainTime = r.Next(100, 200),
  109. };
  110. recipe.RecipeInfo.Add("PJobID", "TestPJob");
  111. recipe.RecipeInfo.Add("CJboID", "TestCJob");
  112. recipe.RecipeInfo.Add("RecipeType", (RecipeType)r.Next(0, 8));
  113. DeviceData_VM deviceData = new()
  114. {
  115. DeviceId = guid,
  116. DeviceModel = DeviceModel.Proxima,
  117. DeviceStatus = ((DeviceStatus)r.Next(0, 12)).ToString(),
  118. //PMCMode = PMCMode.Running,
  119. RecipeInfo = recipe,
  120. Alarms = []
  121. };
  122. deviceData.OtherInfo.Add("子型号", ProximaSubModel.Proxima_ELK);
  123. deviceData.OtherInfo.Add(nameof(PMCMode), PMCMode.Running);
  124. _deviceCollection.DeviceDataList.Add(guid, deviceData);
  125. _deviceCollection.DeviceList.Add(guid, device);
  126. }
  127. }
  128. [ObservableProperty]
  129. private string? _CurrentModule;
  130. [RelayCommand]
  131. private void Open(ContainerInfo para)
  132. {
  133. try
  134. {
  135. _commonContainer.RequestNavigation(para.ModuleName);
  136. this.CurrentModule = para.Name;
  137. }
  138. catch
  139. {
  140. }
  141. }
  142. }