浏览代码

update Fix

Zixuan 1 周之前
父节点
当前提交
690f3ca578
共有 3 个文件被更改,包括 70 次插入69 次删除
  1. 63 49
      MinicsConsole/Helper/Mini8DataDispatcher.cs
  2. 0 7
      MinicsConsole/HostLifetime.cs
  3. 7 13
      MinicsUI/Views/MainWindow.xaml.cs

+ 63 - 49
MinicsConsole/Helper/Mini8DataDispatcher.cs

@@ -1,78 +1,92 @@
-using HardwareData;
-using MinicsConsole.Connector;
-using System.Diagnostics;
-using System.Net.NetworkInformation;
-using System.Threading.Channels;
-
-namespace MinicsConsole.Helper;
+namespace MinicsConsole.Helper;
 
 public class Mini8DataDispatcher
 {
-    public Mini8DataDispatcher(ILog log)
+    public Mini8DataDispatcher(ILog log,
+        UISender uiNotifier,
+        RTNotifier rtNotifer,
+        PLCNotifier plcNotifier)
+        //KanbanNotifier kanbanNotifier)
     {
-        this.log = log;
+        this._log = log;
+        this._Connectors.TryAdd("PLC", plcNotifier);
+        this._Connectors.TryAdd("UI", uiNotifier);
+        this._Connectors.TryAdd("RT", rtNotifer);
+        //this._Connectors.TryAdd("Kanban", kanbanNotifier);
+
+        this._UINotifier = uiNotifier;
+        this._PlcNotifier = plcNotifier;
+        this._RTNotifier = rtNotifer;
+
+        this._UIQueue = new(UIQueueHandler);
+        this._RTQueue = new(RTQueueHandler);
+        this._PLCQueue = new(PLCQueueHandler);
     }
-    private readonly ILog log;
+
+    private readonly ILog _log;
 
     private readonly ConcurrentDictionary<string, IMini8DataNotifier> _Connectors = [];
-    private readonly ConcurrentDictionary<string, EventQueue<(string name, byte mini8, byte channel, ChannelData channelData)>> _ConnectorQueue = [];
 
-    private void QueueHandler((string name, byte mini8, byte channel, ChannelData channelData) t)
+    private readonly IMini8DataNotifier _UINotifier;
+    private readonly IMini8DataNotifier _PlcNotifier;
+    private readonly IMini8DataNotifier _RTNotifier;
+
+    private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _UIQueue;
+    private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _PLCQueue;
+    private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _RTQueue;
+
+    private void RTQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
     {
-        if (!_Connectors.TryGetValue(t.name, out IMini8DataNotifier? notifer) || notifer is null)
+        if (this._RTQueue.Count >= 2)
             return;
 
         try
         {
-            notifer.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
+            this._RTNotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
         }
         catch
         {
-            log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {t.name} mini8 {t.mini8} channel {t.channel}");
+            _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed RT mini8 {t.mini8} channel {t.channel}");
         }
     }
 
-    public bool TryAddNotifier(string name, IMini8DataNotifier connector)
+    private void UIQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
     {
-        if (!_Connectors.TryAdd(name, connector))
-            return false;
-
-        _ConnectorQueue[name] = new(QueueHandler);
+        if (this._UIQueue.Count >= 2)
+            return;
 
-        return true;
+        try
+        {
+            this._UINotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
+        }
+        catch
+        {
+            _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed UI mini8 {t.mini8} channel {t.channel}");
+        }
     }
 
-    public bool TryRemoveConnector(string name)
+    private void PLCQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
     {
-        _ConnectorQueue.TryRemove(name, out _);
-        return _Connectors.TryRemove(name, out _);
+        if (this._PLCQueue.Count >= 2)
+            return;
+
+        try
+        {
+            this._PlcNotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
+        }
+        catch
+        {
+            _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed PLC mini8 {t.mini8} channel {t.channel}");
+        }
     }
 
     public void ChannelInfoNotify(byte mini8, byte channel, ChannelData channelData)
     {
         if (channelData is null)
             return;
-
-        foreach (var item in _ConnectorQueue)
-        {
-            item.Value.Enqueue((item.Key, mini8, channel, channelData));
-        }
-
-        //Parallel.ForEach(_Connectors.Values, item =>
-        //{
-        //    Task.Factory.StartNew(() =>
-        //    {
-
-        //        try
-        //        {
-        //            item?.ChannelInfoNotify(mini8, channel, channelData);
-        //        }
-        //        catch
-        //        {
-        //            log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {item.Name} mini8 {mini8} channel {channel}");
-        //        }
-        //    });
-        //});
+        _RTQueue.Enqueue((mini8, channel, channelData));
+        _PLCQueue.Enqueue((mini8, channel, channelData));
+        _UIQueue.Enqueue((mini8, channel, channelData));
     }
 
     public void AlarmNotify(byte mini8, byte channel, float temperature)
@@ -85,7 +99,7 @@ public class Mini8DataDispatcher
             }
             catch
             {
-                log.Warning($"DataDispatcher try send AlarmNotify failed {item.Name} mini8 {mini8} channel {channel}");
+                _log.Warning($"DataDispatcher try send AlarmNotify failed {item.Name} mini8 {mini8} channel {channel}");
             }
         });
     }
