public MainWindowViewModel() { if (Design.IsInDesignMode) { return; } this.CloseMainWindow = new DelegateCommand(() => { VirtualRoot.Execute(new CloseMainWindowCommand("已切换为无界面模式运行")); }); this.CustomTheme = new DelegateCommand(() => { VirtualRoot.Execute(new ShowLogColorCommand()); }); this.UseThisPcName = new DelegateCommand(() => { string thisPcName = NTMinerRoot.GetThisPcName(); this.ShowDialog(message: $"确定使用本机名{thisPcName}作为矿机名吗?", title: "确认", onYes: () => { MinerProfile.MinerName = thisPcName; }, icon: IconConst.IconConfirm); }); if (DevMode.IsDevMode) { _serverJsonVersion = GetServerJsonVersion(); } }
public ResponseBase SetAppSettings([FromBody] DataRequest <List <AppSettingData> > request) { if (request == null || request.Data == null) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!request.IsValid(User, Sign, Timestamp, ClientIp, out ResponseBase response)) { return(response); } foreach (var item in request.Data) { VirtualRoot.Execute(new ChangeLocalAppSettingCommand(item)); } Logger.InfoDebugLine($"{nameof(SetAppSettings)} {string.Join(",", request.Data.Select(a => $"{a.Key}:{a.Value}"))}"); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public KernelsWindowViewModel() { if (WpfUtil.IsInDesignMode) { return; } this._pagingVm = new PagingViewModel(() => this.PageIndex, () => this.PageSize); this.ChangeCurrentKernelMenu = new DelegateCommand <KernelMenu>((kernelMenu) => { SetCurrentKernelMenu(kernelMenu); this.PageIndex = 1; }); this.Home = new DelegateCommand(() => { ChangeCurrentKernelMenu.Execute(_repositoryKernelMenu); }); this._kernelMenus.Add(_repositoryKernelMenu); this._kernelMenus.Add(_uninstallKernelMenu); this.Add = new DelegateCommand(() => { new KernelViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); this.Search = new DelegateCommand(() => { this.PageIndex = 1; }); this.ClearKeyword = new DelegateCommand(() => { Keyword = string.Empty; }); this.PageSub = new DelegateCommand(() => { this.PageIndex -= 1; }); this.PageAdd = new DelegateCommand(() => { this.PageIndex += 1; }); this.ShowPackages = new DelegateCommand(() => { VirtualRoot.Execute(new ShowPackagesWindowCommand()); }); this.Home.Execute(null); }
public InputSegmentEditViewModel(CoinKernelViewModel coinKernelVm, InputSegmentViewModel segment) { _old = segment; segment = new InputSegmentViewModel(segment); _targetGpu = segment.TargetGpu; _name = segment.Name; _segment = segment.Segment; _description = segment.Description; _isDefault = segment.IsDefault; this.Save = new DelegateCommand(() => { if (string.IsNullOrEmpty(this.Name)) { throw new ValidationException("片段名不能为空"); } segment.TargetGpu = this.TargetGpu; segment.Name = this.Name; segment.Segment = this.Segment; segment.Description = this.Description; segment.IsDefault = this.IsDefault; bool isUpdate = !string.IsNullOrEmpty(_old.Name); if (isUpdate) { var existItem = coinKernelVm.InputSegments.FirstOrDefault(a => a.Name == _old.Name && a.Segment == _old.Segment); if (existItem != null) { existItem.Update(segment); } } else { coinKernelVm.InputSegments.Add(new InputSegment(segment)); } coinKernelVm.InputSegments = coinKernelVm.InputSegments.ToList(); VirtualRoot.Execute(new CloseWindowCommand(this.Id)); }); }
protected override void OnClosing(CancelEventArgs e) { foreach (var handler in _handlers) { VirtualRoot.UnPath(handler); } VirtualRoot.Execute(new ChangeAppSettingsCommand( new AppSettingData[] { new AppSettingData { Key = "FrozenColumnCount", Value = Vm.FrozenColumnCount }, new AppSettingData { Key = "MaxTemp", Value = Vm.MaxTemp }, new AppSettingData { Key = "MinTemp", Value = Vm.MinTemp }, new AppSettingData { Key = "RejectPercent", Value = Vm.RejectPercent } })); base.OnClosing(e); }
public ResponseBase AddOrUpdateKernelOutputKeyword(DataRequest <KernelOutputKeywordData> request) { if (request == null || request.Data == null) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!IsValidAdmin(request, out ResponseBase response)) { return(response); } if (request.Data.GetDataLevel() != DataLevel.Global) { return(ResponseBase.InvalidInput("添加到服务器的内核输出关键字记录的DataLevel属性必须赋值为Global")); } VirtualRoot.Execute(new AddOrUpdateKernelOutputKeywordCommand(request.Data)); WebApiRoot.UpdateKernelOutputKeywordTimestamp(DateTime.Now); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase ActiveControlCenterAdmin([FromBody] string password) { if (string.IsNullOrEmpty(password)) { return(ResponseBase.InvalidInput("密码不能为空")); } IUser user = HostRoot.Instance.UserSet.GetUser("admin"); if (user == null) { var userData = new UserData { LoginName = "admin", IsEnabled = true, Description = "群控初始用户", Password = password }; VirtualRoot.Execute(new AddUserCommand(userData)); return(ResponseBase.Ok()); } else { return(ResponseBase.Forbidden()); } }
public ServerMessageViewModel(Guid id) { _id = id; this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } VirtualRoot.Execute(new ServerMessageEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowDialog(new DialogWindowViewModel(message: $"您确定标记删除'{this.Content}'这条消息吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new MarkDeleteServerMessageCommand(this.Id)); })); }); this.Save = new DelegateCommand(() => { VirtualRoot.Execute(new AddOrUpdateServerMessageCommand(this)); CloseWindow?.Invoke(); }); }
public ColumnsShowViewModel(Guid id) { this.Id = id; this.Hide = new DelegateCommand <string>((propertyName) => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { propertyInfo.SetValue(this, false, null); } }); this.Edit = new DelegateCommand(() => { VirtualRoot.Execute(new EditColumnsShowCommand(this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { this.ShowSoftDialog(new DialogWindowViewModel(message: "该项不能删除", title: "警告", icon: "Icon_Error")); return; } this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除 “{this.ColumnsShowName}” 列分组吗?", title: "确认", onYes: () => { NTMinerContext.Instance.MinerStudioContext.ColumnsShowSet.Remove(this.Id); })); }); }
public StateBarViewModel() { if (WpfUtil.IsInDesignMode) { return; } UpdateDateTime(); this.WindowsAutoLogon = new DelegateCommand(() => { if (IsAutoAdminLogon) { return; } VirtualRoot.Execute(new EnableOrDisableWindowsAutoLoginCommand()); }); this.EnableRemoteDesktop = new DelegateCommand(() => { if (IsRemoteDesktopEnabled) { return; } VirtualRoot.Execute(new EnableRemoteDesktopCommand()); }); _localIps = VirtualRoot.FormatLocalIps(out string _); SetCheckUpdateForeground(isLatest: EntryAssemblyInfo.CurrentVersion >= NTMinerContext.ServerVersion); }
public ColumnsShowViewModel(Guid id) { this.Id = id; this.Hide = new DelegateCommand <string>((propertyName) => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { propertyInfo.SetValue(this, false, null); } }); this.Save = new DelegateCommand(() => { if (NTMinerRoot.Instance.ColumnsShowSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateColumnsShowCommand(this)); NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage($"保存成功"); } else { VirtualRoot.Execute(new AddColumnsShowCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { VirtualRoot.Execute(new ColumnsShowEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { this.ShowDialog(message: "该项不能删除", title: "警告", icon: "Icon_Error"); return; } this.ShowDialog(message: $"您确定删除{this.ColumnsShowName}吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveColumnsShowCommand(this.Id)); }, icon: IconConst.IconConfirm); }); }
private void ReportSpeed() { try { SpeedData data = CreateSpeedData(); RpcRoot.Server.ReportService.ReportSpeedAsync(NTKeyword.OfficialServerHost, data, response => { if (response.IsSuccess()) { AppVersionChangedEvent.PublishIfNewVersion(response.ServerState.MinerClientVersion); if (response.NewServerMessages.Count != 0) { VirtualRoot.Execute(new ReceiveServerMessageCommand(response.NewServerMessages)); } else { VirtualRoot.Execute(new LoadNewServerMessageCommand(response.ServerState.MessageTimestamp)); } VirtualRoot.Execute(new LoadKernelOutputKeywordCommand(response.ServerState.OutputKeywordTimestamp)); } }); } catch (Exception e) { Logger.ErrorDebugLine(e); } }
public OverClockDataViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } IOverClockData group; if (NTMinerRoot.Instance.OverClockDataSet.TryGetOverClockData(this.Id, out group)) { VirtualRoot.Execute(new UpdateOverClockDataCommand(this)); } else { VirtualRoot.Execute(new AddOverClockDataCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } VirtualRoot.Execute(new OverClockDataEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowDialog(message: $"您确定删除{this.Name}吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveOverClockDataCommand(this.Id)); }, icon: IconConst.IconConfirm); }); }
public void Refresh() { // 触发从远程加载数据的逻辑 VirtualRoot.Execute(new RefreshNTMinerFileSetCommand()); }
public CoinKernelSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <AddCoinKernelCommand>("添加币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicById.Values.Any(a => a.CoinId == message.Input.CoinId && a.KernelId == message.Input.KernelId)) { return; } CoinKernelData entity = new CoinKernelData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); repository.Add(entity); VirtualRoot.Happened(new CoinKernelAddedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(message.Input.CoinId, out coin)) { IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { Guid poolKernelId = Guid.NewGuid(); var poolKernel = new PoolKernelData() { Id = poolKernelId, Args = string.Empty, KernelId = message.Input.KernelId, PoolId = pool.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }); _root.ServerContextWindow <UpdateCoinKernelCommand>("更新币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } CoinKernelData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveCoinKernelCommand>("移除币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinKernelData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); repository.Remove(entity.Id); VirtualRoot.Happened(new CoinKernelRemovedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(entity.CoinId, out coin)) { List <Guid> toRemoves = new List <Guid>(); IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { foreach (PoolKernelData poolKernel in root.PoolKernelSet.Where(a => a.PoolId == pool.GetId() && a.KernelId == entity.KernelId)) { toRemoves.Add(poolKernel.Id); } } foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } } }); _root.ServerContextOn <FileWriterRemovedEvent>("移除文件书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); var entities = _dicById.Values.Where(a => a.FileWriterIds.Contains(message.Source.GetId())).ToArray(); foreach (var entity in entities) { entity.FileWriterIds = new List <Guid>(entity.FileWriterIds.Where(a => a != message.Source.GetId())); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); } }); _root.ServerContextOn <FragmentWriterRemovedEvent>("移除命令行片段书写器后移除引用关系", LogEnum.DevConsole, action: message => { var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(); var entities = _dicById.Values.Where(a => a.FragmentWriterIds.Contains(message.Source.GetId())).ToArray(); foreach (var entity in entities) { entity.FragmentWriterIds = new List <Guid>(entity.FragmentWriterIds.Where(a => a != message.Source.GetId())); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); } }); }
public SysDicSet(IServerContext context) { _context = context; context.AddCmdPath <AddSysDicCommand>(LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("dic code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicByCode.ContainsKey(message.Input.Code)) { throw new ValidationException("编码重复"); } SysDicData entity = new SysDicData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByCode.Add(entity.Code, entity); var repository = context.CreateServerRepository <SysDicData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new SysDicAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <UpdateSysDicCommand>(LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("sysDic code can't be null or empty"); } if (!_dicById.TryGetValue(message.Input.GetId(), out SysDicData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <SysDicData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new SysDicUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <RemoveSysDicCommand>(LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } SysDicData entity = _dicById[message.EntityId]; List <Guid> toRemoves = context.SysDicItemSet.GetSysDicItems(entity.Code).Select(a => a.GetId()).ToList(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveSysDicItemCommand(id)); } _dicById.Remove(entity.Id); if (_dicByCode.ContainsKey(entity.Code)) { _dicByCode.Remove(entity.Code); } var repository = context.CreateServerRepository <SysDicData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new SysDicRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public CoinKernelViewModel(Guid id) { _id = id; _environmentVariables = new List <EnvironmentVariable>(); this.AddEnvironmentVariable = new DelegateCommand(() => { EnvironmentVariableEdit.ShowWindow(this, new EnvironmentVariable()); }); this.EditEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => { EnvironmentVariableEdit.ShowWindow(this, environmentVariable); }); this.RemoveEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => { DialogWindow.ShowDialog(message: $"您确定删除环境变量{environmentVariable.Key}吗?", title: "确认", onYes: () => { this.EnvironmentVariables.Remove(environmentVariable); EnvironmentVariables = EnvironmentVariables.ToList(); }, icon: IconConst.IconConfirm); }); this.Save = new DelegateCommand(() => { if (NTMinerRoot.Current.CoinKernelSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { CoinKernelEdit.ShowWindow(formType ?? FormType.Edit, this); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } DialogWindow.ShowDialog(message: $"您确定删除{Kernel.Code}币种内核吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveCoinKernelCommand(this.Id)); Kernel.OnPropertyChanged(nameof(Kernel.SupportedCoins)); }, icon: IconConst.IconConfirm); }); this.SortUp = new DelegateCommand(() => { CoinKernelViewModel upOne = CoinKernelViewModels.Current.AllCoinKernels.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber < this.SortNumber); if (upOne != null) { int sortNumber = upOne.SortNumber; upOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(upOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(this.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels)); CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins)); } }); this.SortDown = new DelegateCommand(() => { CoinKernelViewModel nextOne = CoinKernelViewModels.Current.AllCoinKernels.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber > this.SortNumber); if (nextOne != null) { int sortNumber = nextOne.SortNumber; nextOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(nextOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(this.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels)); CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins)); } }); }
public MineWorkViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (string.IsNullOrEmpty(this.Name)) { NotiCenterWindowViewModel.Current.Manager.ShowErrorMessage("作业名称是必须的"); } bool isMinerProfileChanged = false; IMineWork entity; if (NTMinerRoot.Current.MineWorkSet.TryGetMineWork(this.Id, out entity)) { string sha1 = NTMinerRoot.Current.MinerProfile.GetSha1(); if (this.Sha1 != sha1) { isMinerProfileChanged = true; } if (entity.Name != this.Name || entity.Description != this.Description) { VirtualRoot.Execute(new UpdateMineWorkCommand(this)); } CloseWindow?.Invoke(); } else { isMinerProfileChanged = true; VirtualRoot.Execute(new AddMineWorkCommand(this)); CloseWindow?.Invoke(); this.Edit.Execute(FormType.Edit); } if (isMinerProfileChanged) { Write.DevLine("检测到MinerProfile状态变更"); string localJson; string serverJson; NTMinerRoot.ExportWorkJson(new MineWorkData(this), out localJson, out serverJson); if (!string.IsNullOrEmpty(localJson) && !string.IsNullOrEmpty(serverJson)) { Server.ControlCenterService.ExportMineWorkAsync(this.Id, localJson, serverJson, callback: null); } } }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } MineWorkViewModel mineWorkVm; if (!MineWorkViewModels.Current.TryGetMineWorkVm(this.Id, out mineWorkVm)) { InputWindow.ShowDialog("作业名称", 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 = Server.ControlCenterService.GetLocalJson(this.Id); if (!string.IsNullOrEmpty(json)) { File.WriteAllText(SpecialPath.LocalJsonFileFullName, json); } else { File.Delete(SpecialPath.LocalJsonFileFullName); } NTMinerRoot.Current.ReInitMinerProfile(); this.Sha1 = NTMinerRoot.Current.MinerProfile.GetSha1(); MineWorkEdit.ShowWindow(formType ?? FormType.Edit, new MineWorkViewModel(this)); } }, formType => { if (this == PleaseSelect) { return(false); } return(true); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } DialogWindow.ShowDialog(message: $"您确定删除吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveMineWorkCommand(this.Id)); }, icon: IconConst.IconConfirm); }, () => { if (this == PleaseSelect) { return(false); } return(true); }); }
public LocalMessagesViewModel() { if (WpfUtil.IsInDesignMode) { return; } foreach (var messageChannel in LocalMessageChannelEnumItems) { var values = new Dictionary <LocalMessageType, MessageTypeItem <LocalMessageType> >(); foreach (var messageType in NTMinerContext.LocalMessageTypeEnumItems) { values.Add(messageType.Value, new MessageTypeItem <LocalMessageType>(messageType, LocalMessageViewModel.GetIcon, LocalMessageViewModel.GetIconFill, RefreshQueryResults)); } _count.Add(messageChannel, values); } _selectedChannel = LocalMessageChannelEnumItems.FirstOrDefault(); Init(); this.ClearKeyword = new DelegateCommand(() => { this.Keyword = string.Empty; }); this.Clear = new DelegateCommand(() => { this.ShowSoftDialog(new DialogWindowViewModel(message: "确定清空吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new ClearLocalMessageSetCommand()); })); }); VirtualRoot.AddEventPath <LocalMessageSetClearedEvent>("清空本地消息集后刷新VM内存", LogEnum.DevConsole, action: message => { Init(); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalMessageAddedEvent>("发生了本地消息后刷新Vm内存", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { var vm = new LocalMessageViewModel(message.Source); _localMessageVms.Insert(0, vm); if (IsSatisfyQuery(vm)) { _queyResults.Insert(0, vm); } foreach (var item in message.Removes) { var toRemove = _localMessageVms.FirstOrDefault(a => a.Id == item.Id); if (toRemove != null) { _localMessageVms.Remove(toRemove); if (IsSatisfyQuery(toRemove)) { _queyResults.Remove(toRemove); } } } int removedCount = message.Removes.Count(a => a.MessageType == vm.MessageTypeEnum.GetName()); if (removedCount != 1) { _count[vm.ChannelEnum.GetEnumItem()][vm.MessageTypeEnum].Count += 1 - removedCount; UpdateChannelAll(); } OnPropertyChanged(nameof(IsNoRecord)); }); }, location: this.GetType()); VirtualRoot.AddEventPath <NewDayEvent>("新的一天到来时刷新消息集中的可读性时间戳展示", LogEnum.DevConsole, action: message => { if (QueryResults == null) { return; } foreach (var item in QueryResults) { if (item.Timestamp.Date.AddDays(3) >= message.BornOn.Date) { item.OnPropertyChanged(nameof(item.TimestampText)); } else { // 因为是按照时间倒叙排列的,所以可以break break; } } }, location: this.GetType()); }
public PoolSet(INTMinerRoot root) { _root = root; _root.ServerContextCmdPath <AddPoolCommand>("添加矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Server)) { throw new ValidationException("pool poolurl can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } PoolData entity = new PoolData().Update(message.Input); _dicById.Add(entity.Id, entity); if (VirtualRoot.IsMinerStudio) { Server.PoolService.AddOrUpdatePoolAsync(entity, callback: null); } else { var repository = NTMinerRoot.CreateCompositeRepository <PoolData>(); repository.Add(entity); } VirtualRoot.RaiseEvent(new PoolAddedEvent(entity)); if (root.CoinSet.TryGetCoin(message.Input.CoinId, out ICoin coin)) { ICoinKernel[] coinKernels = root.CoinKernelSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (ICoinKernel coinKernel in coinKernels) { Guid poolKernelId = Guid.NewGuid(); var poolKernel = new PoolKernelData() { Id = poolKernelId, Args = string.Empty, KernelId = coinKernel.KernelId, PoolId = message.Input.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }); _root.ServerContextCmdPath <UpdatePoolCommand>("更新矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Server)) { throw new ValidationException("pool poolurl can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("pool name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } PoolData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); if (VirtualRoot.IsMinerStudio) { Server.PoolService.AddOrUpdatePoolAsync(entity, callback: null); } else { var repository = NTMinerRoot.CreateCompositeRepository <PoolData>(); repository.Update(new PoolData().Update(message.Input)); } VirtualRoot.RaiseEvent(new PoolUpdatedEvent(entity)); }); _root.ServerContextCmdPath <RemovePoolCommand>("移除矿池", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } PoolData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (VirtualRoot.IsMinerStudio) { Server.PoolService.RemovePoolAsync(entity.Id, callback: null); } else { var repository = NTMinerRoot.CreateCompositeRepository <PoolData>(); repository.Remove(message.EntityId); } VirtualRoot.RaiseEvent(new PoolRemovedEvent(entity)); Guid[] toRemoves = root.PoolKernelSet.Where(a => a.PoolId == message.EntityId).Select(a => a.GetId()).ToArray(); foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } }); VirtualRoot.BuildEventPath <PoolDelayPickedEvent>("提取了矿池延时后记录进内存", LogEnum.DevConsole, action: message => { if (message.IsDual) { if (_poolDelayById.TryGetValue(message.PoolId, out PoolDelay poolDelay)) { poolDelay.DualCoinPoolDelayText = message.PoolDelayText; } else { _poolDelayById.Add(message.PoolId, new PoolDelay { MainCoinPoolDelayText = string.Empty, DualCoinPoolDelayText = message.PoolDelayText }); } } else { if (_poolDelayById.TryGetValue(message.PoolId, out PoolDelay poolDelay)) { poolDelay.MainCoinPoolDelayText = message.PoolDelayText; } else { _poolDelayById.Add(message.PoolId, new PoolDelay { MainCoinPoolDelayText = message.PoolDelayText, DualCoinPoolDelayText = string.Empty }); } } }); }
public SysDicItemViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (NTMinerRoot.Instance.SysDicItemSet.ContainsKey(this.Id)) { VirtualRoot.Execute(new UpdateSysDicItemCommand(this)); } else { VirtualRoot.Execute(new AddSysDicItemCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } VirtualRoot.Execute(new SysDicItemEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowDialog(message: $"您确定删除{this.Code}系统字典项吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveSysDicItemCommand(this.Id)); }, icon: IconConst.IconConfirm); }); this.SortUp = new DelegateCommand(() => { SysDicItemViewModel upOne = AppContext.Instance.SysDicItemVms.List.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber); if (upOne != null) { int sortNumber = upOne.SortNumber; upOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateSysDicItemCommand(upOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateSysDicItemCommand(this)); if (AppContext.Instance.SysDicVms.TryGetSysDicVm(this.DicId, out SysDicViewModel sysDicVm)) { sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems)); sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect)); } } }); this.SortDown = new DelegateCommand(() => { SysDicItemViewModel nextOne = AppContext.Instance.SysDicItemVms.List.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber); if (nextOne != null) { int sortNumber = nextOne.SortNumber; nextOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateSysDicItemCommand(nextOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateSysDicItemCommand(this)); if (AppContext.Instance.SysDicVms.TryGetSysDicVm(this.DicId, out SysDicViewModel sysDicVm)) { sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems)); sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect)); } } }); }
public ToolboxViewModel() { if (WpfUtil.IsInDesignMode) { return; } this.SwitchRadeonGpu = new DelegateCommand(() => { if (MinerProfileViewModel.Instance.IsMining) { VirtualRoot.Out.ShowInfo("请先停止挖矿"); return; } var config = new DialogWindowViewModel( isConfirmNo: true, btnNoToolTip: "注意:关闭计算模式挖矿算力会减半", message: $"过程大概需要花费5到10秒钟", title: "确认", onYes: () => { VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: true)); }, onNo: () => { VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: false)); return(true); }, btnYesText: "开启计算模式", btnNoText: "关闭计算模式"); this.ShowSoftDialog(config); }); this.AtikmdagPatcher = new DelegateCommand(() => { if (MinerProfileViewModel.Instance.IsMining) { VirtualRoot.Out.ShowInfo("请先停止挖矿"); return; } VirtualRoot.Execute(new AtikmdagPatcherCommand()); }); this.RegCmdHere = new DelegateCommand(() => { if (IsRegedCmdHere) { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定移除windows右键上下文菜单中的\"命令行\"菜单吗?", title: "确认", onYes: () => { Task.Factory.StartNew(() => { VirtualRoot.Execute(new UnRegCmdHereCommand()); OnPropertyChanged(nameof(IsRegedCmdHere)); }); }, btnYesText: "移除")); } else { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定在windows右键上下文菜单中添加\"命令行\"菜单吗?", title: "确认", onYes: () => { Task.Factory.StartNew(() => { this.IsWinCmdLoading = true; VirtualRoot.SetInterval(per: TimeSpan.FromMilliseconds(100), perCallback: () => { this.WinCmdLodingIconAngle += 30; }, stopCallback: () => { this.IsWinCmdLoading = false; OnPropertyChanged(nameof(IsRegedCmdHere)); }, timeout: TimeSpan.FromSeconds(6), requestStop: () => { return(IsRegedCmdHere); }); VirtualRoot.Execute(new RegCmdHereCommand()); }); }, btnYesText: "添加")); } }); this.BlockWAU = new DelegateCommand(() => { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定禁用Windows系统更新吗?禁用后可在Windows服务中找到Windows Update手动启用。", title: "确认", onYes: () => { VirtualRoot.Execute(new BlockWAUCommand()); }, helpUrl: "https://www.cnblogs.com/ntminer/p/12155769.html")); }); this.Win10Optimize = new DelegateCommand(() => { this.ShowSoftDialog(new DialogWindowViewModel(message: $"确定面向挖矿优化windows吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new Win10OptimizeCommand()); }, helpUrl: "https://www.cnblogs.com/ntminer/p/12155773.html")); }); this.EnableWindowsRemoteDesktop = new DelegateCommand(() => { VirtualRoot.Execute(new EnableWindowsRemoteDesktopCommand()); }); this.WindowsAutoLogon = new DelegateCommand(() => { VirtualRoot.Execute(new EnableOrDisableWindowsAutoLoginCommand()); }); this.OpenDevmgmt = new DelegateCommand(() => { Process.Start("devmgmt.msc"); }); this.OpenEventvwr = new DelegateCommand(() => { Process.Start("eventvwr.msc", "/c:Application"); }); }
public KernelOutputTranslaterViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { int sortNumber = this.SortNumber; if (NTMinerRoot.Current.KernelOutputTranslaterSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this)); } else { VirtualRoot.Execute(new AddKernelOutputTranslaterCommand(this)); } if (sortNumber != this.SortNumber) { if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm)) { kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters)); } } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { KernelOutputTranslaterEdit.ShowWindow(formType ?? FormType.Edit, this); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } DialogWindow.ShowDialog(message: $"您确定删除{this.RegexPattern}内核输出翻译器吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(this.Id)); }, icon: IconConst.IconConfirm); }); this.SortUp = new DelegateCommand(() => { KernelOutputTranslaterViewModel upOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelOutputId).OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber); if (upOne != null) { int sortNumber = upOne.SortNumber; upOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(upOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this)); KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms)); if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm)) { kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters)); } } }); this.SortDown = new DelegateCommand(() => { KernelOutputTranslaterViewModel nextOne = KernelOutputTranslaterViewModels.Current.GetListByKernelId(this.KernelOutputId).OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber); if (nextOne != null) { int sortNumber = nextOne.SortNumber; nextOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(nextOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateKernelOutputTranslaterCommand(this)); KernelOutputTranslaterViewModels.Current.OnPropertyChanged(nameof(KernelOutputTranslaterViewModels.AllKernelOutputTranslaterVms)); if (KernelOutputViewModels.Current.TryGetKernelOutputVm(this.KernelOutputId, out KernelOutputViewModel kernelOutputVm)) { kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters)); } } }); }
public CoinKernelViewModel(Guid id) { _id = id; this.AddEnvironmentVariable = new DelegateCommand(() => { VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, new EnvironmentVariable())); }); this.EditEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => { VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, environmentVariable)); }); this.RemoveEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => { this.ShowDialog(message: $"您确定删除环境变量{environmentVariable.Key}吗?", title: "确认", onYes: () => { this.EnvironmentVariables.Remove(environmentVariable); EnvironmentVariables = EnvironmentVariables.ToList(); }, icon: IconConst.IconConfirm); }); this.AddSegment = new DelegateCommand(() => { VirtualRoot.Execute(new InputSegmentEditCommand(this, new InputSegment())); }); this.EditSegment = new DelegateCommand <InputSegment>((segment) => { VirtualRoot.Execute(new InputSegmentEditCommand(this, segment)); }); this.RemoveSegment = new DelegateCommand <InputSegment>((segment) => { this.ShowDialog(message: $"您确定删除片段{segment.Name}吗?", title: "确认", onYes: () => { this.InputSegments.Remove(segment); InputSegments = InputSegments.ToList(); }, icon: IconConst.IconConfirm); }); this.RemoveFileWriter = new DelegateCommand <FileWriterViewModel>((writer) => { this.ShowDialog(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => { this.FileWriterVms.Remove(writer); List <Guid> writerIds = new List <Guid>(this.FileWriterIds); writerIds.Remove(writer.Id); this.FileWriterIds = writerIds; }, icon: IconConst.IconConfirm); }); this.RemoveFragmentWriter = new DelegateCommand <FragmentWriterViewModel>((writer) => { this.ShowDialog(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => { this.FragmentWriterVms.Remove(writer); List <Guid> writerIds = new List <Guid>(this.FragmentWriterIds); writerIds.Remove(writer.Id); this.FragmentWriterIds = writerIds; }, icon: IconConst.IconConfirm); }); this.Save = new DelegateCommand(() => { if (NTMinerRoot.Instance.CoinKernelSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { VirtualRoot.Execute(new CoinKernelEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowDialog(message: $"您确定删除{Kernel.Code}币种内核吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveCoinKernelCommand(this.Id)); Kernel.OnPropertyChanged(nameof(Kernel.SupportedCoins)); }, icon: IconConst.IconConfirm); }); this.SortUp = new DelegateCommand(() => { CoinKernelViewModel upOne = AppContext.Instance.CoinKernelVms.AllCoinKernels.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber < this.SortNumber); if (upOne != null) { int sortNumber = upOne.SortNumber; upOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(upOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins)); } }); this.SortDown = new DelegateCommand(() => { CoinKernelViewModel nextOne = AppContext.Instance.CoinKernelVms.AllCoinKernels.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber > this.SortNumber); if (nextOne != null) { int sortNumber = nextOne.SortNumber; nextOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(nextOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinKernelCommand(this)); if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins)); } }); }
public ServerMessagesViewModel() { if (WpfUtil.IsInDesignMode) { return; } foreach (var messageType in NTMinerContext.ServerMessageTypeEnumItems) { _count.Add(messageType.Value, new MessageTypeItem <ServerMessageType>(messageType, ServerMessageViewModel.GetIcon, ServerMessageViewModel.GetIconFill, RefreshQueryResults)); } Init(); this.Add = new DelegateCommand(() => { new ServerMessageViewModel(new ServerMessageData { Id = Guid.NewGuid(), MessageType = ServerMessageType.Info.GetName(), Provider = "admin", Content = string.Empty, Timestamp = DateTime.MinValue }).Edit.Execute(FormType.Add); }); this.ClearKeyword = new DelegateCommand(() => { this.Keyword = string.Empty; }); this.Clear = new DelegateCommand(() => { this.ShowSoftDialog(new DialogWindowViewModel(message: "确定清空吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new ClearServerMessages()); })); }); VirtualRoot.AddEventPath <ServerMessagesClearedEvent>("清空了本地存储的服务器消息后刷新Vm内存", LogEnum.DevConsole, action: message => { Init(); }, location: this.GetType()); VirtualRoot.AddEventPath <NewServerMessageLoadedEvent>("从服务器加载了新消息后刷新Vm内存", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { foreach (var item in message.Data) { var vm = new ServerMessageViewModel(item); var exist = _serverMessageVms.FirstOrDefault(a => a.Id == item.Id); if (exist != null) { _serverMessageVms.Remove(exist); if (item.IsDeleted) { _count[exist.MessageTypeEnum].Count--; } else { _serverMessageVms.Insert(0, vm); if (exist.MessageType != item.MessageType) { _count[exist.MessageTypeEnum].Count--; _count[vm.MessageTypeEnum].Count++; } } } else if (!vm.IsDeleted) { _serverMessageVms.Insert(0, vm); _count[vm.MessageTypeEnum].Count++; } if (IsSatisfyQuery(vm)) { exist = _queyResults.FirstOrDefault(a => a.Id == item.Id); if (exist != null) { _queyResults.Remove(exist); } if (!vm.IsDeleted) { _queyResults.Insert(0, vm); } } } OnPropertyChanged(nameof(IsNoRecord)); }); }, location: this.GetType()); VirtualRoot.AddEventPath <NewDayEvent>("新的一天到来时刷新消息集中的可读性时间戳展示", LogEnum.DevConsole, action: message => { if (QueryResults == null) { return; } foreach (var item in QueryResults) { if (item.Timestamp.Date.AddDays(3) >= message.BornOn.Date) { item.OnPropertyChanged(nameof(item.TimestampText)); } else { // 因为是按照时间倒叙排列的,所以可以break break; } } }, location: this.GetType()); }
public MinerGroupViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (RpcRoot.IsOuterNet) { RpcRoot.OfficialServer.UserMinerGroupService.AddOrUpdateMinerGroupAsync(new MinerGroupData().Update(this), (response, e) => { if (response.IsSuccess()) { if (MinerStudioRoot.MinerGroupVms.TryGetMineWorkVm(this.Id, out MinerGroupViewModel vm)) { VirtualRoot.RaiseEvent(new MinerGroupUpdatedEvent(Guid.Empty, this)); } else { VirtualRoot.RaiseEvent(new MinerGroupAddedEvent(Guid.Empty, this)); } VirtualRoot.Execute(new CloseWindowCommand(this.Id)); } }); } else { if (NTMinerContext.MinerStudioContext.MinerGroupSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateMinerGroupCommand(this)); } else { VirtualRoot.Execute(new AddMinerGroupCommand(this)); } VirtualRoot.Execute(new CloseWindowCommand(this.Id)); } }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } VirtualRoot.Execute(new EditMinerGroupCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除 “{this.Name}” 矿机分组吗?", title: "确认", onYes: () => { if (RpcRoot.IsOuterNet) { RpcRoot.OfficialServer.UserMinerGroupService.RemoveMinerGroupAsync(this.Id, (response, e) => { if (response.IsSuccess()) { VirtualRoot.RaiseEvent(new MinerGroupRemovedEvent(PathId.Empty, this)); } }); } else { VirtualRoot.Execute(new RemoveMinerGroupCommand(this.Id)); } })); }); }
public KernelOutputSet(IServerContext context) { _context = context; #region 接线 context.AddCmdPath <AddKernelOutputCommand>("添加内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputData entity = new KernelOutputData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = context.CreateServerRepository <KernelOutputData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelOutputAddedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <UpdateKernelOutputCommand>("更新内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException($"{nameof(message.Input.Name)} can't be null or empty"); } if (!_dicById.TryGetValue(message.Input.GetId(), out KernelOutputData entity)) { return; } if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = context.CreateServerRepository <KernelOutputData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelOutputUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); context.AddCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } IKernel[] outputUses = context.KernelSet.AsEnumerable().Where(a => a.KernelOutputId == message.EntityId).ToArray(); if (outputUses.Length != 0) { throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUses.Select(a => a.GetFullName()))}"); } KernelOutputData entity = _dicById[message.EntityId]; List <Guid> kernelOutputTranslaterIds = context.KernelOutputTranslaterSet.AsEnumerable().Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds) { VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId)); } _dicById.Remove(entity.GetId()); var repository = context.CreateServerRepository <KernelOutputData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new KernelOutputRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); #endregion }
public CoinViewModel(Guid id) { _id = id; _coinIncomeVm = new CoinIncomeViewModel(this); this.BrowseIcon = new DelegateCommand(() => { if (!DevMode.IsDevMode) { return; } OpenFileDialog openFileDialog = new OpenFileDialog { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Filter = "png (*.png)|*.png", FilterIndex = 1 }; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { string iconFileFullName = openFileDialog.FileName; this.IconImageSource = new Uri(iconFileFullName, UriKind.Absolute).ToString(); string pngFileName = Path.GetFileName(iconFileFullName); if (AppContext.Instance.CoinVms.AllCoins.Any(a => a.Icon == pngFileName && a.Id != this.Id)) { throw new ValidationException("币种图标不能重名"); } this.Icon = pngFileName; } catch (Exception e) { Logger.ErrorDebugLine(e); } } }); this.ApplyTemplateOverClock = new DelegateCommand <OverClockDataViewModel>((data) => { this.ShowDialog(message: data.Tooltip, title: "确定应用该超频设置吗?", onYes: () => { FillOverClock(data); ApplyOverClock(); }, icon: IconConst.IconConfirm); }); this.ApplyCustomOverClock = new DelegateCommand(() => { this.ShowDialog(message: $"确定应用您的自定义超频吗?", title: "确认自定义超频", onYes: () => { ApplyOverClock(); }, icon: IconConst.IconConfirm); }); this.RestoreOverClock = new DelegateCommand(() => { this.ShowDialog(message: $"确定恢复默认并禁用超频界面吗?", title: "确认", onYes: () => { NTMinerRoot.Instance.GpuSet.OverClock.Restore(); this.IsOverClockEnabled = false; }, icon: IconConst.IconConfirm); }); this.FillOverClockForm = new DelegateCommand <OverClockDataViewModel>((data) => { FillOverClock(data); }); this.FillOverClockForms = new DelegateCommand(() => { this.ShowDialog(message: "确定将统一超频的数据一键填充到每张卡吗?", title: "一键填充表单", onYes: () => { var data = GpuAllProfileVm; foreach (var item in GpuProfileVms) { if (item.Index == NTMinerRoot.GpuAllId) { continue; } item.Update((IOverClockInput)data); } }, icon: IconConst.IconConfirm); }); this.AddOverClockData = new DelegateCommand(() => { new OverClockDataViewModel(Guid.NewGuid()) { CoinId = this.Id }.Edit.Execute(FormType.Add); }); this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (NTMinerRoot.Instance.CoinSet.Contains(this.Id)) { VirtualRoot.Execute(new UpdateCoinCommand(this)); } else { VirtualRoot.Execute(new AddCoinCommand(this)); } CloseWindow?.Invoke(); }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } VirtualRoot.Execute(new CoinEditCommand(formType ?? FormType.Edit, this)); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowDialog(message: $"您确定删除{this.Code}币种吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveCoinCommand(this.Id)); }, icon: IconConst.IconConfirm); }); this.SortUp = new DelegateCommand(() => { CoinViewModel upOne = AppContext.Instance.CoinVms.AllCoins.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber); if (upOne != null) { int sortNumber = upOne.SortNumber; upOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinCommand(upOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinCommand(this)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.AllCoins)); } }); this.SortDown = new DelegateCommand(() => { CoinViewModel nextOne = AppContext.Instance.CoinVms.AllCoins.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber); if (nextOne != null) { int sortNumber = nextOne.SortNumber; nextOne.SortNumber = this.SortNumber; VirtualRoot.Execute(new UpdateCoinCommand(nextOne)); this.SortNumber = sortNumber; VirtualRoot.Execute(new UpdateCoinCommand(this)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins)); AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.AllCoins)); } }); this.AddPool = new DelegateCommand(() => { int sortNumber = this.Pools.Count == 0 ? 1 : this.Pools.Max(a => a.SortNumber) + 1; new PoolViewModel(Guid.NewGuid()) { CoinId = Id, SortNumber = sortNumber }.Edit.Execute(FormType.Add); }); this.AddWallet = new DelegateCommand(() => { int sortNumber = this.Wallets.Count == 0 ? 1 : this.Wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(Guid.NewGuid()) { CoinId = Id, SortNumber = sortNumber }.Edit.Execute(FormType.Add); }); }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Restart(); #endif UIThread.StartTimer(); InitializeComponent(); NTMinerRoot.RefreshArgsAssembly.Invoke(); if (Design.IsInDesignMode) { return; } this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } }; this.SizeChanged += (object sender, SizeChangedEventArgs e) => { if (e.WidthChanged) { const double width = 800; if (e.NewSize.Width < width) { Collapse(); } else if (e.NewSize.Width >= width) { Expand(); } } }; this.ConsoleRectangle.SizeChanged += (object sender, SizeChangedEventArgs e) => { ReSizeConsoleWindow(); }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += changeNotiCenterWindowLocation; this.LocationChanged += changeNotiCenterWindowLocation; if (DevMode.IsDevMode) { this.On <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = Vm.GetServerJsonVersion(); }); }); } this.On <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.On <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.GetIsAutoNoUi() && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.GetAutoNoUiMinutes()) < message.Timestamp) { VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.GetAutoNoUiMinutes()}分钟后自动切换为无界面模式,可在选项页调整配置")); } } Vm.RefreshDaemonStateBrush(); }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public ServerMessageSet(string dbFileFullName, bool isServer) { if (!string.IsNullOrEmpty(dbFileFullName)) { _connectionString = $"filename={dbFileFullName};journal=false"; } _isServer = isServer; if (!_isServer) { VirtualRoot.BuildCmdPath <LoadNewServerMessageCommand>(action: message => { DateTime localTimestamp = VirtualRoot.LocalServerMessageSetTimestamp; // 如果已知服务器端最新消息的时间戳不比本地已加载的最新消息新就不用加载了 if (message.KnowServerMessageTimestamp <= Timestamp.GetTimestamp(localTimestamp)) { return; } OfficialServer.ServerMessageService.GetServerMessagesAsync(localTimestamp, (response, e) => { if (response.IsSuccess() && response.Data.Count > 0) { LinkedList <ServerMessageData> data = new LinkedList <ServerMessageData>(); lock (_locker) { DateTime maxTime = localTimestamp; foreach (var item in response.Data.OrderBy(a => a.Timestamp)) { if (item.Timestamp > maxTime) { maxTime = item.Timestamp; } data.AddLast(item); _linkedList.AddFirst(item); } if (maxTime != localTimestamp) { VirtualRoot.LocalServerMessageSetTimestamp = maxTime; } } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); foreach (var item in data) { col.Insert(item); } } VirtualRoot.RaiseEvent(new NewServerMessageLoadedEvent(data)); } }); }); } VirtualRoot.BuildCmdPath <AddOrUpdateServerMessageCommand>(action: message => { if (string.IsNullOrEmpty(_connectionString)) { return; } InitOnece(); if (_isServer) { #region Server ServerMessageData exist; List <ServerMessageData> toRemoves = new List <ServerMessageData>(); ServerMessageData data = null; lock (_locker) { exist = _linkedList.FirstOrDefault(a => a.Id == message.Input.Id); if (exist != null) { DateTime timestamp = exist.Timestamp; exist.Update(message.Input); // 如果更新前后时间戳没有变化则自动变更时间戳 if (timestamp == exist.Timestamp) { exist.Timestamp = DateTime.Now; } } else { data = new ServerMessageData(message.Input); _linkedList.AddFirst(data); while (_linkedList.Count > NTKeyword.ServerMessageSetCapacity) { toRemoves.Add(_linkedList.Last.Value); _linkedList.RemoveLast(); } } } if (exist != null) { using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); col.Update(exist); } } else { using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); if (toRemoves.Count != 0) { foreach (var item in toRemoves) { col.Delete(item.Id); } } col.Insert(data); } } #endregion } else { OfficialServer.ServerMessageService.AddOrUpdateServerMessageAsync(new ServerMessageData(message.Input), (response, ex) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadNewServerMessageCommand()); } }); } }); VirtualRoot.BuildCmdPath <MarkDeleteServerMessageCommand>(action: message => { if (string.IsNullOrEmpty(_connectionString)) { return; } InitOnece(); if (_isServer) { #region Server ServerMessageData exist = null; lock (_locker) { exist = _linkedList.FirstOrDefault(a => a.Id == message.EntityId); if (exist != null) { exist.IsDeleted = true; exist.Timestamp = DateTime.Now; } } if (exist != null) { using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); col.Update(exist); } } #endregion } else { OfficialServer.ServerMessageService.MarkDeleteServerMessageAsync(message.EntityId, (response, ex) => { VirtualRoot.Execute(new LoadNewServerMessageCommand()); }); } }); VirtualRoot.BuildCmdPath <ClearServerMessages>(action: message => { if (string.IsNullOrEmpty(_connectionString)) { return; } InitOnece(); // 服务端不应有清空消息的功能 if (_isServer) { return; } using (LiteDatabase db = new LiteDatabase(_connectionString)) { lock (_locker) { _linkedList.Clear(); } db.DropCollection(nameof(ServerMessageData)); } VirtualRoot.RaiseEvent(new ServerMessagesClearedEvent()); }); }