ntminer 5 năm trước cách đây
mục cha
commit
6b907a7924

+ 0 - 11
src/AppModels/Messages.cs

@@ -1,7 +1,5 @@
 using NTMiner.Core;
-using NTMiner.Core.MinerClient;
 using NTMiner.Hub;
-using NTMiner.MinerStudio;
 using NTMiner.MinerStudio.Vms;
 using NTMiner.Vms;
 using System;
@@ -19,15 +17,6 @@ namespace NTMiner {
         public Action Callback { get; private set; }
     }
 
-    [MessageType(description: "释放并执行挖矿端嵌入的工具")]
-    public class MinerClientActionCommand : Cmd {
-        public MinerClientActionCommand(MinerClientActionType actionType) {
-            this.ActionType = actionType;
-        }
-
-        public MinerClientActionType ActionType { get; private set; }
-    }
-
     [MessageType(description: "启用windows远程桌面")]
     public class EnableRemoteDesktopCommand : Cmd {
         public EnableRemoteDesktopCommand() {

+ 15 - 33
src/MinerClient/App.xaml.cs

@@ -53,14 +53,6 @@ namespace NTMiner {
                     UIThread.Execute(() => { Environment.Exit(0); });
                 }));
             }
-            /// 释放和执行<see cref="MinerClientActionType"/>
-            else if (!string.IsNullOrEmpty(CommandLineArgs.Action)) {
-                // 启动计时器以放置后续的逻辑中用到计时器
-                VirtualRoot.StartTimer(new WpfTimingEventProducer());
-                if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType)) {
-                    VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
-                }
-            }
             else {
                 DoRun();
             }
@@ -95,6 +87,7 @@ namespace NTMiner {
 
                         }).Queue();
                 }
+                BuildPaths();
                 NTMinerContext.Instance.Init(() => {
                     _appViewFactory.Link();
                     if (VirtualRoot.IsLTWin10) {
@@ -125,6 +118,9 @@ namespace NTMiner {
                         StartStopMineButtonViewModel.Instance.AutoStart();
                         // 注意:因为推迟到这里才启动的计时器,所以别忘了在Upgrade、和Action情况时启动计时器
                         VirtualRoot.StartTimer(new WpfTimingEventProducer());
+                        if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType)) {
+                            VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
+                        }
                     });
                     Task.Factory.StartNew(() => {
                         var minerProfile = NTMinerContext.Instance.MinerProfile;
@@ -153,7 +149,6 @@ namespace NTMiner {
                         }
                     });
                 });
-                BuildPaths();
             }
             else {
                 try {
@@ -178,47 +173,34 @@ namespace NTMiner {
             VirtualRoot.AddCmdPath<UpgradeCommand>(action: message => {
                 AppRoot.Upgrade(NTMinerAppType.MinerClient, message.FileName, message.Callback);
             }, location: this.GetType());
+        }
+
+        private void BuildPaths() {
             VirtualRoot.AddCmdPath<MinerClientActionCommand>(action: message => {
                 #region
                 try {
-                    // 注意不要提前return,因为最后需要执行Environment.Exit(0)
                     switch (message.ActionType) {
-                        case MinerClientActionType.AtikmdagPatcher: {
-                                AdlHelper adlHelper = new AdlHelper();
-                                if (adlHelper.GpuCount != 0) {
-                                    AtikmdagPatcher.AtikmdagPatcherUtil.DoRun();
-                                }
-                            }
+                        case MinerClientActionType.AtikmdagPatcher:
+                            VirtualRoot.Execute(new AtikmdagPatcherCommand());
                             break;
-                        case MinerClientActionType.SwitchRadeonGpuOn: {
-                                AdlHelper adlHelper = new AdlHelper();
-                                if (adlHelper.GpuCount != 0) {
-                                    SwitchRadeonGpu.SwitchRadeonGpu.DoRun(on: true);
-                                }
-                            }
+                        case MinerClientActionType.SwitchRadeonGpuOn:
+                            VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: true));
                             break;
-                        case MinerClientActionType.SwitchRadeonGpuOff: {
-                                AdlHelper adlHelper = new AdlHelper();
-                                SwitchRadeonGpu.SwitchRadeonGpu.DoRun(on: false);
-                            }
+                        case MinerClientActionType.SwitchRadeonGpuOff:
+                            VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: false));
                             break;
                         case MinerClientActionType.BlockWAU:
-                            NTMiner.Windows.WindowsUtil.DoBlockWAU();
+                            VirtualRoot.Execute(new BlockWAUCommand());
                             break;
                         default:
                             break;
                     }
                 }
-                catch(Exception e) {
+                catch (Exception e) {
                     Logger.ErrorDebugLine(e);
                 }
-                // 注意确保以上没有异步的逻辑
-                Environment.Exit(0);
                 #endregion
             }, location: this.GetType());
