Esempio n. 1
0
            private GpuSpeedViewModels()
            {
#if DEBUG
                VirtualRoot.Stopwatch.Restart();
#endif
                if (Design.IsInDesignMode)
                {
                    return;
                }
                this.GpuAllVm = AppContext.Instance.GpuVms.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId);
                IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed;
                foreach (var item in gpuSpeeds)
                {
                    this._list.Add(new GpuSpeedViewModel(item));
                }
                _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId);
                On <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole,
                                          action: (message) => {
                    Guid mainCoinId = NTMinerRoot.Instance.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);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText));
                        }
                        else
                        {
                            gpuSpeedVm.MainCoinSpeed.Update(message.Source.MainCoinSpeed);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText));
                        }
                    }
                    if (index == _totalSpeedVm.GpuVm.Index)
                    {
                        IMineContext mineContext = NTMinerRoot.Instance.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.Instance.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.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code);
                                IncomeMainCoinPerDay      = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin;
                                IncomeMainCoinUsdPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd;
                                IncomeMainCoinCnyPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny;
                            }
                        }
                    }
                });
                On <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None,
                                     action: message => {
                    TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                    TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                });
#if DEBUG
                Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Esempio n. 2
0
            private GpuSpeedViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                this.GpuAllVm = GpuVms.Items.FirstOrDefault(a => a.Index == NTMinerContext.GpuAllId);
                IGpusSpeed gpuSpeeds = NTMinerContext.Instance.GpusSpeed;

                foreach (var item in gpuSpeeds.AsEnumerable())
                {
                    this._list.Add(new GpuSpeedViewModel(item));
                }
                _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerContext.GpuAllId);
                AddEventPath <GpuShareChangedEvent>("显卡份额变更后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare  = message.Source.MainCoinSpeed.FoundShare;
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                }, location: this.GetType());
                AddEventPath <FoundShareIncreasedEvent>("找到一个份额后刷新VM内存", LogEnum.DevConsole,
                                                        action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare;
                    }
                }, location: this.GetType());
                AddEventPath <AcceptShareIncreasedEvent>("接受一个份额后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                    }
                }, location: this.GetType());
                AddEventPath <RejectShareIncreasedEvent>("拒绝一个份额后刷新VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                }, location: this.GetType());
                AddEventPath <IncorrectShareIncreasedEvent>("产生一个错误份额后刷新VM内存", LogEnum.DevConsole,
                                                            action: message => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.IncorrectShare = message.Source.MainCoinSpeed.IncorrectShare;
                    }
                }, location: this.GetType());
                AddEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    ResetIfMainCoinSwitched();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        if (message.IsDual)
                        {
                            gpuSpeedVm.DualCoinSpeed.UpdateSpeed(message.Source.DualCoinSpeed.Value, message.Source.DualCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText));
                        }
                        else
                        {
                            gpuSpeedVm.MainCoinSpeed.UpdateSpeed(message.Source.MainCoinSpeed.Value, message.Source.MainCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText));
                        }
                    }
                    if (index == _totalSpeedVm.GpuVm.Index)
                    {
                        var mineContext = NTMinerContext.Instance.LockedMineContext;
                        if (mineContext == null)
                        {
                            IncomeMainCoinPerDay    = 0;
                            IncomeMainCoinUsdPerDay = 0;
                            IncomeMainCoinCnyPerDay = 0;
                            IncomeDualCoinPerDay    = 0;
                            IncomeDualCoinUsdPerDay = 0;
                            IncomeDualCoinCnyPerDay = 0;
                        }
                        else
                        {
                            if (message.IsDual)
                            {
                                if (mineContext is IDualMineContext dualMineContext)
                                {
                                    IncomePerDay incomePerDay = NTMinerContext.Instance.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 = NTMinerContext.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code);
                                IncomeMainCoinPerDay      = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin;
                                IncomeMainCoinUsdPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd;
                                IncomeMainCoinCnyPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny;
                            }
                        }
                    }
                }, location: this.GetType());
                AddEventPath <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None,
                                               action: message => {
                    TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                    TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                }, location: this.GetType());
            }
            private GpuSpeedViewModels()
            {
#if DEBUG
                Write.Stopwatch.Restart();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                this.GpuAllVm = AppContext.Instance.GpuVms.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId);
                IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed;
                foreach (var item in gpuSpeeds)
                {
                    this._list.Add(new GpuSpeedViewModel(item));
                }
                _totalSpeedVm = this._list.FirstOrDefault(a => a.GpuVm.Index == NTMinerRoot.GpuAllId);
                AppContextEventPath <GpuShareChangedEvent>("显卡份额变更后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare  = message.Source.MainCoinSpeed.FoundShare;
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                });
                AppContextEventPath <FoundShareIncreasedEvent>("找到一个份额后刷新VM内存", LogEnum.DevConsole,
                                                               action: message => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.FoundShare = message.Source.MainCoinSpeed.FoundShare;
                    }
                });
                AppContextEventPath <AcceptShareIncreasedEvent>("接受一个份额后刷新VM内存", LogEnum.DevConsole,
                                                                action: message => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.AcceptShare = message.Source.MainCoinSpeed.AcceptShare;
                    }
                });
                AppContextEventPath <RejectShareIncreasedEvent>("拒绝一个份额后刷新VM内存", LogEnum.DevConsole,
                                                                action: message => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.RejectShare = message.Source.MainCoinSpeed.RejectShare;
                    }
                });
                AppContextEventPath <IncorrectShareIncreasedEvent>("产生一个错误份额后刷新VM内存", LogEnum.DevConsole,
                                                                   action: message => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        gpuSpeedVm.MainCoinSpeed.IncorrectShare = message.Source.MainCoinSpeed.IncorrectShare;
                    }
                });
                AppContextEventPath <GpuSpeedChangedEvent>("显卡算力变更后刷新VM内存", LogEnum.DevConsole,
                                                           action: (message) => {
                    CheckReset();
                    int index = message.Source.Gpu.Index;
                    GpuSpeedViewModel gpuSpeedVm = _list.FirstOrDefault(a => a.GpuVm.Index == index);
                    if (gpuSpeedVm != null)
                    {
                        if (message.IsDual)
                        {
                            gpuSpeedVm.DualCoinSpeed.UpdateSpeed(message.Source.DualCoinSpeed.Value, message.Source.DualCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageDualCoinSpeedText));
                        }
                        else
                        {
                            gpuSpeedVm.MainCoinSpeed.UpdateSpeed(message.Source.MainCoinSpeed.Value, message.Source.MainCoinSpeed.SpeedOn);
                            gpuSpeedVm.OnPropertyChanged(nameof(gpuSpeedVm.AverageMainCoinSpeedText));
                        }
                    }
                    if (index == _totalSpeedVm.GpuVm.Index)
                    {
                        IMineContext mineContext = NTMinerRoot.Instance.CurrentMineContext;
                        if (mineContext == null)
                        {
                            IncomeMainCoinPerDay    = 0;
                            IncomeMainCoinUsdPerDay = 0;
                            IncomeMainCoinCnyPerDay = 0;
                            IncomeDualCoinPerDay    = 0;
                            IncomeDualCoinUsdPerDay = 0;
                            IncomeDualCoinCnyPerDay = 0;
                        }
                        else
                        {
                            if (message.IsDual)
                            {
                                if (mineContext is IDualMineContext dualMineContext)
                                {
                                    IncomePerDay incomePerDay = NTMinerRoot.Instance.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.Instance.CalcConfigSet.GetIncomePerHashPerDay(mineContext.MainCoin.Code);
                                IncomeMainCoinPerDay      = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCoin;
                                IncomeMainCoinUsdPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeUsd;
                                IncomeMainCoinCnyPerDay   = _totalSpeedVm.MainCoinSpeed.Value * incomePerDay.IncomeCny;
                            }
                        }
                    }
                });
                AppContextEventPath <Per1SecondEvent>("每秒钟更新算力活动时间", LogEnum.None,
                                                      action: message => {
                    TotalSpeedVm.MainCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                    TotalSpeedVm.DualCoinSpeed.OnPropertyChanged(nameof(SpeedViewModel.LastSpeedOnText));
                });
#if DEBUG
                Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }