public NTMinerFileViewModel() { _id = Guid.NewGuid(); _publishOn = DateTime.Now; this.Save = new DelegateCommand(() => { if (Login()) { OfficialServer.FileUrlService.AddOrUpdateNTMinerFileAsync(new NTMinerFileData().Update(this), (response, e) => { if (response.IsSuccess()) { MainWindowViewModel.Instance.Refresh(); UIThread.Execute(() => { TopWindow.GetTopWindow()?.Close(); }); } else { Logger.ErrorDebugLine($"AddOrUpdateNTMinerFileAsync失败"); } }); } }); this.Edit = new DelegateCommand(() => { NTMinerFileEdit window = new NTMinerFileEdit("Icon_Edit", new NTMinerFileViewModel(this)); window.ShowDialogEx(); }); this.Remove = new DelegateCommand(() => { if (Login()) { this.ShowDialog(message: $"确定删除{this.Version}({this.VersionTag})吗?", title: "确认", onYes: () => { OfficialServer.FileUrlService.RemoveNTMinerFileAsync(this.Id, (response, e) => { MainWindowViewModel.Instance.SelectedNTMinerFile = MainWindowViewModel.Instance.NTMinerFiles.FirstOrDefault(); if (this == MainWindowViewModel.Instance.ServerLatestVm) { MainWindowViewModel.Instance.ServerLatestVm = MainWindowViewModel.Instance.NTMinerFiles .FirstOrDefault(a => a != this && a.VersionData > MainWindowViewModel.Instance.LocalNTMinerVersion); } MainWindowViewModel.Instance.Refresh(); }); }, icon: IconConst.IconConfirm); } }); }
public NTMinerFileViewModel() { _id = Guid.NewGuid(); _publishOn = DateTime.Now; this.Save = new DelegateCommand(() => { if (Login()) { Server.FileUrlService.AddOrUpdateNTMinerFile(new NTMinerFileData().Update(this), response => { if (response != null && response.IsSuccess()) { MainWindowViewModel.Current.Refresh(); Execute.OnUIThread(() => { TopWindow.GetTopWindow()?.Close(); }); } }); } }); this.Edit = new DelegateCommand(() => { NTMinerFileEdit window = new NTMinerFileEdit("编辑", "Icon_Edit", new NTMinerFileViewModel(this)); window.ShowDialogEx(); }); this.Remove = new DelegateCommand(() => { if (Login()) { DialogWindow.ShowDialog(message: $"确定删除{this.Version}({this.VersionTag})吗?", title: "确认", onYes: () => { Server.FileUrlService.RemoveNTMinerFile(this.Id, isSuccess => { MainWindowViewModel.Current.SelectedNTMinerFile = MainWindowViewModel.Current.NTMinerFiles.FirstOrDefault(); if (this == MainWindowViewModel.Current.ServerLatestVm) { MainWindowViewModel.Current.ServerLatestVm = MainWindowViewModel.Current.NTMinerFiles .FirstOrDefault(a => a != this && a.VersionData > MainWindowViewModel.Current.LocalNTMinerVersion); } MainWindowViewModel.Current.Refresh(); }); }, icon: "Icon_Confirm"); } }); }
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(); }); }
private MainWindowViewModel() { if (App.IsInDesignMode) { return; } this.Refresh(); this.CancelDownload = new DelegateCommand(() => { this.cancel?.Invoke(); this.IsDownloading = false; }); this.Install = new DelegateCommand(() => { object locationValue = Windows.Registry.GetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Location"); object argumentsValue = Windows.Registry.GetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments"); if (locationValue == null) { return; } 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 = "更新成功,正在重启"; Task.Factory.StartNew(CloseNTMinerMainWindow); TimeSpan.FromSeconds(2).Delay().ContinueWith((t) => { string location = (string)locationValue; File.Copy(saveFileFullName, location, overwrite: true); File.Delete(saveFileFullName); Process.Start(location, (string)argumentsValue); this.IsDownloading = false; Execute.OnUIThread(() => { 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; if (ServerLatestVm != null) { this.IsBtnInstallVisible = Visibility.Visible; } else { this.IsBtnInstallVisible = Visibility.Collapsed; } } else { IsHistoryVisible = Visibility.Visible; if (this.NTMinerFiles.Count != 0) { this.IsBtnInstallVisible = Visibility.Visible; } } }); this.AddNTMinerFile = new DelegateCommand(() => { NTMinerFileEdit window = new NTMinerFileEdit("添加", "Icon_Add", new NTMinerFileViewModel()); window.ShowDialogEx(); }); }
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(); }); }