ntminer 5 years ago
parent
commit
ee95f0eab0

+ 1 - 1
src/AppViews0/Ucs/CoinPage.xaml.cs

@@ -11,7 +11,7 @@ namespace NTMiner.Views.Ucs {
                 IconName = "Icon_Coin",
                 CloseVisible = System.Windows.Visibility.Visible,
                 FooterVisible = System.Windows.Visibility.Collapsed,
-                Width = DevMode.IsDebugMode ? AppStatic.MainWindowWidth : 960,
+                Width = DevMode.IsDebugMode ? AppStatic.MainWindowWidth : 1000,
                 Height = 520
             },
             ucFactory: (window) => new CoinPage(),

+ 5 - 0
src/NTMinerBus/Bus/EventBase.cs

@@ -7,6 +7,11 @@ namespace NTMiner.Bus {
             this.Timestamp = DateTime.Now;
         }
 
+        protected EventBase(Guid id) {
+            this.Id = id;
+            this.Timestamp = DateTime.Now;
+        }
+
         public Guid Id { get; private set; }
 
         public DateTime Timestamp { get; private set; }

+ 1 - 1
src/NTMinerBus/Bus/IMessageDispatcher.cs

@@ -4,7 +4,7 @@ using System.Collections.Generic;
 namespace NTMiner.Bus {
     public interface IMessageDispatcher {
         IEnumerable<IMessagePathId> GetAllPaths();
-        void Dispatch<TMessage>(TMessage message);
+        void Dispatch<TMessage>(TMessage message) where TMessage : IMessage;
 
         void Connect<TMessage>(MessagePath<TMessage> handler);
 

+ 1 - 0
src/NTMinerBus/Bus/IMessagePathId.cs

@@ -3,6 +3,7 @@
 namespace NTMiner.Bus {
     
     public interface IMessagePathId {
+        Guid PathId { get; }
         int ViaLimit { get; }
         Type MessageType { get; }
         bool IsEnabled { get; set; }

+ 24 - 19
src/NTMinerBus/Bus/MessageDispatcher.cs

@@ -21,7 +21,7 @@
             }
         }
 
-        public void Dispatch<TMessage>(TMessage message) {
+        public void Dispatch<TMessage>(TMessage message) where TMessage : IMessage {
             if (message == null) {
                 throw new ArgumentNullException(nameof(message));
             }
@@ -30,12 +30,15 @@
                 var messageHandlers = _handlers[messageType].ToArray();
                 foreach (var messageHandler in messageHandlers) {
                     var tMessageHandler = (MessagePath<TMessage>)messageHandler;
+                    bool isMatch = tMessageHandler.PathId == Guid.Empty || tMessageHandler.PathId == message.Id;
                     if (tMessageHandler.ViaLimit > 0) {
-                        lock (tMessageHandler) {
-                            if (tMessageHandler.ViaLimit > 0) {
-                                tMessageHandler.ViaLimit--;
-                                if (tMessageHandler.ViaLimit == 0) {
-                                    Disconnect(tMessageHandler);
+                        if (isMatch) {
+                            lock (tMessageHandler) {
+                                if (tMessageHandler.ViaLimit > 0) {
+                                    tMessageHandler.ViaLimit--;
+                                    if (tMessageHandler.ViaLimit == 0) {
+                                        Disconnect(tMessageHandler);
+                                    }
                                 }
                             }
                         }
@@ -43,20 +46,22 @@
                     if (!tMessageHandler.IsEnabled) {
                         continue;
                     }
-                    switch (tMessageHandler.LogType) {
-                        case LogEnum.DevConsole:
-                            if (DevMode.IsDevMode) {
-                                Write.DevDebug($"({messageType.Name})->({tMessageHandler.Location.Name}){tMessageHandler.Description}");
-                            }
-                            break;
-                        case LogEnum.Log:
-                            Logger.InfoDebugLine($"({messageType.Name})->({tMessageHandler.Location.Name}){tMessageHandler.Description}");
-                            break;
-                        case LogEnum.None:
-                        default:
-                            break;
+                    if (isMatch) {
+                        switch (tMessageHandler.LogType) {
+                            case LogEnum.DevConsole:
+                                if (DevMode.IsDevMode) {
+                                    Write.DevDebug($"({messageType.Name})->({tMessageHandler.Location.Name}){tMessageHandler.Description}");
+                                }
+                                break;
+                            case LogEnum.Log:
+                                Logger.InfoDebugLine($"({messageType.Name})->({tMessageHandler.Location.Name}){tMessageHandler.Description}");
+                                break;
+                            case LogEnum.None:
+                            default:
+                                break;
+                        }
+                        tMessageHandler.Run(message);
                     }
-                    tMessageHandler.Run(message);
                 }
             }
             else {

+ 15 - 6
src/NTMinerBus/Bus/MessagePath`1.cs

@@ -2,23 +2,29 @@
 using System.ComponentModel;
 
 namespace NTMiner.Bus {
-    public class MessagePath<TMessage> : IMessagePathId, INotifyPropertyChanged {
+    public class MessagePath<TMessage> : IMessagePathId
+#if DEBUG
+        , INotifyPropertyChanged
+#endif
+        {
         private readonly Action<TMessage> _path;
         private bool _isEnabled;
         private int _viaLimit;
 
+#if DEBUG
         public event PropertyChangedEventHandler PropertyChanged;
+#endif
 
-        public static MessagePath<TMessage> Build(IMessageDispatcher dispatcher, Type location, string description, LogEnum logType, Action<TMessage> action, int viaLimit = -1) {
-            if (action == null) {
-                throw new ArgumentNullException(nameof(action));
+        public static MessagePath<TMessage> Build(IMessageDispatcher dispatcher, Type location, string description, LogEnum logType, Action<TMessage> path, Guid pathId, int viaLimit = -1) {
+            if (path == null) {
+                throw new ArgumentNullException(nameof(path));
             }
-            MessagePath<TMessage> handler = new MessagePath<TMessage>(location, description, logType, action, viaLimit);
+            MessagePath<TMessage> handler = new MessagePath<TMessage>(location, description, logType, path, pathId, viaLimit);
             dispatcher.Connect(handler);
             return handler;
         }
 
-        private MessagePath(Type location, string description, LogEnum logType, Action<TMessage> path, int viaLimit) {
+        private MessagePath(Type location, string description, LogEnum logType, Action<TMessage> path, Guid pathId, int viaLimit) {
             this.IsEnabled = true;
             MessageType = typeof(TMessage);
             Location = location;
@@ -26,6 +32,7 @@ namespace NTMiner.Bus {
             Description = description;
             LogType = logType;
             _path = path;
+            PathId = pathId;
             ViaLimit = viaLimit;
         }
 
@@ -38,6 +45,8 @@ namespace NTMiner.Bus {
 #endif
             }
         }
+
+        public Guid PathId { get; private set; }
         public Type MessageType { get; private set; }
         public Type Location { get; private set; }
         public string Path { get; private set; }

+ 1 - 4
src/NTMinerClient/Core/Messages.cs

@@ -366,11 +366,8 @@ namespace NTMiner.Core {
     
     [MessageType(description: "币种超频完成后")]
     public class CoinOverClockDoneEvent : EventBase {
-        public CoinOverClockDoneEvent(Guid cmdId) {
-            this.CmdId = cmdId;
+        public CoinOverClockDoneEvent(Guid id) : base(id) {
         }
-
-        public Guid CmdId { get; private set; }
     }
 
     [MessageType(description: "Gpu超频数据添加或更新后")]

+ 2 - 2
src/NTMinerClient/NTMinerRoot.partials.MinerProcess.cs

@@ -42,7 +42,7 @@ namespace NTMiner {
                                         if (mineContext == Instance.LockedMineContext) {
                                             ContinueCreateProcess(mineContext);
                                         }
-                                    });
+                                    }, pathId: cmd.Id);
                                 // 超频是在另一个线程执行的,因为N卡超频当cpu性能非常差时较耗时
                                 VirtualRoot.Execute(cmd);
                             }
@@ -284,7 +284,7 @@ namespace NTMiner {
                                     CloseHandle(hWriteOut);
                                     isHWriteOutHasClosed = true;
                                 }
-                            });
+                            }, pathId: Guid.Empty);
                         Task.Factory.StartNew(() => {
                             using (FileStream fs = new FileStream(mineContext.LogFileFullName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
                                 const byte r = (byte)'\r';

+ 4 - 4
src/NTMinerlib/VirtualRoot.partials.Bus.cs

@@ -22,21 +22,21 @@ namespace NTMiner {
             StackTrace ss = new StackTrace(false);
             // 0是CreatePath,1是CreateCmdPath或CreateEventPath,2是当地
             Type location = ss.GetFrame(2).GetMethod().DeclaringType;
-            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action);
+            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action, Guid.Empty);
         }
 
-        public static IMessagePathId BuildOnecePath<TMessage>(string description, LogEnum logType, Action<TMessage> action) {
+        public static IMessagePathId BuildOnecePath<TMessage>(string description, LogEnum logType, Action<TMessage> action, Guid pathId) {
             StackTrace ss = new StackTrace(false);
             // 0是CreatePath,1是CreateCmdPath或CreateEventPath,2是当地
             Type location = ss.GetFrame(2).GetMethod().DeclaringType;
-            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action, viaLimit: 1);
+            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action, pathId, viaLimit: 1);
         }
 
         public static IMessagePathId BuildViaLimitPath<TMessage>(string description, LogEnum logType, Action<TMessage> action, int viaLimit) {
             StackTrace ss = new StackTrace(false);
             // 0是CreatePath,1是CreateCmdPath或CreateEventPath,2是当地
             Type location = ss.GetFrame(2).GetMethod().DeclaringType;
-            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action, viaLimit);
+            return MessagePath<TMessage>.Build(MessageDispatcher, location, description, logType, action, Guid.Empty, viaLimit);
         }
 
         public static void BuildCmdPath<TCmd>(Action<TCmd> action, LogEnum logType = LogEnum.DevConsole)