-        }
-
-        private void BuildPaths() {
             #region 处理显示主界面命令
             VirtualRoot.AddCmdPath<ShowMainWindowCommand>(action: message => {
                 UIThread.Execute(() => {

+ 10 - 0
src/MinerClientSelfHost/MinerClientController.cs

@@ -1,6 +1,7 @@
 using NTMiner.Controllers;
 using NTMiner.Core;
 using NTMiner.Core.Daemon;
+using NTMiner.Core.MinerClient;
 using NTMiner.Report;
 using NTMiner.Ws;
 using System;
@@ -138,5 +139,14 @@ namespace NTMiner {
             VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"通过群控刷新超频", toConsole: true);
             NTMinerContext.Instance.GpuProfileSet.Refresh();
         }
+
+        [HttpPost]
+        public void RunAction([FromBody]DataRequest<MinerClientActionType> request) {
+            if (request == null) {
+                return;
+            }
+            VirtualRoot.ThisLocalInfo(nameof(MinerClientController), request.Data.GetDescription(), toConsole: true);
+            VirtualRoot.Execute(new MinerClientActionCommand(request.Data));
+        }
     }
 }

+ 2 - 0
src/NTMiner.Controllers/IMinerClientController.cs

@@ -1,5 +1,6 @@
 using NTMiner.Core;
 using NTMiner.Core.Daemon;
+using NTMiner.Core.MinerClient;
 using NTMiner.Report;
 using NTMiner.Ws;
 using System.Collections.Generic;
@@ -21,5 +22,6 @@ namespace NTMiner.Controllers {
         void RefreshIsRemoteDesktopEnabled();
         void ReportWsDaemonState(WsClientState state);
         void OverClock();
+        void RunAction(DataRequest<MinerClientActionType> request);
     }
 }

+ 10 - 0
src/NTMinerClient/Messages.cs

@@ -1,5 +1,6 @@
 using NTMiner.Core;
 using NTMiner.Core.Gpus;
+using NTMiner.Core.MinerClient;
 using NTMiner.Core.MinerServer;
 using NTMiner.Core.MinerStudio;
 using NTMiner.Core.Profile;
@@ -10,6 +11,15 @@ using NTMiner.Ws;
 using System;
 
 namespace NTMiner {
+    [MessageType(description: "释放并执行挖矿端嵌入的工具")]
+    public class MinerClientActionCommand : Cmd {
+        public MinerClientActionCommand(MinerClientActionType actionType) {
+            this.ActionType = actionType;
+        }
+
+        public MinerClientActionType ActionType { get; private set; }
+    }
+
     [MessageType(description: "停止挖矿")]
     public class StopMineCommand : Cmd {
         public StopMineCommand() { }

+ 18 - 22
src/NTMinerDaemon/Core/Impl/DaemonOperation.cs

@@ -34,40 +34,36 @@ namespace NTMiner.Core.Impl {
         }
         #endregion
 
-        #region BlockWAU
-        public ResponseBase BlockWAU() {
-            if (TryGetMinerClientLocation(out string location)) {
-                Windows.Cmd.RunClose(location, $"{NTKeyword.ActionCmdParameterName}{MinerClient.MinerClientActionType.BlockWAU.ToString()}");
+        private ResponseBase RunAction(MinerClientActionType actionType) {
+            if (IsNTMinerOpened()) {
+                var request = new DataRequest<MinerClientActionType> {
+                    Data = actionType
+                };
+                JsonRpcRoot.FirePostAsync(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.RunAction), null, data: request);
             }
-            ResponseBase response = ResponseBase.Ok("禁用windows系统更新");
+            else if (TryGetMinerClientLocation(out string location)) {
+                Windows.Cmd.RunClose(location, $"{NTKeyword.ActionCmdParameterName}{actionType.ToString()}");
+            }
+            ResponseBase response = ResponseBase.Ok(actionType.GetDescription());
             VirtualRoot.OperationResultSet.Add(response.ToOperationResult());
             return response;
         }
-        #endregion
 
         #region AtikmdagPatcher
         public ResponseBase AtikmdagPatcher() {
-            if (TryGetMinerClientLocation(out string location)) {
-                Windows.Cmd.RunClose(location, $"{NTKeyword.ActionCmdParameterName}{MinerClient.MinerClientActionType.AtikmdagPatcher.ToString()}");
-            }
-            ResponseBase response = ResponseBase.Ok("A卡驱动签名,如果本机不是A卡将被忽略");
-            VirtualRoot.OperationResultSet.Add(response.ToOperationResult());
-            return response;
+            return RunAction(MinerClientActionType.AtikmdagPatcher);
         }
         #endregion
 
         #region SwitchRadeonGpu
         public ResponseBase SwitchRadeonGpu(bool on) {
-            if (TryGetMinerClientLocation(out string location)) {
-                MinerClientActionType actionType = MinerClientActionType.SwitchRadeonGpuOn;
-                if (!on) {
-                    actionType = MinerClientActionType.SwitchRadeonGpuOff;
-                }
-                Windows.Cmd.RunClose(location, $"{NTKeyword.ActionCmdParameterName}{actionType.GetName()}");
-            }
-            ResponseBase response = ResponseBase.Ok($"{(on ? "开启" : "关闭")}A卡计算模式,如果本机不是A卡将被忽略");
-            VirtualRoot.OperationResultSet.Add(response.ToOperationResult());
-            return response;
+            return RunAction(on ? MinerClientActionType.SwitchRadeonGpuOn : MinerClientActionType.SwitchRadeonGpuOff);
+        }
+        #endregion
+
+        #region BlockWAU
+        public ResponseBase BlockWAU() {
+            return RunAction(MinerClientActionType.BlockWAU);
         }
         #endregion
 

+ 5 - 5
src/NTMinerDaemon/Ws/DaemonWsMessageHandler.cs

@@ -105,11 +105,6 @@ namespace NTMiner.Ws {
                     VirtualRoot.DaemonOperation.EnableRemoteDesktop();
                 });
             },
-            [WsMessage.BlockWAU] = (sendAsync, message) => {
-                Task.Factory.StartNew(() => {
-                    VirtualRoot.DaemonOperation.BlockWAU();
-                });
-            },
             [WsMessage.SetVirtualMemory] = (sendAsync, message) => {
                 if (message.TryGetData(out Dictionary<string, int> data)) {
                     Task.Factory.StartNew(() => {
@@ -136,6 +131,11 @@ namespace NTMiner.Ws {
                     });
                 }
             },
+            [WsMessage.BlockWAU] = (sendAsync, message) => {
+                Task.Factory.StartNew(() => {
+                    VirtualRoot.DaemonOperation.BlockWAU();
+                });
+            },
             [WsMessage.RestartWindows] = (sendAsync, message) => {
                 Task.Factory.StartNew(() => {
                     VirtualRoot.DaemonOperation.RestartWindows();

+ 7 - 1
src/NTMinerDataSchemas/Core/MinerClient/MinerClientActionType.cs

@@ -1,8 +1,14 @@
-namespace NTMiner.Core.MinerClient {
+using System.ComponentModel;
+
+namespace NTMiner.Core.MinerClient {
     public enum MinerClientActionType {
+        [Description("A卡驱动签名,如果本机不是A卡将被忽略")]
         AtikmdagPatcher,
+        [Description("开启A卡计算模式,如果本机不是A卡将被忽略")]
         SwitchRadeonGpuOn,
+        [Description("关闭A卡计算模式,如果本机不是A卡将被忽略")]
         SwitchRadeonGpuOff,
+        [Description("禁用Widnows系统更新")]
         BlockWAU
     }
 }