private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } VirtualRoot.AddCmdPath <StopMineCommand>(action: message => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerContext.IsAutoStartCanceled = true; NTMinerContext.Instance.StopMineAsync(StopMineReason.LocalUserAction, () => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }, this.GetType(), LogEnum.DevConsole); this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); NTMinerContext.Instance.StartMine(); }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动停止挖矿", toConsole: true); VirtualRoot.Execute(new StopMineCommand()); }); }
public LocalMessageSet(string dbFileFullName) { if (!string.IsNullOrEmpty(dbFileFullName)) { _connectionString = $"filename={dbFileFullName};journal=false"; } VirtualRoot.AddCmdPath <AddLocalMessageCommand>(action: message => { if (string.IsNullOrEmpty(_connectionString)) { return; } InitOnece(); var data = LocalMessageData.Create(message.Input); // TODO:批量持久化,异步持久化 List <ILocalMessage> removes = new List <ILocalMessage>(); lock (_locker) { _records.AddFirst(data); while (_records.Count > NTKeyword.LocalMessageSetCapacity) { var toRemove = _records.Last; removes.Add(toRemove.Value); _records.RemoveLast(); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <LocalMessageData>(); col.Delete(toRemove.Value.Id); } } } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <LocalMessageData>(); col.Insert(data); } VirtualRoot.RaiseEvent(new LocalMessageAddedEvent(message.Id, data, removes)); }, location: this.GetType()); VirtualRoot.AddCmdPath <ClearLocalMessageSetCommand>(action: message => { if (string.IsNullOrEmpty(_connectionString)) { return; } lock (_locker) { _records.Clear(); } using (LiteDatabase db = new LiteDatabase(_connectionString)) { db.DropCollection(nameof(LocalMessageData)); } VirtualRoot.RaiseEvent(new LocalMessageSetClearedEvent()); }, location: this.GetType()); }
public AbstractAppViewFactory() { VirtualRoot.AddCmdPath <CloseNTMinerCommand>(action: message => { // 不能推迟这个日志记录的时机,因为推迟会有windows异常日志 VirtualRoot.ThisLocalInfo(nameof(AbstractAppViewFactory), $"退出{VirtualRoot.AppName}。原因:{message.Reason}"); UIThread.Execute(() => { try { Application.Current.Shutdown(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); Environment.Exit(0); } }); }, location: typeof(AbstractAppViewFactory)); }
public LocalMessageSet() { if (ClientAppType.IsMinerClient) { LocalMessageDtoSet = new LocalMessageDtoSet(); } VirtualRoot.AddCmdPath <AddLocalMessageCommand>(action: message => { InitOnece(); var data = LocalMessageData.Create(message.Input); List <ILocalMessage> removeds = new List <ILocalMessage>(); lock (_locker) { _records.AddFirst(data); _dbToInserts.Add(data); while (_records.Count > NTKeyword.LocalMessageSetCapacity) { var toRemove = _records.Last.Value; removeds.Add(toRemove); _records.RemoveLast(); } _dbToRemoveIds.AddRange(removeds.Select(a => a.Id)); } LocalMessageDtoSet.Add(data.ToDto()); VirtualRoot.RaiseEvent(new LocalMessageAddedEvent(message.MessageId, data, removeds)); }, location: this.GetType()); VirtualRoot.AddCmdPath <ClearLocalMessageSetCommand>(action: message => { lock (_locker) { _records.Clear(); _dbToRemoveIds.Clear(); _dbToInserts.Clear(); } try { using (LiteDatabase db = new LiteDatabase(ConnString)) { db.DropCollection(nameof(LocalMessageData)); } } catch (Exception e) { Logger.ErrorDebugLine(e); } VirtualRoot.RaiseEvent(new LocalMessageSetClearedEvent()); }, location: this.GetType()); VirtualRoot.AddEventPath <Per1MinuteEvent>("周期保存LocalMessage到数据库", LogEnum.DevConsole, action: message => { SaveToDb(); }, this.GetType()); VirtualRoot.AddEventPath <AppExitEvent>("程序退出时保存LocalMessage到数据库", LogEnum.DevConsole, action: message => { SaveToDb(); }, this.GetType()); }
public MineWorkSet() { VirtualRoot.AddEventPath <MinerStudioServiceSwitchedEvent>("切换了群口后台服务类型后刷新内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); _isInited = false; // 初始化以触发MineWorkSetInitedEvent事件 InitOnece(); }, this.GetType()); VirtualRoot.AddCmdPath <AddMineWorkCommand>(action: message => { InitOnece(); if (!_dicById.ContainsKey(message.Input.Id)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); var data = new MineWorkData().Update(message.Input); data.CreatedOn = DateTime.Now; _dicById.Add(data.Id, data); repository.Add(data); VirtualRoot.RaiseEvent(new MineWorkAddedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <UpdateMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.Input.Id, out MineWorkData data)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); data.Update(message.Input); data.ModifiedOn = DateTime.Now; repository.Update(data); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <RemoveMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.EntityId, out MineWorkData entity)) { _dicById.Remove(message.EntityId); var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); repository.Remove(message.EntityId); MinerStudioPath.DeleteMineWorkFiles(message.EntityId); VirtualRoot.RaiseEvent(new MineWorkRemovedEvent(message.MessageId, entity)); } }, this.GetType()); }
public UserSet(string dbFileFullName) { _dbFileFullName = dbFileFullName; VirtualRoot.AddCmdPath <AddUserCommand>(action: message => { if (!_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = new UserData(message.User); _dicByLoginName.Add(message.User.LoginName, entity); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Insert(entity); } VirtualRoot.RaiseEvent(new UserAddedEvent(message.MessageId, entity)); } }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateUserCommand>(action: message => { if (_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = _dicByLoginName[message.User.LoginName]; entity.Update(message.User); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Update(entity); } VirtualRoot.RaiseEvent(new UserUpdatedEvent(message.MessageId, entity)); } }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveUserCommand>(action: message => { if (_dicByLoginName.ContainsKey(message.LoginName)) { UserData entity = _dicByLoginName[message.LoginName]; _dicByLoginName.Remove(entity.LoginName); using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) { var col = db.GetCollection <UserData>(); col.Delete(message.LoginName); } VirtualRoot.RaiseEvent(new UserRemovedEvent(message.MessageId, entity)); } }, location: this.GetType()); }
private StartStopMineButtonViewModel() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG NTStopwatch.Start(); #endif VirtualRoot.AddCmdPath <StopMineCommand>(action: message => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerContext.IsAutoStartCanceled = true; NTMinerContext.Instance.StopMineAsync(StopMineReason.LocalUserAction, () => { if (!NTMinerContext.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }, this.GetType(), LogEnum.DevConsole); this.StartMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动开始挖矿", toConsole: true); NTMinerContext.Instance.StartMine(); }); this.StopMine = new DelegateCommand(() => { VirtualRoot.ThisLocalInfo(nameof(StartStopMineButtonViewModel), $"手动停止挖矿", toConsole: true); VirtualRoot.Execute(new StopMineCommand()); }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MineWorkSet() { VirtualRoot.AddCmdPath <AddMineWorkCommand>(action: message => { InitOnece(); if (!_dicById.ContainsKey(message.Input.Id)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); var data = new MineWorkData().Update(message.Input); data.CreatedOn = DateTime.Now; _dicById.Add(data.Id, data); repository.Add(data); VirtualRoot.RaiseEvent(new MineWorkAddedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <UpdateMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.Input.Id, out MineWorkData data)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); data.Update(message.Input); data.ModifiedOn = DateTime.Now; repository.Update(data); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <RemoveMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.EntityId, out MineWorkData entity)) { _dicById.Remove(message.EntityId); var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); repository.Remove(message.EntityId); MinerStudioPath.DeleteMineWorkFiles(message.EntityId); VirtualRoot.RaiseEvent(new MineWorkRemovedEvent(message.MessageId, entity)); } }, this.GetType()); }
public GpuProfileSet(INTMinerContext root) { VirtualRoot.AddCmdPath <AddOrUpdateGpuProfileCommand>(action: message => { GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index); if (data != null) { data.Update(message.Input); Save(); } else { data = new GpuProfileData().Update(message.Input); _data.GpuProfiles.Add(data); Save(); } VirtualRoot.RaiseEvent(new GpuProfileAddedOrUpdatedEvent(message.MessageId, data)); }, location: this.GetType()); VirtualRoot.AddCmdPath <CoinOverClockCommand>(action: message => { Task.Factory.StartNew(() => { CoinOverClock(root, message.CoinId); VirtualRoot.RaiseEvent(new CoinOverClockDoneEvent(targetPathId: message.MessageId)); }); }, location: this.GetType()); }
public KernelOutputKeywordSet(string dbFileFullName, bool isServer) { if (string.IsNullOrEmpty(dbFileFullName)) { throw new ArgumentNullException(nameof(dbFileFullName)); } _connectionString = $"filename={dbFileFullName}"; _isServer = isServer; if (!isServer) { VirtualRoot.AddCmdPath <LoadKernelOutputKeywordCommand>(action: message => { DateTime localTimestamp = VirtualRoot.LocalKernelOutputKeywordSetTimestamp; // 如果已知服务器端最新内核输出关键字时间戳不比本地已加载的最新内核输出关键字时间戳新就不用加载了 if (message.KnowKernelOutputKeywordTimestamp <= Timestamp.GetTimestamp(localTimestamp)) { return; } RpcRoot.OfficialServer.KernelOutputKeywordService.GetKernelOutputKeywords((response, e) => { if (response.IsSuccess()) { KernelOutputKeywordData[] toRemoves = _dicById.Where(a => a.Value.GetDataLevel() == DataLevel.Global).Select(a => a.Value).ToArray(); foreach (var item in toRemoves) { _dicById.Remove(item.Id); if (_dicByKernelOutputId.TryGetValue(item.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(item); } } if (response.Data.Count != 0) { foreach (var item in response.Data) { item.SetDataLevel(DataLevel.Global); _dicById.Add(item.Id, item); if (!_dicByKernelOutputId.TryGetValue(item.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(item.KernelOutputId, list); } list.Add(item); } if (response.Timestamp != Timestamp.GetTimestamp(localTimestamp)) { VirtualRoot.LocalKernelOutputKeywordSetTimestamp = Timestamp.FromTimestamp(response.Timestamp); } CacheServerKernelOutputKeywords(response.Data); VirtualRoot.RaiseEvent(new KernelOutputKeywordLoadedEvent(response.Data)); } } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); } VirtualRoot.AddCmdPath <AddOrUpdateKernelOutputKeywordCommand>(action: (message) => { InitOnece(); if (isServer || !DevMode.IsDevMode) { DataLevel dataLevel = isServer ? DataLevel.Global : DataLevel.Profile; if (_dicById.TryGetValue(message.Input.GetId(), out KernelOutputKeywordData exist)) { exist.Update(message.Input); exist.SetDataLevel(dataLevel); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Update(exist); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordUpdatedEvent(message.MessageId, exist)); } } else { KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input); entity.SetDataLevel(dataLevel); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list = new List <IKernelOutputKeyword>(); _dicByKernelOutputId.Add(entity.KernelOutputId, list); } list.Add(entity); using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Insert(entity); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordAddedEvent(message.MessageId, entity)); } } } else if (DevMode.IsDevMode) { message.Input.SetDataLevel(DataLevel.Global); RpcRoot.OfficialServer.KernelOutputKeywordService.AddOrUpdateKernelOutputKeywordAsync(KernelOutputKeywordData.Create(message.Input), (response, e) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadKernelOutputKeywordCommand()); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); } }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveKernelOutputKeywordCommand>(action: (message) => { InitOnece(); if (isServer || !DevMode.IsDevMode) { if (message == null || message.EntityId == Guid.Empty) { return; } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputKeywordData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); if (_dicByKernelOutputId.TryGetValue(entity.KernelOutputId, out List <IKernelOutputKeyword> list)) { list.Remove(entity); } using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <KernelOutputKeywordData>(); col.Delete(message.EntityId); } if (!isServer) { VirtualRoot.RaiseEvent(new UserKernelOutputKeywordRemovedEvent(message.MessageId, entity)); } } else if (DevMode.IsDevMode) { RpcRoot.OfficialServer.KernelOutputKeywordService.RemoveKernelOutputKeyword(message.EntityId, (response, e) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadKernelOutputKeywordCommand()); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); } }, location: this.GetType()); }
public override void Link() { var location = this.GetType(); VirtualRoot.AddCmdPath <ShowDialogWindowCommand>(action: message => { UIThread.Execute(() => { DialogWindow.ShowSoftDialog(new DialogWindowViewModel(message: message.Message, title: message.Title, onYes: message.OnYes, icon: message.Icon)); }); }, location: location); VirtualRoot.AddCmdPath <ShowQQGroupQrCodeCommand>(action: message => { UIThread.Execute(() => { QQGroupQrCode.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowCalcCommand>(action: message => { UIThread.Execute(() => { Calc.ShowWindow(message.CoinVm); }); }, location: location); VirtualRoot.AddCmdPath <ShowLocalIpsCommand>(action: message => { UIThread.Execute(() => { LocalIpConfig.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowEthNoDevFeeCommand>(action: message => { UIThread.Execute(() => { EthNoDevFeeEdit.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowCalcConfigCommand>(action: message => { UIThread.Execute(() => { CalcConfig.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowMinerClientsWindowCommand>(action: message => { UIThread.Execute(() => { MinerClientsWindow.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowNTMinerUpdaterConfigCommand>(action: message => { UIThread.Execute(() => { NTMinerUpdaterConfig.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowAboutPageCommand>(action: message => { UIThread.Execute(() => { AboutPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowKernelOutputPageCommand>(action: message => { UIThread.Execute(() => { KernelOutputPage.ShowWindow(message.SelectedKernelOutputVm); }); }, location: location); VirtualRoot.AddCmdPath <ShowKernelInputPageCommand>(action: message => { UIThread.Execute(() => { KernelInputPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowTagBrandCommand>(action: message => { if (NTMinerRoot.IsBrandSpecified) { return; } UIThread.Execute(() => { BrandTag.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowCoinPageCommand>(action: message => { UIThread.Execute(() => { CoinPage.ShowWindow(message.CurrentCoin, message.TabType); }); }, location: location); VirtualRoot.AddCmdPath <ShowGroupPageCommand>(action: message => { UIThread.Execute(() => { GroupPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowSysDicPageCommand>(action: message => { UIThread.Execute(() => { SysDicPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowVirtualMemoryCommand>(action: message => { UIThread.Execute(() => { VirtualMemory.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowRestartWindowsCommand>(action: message => { UIThread.Execute(() => { RestartWindows.ShowDialog(); }); }, location: location); VirtualRoot.AddCmdPath <ShowNotificationSampleCommand>(action: message => { UIThread.Execute(() => { NotificationSample.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowPropertyCommand>(action: message => { UIThread.Execute(() => { Property.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowChartsWindowCommand>(action: message => { UIThread.Execute(() => { ChartsWindow.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowOverClockDataPageCommand>(action: message => { UIThread.Execute(() => { OverClockDataPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowNTMinerWalletPageCommand>(action: message => { UIThread.Execute(() => { NTMinerWalletPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowMessagePathIdsCommand>(action: message => { UIThread.Execute(() => { MessagePathIds.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowUserPageCommand>(action: message => { UIThread.Execute(() => { UserPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowRemoteDesktopLoginDialogCommand>(action: message => { UIThread.Execute(() => { RemoteDesktopLogin.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.AddCmdPath <ShowKernelsWindowCommand>(action: message => { UIThread.Execute(() => { KernelsWindow.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <ShowKernelDownloaderCommand>(action: message => { UIThread.Execute(() => { KernelDownloading.ShowWindow(message.KernelId, message.DownloadComplete); }); }, location: location); VirtualRoot.AddCmdPath <EnvironmentVariableEditCommand>(action: message => { UIThread.Execute(() => { EnvironmentVariableEdit.ShowWindow(message.CoinKernelVm, message.EnvironmentVariable); }); }, location: location); VirtualRoot.AddCmdPath <InputSegmentEditCommand>(action: message => { UIThread.Execute(() => { InputSegmentEdit.ShowWindow(message.CoinKernelVm, message.Segment); }); }, location: location); VirtualRoot.AddCmdPath <CoinKernelEditCommand>(action: message => { UIThread.Execute(() => { CoinKernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <CoinEditCommand>(action: message => { UIThread.Execute(() => { CoinEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ColumnsShowEditCommand>(action: message => { UIThread.Execute(() => { ColumnsShowEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ShowSpeedChartsCommand>(action: message => { UIThread.Execute(() => { SpeedCharts.ShowWindow(message.GpuSpeedVm); }); }, location: location); VirtualRoot.AddCmdPath <ShowFileWriterPageCommand>(action: message => { UIThread.Execute(() => { FileWriterPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <FileWriterEditCommand>(action: message => { UIThread.Execute(() => { FileWriterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ShowFragmentWriterPageCommand>(action: message => { UIThread.Execute(() => { FragmentWriterPage.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <FragmentWriterEditCommand>(action: message => { UIThread.Execute(() => { FragmentWriterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <GroupEditCommand>(action: message => { UIThread.Execute(() => { GroupEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ServerMessageEditCommand>(action: message => { UIThread.Execute(() => { ServerMessageEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <KernelInputEditCommand>(action: message => { UIThread.Execute(() => { KernelInputEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <KernelOutputKeywordEditCommand>(action: message => { UIThread.Execute(() => { KernelOutputKeywordEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <KernelOutputTranslaterEditCommand>(action: message => { UIThread.Execute(() => { KernelOutputTranslaterEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <KernelOutputEditCommand>(action: message => { UIThread.Execute(() => { KernelOutputEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ShowPackagesWindowCommand>(action: message => { UIThread.Execute(() => { PackagesWindow.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <KernelEditCommand>(action: message => { UIThread.Execute(() => { KernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ShowMinerClientSettingCommand>(action: message => { UIThread.Execute(() => { MinerClientSetting.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.AddCmdPath <ShowMinerNamesSeterCommand>(action: message => { UIThread.Execute(() => { MinerNamesSeter.ShowWindow(message.Vm); }); }, location: location); VirtualRoot.AddCmdPath <ShowGpuProfilesPageCommand>(action: message => { UIThread.Execute(() => { GpuProfilesPage.ShowWindow(message.MinerClientsWindowVm); }); }, location: location); VirtualRoot.AddCmdPath <ShowMinerClientAddCommand>(action: message => { UIThread.Execute(() => { MinerClientAdd.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <MinerGroupEditCommand>(action: message => { UIThread.Execute(() => { MinerGroupEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <NTMinerWalletEditCommand>(action: message => { UIThread.Execute(() => { NTMinerWalletEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <MineWorkEditCommand>(action: message => { UIThread.Execute(() => { MineWorkEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <OverClockDataEditCommand>(action: message => { UIThread.Execute(() => { OverClockDataEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <PackageEditCommand>(action: message => { UIThread.Execute(() => { PackageEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <PoolKernelEditCommand>(action: message => { UIThread.Execute(() => { PoolKernelEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <PoolEditCommand>(action: message => { UIThread.Execute(() => { PoolEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <SysDicItemEditCommand>(action: message => { UIThread.Execute(() => { SysDicItemEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <SysDicEditCommand>(action: message => { UIThread.Execute(() => { SysDicEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <ShowKernelOutputKeywordsCommand>(action: message => { UIThread.Execute(() => { KernelOutputKeywords.ShowWindow(); }); }, location: location); VirtualRoot.AddCmdPath <UserEditCommand>(action: message => { UIThread.Execute(() => { UserEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); VirtualRoot.AddCmdPath <WalletEditCommand>(action: message => { UIThread.Execute(() => { WalletEdit.ShowWindow(message.FormType, message.Source); }); }, location: location); }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } if (!NTMinerConsole.IsEnabled) { NTMinerConsole.Enable(); } this.Vm = new MainWindowViewModel(); this.DataContext = Vm; this.MinHeight = 430; this.MinWidth = 640; this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; this.Owner = ConsoleWindow.Instance; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { ConsoleTabItemTopBorder.Margin = new Thickness(0, ConsoleTabItem.ActualHeight - 1, 0, 0); MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnOverClockBackground = BtnOverClock.Background; // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainTabControl.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } RpcRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } if (selectedItem == ConsoleTabItem) { ConsoleTabItemTopBorder.Visibility = Visibility.Visible; } else { ConsoleTabItemTopBorder.Visibility = Visibility.Collapsed; } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerContext.IsUiVisible = true; } else { NTMinerContext.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Collapsed; } else { this.OpenLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Visible; } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Bind(this, ownerIsTopMost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.AddCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }, location: this.GetType()); this.AddEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, action: message => { if (NTMinerContext.IsUiVisible && NTMinerContext.Instance.MinerProfile.IsAutoNoUi && NTMinerContext.Instance.IsMining) { if (NTMinerContext.MainWindowRendedOn.AddMinutes(NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public NTMinerWalletSet() { VirtualRoot.AddCmdPath <AddNTMinerWalletCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Wallet)) { throw new ValidationException("NTMinerWallet Wallet can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } NTMinerWalletData entity = new NTMinerWalletData().Update(message.Input); RpcRoot.OfficialServer.NTMinerWalletService.AddOrUpdateNTMinerWalletAsync(entity, (response, e) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new NTMinerWalletAddedEvent(message.MessageId, entity)); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateNTMinerWalletCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Wallet)) { throw new ValidationException("minerGroup Wallet can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } NTMinerWalletData entity = _dicById[message.Input.GetId()]; NTMinerWalletData oldValue = new NTMinerWalletData().Update(entity); entity.Update(message.Input); RpcRoot.OfficialServer.NTMinerWalletService.AddOrUpdateNTMinerWalletAsync(entity, (response, e) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new NTMinerWalletUpdatedEvent(message.MessageId, entity)); VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); VirtualRoot.RaiseEvent(new NTMinerWalletUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveNTMinerWalletCommand>(action: (message) => { if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } NTMinerWalletData entity = _dicById[message.EntityId]; RpcRoot.OfficialServer.NTMinerWalletService.RemoveNTMinerWalletAsync(entity.Id, (response, e) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new NTMinerWalletRemovedEvent(message.MessageId, entity)); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); }
public MineWorkSet() { VirtualRoot.AddCmdPath <AddMineWorkCommand>(action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = new MineWorkData().Update(message.Input); var response = RpcRoot.Server.MineWorkService.AddOrUpdateMineWork(entity); if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new MineWorkAddedEvent(message.Id, entity)); } else { Write.UserFail(response?.Description); } }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateMineWorkCommand>(action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = _dicById[message.Input.GetId()]; MineWorkData oldValue = new MineWorkData().Update(entity); entity.Update(message.Input); RpcRoot.Server.MineWorkService.AddOrUpdateMineWorkAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.Id, entity)); Write.UserFail(response.ReadMessage(exception)); } }); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.Id, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveMineWorkCommand>(action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MineWorkData entity = _dicById[message.EntityId]; RpcRoot.Server.MineWorkService.RemoveMineWorkAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new MineWorkRemovedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }, location: this.GetType()); }
public UserSet() { VirtualRoot.AddCmdPath <AddUserCommand>(action: message => { if (!_dicByLoginName.ContainsKey(message.User.LoginName)) { RpcRoot.Server.UserService.AddUserAsync(new UserData { LoginName = message.User.LoginName, Password = message.User.Password, IsEnabled = message.User.IsEnabled, Description = message.User.Description }, (response, exception) => { if (response.IsSuccess()) { UserData entity = new UserData(message.User); _dicByLoginName.Add(message.User.LoginName, entity); VirtualRoot.RaiseEvent(new UserAddedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); } }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateUserCommand>(action: message => { if (_dicByLoginName.ContainsKey(message.User.LoginName)) { UserData entity = _dicByLoginName[message.User.LoginName]; UserData oldValue = new UserData(entity); entity.Update(message.User); RpcRoot.Server.UserService.UpdateUserAsync(new UserData { LoginName = message.User.LoginName, Password = message.User.Password, IsEnabled = message.User.IsEnabled, Description = message.User.Description }, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new UserUpdatedEvent(message.Id, entity)); Write.UserFail(response.ReadMessage(exception)); } }); VirtualRoot.RaiseEvent(new UserUpdatedEvent(message.Id, entity)); } }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveUserCommand>(action: message => { if (_dicByLoginName.ContainsKey(message.LoginName)) { UserData entity = _dicByLoginName[message.LoginName]; RpcRoot.Server.UserService.RemoveUserAsync(message.LoginName, (response, exception) => { if (response.IsSuccess()) { _dicByLoginName.Remove(entity.LoginName); VirtualRoot.RaiseEvent(new UserRemovedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); } }, location: this.GetType()); }
public ServerMessageSet(string dbFileFullName, bool isServer) { if (string.IsNullOrEmpty(dbFileFullName)) { throw new ArgumentNullException(nameof(dbFileFullName)); } _connectionString = $"filename={dbFileFullName}"; if (!isServer) { VirtualRoot.AddCmdPath <LoadNewServerMessageCommand>(action: message => { if (!VirtualRoot.IsServerMessagesVisible) { return; } DateTime localTimestamp = VirtualRoot.LocalServerMessageSetTimestamp; // 如果已知服务器端最新消息的时间戳不比本地已加载的最新消息新就不用加载了 if (message.KnowServerMessageTimestamp <= Timestamp.GetTimestamp(localTimestamp)) { return; } RpcRoot.OfficialServer.ServerMessageService.GetServerMessagesAsync(localTimestamp, (response, e) => { if (response.IsSuccess()) { if (response.Data.Count > 0) { ReceiveServerMessage(response.Data); } } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); VirtualRoot.AddCmdPath <ReceiveServerMessageCommand>(action: message => { ReceiveServerMessage(message.Data); }, location: this.GetType()); } VirtualRoot.AddCmdPath <AddOrUpdateServerMessageCommand>(action: message => { 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) { exist.Update(message.Input); exist.Timestamp = DateTime.Now; _linkedList.Remove(exist); _linkedList.AddFirst(exist); } else { data = new ServerMessageData().Update(message.Input); data.Timestamp = DateTime.Now; _linkedList.AddFirst(data); while (_linkedList.Count > NTKeyword.ServerMessageSetCapacity) { toRemoves.Add(_linkedList.Last.Value); _linkedList.RemoveLast(); } } } if (exist != null) { try { using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); col.Update(exist); } } catch (Exception e) { Logger.ErrorDebugLine(e); } } else { try { 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); } } catch (Exception e) { Logger.ErrorDebugLine(e); } } #endregion } else { RpcRoot.OfficialServer.ServerMessageService.AddOrUpdateServerMessageAsync(new ServerMessageData().Update(message.Input), (response, ex) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadNewServerMessageCommand()); } else { VirtualRoot.Out.ShowError(response.ReadMessage(ex), autoHideSeconds: 4); } }); } }, location: this.GetType()); VirtualRoot.AddCmdPath <MarkDeleteServerMessageCommand>(action: message => { 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.Content = string.Empty; exist.Timestamp = DateTime.Now; _linkedList.Remove(exist); _linkedList.AddFirst(exist); } } if (exist != null) { try { using (LiteDatabase db = new LiteDatabase(_connectionString)) { var col = db.GetCollection <ServerMessageData>(); col.Update(exist); } } catch (Exception e) { Logger.ErrorDebugLine(e); } } #endregion } else { RpcRoot.OfficialServer.ServerMessageService.MarkDeleteServerMessageAsync(message.EntityId, (response, ex) => { if (response.IsSuccess()) { VirtualRoot.Execute(new LoadNewServerMessageCommand()); } else { VirtualRoot.Out.ShowError(response.ReadMessage(ex), autoHideSeconds: 4); } }); } }, location: this.GetType()); VirtualRoot.AddCmdPath <ClearServerMessages>(action: message => { InitOnece(); // 服务端不应有清空消息的功能 if (isServer) { return; } try { using (LiteDatabase db = new LiteDatabase(_connectionString)) { lock (_locker) { _linkedList.Clear(); } db.DropCollection(nameof(ServerMessageData)); } } catch (Exception e) { Logger.ErrorDebugLine(e); } VirtualRoot.RaiseEvent(new ServerMessagesClearedEvent()); }, location: this.GetType()); }
public MinerProfileViewModel() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, (int)propertyInfo.GetValue(this, null) + 1, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, Math.Round((double)propertyInfo.GetValue(this, null) + 0.1, 2), null); } #endregion }); this.Down = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { int value = (int)propertyInfo.GetValue(this, null); if (value > 0) { propertyInfo.SetValue(this, value - 1, null); } } else if (propertyInfo.PropertyType == typeof(double)) { double value = (double)propertyInfo.GetValue(this, null); if (value > 0.1) { propertyInfo.SetValue(this, Math.Round(value - 0.1, 2), null); } } #endregion }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); bool isRefreshed = false; if (ClientAppType.IsMinerClient) { VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; Write.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { isRefreshed = true; this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open; if (message.WsClientState.ToOut) { VirtualRoot.Out.ShowWarn(message.WsClientState.Description, autoHideSeconds: 3); } if (!message.WsClientState.ToOut || !this.IsWsOnline) { this.WsDescription = message.WsClientState.Description; } if (!this.IsWsOnline) { if (message.WsClientState.LastTryOn != DateTime.MinValue) { this.WsLastTryOn = message.WsClientState.LastTryOn; } if (message.WsClientState.NextTrySecondsDelay > 0) { WsNextTrySecondsDelay = message.WsClientState.NextTrySecondsDelay; } } } #endregion }, this.GetType(), LogEnum.DevConsole); VirtualRoot.AddEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { if (WsNextTrySecondsDelay > 0) { WsNextTrySecondsDelay--; } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); if (IsOuterUserEnabled) { RpcRoot.Client.NTMinerDaemonService.GetWsDaemonStateAsync((WsClientState state, Exception e) => { if (state != null && !isRefreshed) { this.IsWsOnline = state.Status == WsClientStatus.Open; this.WsDescription = state.Description; if (state.NextTrySecondsDelay > 0) { this.WsNextTrySecondsDelay = state.NextTrySecondsDelay; } this.WsLastTryOn = state.LastTryOn; } }); } } NTMinerContext.SetRefreshArgsAssembly((reason) => { Write.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #if DEBUG NTStopwatch.Start(); #endif #region 确保双挖权重在合法的范围内 if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerContext.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } #endregion NTMinerContext.Instance.CurrentMineContext = NTMinerContext.Instance.CreateMineContext(); if (NTMinerContext.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } #if DEBUG var milliseconds = NTStopwatch.Stop(); if (milliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{milliseconds} {this.GetType().Name}.SetRefreshArgsAssembly"); } #endif }); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, location: this.GetType()); AppRoot.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerContext.Instance.ServerContext.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppRoot.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); VirtualRoot.AddEventPath <CoinVmAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); VirtualRoot.AddEventPath <CoinVmRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public WalletSet(INTMinerRoot root) { _root = root; VirtualRoot.AddCmdPath <AddWalletCommand>(action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.ServerContext.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet code and Address can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = new WalletData().Update(message.Input); _dicById.Add(entity.Id, entity); AddWallet(entity); VirtualRoot.RaiseEvent(new WalletAddedEvent(message.Id, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateWalletCommand>(action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.ServerContext.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet Address can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("wallet name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); UpdateWallet(entity); VirtualRoot.RaiseEvent(new WalletUpdatedEvent(message.Id, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveWalletCommand>(action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WalletData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); RemoveWallet(entity.Id); VirtualRoot.RaiseEvent(new WalletRemovedEvent(message.Id, entity)); }, location: this.GetType()); }
public OverClockDataSet(INTMinerContext root) { _root = root; VirtualRoot.AddCmdPath <AddOverClockDataCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("OverClockData name can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } OverClockData entity = new OverClockData().Update(message.Input); RpcRoot.OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new OverClockDataAddedEvent(message.MessageId, entity)); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateOverClockDataCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("minerGroup name can't be null or empty"); } if (!_dicById.TryGetValue(message.Input.GetId(), out OverClockData entity)) { return; } OverClockData oldValue = new OverClockData().Update(entity); entity.Update(message.Input); RpcRoot.OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new OverClockDataUpdatedEvent(message.MessageId, entity)); VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); VirtualRoot.RaiseEvent(new OverClockDataUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveOverClockDataCommand>(action: (message) => { if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } OverClockData entity = _dicById[message.EntityId]; RpcRoot.OfficialServer.OverClockDataService.RemoveOverClockDataAsync(entity.Id, (response, e) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new OverClockDataRemovedEvent(message.MessageId, entity)); } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); }, location: this.GetType()); }
public LocalIpSet() { NetworkChange.NetworkAddressChanged += (object sender, EventArgs e) => { // 延迟获取网络信息以防止立即获取时获取不到 1.SecondsDelay().ContinueWith(t => { var old = _localIps; _isInited = false; InitOnece(); var localIps = _localIps; if (localIps.Length == 0) { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), "网络连接已断开", toConsole: true); } else { if (old.Length == 0) { VirtualRoot.ThisLocalInfo(nameof(LocalIpSet), "网络连接已连接", toConsole: true); } else { bool isIpChanged = false; if (old.Length != localIps.Length) { isIpChanged = true; } else { foreach (var item in localIps) { var oldItem = old.FirstOrDefault(a => a.SettingID == item.SettingID); if (item != oldItem) { isIpChanged = true; break; } } } VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络接口的 IP 地址发生了 {(isIpChanged ? "变更" : "刷新")}", toConsole: true); } } }); }; NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => { if (e.IsAvailable) { VirtualRoot.ThisLocalInfo(nameof(LocalIpSet), $"网络可用", toConsole: true); } else { VirtualRoot.ThisLocalWarn(nameof(LocalIpSet), $"网络不可用", toConsole: true); } }; VirtualRoot.AddCmdPath <SetLocalIpCommand>(action: message => { ManagementObject mo = null; using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration")) using (ManagementObjectCollection moc = mc.GetInstances()) { foreach (ManagementObject item in moc) { if ((string)item["SettingID"] == message.Input.SettingID) { mo = item; break; } } } if (mo != null) { if (message.Input.DHCPEnabled) { mo.InvokeMethod("EnableStatic", null); mo.InvokeMethod("SetGateways", null); mo.InvokeMethod("EnableDHCP", null); 1.SecondsDelay().ContinueWith(t => { _isInited = false; InitOnece(); }); } else { ManagementBaseObject inPar = mo.GetMethodParameters("EnableStatic"); inPar["IPAddress"] = new string[] { message.Input.IPAddress }; inPar["SubnetMask"] = new string[] { message.Input.IPSubnet }; mo.InvokeMethod("EnableStatic", inPar, null); inPar = mo.GetMethodParameters("SetGateways"); inPar["DefaultIPGateway"] = new string[] { message.Input.DefaultIPGateway }; mo.InvokeMethod("SetGateways", inPar, null); } if (message.IsAutoDNSServer) { mo.InvokeMethod("SetDNSServerSearchOrder", null); } else { ManagementBaseObject inPar = mo.GetMethodParameters("SetDNSServerSearchOrder"); inPar["DNSServerSearchOrder"] = new string[] { message.Input.DNSServer0, message.Input.DNSServer1 }; mo.InvokeMethod("SetDNSServerSearchOrder", inPar, null); } } }, location: this.GetType()); }
public ColumnsShowSet() { VirtualRoot.AddCmdPath <AddColumnsShowCommand>(action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty || message.Input.GetId() == ColumnsShowData.PleaseSelect.Id) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } ColumnsShowData entity = new ColumnsShowData().Update(message.Input); RpcRoot.Server.ColumnsShowService.AddOrUpdateColumnsShowAsync(entity, (response, exception) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new ColumnsShowAddedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateColumnsShowCommand>(action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } ColumnsShowData entity = _dicById[message.Input.GetId()]; ColumnsShowData oldValue = new ColumnsShowData().Update(entity); entity.Update(message.Input); RpcRoot.Server.ColumnsShowService.AddOrUpdateColumnsShowAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new ColumnsShowUpdatedEvent(message.Id, entity)); Write.UserFail(response.ReadMessage(exception)); } }); VirtualRoot.RaiseEvent(new ColumnsShowUpdatedEvent(message.Id, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveColumnsShowCommand>(action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty || message.EntityId == ColumnsShowData.PleaseSelect.Id) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } ColumnsShowData entity = _dicById[message.EntityId]; RpcRoot.Server.ColumnsShowService.RemoveColumnsShowAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new ColumnsShowRemovedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }, location: this.GetType()); }
public MinerGroupSet() { VirtualRoot.AddCmdPath <AddMinerGroupCommand>(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("minerGroup name can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } MinerGroupData entity = new MinerGroupData().Update(message.Input); RpcRoot.Server.MinerGroupService.AddOrUpdateMinerGroupAsync(entity, (response, exception) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new MinerGroupAddedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateMinerGroupCommand>(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("minerGroup name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } MinerGroupData entity = _dicById[message.Input.GetId()]; MinerGroupData oldValue = new MinerGroupData().Update(entity); entity.Update(message.Input); RpcRoot.Server.MinerGroupService.AddOrUpdateMinerGroupAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new MinerGroupUpdatedEvent(message.Id, entity)); Write.UserFail(response.ReadMessage(exception)); } }); VirtualRoot.RaiseEvent(new MinerGroupUpdatedEvent(message.Id, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveMinerGroupCommand>(action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MinerGroupData entity = _dicById[message.EntityId]; RpcRoot.Server.MinerGroupService.RemoveMinerGroupAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new MinerGroupRemovedEvent(message.Id, entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }, location: this.GetType()); }
public MinerProfileViewModel() { if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { WpfUtil.Up(this, propertyName); }); this.Down = new DelegateCommand <string>(propertyName => { WpfUtil.Down(this, propertyName); }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); if (ClientAppType.IsMinerClient) { VirtualRoot.AddCmdPath <SetAutoStartCommand>(message => { this.IsAutoStart = message.IsAutoStart; this.IsAutoBoot = message.IsAutoBoot; }, this.GetType(), LogEnum.None); VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; NTMinerConsole.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open; if (message.WsClientState.ToOut) { VirtualRoot.Out.ShowWarn(message.WsClientState.Description, autoHideSeconds: 3); } if (!message.WsClientState.ToOut || !this.IsWsOnline) { this.WsDescription = message.WsClientState.Description; } if (!this.IsWsOnline) { if (message.WsClientState.LastTryOn != DateTime.MinValue) { this.WsLastTryOn = message.WsClientState.LastTryOn; } if (message.WsClientState.NextTrySecondsDelay > 0) { WsNextTrySecondsDelay = message.WsClientState.NextTrySecondsDelay; } } } #endregion }, this.GetType(), LogEnum.DevConsole); VirtualRoot.AddEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { if (WsNextTrySecondsDelay > 0) { WsNextTrySecondsDelay--; } else if (WsLastTryOn == DateTime.MinValue) { this.RefreshWsDaemonState(); } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); } NTMinerContext.SetRefreshArgsAssembly((reason) => { NTMinerConsole.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #region 确保双挖权重在合法的范围内 if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerContext.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } #endregion NTMinerContext.Instance.CurrentMineContext = NTMinerContext.Instance.CreateMineContext(); if (NTMinerContext.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } }); AppRoot.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { this.OnPropertyChanged(nameof(IsAutoBoot)); this.OnPropertyChanged(nameof(IsAutoStart)); }, location: this.GetType()); AppRoot.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextReInitedEventHandledEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); VirtualRoot.AddEventPath <CoinVmAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); VirtualRoot.AddEventPath <CoinVmRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; ConsoleWindow.Instance.Hide(); this.Owner = ConsoleWindow.Instance; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnLeftDrawerGripBrush = BtnLeftDrawerGrip.Background; NTMinerRoot.RefreshArgsAssembly.Invoke(); // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainArea.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainArea.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } VirtualRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); } else { this.OpenLeftDrawer(); } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Instance.Bind(this, ownerIsTopMost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.AddCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => () => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }, location: this.GetType()); this.AddEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }, location: this.GetType()); this.AddEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }, location: this.GetType()); this.AddEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => () => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }, location: this.GetType()); this.AddEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }, location: this.GetType()); this.AddEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None, action: message => { UpdateCpuView(); }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }