UIViewModelBase.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms.VisualStyles;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.UI.MVVM;
  6. using Aitex.Core.Utilities;
  7. using Aitex.Triton160.Common;
  8. using Aitex.Triton160.UI.Config;
  9. namespace Aitex.Triton160.UI.ViewModel
  10. {
  11. public class UIViewModelBase : SubscriptionViewModelBase
  12. {
  13. protected const string SystemDeviceModule = "Device.System";
  14. protected const string SystemStateModule = "System";
  15. [IgnorePropertyChange]
  16. protected SCValue SCLocal
  17. {
  18. get;
  19. set;
  20. }
  21. [IgnorePropertyChange]
  22. private List<Tuple<string, string, string, bool>> _allDataItems = new List<Tuple<string, string, string, bool>>();
  23. public UIViewModelBase(string vmName)
  24. : base(vmName)
  25. {
  26. SCLocal = new SCValue();
  27. PollDataFunction = (IEnumerable<string> keys) =>
  28. {
  29. return Triton160UiSystem.Instance.WCF.Query.PollData(keys);
  30. };
  31. InvokeFunction = (string[] param) =>
  32. {
  33. if (param.Length == 1)
  34. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0]);
  35. else if (param.Length == 2)
  36. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0], param[1]);
  37. else if (param.Length == 3)
  38. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(param[0], param[1], param[2]);
  39. };
  40. DeviceFunction = (string deviceName, string operationName) =>
  41. {
  42. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), deviceName, operationName);
  43. };
  44. DeviceControlFunction = (object[] args) =>
  45. {
  46. if (args.Length == 2)
  47. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1]);
  48. else if (args.Length == 3)
  49. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1], args[2]);
  50. else if (args.Length == 4)
  51. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), args[0], args[1], args[2], args[3]);
  52. };
  53. _allDataItems = SystemConfigManager.Instance.GetMonitorDataList();
  54. }
  55. public void UpdateAllConfig()
  56. {
  57. SCLocal.Update(Triton160UiSystem.Instance.WCF.Query.PollConfig(SCLocal.GetKeys()));
  58. }
  59. public Dictionary<string, Tuple<string, string, bool>> GetDataElements(string culture)
  60. {
  61. Dictionary<string, Tuple<string, string, bool>> result = new Dictionary<string, Tuple<string, string, bool>>();
  62. Dictionary<string, Tuple<string, string, string, bool>> all = GetDataElements();
  63. foreach (var tuple in all)
  64. {
  65. result.Add(tuple.Key, Tuple.Create(tuple.Value.Item1, culture==CultureSupported.Chinese ? tuple.Value.Item3 : tuple.Value.Item2, tuple.Value.Item4));
  66. }
  67. return result;
  68. }
  69. public Dictionary<string, Tuple<string, string, string, bool>> GetDataElements()
  70. {
  71. UpdateAllConfig();
  72. Dictionary<string, Tuple<string, string, string, bool>> dicItems = new Dictionary<string, Tuple<string, string, string, bool>>();
  73. foreach (var dataItem in _allDataItems)
  74. {
  75. dicItems[dataItem.Item1] = dataItem;
  76. }
  77. //更新Gas
  78. UpdateGasItem(SCLocal.GasLineConfig.Gas1Enable, SCLocal.GasLineConfig.Gas1Name, "Gas1", "System.IoMfc.MfcGas1.FeedBack", dicItems);
  79. UpdateGasItem(SCLocal.GasLineConfig.Gas1Enable, SCLocal.GasLineConfig.Gas1Name, "Gas1", "System.IoMfc.MfcGas1.SetPoint", dicItems);
  80. UpdateGasItem(SCLocal.GasLineConfig.Gas2Enable, SCLocal.GasLineConfig.Gas2Name, "Gas2", "System.IoMfc.MfcGas2.FeedBack", dicItems);
  81. UpdateGasItem(SCLocal.GasLineConfig.Gas2Enable, SCLocal.GasLineConfig.Gas2Name, "Gas2", "System.IoMfc.MfcGas2.SetPoint", dicItems);
  82. UpdateGasItem(SCLocal.GasLineConfig.Gas3Enable, SCLocal.GasLineConfig.Gas3Name, "Gas3", "System.IoMfc.MfcGas3.FeedBack", dicItems);
  83. UpdateGasItem(SCLocal.GasLineConfig.Gas3Enable, SCLocal.GasLineConfig.Gas3Name, "Gas3", "System.IoMfc.MfcGas3.SetPoint", dicItems);
  84. UpdateGasItem(SCLocal.GasLineConfig.Gas4Enable, SCLocal.GasLineConfig.Gas4Name, "Gas4", "System.IoMfc.MfcGas4.FeedBack", dicItems);
  85. UpdateGasItem(SCLocal.GasLineConfig.Gas4Enable, SCLocal.GasLineConfig.Gas4Name, "Gas4", "System.IoMfc.MfcGas4.SetPoint", dicItems);
  86. UpdateGasItem(SCLocal.GasLineConfig.Gas5Enable, SCLocal.GasLineConfig.Gas5Name, "Gas5", "System.IoMfc.MfcGas5.FeedBack", dicItems);
  87. UpdateGasItem(SCLocal.GasLineConfig.Gas5Enable, SCLocal.GasLineConfig.Gas5Name, "Gas5", "System.IoMfc.MfcGas5.SetPoint", dicItems);
  88. //更新TV
  89. if (!SCLocal.PressureControlConfig.EnableThrottleValve)
  90. {
  91. dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPosition");
  92. dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPositionSetPoint");
  93. dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPressure");
  94. dicItems.Remove("System.IoThrottleValve.ThrottleValve.TVPressureSetPoint");
  95. }
  96. if (!SCLocal.PressureControlConfig.PumpEnableN2Pressure)
  97. {
  98. dicItems.Remove("System.IoPump.MainPump.N2PressureValue");
  99. }
  100. if (!SCLocal.PressureControlConfig.PumpEnableWaterFlow)
  101. {
  102. dicItems.Remove("System.IoPump.MainPump.WaterFlowValue");
  103. }
  104. return dicItems;
  105. }
  106. void UpdateGasItem(bool enable, string display, string id, string key, Dictionary<string, Tuple<string, string, string, bool>> dicItems)
  107. {
  108. if (enable && dicItems.ContainsKey(key))
  109. {
  110. dicItems[key] = Tuple.Create(key,
  111. dicItems[key].Item2.Replace(id, display),
  112. dicItems[key].Item3.Replace(id, display),
  113. dicItems[key].Item4);
  114. }
  115. else
  116. {
  117. dicItems.Remove(key);
  118. }
  119. }
  120. }
  121. }