ntminer 6 years ago
parent
commit
54d19172ad

+ 0 - 1
src/AppModels/Vms/StateBarViewModel.cs

@@ -39,7 +39,6 @@ namespace NTMiner.Vms {
                 }
                 VirtualRoot.Execute(new EnableWindowsRemoteDesktopCommand());
             });
-            _localIps = GetLocalIps();
             SetCheckUpdateForeground(isLatest: MainAssemblyInfo.CurrentVersion >= NTMinerRoot.ServerVersion);
         }
 

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

@@ -21,7 +21,7 @@ namespace NTMiner.Views.Ucs {
                         window.DragMove();
                     }
                 };
-                window.BuildEventPath<LocalIpSetRefreshedEvent>("本机IP集刷新后刷新IP设置页", LogEnum.DevConsole,
+                window.BuildEventPath<LocalIpSetInitedEvent>("本机IP集刷新后刷新IP设置页", LogEnum.DevConsole,
                     action: message => {
                         UIThread.Execute(()=> uc.Vm.Refresh());
                     });

+ 2 - 1
src/AppViews0/Ucs/StateBar.xaml.cs

@@ -25,7 +25,7 @@ namespace NTMiner.Views.Ucs {
                     Vm.OnPropertyChanged(nameof(Vm.IsRemoteDesktopEnabled));
                     Vm.OnPropertyChanged(nameof(Vm.RemoteDesktopToolTip));
                 };
-                window.BuildEventPath<LocalIpSetRefreshedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole,
+                window.BuildEventPath<LocalIpSetInitedEvent>("本机IP集刷新后刷新状态栏", LogEnum.DevConsole,
                     action: message => {
                         UIThread.Execute(()=> Vm.RefreshLocalIps());
                     });
@@ -70,6 +70,7 @@ namespace NTMiner.Views.Ucs {
             if (NTMinerRoot.OSVirtualMemoryMb < gpuSet.Count * 4) {
                 BtnShowVirtualMemory.Foreground = WpfUtil.RedBrush;
             }
+            VirtualRoot.LocalIpSet.InitOnece();
 #if DEBUG
             var elapsedMilliseconds = Write.Stopwatch.Stop();
             Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");

+ 3 - 1
src/NTMinerDataObjects/MinerServer/ClientData.cs

@@ -205,7 +205,9 @@ namespace NTMiner.MinerServer {
             _preDualCoin = this.DualCoinCode;
 
             this.ClientId = speedData.ClientId;
-            this.MACAddress = speedData.MACAddress;
+            if (!string.IsNullOrEmpty(speedData.MACAddress)) {
+                this.MACAddress = speedData.MACAddress;
+            }
             this.IsAutoBoot = speedData.IsAutoBoot;
             this.IsAutoStart = speedData.IsAutoStart;
             this.AutoStartDelaySeconds = speedData.AutoStartDelaySeconds;

+ 1 - 0
src/NTMinerlib/Ip/ILocalIpSet.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 
 namespace NTMiner.Ip {
     public interface ILocalIpSet {
+        void InitOnece();
         IEnumerable<ILocalIp> AsEnumerable();
     }
 }

+ 14 - 11
src/NTMinerlib/Ip/LocalIpSet.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Management;
 using System.Net.NetworkInformation;
+using System.Threading.Tasks;
 
 namespace NTMiner.Ip {
     public class LocalIpSet : ILocalIpSet {
@@ -127,7 +128,6 @@ namespace NTMiner.Ip {
                             VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络接口的 IP 地址发生了 {(isIpChanged ? "变更" : "刷新")}", toConsole: true);
                         }
                     }
-                    VirtualRoot.RaiseEvent(new LocalIpSetRefreshedEvent());
                 });
             };
             NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => {
@@ -180,7 +180,7 @@ namespace NTMiner.Ip {
         private bool _isInited = false;
         private readonly object _locker = new object();
 
-        private void InitOnece() {
+        public void InitOnece() {
             if (_isInited) {
                 return;
             }
@@ -188,20 +188,23 @@ namespace NTMiner.Ip {
         }
 
         private void Init() {
-#if DEBUG
-            Write.Stopwatch.Start();
-#endif
             lock (_locker) {
                 if (!_isInited) {
-                    _localIps = GetLocalIps();
                     _isInited = true;
-                }
-            }
+                    Task.Factory.StartNew(() => {
 #if DEBUG
-            // 将近300毫秒
-            var elapsedMilliseconds = Write.Stopwatch.Stop();
-            Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(Init)}");
+                        Write.Stopwatch.Start();
 #endif
+                        _localIps = GetLocalIps();
+                        VirtualRoot.RaiseEvent(new LocalIpSetInitedEvent());
+#if DEBUG
+                        // 将近300毫秒
+                        var elapsedMilliseconds = Write.Stopwatch.Stop();
+                        Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(Init)}");
+#endif
+                    });
+                }
+            }
         }
 
         public IEnumerable<ILocalIp> AsEnumerable() {

+ 3 - 3
src/NTMinerlib/Messages.cs

@@ -92,9 +92,9 @@ namespace NTMiner {
         }
     }
 
-    [MessageType(description: "本机IP集刷新后")]
-    public class LocalIpSetRefreshedEvent : EventBase {
-        public LocalIpSetRefreshedEvent() { }
+    [MessageType(description: "本机IP集初始化后")]
+    public class LocalIpSetInitedEvent : EventBase {
+        public LocalIpSetInitedEvent() { }
     }
 
     [MessageType(description: "LocalAppSetting变更后")]