PageStationAll.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Models.BoostStation;
  3. using NEIntelligentControl2.Models.Messages;
  4. using NEIntelligentControl2.Models.Pages;
  5. using NEIntelligentControl2.Properties;
  6. using NEIntelligentControl2.Service.Station;
  7. using NEIntelligentControl2.Service.Voice;
  8. using NEIntelligentControl2.Service.WebSocket;
  9. using NEIntelligentControl2.Views.BoostStation;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Runtime.CompilerServices;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Data;
  19. using System.Windows.Documents;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Navigation;
  24. using System.Windows.Shapes;
  25. namespace NEIntelligentControl2.Pages.BoostStation
  26. {
  27. /// <summary>
  28. /// 升压站缩略图
  29. /// </summary>
  30. public partial class PageStationAll : Page
  31. {
  32. private List<SVGViewer.Models.Info.ShapeInfo> shapeInfos;
  33. private StationManager _StationManager;
  34. private FaultPopupBridge _FaultPopupBridge;
  35. private MessageBridge _MessageBridge;
  36. private Dictionary<string, ThumbnailView> _ThumbnailViews;
  37. public Action<string> StationChanged { get; internal set; }
  38. public PageStationAll(List<SVGViewer.Models.Info.ShapeInfo> sis)
  39. {
  40. InitializeComponent();
  41. shapeInfos = sis;
  42. _StationManager = App.ServiceProvider.GetService(typeof(StationManager)) as StationManager;
  43. _FaultPopupBridge = new FaultPopupBridge() { Messaged = OnAlarmMessage };
  44. _MessageBridge = App.ServiceProvider.GetService(typeof(MessageBridge)) as MessageBridge;
  45. _ThumbnailViews = new Dictionary<string, ThumbnailView>();
  46. Init();
  47. }
  48. private void Init()
  49. {
  50. var cs = Math.Max(3, Settings.Default.BoostStationColumns);
  51. _ug.Columns = cs;
  52. foreach (var v in shapeInfos)
  53. {
  54. var vv = v.Clone() as SVGViewer.Models.Info.ShapeInfo;
  55. ThumbnailView tv = new ThumbnailView(vv, _StationManager.GetCustomizeShapesDic()) { DoubleClicked = ThumbnailDoubleClicked };
  56. _ug.Children.Add(tv);
  57. if (!_ThumbnailViews.ContainsKey(v.Id))
  58. {
  59. _ThumbnailViews.Add(v.Id, tv);
  60. }
  61. }
  62. }
  63. private void ThumbnailDoubleClicked(string obj)
  64. {
  65. StationChanged?.Invoke(obj);
  66. }
  67. private void OnAlarmMessage(List<FaultInfo> obj)
  68. {
  69. if (obj == null || obj.Count == 0) return;
  70. var set = obj.Where(o => _ThumbnailViews.ContainsKey(o.Category2)).Select(o => o.Category2).ToHashSet();
  71. Dispatcher.Invoke(() =>
  72. {
  73. foreach (var v in _ThumbnailViews)
  74. {
  75. v.Value.IsAlarm = set.Contains(v.Key);
  76. }
  77. });
  78. }
  79. private void Page_Loaded(object sender, RoutedEventArgs e)
  80. {
  81. _MessageBridge.Register(_FaultPopupBridge);
  82. }
  83. private void Page_Unloaded(object sender, RoutedEventArgs e)
  84. {
  85. _MessageBridge.Unregister(_FaultPopupBridge);
  86. }
  87. internal void SwitchSize(int v)
  88. {
  89. _ug.Columns = v;
  90. Settings.Default.BoostStationColumns = v;
  91. Settings.Default.Save();
  92. }
  93. }
  94. }