private MinerClientsWindow() { Width = SystemParameters.FullPrimaryScreenWidth * 0.95; Height = SystemParameters.FullPrimaryScreenHeight * 0.95; InitializeComponent(); VirtualRoot.On <Per1SecondEvent>("刷新倒计时秒表,周期性挥动铲子表示在挖矿中", LogEnum.None, action: message => { var minerClients = Vm.MinerClients.ToArray(); if (Vm.CountDown > 0) { Vm.CountDown = Vm.CountDown - 1; foreach (var item in minerClients) { item.OnPropertyChanged(nameof(item.LastActivedOnText)); } } // 周期性挥动铲子表示在挖矿中 foreach (var item in minerClients) { if (item.IsMining) { item.IsShovelEmpty = !item.IsShovelEmpty; } } }).AddToCollection(_handlers); VirtualRoot.On <Per10SecondEvent>("周期刷新在线客户端列表", LogEnum.DevConsole, action: message => { MinerClientsWindowViewModel.Current.QueryMinerClients(); }).AddToCollection(_handlers); EventHandler changeNotiCenterWindowLocation = Wpf.Util.ChangeNotiCenterWindowLocation(this); this.Activated += changeNotiCenterWindowLocation; this.LocationChanged += changeNotiCenterWindowLocation; ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources); MinerClientsWindowViewModel.Current.QueryMinerClients(); }
private PoolKernelViewModels() { VirtualRoot.On <PoolKernelAddedEvent>("新添了矿池内核后刷新矿池内核VM内存", LogEnum.DevConsole, action: (message) => { if (!_dicById.ContainsKey(message.Source.GetId())) { PoolViewModel poolVm; if (PoolViewModels.Current.TryGetPoolVm(message.Source.PoolId, out poolVm)) { _dicById.Add(message.Source.GetId(), new PoolKernelViewModel(message.Source)); poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels)); } } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); VirtualRoot.On <PoolKernelRemovedEvent>("移除了币种内核后刷新矿池内核VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { var vm = _dicById[message.Source.GetId()]; _dicById.Remove(message.Source.GetId()); PoolViewModel poolVm; if (PoolViewModels.Current.TryGetPoolVm(vm.PoolId, out poolVm)) { poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels)); } } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); VirtualRoot.On <PoolKernelUpdatedEvent>("更新了矿池内核后刷新VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { _dicById[message.Source.GetId()].Update(message.Source); } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); Init(); }
public SpeedCharts() { InitializeComponent(); ResourceDictionarySet.Instance.FillResourceDic(this, this.Resources); if (Design.IsInDesignMode) { return; } Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; VirtualRoot.On <GpuSpeedChangedEvent>("显卡算力变更后刷新算力图界面", LogEnum.DevConsole, action: (message) => { UIThread.Execute(() => { if (mainCoinId != NTMinerRoot.Current.MinerProfile.CoinId) { mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; foreach (var speedChartVm in Vm.SpeedChartVms) { SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; foreach (var item in series) { item.Values.Clear(); } foreach (var item in seriesShadow) { item.Values.Clear(); } } } IGpuSpeed gpuSpeed = message.Source; int index = gpuSpeed.Gpu.Index; if (Vm.SpeedChartVms.ContainsKey(index)) { SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { IChartValues chartValues = series[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[0].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { IChartValues chartValues = series[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } chartValues = seriesShadow[1].Values; chartValues.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); if (((MeasureModel)chartValues[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { chartValues.RemoveAt(0); } } speedChartVm.SetAxisLimits(now); } }); }).AddToCollection(_handlers); Vm.ItemsPanelColumns = 1; this.Unloaded += (object sender, RoutedEventArgs e) => { foreach (var handler in _handlers) { VirtualRoot.UnPath(handler); } foreach (var item in Vm.SpeedChartVms) { item.Series = null; item.SeriesShadow = null; item.AxisX = null; item.AxisY = null; item.AxisXShadow = null; item.AxisYShadow = null; } _chartDic.Clear(); }; SolidColorBrush White = new SolidColorBrush(Colors.White); Vm.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => { if (e.PropertyName == nameof(Vm.CurrentSpeedChartVm)) { SpeedChartViewModel currentItem = Vm.CurrentSpeedChartVm; if (currentItem != null) { foreach (var item in _chartDic.Values) { item.Visibility = Visibility.Collapsed; } CartesianChart chart; if (!_chartDic.ContainsKey(currentItem)) { chart = new CartesianChart() { DisableAnimations = true, Hoverable = false, DataTooltip = null, Background = White, Padding = new Thickness(4, 0, 0, 0), Visibility = Visibility.Visible }; chart.Series = currentItem.SeriesShadow; chart.AxisX = currentItem.AxisXShadow; chart.AxisY = currentItem.AxisYShadow; _chartDic.Add(currentItem, chart); DetailsGrid.Children.Add(chart); } else { chart = _chartDic[currentItem]; chart.Visibility = Visibility.Visible; } } } }; Vm.SetCurrentSpeedChartVm(Vm.SpeedChartVms.FirstOrDefault()); if (MinerProfileViewModel.Current.CoinVm != null) { Guid coinId = MinerProfileViewModel.Current.CoinId; foreach (var item in NTMinerRoot.Current.GpuSet) { List <IGpuSpeed> gpuSpeedHistory = item.GetGpuSpeedHistory(); SpeedChartViewModel speedChartVm = Vm.SpeedChartVms[item.Index]; SeriesCollection series = speedChartVm.Series; SeriesCollection seriesShadow = speedChartVm.SeriesShadow; DateTime now = DateTime.Now; foreach (var gpuSpeed in gpuSpeedHistory) { if (gpuSpeed.MainCoinSpeed != null && series.Count > 0) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.MainCoinSpeed.SpeedOn, Value = gpuSpeed.MainCoinSpeed.Value }); } if (gpuSpeed.DualCoinSpeed != null && series.Count > 1) { series[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); seriesShadow[0].Values.Add(new MeasureModel() { DateTime = gpuSpeed.DualCoinSpeed.SpeedOn, Value = gpuSpeed.DualCoinSpeed.Value }); } } IChartValues values = series[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { series[0].Values.RemoveAt(0); } values = seriesShadow[0].Values; if (values.Count > 0 && ((MeasureModel)values[0]).DateTime.AddMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute) < now) { seriesShadow[0].Values.RemoveAt(0); } speedChartVm.SetAxisLimits(now); } } }
public void Init(INTMinerRoot root) { if (_isInited) { return; } _isInited = true; VirtualRoot.On <GpuStateChangedEvent>("当显卡温度变更时守卫温度防线", LogEnum.None, action: message => { IGpu gpu = message.Source; if (gpu.Index == NTMinerRoot.GpuAllId || root.MinerProfile.CoinId == Guid.Empty) { return; } IGpuProfile gpuProfile; if (GpuProfileSet.Instance.IsOverClockGpuAll(root.MinerProfile.CoinId)) { gpuProfile = GpuProfileSet.Instance.GetGpuProfile(root.MinerProfile.CoinId, NTMinerRoot.GpuAllId); } else { gpuProfile = GpuProfileSet.Instance.GetGpuProfile(root.MinerProfile.CoinId, gpu.Index); } if (!gpuProfile.IsAutoFanSpeed) { return; } // 显卡温度抵达防御温度的时间 DateTime fightedOn; if (!_fightedOnDic.TryGetValue(gpu.Index, out fightedOn)) { fightedOn = DateTime.Now; _fightedOnDic.Add(gpu.Index, fightedOn); } if (gpu.FanSpeed == 100 && gpu.Temperature > _guardTemp) { Write.DevDebug($"GPU{gpu.Index} 温度{gpu.Temperature}大于防线温度{_guardTemp},但风扇转速已达100%"); } else if (gpu.Temperature < _guardTemp) { if (!_preTempDic.ContainsKey(gpu.Index)) { _preTempDic.Add(gpu.Index, 0); } // 如果当前温度比上次的温度大 if (gpu.Temperature > _preTempDic[gpu.Index]) { fightedOn = DateTime.Now; _fightedOnDic[gpu.Index] = fightedOn; } _preTempDic[gpu.Index] = gpu.Temperature; // 如果距离抵达防御温度的时间已经很久了则降速风扇 if (fightedOn.AddSeconds(_fanSpeedDownSeconds) < DateTime.Now) { int cool = (int)(gpu.FanSpeed - _fanSpeedDownStep); // 如果温度低于50度则直接将风扇设为驱动默认的最小转速 if (gpu.Temperature < 50) { cool = gpu.CoolMin; } if (cool >= gpu.CoolMin) { _fightedOnDic[gpu.Index] = DateTime.Now; HashSet <int> effectGpus = new HashSet <int>(); root.GpuSet.OverClock.SetCool(gpu.Index, cool, ref effectGpus); Write.DevDebug($"GPU{gpu.Index} 风扇转速由{gpu.FanSpeed}%调低至{cool}%"); } } } else if (gpu.Temperature > _guardTemp) { uint cool; uint len; // 防线突破可能是由于小量降低风扇转速造成的 if (fightedOn.AddSeconds(_fanSpeedDownSeconds) < DateTime.Now) { _fightedOnDic[gpu.Index] = DateTime.Now; len = 100 - gpu.FanSpeed; } else { len = _fanSpeedDownStep; } cool = gpu.FanSpeed + (uint)Math.Ceiling(len / 2.0); if (cool > 100) { cool = 100; } if (cool <= 100) { HashSet <int> effectGpus = new HashSet <int>(); root.GpuSet.OverClock.SetCool(gpu.Index, (int)cool, ref effectGpus); Write.DevDebug($"GPU{gpu.Index} 风扇转速由{gpu.FanSpeed}%调高至{cool}%"); } } }); }
private void Init() { VirtualRoot.On <CoinKernelAddedEvent>("添加了币种内核后刷新VM内存", LogEnum.DevConsole, action: (message) => { var coinKernelVm = new CoinKernelViewModel(message.Source); _dicById.Add(message.Source.GetId(), coinKernelVm); OnPropertyChanged(nameof(AllCoinKernels)); CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(message.Source.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } var kernelVm = coinKernelVm.Kernel; if (kernelVm != null) { kernelVm.OnPropertyChanged(nameof(kernelVm.IsSupported)); kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels)); kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms)); kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms)); kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins)); } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); VirtualRoot.On <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole, action: (message) => { CoinKernelViewModel entity = _dicById[message.Source.GetId()]; var supportedGpu = entity.SupportedGpu; int sortNumber = entity.SortNumber; Guid dualCoinGroupId = entity.DualCoinGroupId; entity.Update(message.Source); if (supportedGpu != entity.SupportedGpu) { var coinKernels = AllCoinKernels.Where(a => a.KernelId == entity.Id); foreach (var coinKernel in coinKernels) { CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(coinKernel.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.IsSupported)); coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } coinKernel.Kernel.OnPropertyChanged(nameof(coinKernel.Kernel.IsSupported)); } var kernelVm = entity.Kernel; kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels)); } if (dualCoinGroupId != entity.DualCoinGroupId) { entity.OnPropertyChanged(nameof(entity.DualCoinGroup)); } if (sortNumber != entity.SortNumber) { CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(entity.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels)); } } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); VirtualRoot.On <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole, action: (message) => { CoinKernelViewModel coinKernelVm; if (_dicById.TryGetValue(message.Source.GetId(), out coinKernelVm)) { _dicById.Remove(message.Source.GetId()); OnPropertyChanged(nameof(AllCoinKernels)); CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(message.Source.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel)); coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels)); coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported)); } var kernelVm = coinKernelVm.Kernel; kernelVm.OnPropertyChanged(nameof(kernelVm.IsSupported)); kernelVm.OnPropertyChanged(nameof(kernelVm.IsNvidiaIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.IsAMDIconVisible)); kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels)); kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms)); kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms)); kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins)); } }).AddToCollection(NTMinerRoot.Current.ContextHandlers); foreach (var item in NTMinerRoot.Current.CoinKernelSet) { _dicById.Add(item.GetId(), new CoinKernelViewModel(item)); } }
private GpuSpeedViewModels() { if (Design.IsInDesignMode) { return; } this.GpuAllVm = GpuViewModels.Current.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; foreach (var item in gpuSpeeds) { this._list.Add(new GpuSpeedViewModel(item)); } _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId); VirtualRoot.On <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole, action: (message) => { Guid mainCoinId = NTMinerRoot.Current.MinerProfile.CoinId; if (_mainCoinId != mainCoinId) { _mainCoinId = mainCoinId; DateTime now = DateTime.Now; foreach (var item in _list) { item.MainCoinSpeed.Value = 0; item.MainCoinSpeed.SpeedOn = now; item.DualCoinSpeed.Value = 0; item.DualCoinSpeed.SpeedOn = now; } IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } int index = message.Source.Gpu.Index; GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index); if (gpuSpeedVm != null) { if (message.IsDualSpeed) { gpuSpeedVm.DualCoinSpeed.Update(message.Source.DualCoinSpeed); } else { gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed); } } if (index == _totalSpeedVm.GpuVm.Index) { IMineContext mineContext = NTMinerRoot.Current.CurrentMineContext; if (mineContext == null) { IncomeMainCoinPerDay = 0; IncomeMainCoinUsdPerDay = 0; IncomeMainCoinCnyPerDay = 0; IncomeDualCoinPerDay = 0; IncomeDualCoinUsdPerDay = 0; IncomeDualCoinCnyPerDay = 0; } else { if (message.IsDualSpeed) { if (mineContext is IDualMineContext dualMineContext) { IncomePerDay incomePerDay = NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(dualMineContext.DualCoin.Code); IncomeDualCoinPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeDualCoinUsdPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeDualCoinCnyPerDay = _totalSpeedVm.DualCoinSpeed.Value * incomePerDay.IncomeCny; } } else { IncomePerDay incomePerDay = NTMinerRoot.Current.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code); IncomeMainCoinPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin; IncomeMainCoinUsdPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd; IncomeMainCoinCnyPerDay = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny; } } } }); }
public MinerProfileViewModel() { #if DEBUG Write.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } this.AutoStartDelaySecondsUp = new DelegateCommand(() => { this.AutoStartDelaySeconds++; }); this.AutoStartDelaySecondsDown = new DelegateCommand(() => { if (this.AutoStartDelaySeconds > 0) { this.AutoStartDelaySeconds--; } }); this.AutoRestartKernelTimesUp = new DelegateCommand(() => { this.AutoRestartKernelTimes++; }); this.AutoRestartKernelTimesDown = new DelegateCommand(() => { if (this.AutoRestartKernelTimes > 0) { this.AutoRestartKernelTimes--; } }); this.NoShareRestartKernelMinutesUp = new DelegateCommand(() => { this.NoShareRestartKernelMinutes++; }); this.NoShareRestartKernelMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartKernelMinutes > 0) { this.NoShareRestartKernelMinutes--; } }); this.NoShareRestartComputerMinutesUp = new DelegateCommand(() => { this.NoShareRestartComputerMinutes++; }); this.NoShareRestartComputerMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartComputerMinutes > 0) { this.NoShareRestartComputerMinutes--; } }); this.PeriodicRestartKernelHoursUp = new DelegateCommand(() => { this.PeriodicRestartKernelHours++; }); this.PeriodicRestartKernelHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelHours > 0) { this.PeriodicRestartKernelHours--; } }); this.PeriodicRestartKernelMinutesUp = new DelegateCommand(() => { this.PeriodicRestartKernelMinutes++; }); this.PeriodicRestartKernelMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelMinutes > 0) { this.PeriodicRestartKernelMinutes--; } }); this.PeriodicRestartComputerHoursUp = new DelegateCommand(() => { this.PeriodicRestartComputerHours++; }); this.PeriodicRestartComputerHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerHours > 0) { this.PeriodicRestartComputerHours--; } }); this.PeriodicRestartComputerMinutesUp = new DelegateCommand(() => { this.PeriodicRestartComputerMinutes++; }); this.PeriodicRestartComputerMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerMinutes > 0) { this.PeriodicRestartComputerMinutes--; } }); this.EPriceUp = new DelegateCommand(() => { this.EPrice = Math.Round(this.EPrice + 0.1, 2); }); this.EPriceDown = new DelegateCommand(() => { if (this.EPrice > 0.1) { this.EPrice = Math.Round(this.EPrice - 0.1, 2); } }); this.PowerAppendUp = new DelegateCommand(() => { this.PowerAppend++; }); this.PowerAppendDown = new DelegateCommand(() => { if (this.PowerAppend > 0) { this.PowerAppend--; } }); this.MaxTempUp = new DelegateCommand(() => { this.MaxTemp++; }); this.MaxTempDown = new DelegateCommand(() => { if (this.MaxTemp > 0) { this.MaxTemp--; } }); this.AutoNoUiMinutesUp = new DelegateCommand(() => { this.AutoNoUiMinutes++; }); this.AutoNoUiMinutesDown = new DelegateCommand(() => { if (this.AutoNoUiMinutes > 0) { this.AutoNoUiMinutes--; } }); NTMinerRoot.SetRefreshArgsAssembly(() => { 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; } NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } this.ArgsAssembly = NTMinerRoot.Instance.BuildAssembleArgs(out _, out _, out _); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }); AppContext.Window <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.UserConsole, action: message => { OnPropertyChanged(nameof(IsAutoBoot)); OnPropertyChanged(nameof(IsAutoStart)); }); AppContext.On <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); AppContext.On <MineWorkPropertyChangedEvent>("MineWork设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); VirtualRoot.On <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)); } }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private LangViewItemViewModels() { VirtualRoot.On <LangViewItemAddedEvent>("添加了语言项后刷新VM内存", LogEnum.None, action: message => { if (_dicById.ContainsKey(message.Source.GetId())) { return; } LangViewModel langVm; if (LangViewModels.Current.TryGetLangVm(message.Source.LangId, out langVm)) { Dictionary <string, List <LangViewItemViewModel> > dic = null; if (!_dicByLangAndView.ContainsKey(langVm)) { dic = new Dictionary <string, List <LangViewItemViewModel> >(); _dicByLangAndView.Add(langVm, dic); } else { dic = _dicByLangAndView[langVm]; } if (!dic.ContainsKey(message.Source.ViewId)) { dic.Add(message.Source.ViewId, new List <LangViewItemViewModel>()); } var entity = new LangViewItemViewModel(message.Source); dic[message.Source.ViewId].Add(entity); _dicById.Add(entity.Id, entity); } }); VirtualRoot.On <LangViewItemUpdatedEvent>("更新了语言项后刷新VM内存", LogEnum.None, action: message => { LangViewItemViewModel langItemVm; if (_dicById.TryGetValue(message.Source.GetId(), out langItemVm)) { langItemVm.Update(message.Source); } }); VirtualRoot.On <LangViewItemRemovedEvent>("删除了语言项后刷新VM内存", LogEnum.None, action: message => { LangViewItemViewModel langItemVm; if (_dicById.TryGetValue(message.Source.GetId(), out langItemVm)) { _dicById.Remove(langItemVm.Id); LangViewModel langVm; if (LangViewModels.Current.TryGetLangVm(langItemVm.LangId, out langVm)) { if (_dicByLangAndView.ContainsKey(langVm) && _dicByLangAndView[langVm].ContainsKey(langItemVm.ViewId)) { _dicByLangAndView[langVm][langItemVm.ViewId].Remove(langItemVm); if (_dicByLangAndView[langVm][langItemVm.ViewId].Count == 0) { _dicByLangAndView[langVm].Remove(langItemVm.ViewId); if (_dicByLangAndView[langVm].Count == 0) { _dicByLangAndView.Remove(langVm); } } } } } }); Init(); }
public KernelOutputTranslaterSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddKernelOutputTranslaterCommand>("添加内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId)) { _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputTranslaterData>()); } _dicByKernelOutputId[entity.KernelOutputId].Add(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputTranslaterAddedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } string regexPattern = entity.RegexPattern; string color = entity.Color; entity.Update(message.Input); if (entity.RegexPattern != regexPattern) { _regexDic.Remove(entity); } if (entity.Color != color) { _colorDic.Remove(entity); } _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputTranslaterUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputTranslaterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelOutputId[entity.KernelOutputId].Remove(entity); _colorDic.Remove(entity); _regexDic.Remove(entity); _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelOutputTranslaterRemovedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.On <SysDicItemUpdatedEvent>("LogColor字典项更新后刷新翻译器内存", LogEnum.DevConsole, action: message => { ISysDic dic; if (!_root.SysDicSet.TryGetSysDic("LogColor", out dic)) { return; } if (message.Source.DicId != dic.GetId()) { return; } foreach (var entity in _dicById.Values) { if (entity.Color == message.Source.Code) { _colorDic.Remove(entity); } } }).AddToCollection(root.ContextHandlers); }