HardwareConfigViewModel.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Windows.Input;
  5. using Aitex.Core.Common.DeviceData;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.UI.MVVM;
  9. using Aitex.Core.Util;
  10. using Aitex.Core.Utilities;
  11. using Aitex.Triton160.Common;
  12. namespace Aitex.Triton160.UI.ViewModel
  13. {
  14. public class HardwareConfigViewModel : UIViewModelBase
  15. {
  16. [Subscription(TritonDevice.StatisticsRfOnTime, SystemDeviceModule)]
  17. public AITStatisticsData RfStatistics
  18. {
  19. get;
  20. set;
  21. }
  22. [Subscription(TritonDevice.StatisticsPumpOnTime, SystemDeviceModule)]
  23. public AITStatisticsData PumpStatistics
  24. {
  25. get;
  26. set;
  27. }
  28. public ICommand SetConfigCommand
  29. {
  30. get;
  31. private set;
  32. }
  33. [IgnorePropertyChange]
  34. public ICommand ResetCommand
  35. {
  36. get;
  37. set;
  38. }
  39. [IgnorePropertyChange]
  40. public SCValue ConfigFeedBack
  41. {
  42. get;
  43. set;
  44. }
  45. [IgnorePropertyChange]
  46. public SCValue ConfigSetPoint
  47. {
  48. get;
  49. set;
  50. }
  51. public HardwareConfigViewModel()
  52. : base("HardwareConfigViewModel")
  53. {
  54. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  55. ResetCommand = new DelegateCommand<object>(Reset);
  56. ConfigFeedBack = new SCValue();
  57. ConfigSetPoint = new SCValue();
  58. ConfigFeedBack.RetrieveAll();
  59. ConfigSetPoint.RetrieveAll();
  60. }
  61. void SetConfig(object param)
  62. {
  63. string stringParam = param.ToString();
  64. string[] values = stringParam.Split(';');
  65. foreach (var value in values)
  66. {
  67. if (string.IsNullOrEmpty(value))
  68. continue;
  69. string[] props = value.Split('.');
  70. if (props.Length != 3)
  71. {
  72. LOG.Error("Error SetConfig parameter" + param);
  73. continue;
  74. }
  75. string scName = props[1] + "_" + props[2];
  76. object scValue = null;
  77. PropertyInfo[] property = typeof(SCValue).GetProperties();
  78. foreach (PropertyInfo fiGroup in property)
  79. {
  80. if (fiGroup.Name == props[1])
  81. {
  82. object objGroup = fiGroup.GetValue(ConfigSetPoint, null);
  83. foreach (PropertyInfo fiItem in objGroup.GetType().GetProperties())
  84. {
  85. if (fiItem.Name == props[2])
  86. {
  87. scValue = fiItem.GetValue(objGroup, null);
  88. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.SetConfig.ToString(), scName, scValue);
  89. break;
  90. }
  91. }
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. void Reset(object param)
  98. {
  99. Triton160UiSystem.Instance.WCF.InvokeService_DoOperation(TritonOperation.DeviceOperation.ToString(), new object[] { param.ToString(), AITStatisticsOperation.Reset.ToString() });
  100. }
  101. public void UpdateConfig()
  102. {
  103. ConfigFeedBack.Update(Triton160UiSystem.Instance.WCF.Query.PollConfig(ConfigFeedBack.GetKeys()));
  104. ConfigSetPoint.Update(Triton160UiSystem.Instance.WCF.Query.PollConfig(ConfigSetPoint.GetKeys()));
  105. InvokeAllPropertyChanged();
  106. }
  107. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  108. {
  109. if (RfStatistics == null)
  110. {
  111. string key = SystemDeviceModule + "." + TritonDevice.StatisticsRfOnTime;
  112. if (data.ContainsKey(key))
  113. {
  114. AITStatisticsData statistics = data[key] as AITStatisticsData;
  115. if (statistics != null)
  116. {
  117. //RfStatisticsPMIntervalSetPoint = statistics.PMInterval.ToString();
  118. InvokePropertyChanged("RfStatisticsPMIntervalSetPoint");
  119. }
  120. }
  121. }
  122. if (PumpStatistics == null)
  123. {
  124. string key = SystemDeviceModule + "." + TritonDevice.StatisticsPumpOnTime;
  125. if (data.ContainsKey(key))
  126. {
  127. AITStatisticsData statistics = data[key] as AITStatisticsData;
  128. if (statistics != null)
  129. {
  130. //PumpStatisticsPMIntervalSetPoint = statistics.PMInterval.ToString();
  131. InvokePropertyChanged("PumpStatisticsPMIntervalSetPoint");
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }