ntminer 5 years ago
parent
commit
55d4574338

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

@@ -29,7 +29,7 @@ namespace NTMiner.MinerStudio {
                     if (LatestTimestamp == Timestamp.UnixBaseTime) {
                     if (LatestTimestamp == Timestamp.UnixBaseTime) {
                         return "未知";
                         return "未知";
                     }
                     }
-                    return Timestamp.GetTimeSpanText(LatestTimestamp);
+                    return Timestamp.GetTimeSpanBeforeText(LatestTimestamp);
                 }
                 }
             }
             }
 
 

+ 1 - 1
src/AppModels/MinerStudio/Vms/MinerClientViewModel.cs

@@ -344,7 +344,7 @@ namespace NTMiner.MinerStudio.Vms {
                 if (MinerActiveOn <= Timestamp.UnixBaseTime) {
                 if (MinerActiveOn <= Timestamp.UnixBaseTime) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                return Timestamp.GetTimeSpanText(MinerActiveOn);
+                return Timestamp.GetTimeSpanBeforeText(MinerActiveOn);
             }
             }
         }
         }
 
 

+ 7 - 9
src/AppModels/MinerStudio/Vms/MinerClientsWindowViewModel.cs

@@ -5,11 +5,11 @@ using NTMiner.Vms;
 using NTMiner.Ws;
 using NTMiner.Ws;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq;
 using System.Net;
 using System.Net;
 using System.Windows;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Input;
-using System.Collections.ObjectModel;
 
 
 namespace NTMiner.MinerStudio.Vms {
 namespace NTMiner.MinerStudio.Vms {
     public class MinerClientsWindowViewModel : ViewModelBase, IWsStateViewModel {
     public class MinerClientsWindowViewModel : ViewModelBase, IWsStateViewModel {
@@ -598,6 +598,7 @@ namespace NTMiner.MinerStudio.Vms {
             });
             });
             this.PageRefresh = new DelegateCommand(QueryMinerClients);
             this.PageRefresh = new DelegateCommand(QueryMinerClients);
             this._lastSortDirection = new Dictionary<ClientDataSortField, SortDirection>(_sortDirection);
             this._lastSortDirection = new Dictionary<ClientDataSortField, SortDirection>(_sortDirection);
+            #region SortBy
             this.SortByMinerName = new DelegateCommand(() => {
             this.SortByMinerName = new DelegateCommand(() => {
                 if (this.SortField != ClientDataSortField.MinerName) {
                 if (this.SortField != ClientDataSortField.MinerName) {
                     this.SortField = ClientDataSortField.MinerName;
                     this.SortField = ClientDataSortField.MinerName;
@@ -689,6 +690,7 @@ namespace NTMiner.MinerStudio.Vms {
                     }
                     }
                 }
                 }
             });
             });
+            #endregion
             VirtualRoot.AddCmdPath<UpdateMinerClientVmCommand>(action: message => {
             VirtualRoot.AddCmdPath<UpdateMinerClientVmCommand>(action: message => {
                 var vm = _minerClients.FirstOrDefault(a => a.Id == message.ClientData.Id);
                 var vm = _minerClients.FirstOrDefault(a => a.Id == message.ClientData.Id);
                 if (vm != null) {
                 if (vm != null) {
@@ -697,6 +699,7 @@ namespace NTMiner.MinerStudio.Vms {
             }, this.GetType(), LogEnum.DevConsole);
             }, this.GetType(), LogEnum.DevConsole);
             if (RpcRoot.IsOuterNet) {
             if (RpcRoot.IsOuterNet) {
                 VirtualRoot.AddCmdPath<RefreshWsStateCommand>(message => {
                 VirtualRoot.AddCmdPath<RefreshWsStateCommand>(message => {
+                    #region
                     if (message.WsClientState != null) {
                     if (message.WsClientState != null) {
                         this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open;
                         this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open;
                         if (message.WsClientState.ToOut) {
                         if (message.WsClientState.ToOut) {
@@ -714,6 +717,7 @@ namespace NTMiner.MinerStudio.Vms {
                             }
                             }
                         }
                         }
                     }
                     }
+                    #endregion
                 }, this.GetType(), LogEnum.DevConsole);
                 }, this.GetType(), LogEnum.DevConsole);
                 VirtualRoot.Execute(new RefreshWsStateCommand(MinerStudioRoot.WsClient.GetState()));
                 VirtualRoot.Execute(new RefreshWsStateCommand(MinerStudioRoot.WsClient.GetState()));
             }
             }
@@ -862,7 +866,7 @@ namespace NTMiner.MinerStudio.Vms {
                 if (IsWsOnline || WsLastTryOn == DateTime.MinValue) {
                 if (IsWsOnline || WsLastTryOn == DateTime.MinValue) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                return Timestamp.GetTimeSpanText(WsLastTryOn);
+                return Timestamp.GetTimeSpanBeforeText(WsLastTryOn);
             }
             }
         }
         }
 
 
