MainWindowViewModel.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. namespace EEMSMain.ViewModels;
  2. public partial class MainWindowViewModel : ObservableObject
  3. {
  4. public MainWindowViewModel(ICommonContainer commonContainer, ContainerManager containerManager, DeviceCollection deviceCollection)
  5. {
  6. this._commonContainer = commonContainer;
  7. this.ContainerManager = containerManager;
  8. this._deviceCollection = deviceCollection;
  9. containerManager.Containers.CollectionChanged += Containers_CollectionChanged;
  10. this.FakeData();
  11. }
  12. private void Containers_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  13. {
  14. if (sender is not ObservableDictionary<int, ContainerInfo> t)
  15. return;
  16. ContainerInfo? containerInfo = t.Values.FirstOrDefault(x => x.IsDefault);
  17. if (containerInfo is null)
  18. return;
  19. this.Open(containerInfo);
  20. }
  21. private readonly ICommonContainer _commonContainer;
  22. public ContainerManager ContainerManager { get; }
  23. private readonly DeviceCollection _deviceCollection;
  24. void FakeData()
  25. {
  26. Random r = new();
  27. for (int i = 1; i <= 6; i++)
  28. {
  29. DeviceInfo_VM device = new()
  30. {
  31. DeviceModel = DeviceModel.JetKepler,
  32. DeviceSubModel = KeplerSubModel.JetKepler_2200A.ToString(),
  33. DeviceName = $"Device {i}",
  34. Position = $"position-{i}",
  35. SoftwareVersion = "1.0.0.0",
  36. IP = $"192.168.250.{i}",
  37. Port = 50002,
  38. UpdateTime = DateTime.Now,
  39. Guid = Guid.NewGuid(),
  40. IsConnected = Convert.ToBoolean(r.Next(0,2))
  41. };
  42. _deviceCollection.DeviceList.Add(device.Guid.Value, device);
  43. }
  44. for (int i = 1; i <= 3; i++)
  45. {
  46. DeviceInfo_VM device = new()
  47. {
  48. DeviceModel = DeviceModel.Proxima,
  49. DeviceSubModel = ProximaSubModel.Proxima_ELK.ToString(),
  50. DeviceName = $"Device {i}",
  51. Position = $"position-{i}",
  52. SoftwareVersion = "1.0.0.0",
  53. IP = $"192.168.250.{i}",
  54. Port = 50002,
  55. UpdateTime=DateTime.Now,
  56. Guid = Guid.NewGuid(),
  57. IsConnected = Convert.ToBoolean(r.Next(0, 2))
  58. };
  59. _deviceCollection.DeviceList.Add(device.Guid.Value, device);
  60. }
  61. }
  62. [ObservableProperty]
  63. private string? _CurrentModule;
  64. [RelayCommand]
  65. private void Open(ContainerInfo para)
  66. {
  67. try
  68. {
  69. _commonContainer.RequestNavigation(para.ModuleName);
  70. this.CurrentModule = para.Name;
  71. }
  72. catch
  73. {
  74. }
  75. }
  76. }