SubStationWindow.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using NEIntelligentControl2.Models.Datas;
  2. using NEIntelligentControl2.Models.Messages;
  3. using NEIntelligentControl2.Service.Station;
  4. using NEIntelligentControl2.Service.WebSocket;
  5. using SVGViewer.Models.Info;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. namespace NEIntelligentControl2.Windows.BoostStation
  20. {
  21. /// <summary>
  22. /// 升压站二次图窗口
  23. /// </summary>
  24. public partial class SubStationWindow : Window
  25. {
  26. /// <summary>
  27. /// 二次图id
  28. /// </summary>
  29. private string _SubId;
  30. private StationManager _StationManager;
  31. private UrlManager _UrlManager;
  32. private WEBHelper _WEBHelper;
  33. private Dictionary<string, List<TagInfo>> _TagInfos = new Dictionary<string, List<TagInfo>>();
  34. private string _Url;
  35. private bool _IsLoaded;
  36. private Dictionary<string, ShapeInfo> _CustomizeShapes;
  37. public SubStationWindow(string subid)
  38. {
  39. InitializeComponent();
  40. _SubId = subid;
  41. _StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager;
  42. _UrlManager = App.ServiceProvider.GetService(typeof(UrlManager)) as UrlManager;
  43. _WEBHelper = App.ServiceProvider.GetService(typeof(WEBHelper)) as WEBHelper;
  44. Init();
  45. }
  46. private async void Init()
  47. {
  48. if (string.IsNullOrWhiteSpace(_SubId)) return;
  49. ShapeInfo si = await _StationManager.GetSubBoostStation(_SubId);
  50. if (si == null) return;
  51. _CustomizeShapes = _StationManager.GetCustomizeShapesDic();
  52. _svg.InitInfo(si, _CustomizeShapes);
  53. this.Title = si.Name;
  54. var taginfos = si.GetAllTagInfos();
  55. _TagInfos = taginfos.GroupBy(v => v.Tag).ToDictionary(v => v.Key, v => v.ToList());
  56. var keys = string.Join(",", _TagInfos.Keys);
  57. _Url = _UrlManager.DataServicePath + $"/ts/latest?keys={keys}";
  58. }
  59. private void Window_Loaded(object sender, RoutedEventArgs e)
  60. {
  61. _IsLoaded = true;
  62. Task.Factory.StartNew(RefreshData);
  63. }
  64. private async void RefreshData()
  65. {
  66. while (_IsLoaded)
  67. {
  68. try
  69. {
  70. var vs = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>(_Url);
  71. if (vs != null && vs.Count > 0)
  72. {
  73. Dispatcher?.Invoke(() =>
  74. {
  75. foreach (var v in vs)
  76. {
  77. if (!_TagInfos.ContainsKey(v.Key)) continue;
  78. var tgs = _TagInfos[v.Key];
  79. foreach (var tg in tgs)
  80. {
  81. tg.Value = v.Value.Value;
  82. }
  83. }
  84. });
  85. }
  86. }
  87. catch { }
  88. await Task.Delay(2000);
  89. }
  90. }
  91. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  92. {
  93. _IsLoaded = false;
  94. }
  95. }
  96. }