コード例 #1
0
 private MainWindowViewModel()
 {
     if (App.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.CancelDownload = new DelegateCommand(() => {
         this.cancel?.Invoke();
         this.IsDownloading = false;
     });
     this.Install = new DelegateCommand(() => {
         if (this.IsDownloading)
         {
             return;
         }
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version, progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         }, downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage  = message;
             this.DownloadPercent  = 0;
             this.BtnCancelVisible = Visibility.Collapsed;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     Client.MinerClientService.CloseNTMiner();
                 }
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     File.Copy(saveFileFullName, location, overwrite: true);
                     File.Delete(saveFileFullName);
                     string arguments = NTMinerRegistry.GetArguments();
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     UIThread.Execute(() => {
                         Application.Current.MainWindow.Close();
                     });
                 });
             }
             else
             {
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out cancel);
     });
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("添加", "Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowDialogEx();
     });
 }
コード例 #2
0
 private MainWindowViewModel()
 {
     if (App.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version, progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         }, downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     Client.MinerClientService.CloseNTMiner();
                 }
                 TimeSpan.FromSeconds(3).Delay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     try {
                         if (File.Exists(location))
                         {
                             Guid kernelBrandId = VirtualRoot.GetBrandId(location, Consts.KernelBrandId);
                             if (kernelBrandId != Guid.Empty)
                             {
                                 Logger.InfoDebugLine("内核品牌打码开始");
                                 VirtualRoot.TagBrandId(Consts.KernelBrandId, kernelBrandId, saveFileFullName, saveFileFullName);
                                 Logger.OkDebugLine("内核品牌打码成功");
                             }
                             Guid poolBrandId = VirtualRoot.GetBrandId(location, Consts.PoolBrandId);
                             if (poolBrandId != Guid.Empty)
                             {
                                 Logger.InfoDebugLine("矿池打码开始");
                                 VirtualRoot.TagBrandId(Consts.PoolBrandId, poolBrandId, saveFileFullName, saveFileFullName);
                                 Logger.OkDebugLine("矿池打码成功");
                             }
                         }
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     Logger.InfoDebugLine("复制开始");
                     File.Copy(saveFileFullName, location, overwrite: true);
                     File.Delete(saveFileFullName);
                     Logger.InfoDebugLine("复制完成,删除旧文件");
                     string arguments = NTMinerRegistry.GetArguments();
                     Logger.InfoDebugLine("启动新程序");
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     UIThread.Execute(() => {
                         Logger.InfoDebugLine("退出升级器");
                         Application.Current.MainWindow?.Close();
                     });
                 });
             }
             else
             {
                 TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("添加", "Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowDialogEx();
     });
 }
コード例 #3
0
 private MainWindowViewModel()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Refresh();
     this.ShowServerLatestDescription = new DelegateCommand(() => {
         VirtualRoot.Out.ShowInfo(ServerLatestVm.Description, header: $"{ServerLatestVm.Version}({ServerLatestVm.VersionTag})", autoHideSeconds: 0);
     });
     this.CancelDownload = new DelegateCommand(() => {
         this._cancel?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.IsDownloading = true;
         string ntMinerFile = string.Empty;
         string version     = string.Empty;
         if (IsHistoryVisible == Visibility.Collapsed)
         {
             if (ServerLatestVm != null)
             {
                 ntMinerFile = ServerLatestVm.FileName;
                 version     = ServerLatestVm.Version;
             }
         }
         else
         {
             ntMinerFile = SelectedNTMinerFile.FileName;
             version     = SelectedNTMinerFile.Version;
         }
         Download(ntMinerFile, version,
                  progressChanged: (percent) => {
             this.DownloadMessage = percent + "%";
             this.DownloadPercent = (double)percent / 100;
         },
                  downloadComplete: (isSuccess, message, saveFileFullName) => {
             this.DownloadMessage = message;
             this.DownloadPercent = 0;
             if (isSuccess)
             {
                 this.DownloadMessage = "更新成功,正在重启";
                 if (VirtualRoot.IsMinerStudio)
                 {
                     RpcRoot.Client.MinerStudioService.CloseMinerStudio();
                 }
                 else
                 {
                     RpcRoot.Client.MinerClientService.CloseNTMiner();
                 }
                 3.SecondsDelay().ContinueWith((t) => {
                     string location = NTMinerRegistry.GetLocation();
                     if (string.IsNullOrEmpty(location) || !File.Exists(location))
                     {
                         location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ntMinerFile);
                     }
                     try {
                         if (File.Exists(location))
                         {
                             Guid kernelBrandId = VirtualRoot.GetBrandId(location, NTKeyword.KernelBrandId);
                             if (kernelBrandId != Guid.Empty)
                             {
                                 VirtualRoot.TagBrandId(NTKeyword.KernelBrandId, kernelBrandId, saveFileFullName, saveFileFullName);
                             }
                             Guid poolBrandId = VirtualRoot.GetBrandId(location, NTKeyword.PoolBrandId);
                             if (poolBrandId != Guid.Empty)
                             {
                                 VirtualRoot.TagBrandId(NTKeyword.PoolBrandId, poolBrandId, saveFileFullName, saveFileFullName);
                             }
                         }
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     int failCount = 0;
                     while (true)
                     {
                         try {
                             File.Copy(saveFileFullName, location, overwrite: true);
                             break;
                         }
                         catch (Exception e) {
                             failCount++;
                             if (failCount == 3)
                             {
                                 VirtualRoot.Out.ShowError(e.Message);
                                 break;
                             }
                             else
                             {
                                 System.Threading.Thread.Sleep(3000);
                             }
                         }
                     }
                     try {
                         File.Delete(saveFileFullName);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                     string arguments = NTMinerRegistry.GetArguments();
                     Process.Start(location, arguments);
                     this.IsDownloading = false;
                     2.SecondsDelay().ContinueWith(_ => {
                         UIThread.Execute(() => () => {
                             Application.Current.MainWindow?.Close();
                         });
                     });
                 });
             }
             else
             {
                 2.SecondsDelay().ContinueWith((t) => {
                     this.IsDownloading = false;
                 });
             }
         }, cancel: out _cancel);
     }, () => !IsDownloading);
     this.ShowHistory = new DelegateCommand(() => {
         if (IsHistoryVisible == Visibility.Visible)
         {
             IsHistoryVisible = Visibility.Collapsed;
         }
         else
         {
             IsHistoryVisible = Visibility.Visible;
         }
     });
     this.AddNTMinerFile = new DelegateCommand(() => {
         NTMinerFileEdit window = new NTMinerFileEdit("Icon_Add", new NTMinerFileViewModel()
         {
             AppType = App.AppType
         });
         window.ShowSoftDialog();
     });
 }