ntminer 5 years ago
parent
commit
99c04d3983

+ 1 - 1
src/AppModels/MinerStudio/MinerStudioRoot.partials.MineWorkViewModels.cs

@@ -89,7 +89,7 @@ namespace NTMiner.MinerStudio {
             }
 
             public bool TryGetMineWorkVm(Guid id, out MineWorkViewModel mineWorkVm) {
-                if (id == MineWorkData.SelfMineWorkId) {
+                if (id.IsSelfMineWorkId()) {
                     mineWorkVm = MineWorkViewModel.SelfMineWork;
                     return true;
                 }

+ 4 - 4
src/AppModels/MinerStudio/Vms/MineWorkViewModel.cs

@@ -81,7 +81,7 @@ namespace NTMiner.MinerStudio.Vms {
         }
 
         private void DoEdit(FormType? formType) {
-            if (!MinerStudioRoot.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm) && this.Id != MineWorkData.SelfMineWorkId) {
+            if (!MinerStudioRoot.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm) && !this.Id.IsSelfMineWorkId()) {
                 WpfUtil.ShowInputDialog("作业名称", string.Empty, string.Empty, workName => {
                     if (string.IsNullOrEmpty(workName)) {
                         return "作业名称是必须的";
@@ -97,7 +97,7 @@ namespace NTMiner.MinerStudio.Vms {
                     VirtualRoot.Out.ShowError("未选中矿机", autoHideSeconds: 4);
                     return;
                 }
-                if (this.Id == MineWorkData.SelfMineWorkId) {
+                if (this.Id.IsSelfMineWorkId()) {
                     SelfMineWork.Description = $"{_minerClientVm.GetMinerOrClientName()} 矿机的单机作业";
                     if (RpcRoot.IsOuterNet) {
                         if (!_minerClientVm.IsOuterUserEnabled) {
@@ -208,7 +208,7 @@ namespace NTMiner.MinerStudio.Vms {
                 Write.UserInfo("保存作业。");
             }
             if (RpcRoot.IsOuterNet) {
-                if (this.Id != MineWorkData.SelfMineWorkId) {
+                if (!this.Id.IsSelfMineWorkId()) {
                     RpcRoot.OfficialServer.UserMineWorkService.AddOrUpdateMineWorkAsync(new MineWorkData().Update(this), (r, ex) => {
                         if (r.IsSuccess()) {
                             if (isMinerProfileChanged) {
@@ -254,7 +254,7 @@ namespace NTMiner.MinerStudio.Vms {
                 }
             }
             else {
-                if (this.Id != MineWorkData.SelfMineWorkId) {
+                if (!this.Id.IsSelfMineWorkId()) {
                     if (isMinerProfileChanged) {
                         NTMinerContext.ExportWorkJson(mineWorkData, out string localJson, out string serverJson);
                         if (!string.IsNullOrEmpty(localJson) && !string.IsNullOrEmpty(serverJson)) {

+ 1 - 1
src/MinerClientSelfHost/MinerClientController.cs

@@ -51,7 +51,7 @@ namespace NTMiner {
                 WorkType workType = WorkType.None;
                 if (request.WorkId != Guid.Empty) {
                     workType = WorkType.MineWork;
-                    if (request.WorkId == MineWorkData.SelfMineWorkId) {
+                    if (request.WorkId.IsSelfMineWorkId()) {
                         workType = WorkType.SelfWork;
                     }
                 }

+ 2 - 2
src/NTMinerDaemon/Core/Impl/DaemonOperation.cs

@@ -236,7 +236,7 @@ namespace NTMiner.Core.Impl {
             else {
                 try {
                     // 单机作业的localJson和serverJson是在编辑单机作业时提前传递到挖矿端的所以不需要在开始挖矿时再传递
-                    if (request.WorkId != Guid.Empty && request.WorkId != MineWorkData.SelfMineWorkId) {
+                    if (request.WorkId != Guid.Empty && !request.WorkId.IsSelfMineWorkId()) {
                         SpecialPath.WriteMineWorkLocalJsonFile(request.LocalJson);
                         SpecialPath.WriteMineWorkServerJsonFile(request.ServerJson);
                     }
@@ -253,7 +253,7 @@ namespace NTMiner.Core.Impl {
                         if (!string.IsNullOrEmpty(location) && File.Exists(location)) {
                             string arguments = NTKeyword.AutoStartCmdParameterName;
                             if (request.WorkId != Guid.Empty) {
-                                if (request.WorkId == MineWorkData.SelfMineWorkId) {
+                                if (request.WorkId.IsSelfMineWorkId()) {
                                     arguments = "--selfWork " + arguments;
                                 }
                                 else {

+ 9 - 0
src/NTMinerDataSchemas/Core/GuidExtensions.cs

@@ -0,0 +1,9 @@
+using System;
+
+namespace NTMiner.Core {
+    public static class GuidExtensions {
+        public static bool IsSelfMineWorkId(this Guid guid) {
+            return guid == MineWorkData.SelfMineWorkId;
+        }
+    }
+}

+ 1 - 0
src/NTMinerDataSchemas/NTMinerDataSchemas.csproj

@@ -50,6 +50,7 @@
     <Compile Include="Core\Gpus\IGpuNameCount.cs" />
     <Compile Include="Core\Gpus\QueryGpuNameCountsRequest.cs" />
     <Compile Include="Core\Gpus\QueryGpuNameCountsResponse.cs" />
+    <Compile Include="Core\GuidExtensions.cs" />
     <Compile Include="Core\ICaptcha.cs" />
     <Compile Include="Core\IOperationResult.cs" />
     <Compile Include="Core\LocalMessageDto.cs" />

+ 1 - 1
src/WebApiServer/Controllers/UserMineWorkController.cs

@@ -138,7 +138,7 @@ namespace NTMiner.Controllers {
             try {
                 string workerName = string.Empty;
                 // 如果是单机作业
-                if (request.WorkId == MineWorkData.SelfMineWorkId) {
+                if (request.WorkId.IsSelfMineWorkId()) {
                     var clientData = WebApiRoot.ClientDataSet.GetByClientId(request.ClientId);
                     if (clientData != null) {
                         workerName = clientData.WorkerName;