@@ -100,7 +114,7 @@ public class Mini8DataDispatcher
             }
             catch
             {
-                log.Warning($"DataDispatcher try send AlarmTcBrockenNotify failed {item.Name} mini8 {mini8} channel {channel}");
+                _log.Warning($"DataDispatcher try send AlarmTcBrockenNotify failed {item.Name} mini8 {mini8} channel {channel}");
             }
         });
     }
@@ -115,7 +129,7 @@ public class Mini8DataDispatcher
             }
             catch
             {
-                log.Warning($"DataDispatcher try send Mini8Connect to failed {item.Name} mini8 {mini8Index}");
+                _log.Warning($"DataDispatcher try send Mini8Connect to failed {item.Name} mini8 {mini8Index}");
             }
         });
     }
@@ -130,7 +144,7 @@ public class Mini8DataDispatcher
             }
             catch
             {
-                log.Warning($"DataDispatcher try send Mini8Disconnect failed {item.Name} mini8 {mini8Index}");
+                _log.Warning($"DataDispatcher try send Mini8Disconnect failed {item.Name} mini8 {mini8Index}");
             }
         });
     }

+ 0 - 7
MinicsConsole/HostLifetime.cs

@@ -10,11 +10,8 @@ class HostLifetime(
         BasicInfo basicInfo,
         OrmCollections ormCollections,
         DataBaseCleaner dataBaseCleaner,
-        UISender uiNotifier,
         RTNotifier rtNotifer,
         PLCNotifier plcNotifier,
-        KanbanNotifier kanbanNotifier,
-        Mini8DataDispatcher dataDispatcher,
         DailyRoutinHelper dailyRoutinHelper,
         ITlvProvider tlvProvider,
         ILog log) : IHostedService
@@ -48,8 +45,6 @@ class HostLifetime(
             log.Fatal($"PLC configFile Not Exist");
             Environment.Exit(0);
         }
-        dataDispatcher.TryAddNotifier("PLC", plcNotifier);
-        dataDispatcher.TryAddNotifier("UI", uiNotifier);
         //Start RT Server
         if (string.IsNullOrEmpty(basicInfo.RTServerAddress) ||
             !rtNotifer.Initialize(tlvProvider) ||
@@ -58,8 +53,6 @@ class HostLifetime(
             log.Fatal($"Open RT Server {basicInfo.RTServerAddress}:{basicInfo.RTServerPort} Failed");
             Environment.Exit(0);
         }
-        dataDispatcher.TryAddNotifier("RT", rtNotifer);
-        dataDispatcher.TryAddNotifier("Kanban", kanbanNotifier);
 
         log.Info($"Start RT Server  {basicInfo.RTServerAddress}:{basicInfo.RTServerPort} success");
 

+ 7 - 13
MinicsUI/Views/MainWindow.xaml.cs

@@ -61,22 +61,16 @@ public partial class MainWindow : Window
                     {
                         this.Left = 0;
                         this.Top = 0;
-                        //this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
-                        //this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
-                        this.Width = 1024;
-                        this.Height = 768;
+                        this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
+                        this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
+
                     }
                     else
                     {
-                        this.Left = 0;
-                        this.Top = 0;
-                        this.Width = 1024;
-                        this.Height = 768;
-
-                        //this.Left = monitor.StartPixHorizontal;
-                        //this.Top = monitor.StartPixVertical;
-                        //this.Width = monitor.ResolutionHorizontal;
-                        //this.Height = monitor.ResolutionVertical;
+                        this.Left = monitor.StartPixHorizontal;
+                        this.Top = monitor.StartPixVertical;
+                        this.Width = monitor.ResolutionHorizontal;
+                        this.Height = monitor.ResolutionVertical;
                     }
                     break;
                 default: