ntminer 5 jaren geleden
bovenliggende
commit
f41428ba05

+ 44 - 0
src/NTMinerDataSchemas/Core/MinerServer/ServerState.cs

@@ -8,9 +8,53 @@
             OutputKeywordTimestamp = 0
         };
 
+        public static ServerState FromLine(string line) {
+            string jsonFileVersion = string.Empty;
+            string minerClientVersion = string.Empty;
+            long time = Timestamp.GetTimestamp();
+            long messageTimestamp = 0;
+            long kernelOutputKeywordTimestamp = 0;
+            if (!string.IsNullOrEmpty(line)) {
+                line = line.Trim();
+                string[] parts = line.Split(new char[] { '|' });
+                if (parts.Length > 0) {
+                    jsonFileVersion = parts[0];
+                }
+                if (parts.Length > 1) {
+                    minerClientVersion = parts[1];
+                }
+                if (parts.Length > 2) {
+                    long.TryParse(parts[2], out time);
+                }
+                if (parts.Length > 3) {
+                    long.TryParse(parts[3], out messageTimestamp);
+                }
+                if (parts.Length > 4) {
+                    long.TryParse(parts[4], out kernelOutputKeywordTimestamp);
+                }
+            }
+            return new ServerState {
+                JsonFileVersion = jsonFileVersion,
+                MinerClientVersion = minerClientVersion,
+                Time = time,
+                MessageTimestamp = messageTimestamp,
+                OutputKeywordTimestamp = kernelOutputKeywordTimestamp
+            };
+        }
+
         public ServerState() { }
 
+        public string ToLine() {
+            return $"{this.JsonFileVersion}|{this.MinerClientVersion}|{this.Time.ToString()}|{this.MessageTimestamp.ToString()}|{this.OutputKeywordTimestamp.ToString()}";
+        }
+
+        /// <summary>
+        /// server.json版本
+        /// </summary>
         public string JsonFileVersion { get; set; }
+        /// <summary>
+        /// 可升级到的最新的挖矿端客户端版本
+        /// </summary>
         public string MinerClientVersion { get; set; }
         /// <summary>
         /// 服务器当前时间

+ 2 - 32
src/NTMinerRpcClient/Services/Official/AppSettingService.cs

@@ -21,38 +21,8 @@ namespace NTMiner.Services.Official {
             AppSettingRequest request = new AppSettingRequest {
                 Key = key
             };
-            RpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.GetJsonFileVersion), request, (string text, Exception e) => {
-                string jsonFileVersion = string.Empty;
-                string minerClientVersion = string.Empty;
-                long time = Timestamp.GetTimestamp();
-                long messageTimestamp = 0;
-                long kernelOutputKeywordTimestamp = 0;
-                if (!string.IsNullOrEmpty(text)) {
-                    text = text.Trim();
-                    string[] parts = text.Split(new char[] { '|' });
-                    if (parts.Length > 0) {
-                        jsonFileVersion = parts[0];
-                    }
-                    if (parts.Length > 1) {
-                        minerClientVersion = parts[1];
-                    }
-                    if (parts.Length > 2) {
-                        long.TryParse(parts[2], out time);
-                    }
-                    if (parts.Length > 3) {
-                        long.TryParse(parts[3], out messageTimestamp);
-                    }
-                    if (parts.Length > 4) {
-                        long.TryParse(parts[4], out kernelOutputKeywordTimestamp);
-                    }
-                }
-                callback?.Invoke(new ServerState {
-                    JsonFileVersion = jsonFileVersion,
-                    MinerClientVersion = minerClientVersion,
-                    Time = time,
-                    MessageTimestamp = messageTimestamp,
-                    OutputKeywordTimestamp = kernelOutputKeywordTimestamp
-                });
+            RpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.GetJsonFileVersion), request, (string line, Exception e) => {
+                callback?.Invoke(ServerState.FromLine(line));
             }, timeountMilliseconds: 10 * 1000);
         }
         #endregion

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

@@ -13,7 +13,7 @@ namespace NTMiner.Controllers {
         [HttpPost]
         public string GetJsonFileVersion([FromBody]AppSettingRequest request) {
             ServerState serverState = WebApiRoot.GetServerState(request.Key);
-            return $"{serverState.JsonFileVersion}|{serverState.MinerClientVersion}|{serverState.Time.ToString()}|{serverState.MessageTimestamp.ToString()}|{serverState.OutputKeywordTimestamp.ToString()}";
+            return serverState.ToLine();
         }
 
         [HttpPost]