private void PanelEprice_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { WpfUtil.ShowInputDialog("电价", Vm.MinerProfile.EPrice.ToString("f2"), "¥ / 度", eprice => { if (!double.TryParse(eprice, out _)) { return("电价必须是数字"); } return(string.Empty); }, onOk: eprice => { Vm.MinerProfile.EPrice = double.Parse(eprice); }); }
private ColumnsShowViewModels() { if (WpfUtil.IsInDesignMode) { return; } this.Add = new DelegateCommand(() => { WpfUtil.ShowInputDialog("列分组名称", string.Empty, string.Empty, columnsShowName => { if (string.IsNullOrEmpty(columnsShowName)) { return("列分组名称是必须的"); } return(string.Empty); }, onOk: columnsShowName => { ColumnsShowData entity = new ColumnsShowData { ColumnsShowName = columnsShowName, LastActivedOnText = true, BootTimeSpanText = true, MineTimeSpanText = true, Work = true, MinerGroup = true, MinerName = true, WorkerName = true, LocalIp = true, MinerIp = true, GpuType = true, MainCoinCode = true, MainCoinSpeedText = true, MainCoinRejectPercentText = true }; NTMinerContext.MinerStudioContext.ColumnsShowSet.AddOrUpdate(entity); }); }); AppRoot.AddEventPath <ColumnsShowAddedOrUpdatedEvent>("添加或修改了列分组后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.TryGetValue(message.Source.GetId(), out ColumnsShowViewModel vm)) { vm = new ColumnsShowViewModel(message.Source); _dicById.Add(message.Source.GetId(), vm); OnPropertyChanged(nameof(List)); MinerClientsWindowVm.ColumnsShow = vm; } else { vm.Update(message.Source); } }, location: this.GetType()); AppRoot.AddEventPath <ColumnsRemovedEvent>("删除了列分组后刷新Vm内存", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.Source.Id)) { _dicById.Remove(message.Source.Id); OnPropertyChanged(nameof(List)); if (_dicById.TryGetValue(ColumnsShowData.PleaseSelect.Id, out ColumnsShowViewModel vm)) { MinerClientsWindowVm.ColumnsShow = vm; } } }, this.GetType()); foreach (var item in NTMinerContext.MinerStudioContext.ColumnsShowSet.GetAll()) { _dicById.Add(item.Id, new ColumnsShowViewModel(item)); } }
private void DoEdit(FormType?formType) { if (!MinerStudioRoot.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm) && !this.Id.IsSelfMineWorkId()) { WpfUtil.ShowInputDialog("作业名称", string.Empty, string.Empty, workName => { if (string.IsNullOrEmpty(workName)) { return("作业名称是必须的"); } return(string.Empty); }, onOk: workName => { new MineWorkViewModel(this) { Name = workName }.Save.Execute(null); }); } else { _minerClientVm = MinerStudioRoot.MinerClientsWindowVm.SelectedMinerClients.FirstOrDefault(); if (_minerClientVm == null) { VirtualRoot.Out.ShowError("未选中矿机", autoHideSeconds: 4); return; } if (this.Id.IsSelfMineWorkId()) { SelfMineWork.Description = $"{_minerClientVm.GetMinerOrClientName()} 矿机的单机作业"; if (RpcRoot.IsOuterNet) { if (!_minerClientVm.IsOuterUserEnabled) { VirtualRoot.Out.ShowError("无法操作,因为选中的矿机未开启外网群控。", autoHideSeconds: 6); return; } VirtualRoot.AddOnecePath <GetSelfWorkLocalJsonResponsedEvent>("获取到响应结果后填充Vm内存", LogEnum.DevConsole, action: message => { if (message.ClientId == _minerClientVm.ClientId) { string data = message.Data; EditJson(formType, WorkType.SelfWork, data); } }, PathId.Empty, typeof(MineWorkViewModel)); MinerStudioService.Instance.GetSelfWorkLocalJsonAsync(_minerClientVm); } else { RpcRoot.Client.NTMinerDaemonService.GetSelfWorkLocalJsonAsync(_minerClientVm, (json, e) => { string data = json; EditJson(formType, WorkType.SelfWork, data); }); } } else { // 编辑作业前切换上下文 // 根据workId下载json保存到本地并调用LocalJson.Instance.ReInit() if (RpcRoot.IsOuterNet) { RpcRoot.OfficialServer.UserMineWorkService.GetLocalJsonAsync(this.Id, (response, e) => { if (response.IsSuccess()) { string data = response.Data; EditJson(formType, WorkType.MineWork, data); } }); } else { try { string localJsonFileFullName = MinerStudioPath.GetMineWorkLocalJsonFileFullName(this.Id); string data = string.Empty; if (File.Exists(localJsonFileFullName)) { data = File.ReadAllText(localJsonFileFullName); } EditJson(formType, WorkType.MineWork, data); } catch (Exception e) { Logger.ErrorDebugLine(e); } } } } }
public MineWorkViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (string.IsNullOrEmpty(this.Name)) { VirtualRoot.Out.ShowError("作业名称是必须的"); } bool isMineWorkChanged = false; bool isMinerProfileChanged = false; MineWorkData mineWorkData = new MineWorkData(this); if (NTMinerRoot.Instance.MineWorkSet.TryGetMineWork(this.Id, out IMineWork entity)) { string sha1 = NTMinerRoot.Instance.MinerProfile.GetSha1(); // 如果作业设置变更了则一定变更了 if (this.Sha1 != sha1) { isMinerProfileChanged = true; } else { // 如果作业设置没变更但作业引用的服务器数据库记录状态变更了则变更了 LocalJsonDb localJsonObj = new LocalJsonDb(NTMinerRoot.Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(NTMinerRoot.Instance, localJsonObj); var serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); sha1 = HashUtil.Sha1(serverJson); if (sha1 != this.ServerJsonSha1) { isMinerProfileChanged = true; } } if (entity.Name != this.Name || entity.Description != this.Description) { isMineWorkChanged = true; } } else { isMinerProfileChanged = true; VirtualRoot.Execute(new AddMineWorkCommand(this)); this.Edit.Execute(FormType.Edit); } if (isMinerProfileChanged) { Write.DevDebug("检测到MinerProfile状态变更"); NTMinerRoot.ExportWorkJson(mineWorkData, out string localJson, out string serverJson); if (!string.IsNullOrEmpty(localJson) && !string.IsNullOrEmpty(serverJson)) { RpcRoot.Server.MineWorkService.ExportMineWorkAsync(this.Id, localJson, serverJson, callback: null); } if (mineWorkData.ServerJsonSha1 != this.ServerJsonSha1) { this.ServerJsonSha1 = mineWorkData.ServerJsonSha1; isMineWorkChanged = true; } } if (isMineWorkChanged) { VirtualRoot.Execute(new UpdateMineWorkCommand(mineWorkData)); } }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } if (!AppContext.Instance.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm)) { WpfUtil.ShowInputDialog("作业名称", string.Empty, workName => { if (string.IsNullOrEmpty(workName)) { return("作业名称是必须的"); } return(string.Empty); }, onOk: workName => { new MineWorkViewModel(this) { Name = workName }.Save.Execute(null); }); } else { // 编辑作业前切换上下文 // 根据workId下载json保存到本地并调用LocalJson.Instance.ReInit() string json = RpcRoot.Server.MineWorkService.GetLocalJson(this.Id); if (!string.IsNullOrEmpty(json)) { File.WriteAllText(SpecialPath.LocalJsonFileFullName, json); } else { File.Delete(SpecialPath.LocalJsonFileFullName); } NTMinerRoot.Instance.ReInitMinerProfile(); this.Sha1 = NTMinerRoot.Instance.MinerProfile.GetSha1(); VirtualRoot.Execute(new MineWorkEditCommand(formType ?? FormType.Edit, new MineWorkViewModel(this))); } }, formType => { if (this == PleaseSelect) { return(false); } return(true); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveMineWorkCommand(this.Id)); })); }, () => { if (this == PleaseSelect) { return(false); } return(true); }); }
public MinerClientsWindowViewModel(bool isInDesignMode = true) { if (WpfUtil.IsInDesignMode || isInDesignMode) { return; } var appSettings = NTMinerRoot.Instance.ServerAppSettingSet; Guid columnsShowId = ColumnsShowData.PleaseSelect.Id; if (appSettings.TryGetAppSetting(NTKeyword.ColumnsShowIdAppSettingKey, out IAppSetting columnsShowAppSetting) && columnsShowAppSetting.Value != null) { if (Guid.TryParse(columnsShowAppSetting.Value.ToString(), out Guid guid)) { columnsShowId = guid; } } if (appSettings.TryGetAppSetting(NTKeyword.FrozenColumnCountAppSettingKey, out IAppSetting frozenColumnCountAppSetting) && frozenColumnCountAppSetting.Value != null) { if (int.TryParse(frozenColumnCountAppSetting.Value.ToString(), out int frozenColumnCount)) { _frozenColumnCount = frozenColumnCount; } } if (appSettings.TryGetAppSetting(NTKeyword.MaxTempAppSettingKey, out IAppSetting maxTempAppSetting) && maxTempAppSetting.Value != null) { if (uint.TryParse(maxTempAppSetting.Value.ToString(), out uint maxTemp)) { _maxTemp = maxTemp; } } if (appSettings.TryGetAppSetting(NTKeyword.MinTempAppSettingKey, out IAppSetting minTempAppSetting) && minTempAppSetting.Value != null) { if (uint.TryParse(minTempAppSetting.Value.ToString(), out uint minTemp)) { _minTemp = minTemp; } } if (appSettings.TryGetAppSetting(NTKeyword.RejectPercentAppSettingKey, out IAppSetting rejectPercentAppSetting) && rejectPercentAppSetting.Value != null) { if (int.TryParse(rejectPercentAppSetting.Value.ToString(), out int rejectPercent)) { _rejectPercent = rejectPercent; } } this._columnsShow = this.ColumnsShows.List.FirstOrDefault(a => a.Id == columnsShowId); if (this._columnsShow == null) { this._columnsShow = this.ColumnsShows.List.FirstOrDefault(); } this._mineStatusEnumItem = NTMinerRoot.MineStatusEnumItems.FirstOrDefault(a => a.Value == MineStatus.All); this._coinVm = CoinViewModel.PleaseSelect; this._selectedMineWork = MineWorkViewModel.PleaseSelect; this._selectedMinerGroup = MinerGroupViewModel.PleaseSelect; this._pool = string.Empty; // 至少会有一个PleaseSelect所以可以First this._poolVm = _coinVm.OptionPools.First(); this._wallet = string.Empty; this.OneKeySetting = new DelegateCommand(() => { VirtualRoot.Execute(new ShowMinerClientSettingCommand(new MinerClientSettingViewModel(this.SelectedMinerClients))); }, CanCommand); this.OneKeyMinerNames = new DelegateCommand(() => { if (this.SelectedMinerClients.Length == 1) { var selectedMinerClient = this.SelectedMinerClients[0]; WpfUtil.ShowInputDialog("群控矿工名 注意:重新开始挖矿时生效", selectedMinerClient.MinerName, null, minerName => { selectedMinerClient.MinerName = minerName; VirtualRoot.Out.ShowSuccess("设置群控矿工名成功,重新开始挖矿时生效。"); }); return; } MinerNamesSeterViewModel vm = new MinerNamesSeterViewModel( prefix: "miner", suffix: "01", namesByObjectId: this.SelectedMinerClients.Select(a => new Tuple <string, string>(a.Id, string.Empty)).ToList()); VirtualRoot.Execute(new ShowMinerNamesSeterCommand(vm)); if (vm.IsOk) { this.CountDown = 10; RpcRoot.Server.ClientService.UpdateClientsAsync(nameof(MinerClientViewModel.MinerName), vm.NamesByObjectId.ToDictionary(a => a.Item1, a => (object)a.Item2), callback: (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } else { foreach (var kv in vm.NamesByObjectId) { var item = this.SelectedMinerClients.FirstOrDefault(a => a.Id == kv.Item1); if (item != null) { item.UpdateMinerName(kv.Item2); } } QueryMinerClients(); } }); } }, CanCommand); this.OneKeyWindowsLoginName = new DelegateCommand(() => { WpfUtil.ShowInputDialog("远程桌面用户名", string.Empty, null, loginName => { foreach (var item in SelectedMinerClients) { item.WindowsLoginName = loginName; } VirtualRoot.Out.ShowSuccess("设置远程桌面用户名成功,双击矿机可打开远程桌面。"); }); }, CanCommand); this.OneKeyWindowsLoginPassword = new DelegateCommand(() => { WpfUtil.ShowInputDialog("远程桌面密码", string.Empty, null, password => { foreach (var item in SelectedMinerClients) { item.WindowsPassword = password; } VirtualRoot.Out.ShowSuccess("设置远程桌面密码成功,双击矿机可打开远程桌面。"); }); }, CanCommand); this.EditMineWork = new DelegateCommand(() => { this.SelectedMinerClients[0].SelectedMineWork.Edit.Execute(null); }, () => OnlySelectedOne() && this.SelectedMinerClients[0].SelectedMineWork != null && this.SelectedMinerClients[0].SelectedMineWork != MineWorkViewModel.PleaseSelect); this.OneKeyWork = new DelegateCommand <MineWorkViewModel>((work) => { foreach (var item in SelectedMinerClients) { item.SelectedMineWork = work; } }); this.OneKeyGroup = new DelegateCommand <MinerGroupViewModel>((group) => { foreach (var item in SelectedMinerClients) { item.SelectedMinerGroup = group; } }); this.OneKeyOverClock = new DelegateCommand(() => { if (this.SelectedMinerClients.Length == 1) { VirtualRoot.Execute(new ShowGpuProfilesPageCommand(this)); } }, OnlySelectedOne); this.OneKeyUpgrade = new DelegateCommand <NTMinerFileData>((ntminerFileData) => { this.ShowSoftDialog(new DialogWindowViewModel(message: "确定升级到该版本吗?", title: "确认", onYes: () => { foreach (var item in SelectedMinerClients) { RpcRoot.Server.MinerClientService.UpgradeNTMinerAsync(item, ntminerFileData.FileName, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); } })); }, (ntminerFileData) => this.SelectedMinerClients != null && this.SelectedMinerClients.Length != 0); this.AddMinerClient = new DelegateCommand(() => { VirtualRoot.Execute(new ShowMinerClientAddCommand()); }); this.RemoveMinerClients = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定删除选中的矿机吗?", title: "确认", onYes: () => { this.CountDown = 10; RpcRoot.Server.ClientService.RemoveClientsAsync(SelectedMinerClients.Select(a => a.Id).ToList(), (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } else { QueryMinerClients(); } }); })); } }, CanCommand); this.RefreshMinerClients = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { RpcRoot.Server.ClientService.RefreshClientsAsync(SelectedMinerClients.Select(a => a.Id).ToList(), (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } else { foreach (var data in response.Data) { var item = MinerClients.FirstOrDefault(a => a.Id == data.Id); if (item != null) { item.Update(data); } } } }); } }, CanCommand); this.RestartWindows = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定重启选中的电脑吗?", title: "确认", onYes: () => { foreach (var item in SelectedMinerClients) { RpcRoot.Server.MinerClientService.RestartWindowsAsync(item, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); } })); } }, CanCommand); this.ShutdownWindows = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定关闭选中的电脑吗?", title: "确认", onYes: () => { foreach (var item in SelectedMinerClients) { RpcRoot.Server.MinerClientService.ShutdownWindowsAsync(item, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); } })); } }, CanCommand); this.RestartNTMiner = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定重启选中的挖矿客户端吗?", title: "确认", onYes: () => { foreach (var item in SelectedMinerClients) { RpcRoot.Server.MinerClientService.RestartNTMinerAsync(item, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); } })); } }, CanCommand); this.StartMine = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { foreach (var item in SelectedMinerClients) { item.IsMining = true; RpcRoot.Server.MinerClientService.StartMineAsync(item, item.WorkId, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); RpcRoot.Server.ClientService.UpdateClientAsync(item.Id, nameof(item.IsMining), item.IsMining, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); } } }, CanCommand); this.StopMine = new DelegateCommand(() => { if (SelectedMinerClients.Length == 0) { ShowNoRecordSelected(); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定将选中的矿机停止挖矿吗?", title: "确认", onYes: () => { foreach (var item in SelectedMinerClients) { item.IsMining = false; RpcRoot.Server.MinerClientService.StopMineAsync(item, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); RpcRoot.Server.ClientService.UpdateClientAsync(item.Id, nameof(item.IsMining), item.IsMining, (response, e) => { if (!response.IsSuccess()) { VirtualRoot.Out.ShowError($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}"); } }); } })); } }, CanCommand); this.PageUp = new DelegateCommand(() => { this.MinerClientPageIndex -= 1; }); this.PageDown = new DelegateCommand(() => { this.MinerClientPageIndex += 1; }); this.PageFirst = new DelegateCommand(() => { this.MinerClientPageIndex = 1; }); this.PageLast = new DelegateCommand(() => { this.MinerClientPageIndex = MinerClientPageCount; }); this.PageRefresh = new DelegateCommand(QueryMinerClients); }