@@ -872,13 +876,7 @@ namespace NTMiner.MinerStudio.Vms {
                 if (IsWsOnline) {
                 if (IsWsOnline) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                if (seconds >= 3600) {
-                    return $"{(seconds / 3600).ToString()} 小时 {(seconds % 3600 / 60).ToString()} 分钟 {(seconds % 3600 % 60).ToString()} 秒后";
-                }
-                if (seconds > 60) {
-                    return $"{(seconds / 60).ToString()} 分 {(seconds % 60).ToString()} 秒后";
-                }
-                return $"{seconds.ToString()} 秒后";
+                return Timestamp.GetTimeSpanAfterText(seconds);
             }
             }
         }
         }
 
 

+ 1 - 1
src/AppModels/Vms/LocalMessageDtoViewModel.cs

@@ -50,7 +50,7 @@ namespace NTMiner.Vms {
 
 
         public string TimestampText {
         public string TimestampText {
             get {
             get {
-                return NTMiner.Timestamp.GetTimeSpanText(NTMiner.Timestamp.FromTimestamp(this.Timestamp));
+                return NTMiner.Timestamp.GetTimeSpanBeforeText(NTMiner.Timestamp.FromTimestamp(this.Timestamp));
             }
             }
         }
         }
     }
     }

+ 2 - 8
src/AppModels/Vms/MinerProfileViewModel.cs

@@ -332,7 +332,7 @@ namespace NTMiner.Vms {
                 if (IsWsOnline || WsLastTryOn == DateTime.MinValue) {
                 if (IsWsOnline || WsLastTryOn == DateTime.MinValue) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                return Timestamp.GetTimeSpanText(WsLastTryOn);
+                return Timestamp.GetTimeSpanBeforeText(WsLastTryOn);
             }
             }
         }
         }
 
 
@@ -342,13 +342,7 @@ namespace NTMiner.Vms {
                 if (!IsOuterUserEnabled || IsWsOnline) {
                 if (!IsOuterUserEnabled || IsWsOnline) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                if (seconds >= 3600) {
-                    return $"{(seconds / 3600).ToString()} 小时 {(seconds % 3600 / 60).ToString()} 分钟 {(seconds % 3600 % 60).ToString()} 秒后";
-                }
-                if (seconds > 60) {
-                    return $"{(seconds / 60).ToString()} 分 {(seconds % 60).ToString()} 秒后";
-                }
-                return $"{seconds.ToString()} 秒后";
+                return Timestamp.GetTimeSpanAfterText(seconds);
             }
             }
         }
         }
 
 

+ 1 - 1
src/AppModels/Vms/OperationResultViewModel.cs

@@ -42,7 +42,7 @@ namespace NTMiner.Vms {
 
 
         public string TimestampText {
         public string TimestampText {
             get {
             get {
-                return NTMiner.Timestamp.GetTimeSpanText(NTMiner.Timestamp.FromTimestamp(this.Timestamp));
+                return NTMiner.Timestamp.GetTimeSpanBeforeText(NTMiner.Timestamp.FromTimestamp(this.Timestamp));
             }
             }
         }
         }
     }
     }

+ 1 - 1
src/AppModels/Vms/SpeedViewModel.cs

@@ -126,7 +126,7 @@ namespace NTMiner.Vms {
                 if (!NTMinerContext.Instance.IsMining || SpeedOn <= Timestamp.UnixBaseTime) {
                 if (!NTMinerContext.Instance.IsMining || SpeedOn <= Timestamp.UnixBaseTime) {
                     return string.Empty;
                     return string.Empty;
                 }
                 }
-                return Timestamp.GetTimeSpanText(SpeedOn);
+                return Timestamp.GetTimeSpanBeforeText(SpeedOn);
             }
             }
         }
         }
 
 

+ 18 - 1
src/NTMinerDataSchemas/Timestamp.cs

@@ -42,7 +42,7 @@ namespace NTMiner {
             }
             }
         }
         }
 
 
-        public static string GetTimeSpanText(DateTime dateTime) {
+        public static string GetTimeSpanBeforeText(DateTime dateTime) {
             TimeSpan timeSpan = DateTime.Now - dateTime;
             TimeSpan timeSpan = DateTime.Now - dateTime;
             if (timeSpan.Days >= 1) {
             if (timeSpan.Days >= 1) {
                 return timeSpan.Days + " 天前";
                 return timeSpan.Days + " 天前";
@@ -55,5 +55,22 @@ namespace NTMiner {
             }
             }
             return (int)timeSpan.TotalSeconds + " 秒前";
             return (int)timeSpan.TotalSeconds + " 秒前";
         }
         }
+
+        public static string GetTimeSpanAfterText(int seconds) {
+            return GetTimeSpanAfterText(TimeSpan.FromSeconds(seconds));
+        }
+
+        public static string GetTimeSpanAfterText(TimeSpan timeSpan) {
+            if (timeSpan.Days >= 1) {
+                return timeSpan.Days + " 天后";
+            }
+            if (timeSpan.Hours > 0) {
+                return timeSpan.Hours + " 小时后";
+            }
+            if (timeSpan.Minutes > 2) {
+                return timeSpan.Minutes + " 分钟后";
+            }
+            return (int)timeSpan.TotalSeconds + " 秒后";
+        }
     }
     }
 }
 }