HomePage.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Models.Pages;
  4. using NEIntelligentControl2.Models.Windturbine;
  5. using NEIntelligentControl2.Service.WebSocket;
  6. using NEIntelligentControl2.Views.AGC;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace NEIntelligentControl2.Pages.Home
  23. {
  24. /// <summary>
  25. /// 主页页面
  26. /// </summary>
  27. public partial class HomePage : Page, IMessage
  28. {
  29. private readonly string FaultType = ConfigurationManager.AppSettings["SubscribeRuntimeFault"]; // 故障列表类型
  30. private readonly string AlarmType = ConfigurationManager.AppSettings["SubscribeRuntimeAlarm"]; // 报警类型
  31. private MessageBridge _MessageBridge;
  32. private WEBHelper _WEBHelper;
  33. private string _Url;
  34. public List<string> MessageTypes { get; set; }
  35. private WindturbineInfoBridge _WindturbineInfoBridge;
  36. private TagManager _TagManager;
  37. public HomePage(MessageBridge mb,WEBHelper web, TagManager tm)
  38. {
  39. InitializeComponent();
  40. _MessageBridge = mb;
  41. _WEBHelper = web;
  42. _TagManager = tm;
  43. MessageTypes = new List<string>() { FaultType, AlarmType };
  44. _WindturbineInfoBridge = new WindturbineInfoBridge() { Messaged = OnWindturbineInfoMessage };
  45. try
  46. {
  47. #if (DEBUG)
  48. _Url = ConfigurationManager.AppSettings["AlarmPathDebug"];
  49. #else
  50. _Url = ConfigurationManager.AppSettings["AlarmPath"];
  51. #endif
  52. }
  53. catch (Exception ex)
  54. {
  55. Console.WriteLine(ex.Message);
  56. }
  57. }
  58. private void OnWindturbineInfoMessage(Dictionary<string, WindturbineInfo> vs)
  59. {
  60. _SCMCard.UpdateData(vs);
  61. _MMCard.UpdateData(vs);
  62. }
  63. private void Page_Loaded(object sender, RoutedEventArgs e)
  64. {
  65. _TagManager.TagChanged?.Invoke(new List<Models.Station.StationInfo>());
  66. _MessageBridge.Register(this); // 订阅消息
  67. _MessageBridge.Register(_WindturbineInfoBridge); // 订阅消息
  68. Task.Run(LoadAlarmHistory); // 加载报警历史值
  69. }
  70. /// <summary>
  71. /// 加载报警历史值
  72. /// </summary>
  73. private void LoadAlarmHistory()
  74. {
  75. DateTime dt = DateTime.Now.AddDays(-1);
  76. AlarmPage ap = _WEBHelper.HttpGetJSON<AlarmPage>($"{_Url}/alarm/history/page?pagenum=1&pagesize=1000&category1=SYZ&starttime={dt.ToString("yyyy-MM-dd HH:mm:ss")}&endtime={DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
  77. _SACard.UpdateAlarmData(ap);
  78. }
  79. private void Page_Unloaded(object sender, RoutedEventArgs e)
  80. {
  81. _MessageBridge.Unregister(this);// 取消订阅消息
  82. _MessageBridge.Unregister(_WindturbineInfoBridge);
  83. }
  84. public async Task OnMessage(object message)
  85. {
  86. await Task.Run(() =>
  87. {
  88. var stomp = message as StompMessage;
  89. if (stomp == null || !stomp.Headers.ContainsKey("destination")) return;
  90. var type = stomp.Headers["destination"];
  91. if (type == FaultType)// 故障列表
  92. {
  93. UpdateRuntimeFault(stomp);
  94. }
  95. else if (type == AlarmType)// 报警列表
  96. {
  97. UpdateRuntimeAlert(stomp);
  98. }
  99. });
  100. }
  101. private void UpdateRuntimeAlert(StompMessage stomp)
  102. {
  103. List<AlarmInfo> fis = _WEBHelper.Deserialize<List<AlarmInfo>>(stomp.Body);
  104. foreach (var v in fis)
  105. {
  106. if (v.Category1 != "FJ")
  107. {
  108. _SACard.UpdateAlarmData(v);
  109. }
  110. else
  111. {
  112. _WTACard.UpdateAlarmData(v);
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 更新故障列表
  118. /// </summary>
  119. private void UpdateRuntimeFault(StompMessage stomp)
  120. {
  121. List<FaultInfoModel> faultInfoModel = _WEBHelper.Deserialize<List<FaultInfoModel>>(stomp.Body);
  122. if (faultInfoModel == null) return;
  123. foreach (var v in faultInfoModel)
  124. {
  125. if (v.FaultInfo.Category1 != "FJ")
  126. {
  127. _SACard.UpdateAlarmData(v.FaultInfo);
  128. }
  129. else
  130. {
  131. _WTACard.UpdateAlarmData(v.FaultInfo);
  132. }
  133. }
  134. }
  135. /// <summary>
  136. /// AGC场站选择改变事件,勿删
  137. /// </summary>
  138. private void AAGCCard_SelectionChanged(object sender, RoutedEventArgs e)
  139. {
  140. SimpleAGCCard sc = e.OriginalSource as SimpleAGCCard;
  141. if (sc == null) return;
  142. int index = (int)sc.Tag;
  143. _DAGCCard.ChangeCard(index);
  144. }
  145. }
  146. }