コード例 #1
0
 public OverClockDataPageViewModel()
 {
     if (Design.IsInDesignMode)
     {
         return;
     }
     _currentCoin = CoinVms.MainCoins.FirstOrDefault();
 }
コード例 #2
0
 public NTMinerWalletPageViewModel()
 {
     if (Design.IsInDesignMode)
     {
         return;
     }
     _currentCoin = CoinVms.MainCoins.FirstOrDefault();
 }
コード例 #3
0
 public CoinKernelSelectViewModel(CoinViewModel coin, CoinKernelViewModel selected, Action <CoinKernelViewModel> onSelectedChanged)
 {
     _coin              = coin;
     _selectedResult    = selected;
     _onSelectedChanged = onSelectedChanged;
     this.ClearKeyword  = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
コード例 #4
0
 public CoinSelectViewModel(IEnumerable <CoinViewModel> coins, CoinViewModel selected, Action <CoinViewModel> onSelectedChanged)
 {
     _coins             = coins;
     _selectedResult    = selected;
     _onSelectedChanged = onSelectedChanged;
     this.ClearKeyword  = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
コード例 #5
0
 public KernelSelectViewModel(CoinViewModel coin, KernelViewModel selectedKernel, Action <KernelViewModel> onOk)
 {
     _coin             = coin;
     _selectedResult   = selectedKernel;
     OnOk              = onOk;
     this.ClearKeyword = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
コード例 #6
0
 public PoolSelectViewModel(CoinViewModel coin, PoolViewModel selected, Action <PoolViewModel> onOk, bool usedByPool1 = false)
 {
     _coin             = coin;
     _selectedResult   = selected;
     OnOk              = onOk;
     _usedByPool1      = usedByPool1;
     this.ClearKeyword = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
コード例 #7
0
ファイル: CoinViewModels.cs プロジェクト: ranchenglou/ntminer
        public bool TryGetCoinVm(string coinCode, out CoinViewModel coinVm)
        {
            ICoin coin;

            if (NTMinerRoot.Current.CoinSet.TryGetCoin(coinCode, out coin))
            {
                return(TryGetCoinVm(coin.GetId(), out coinVm));
            }
            coinVm = CoinViewModel.Empty;
            return(false);
        }
コード例 #8
0
 private void Init()
 {
     VirtualRoot.On <KernelInputAddedEvent>("添加了内核输入后刷新VM内存", LogEnum.DevConsole,
                                            action: message => {
         var vm = new KernelInputViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), vm);
         OnPropertyChangeds();
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <KernelInputUpdatedEvent>("更新了内核输入后刷新VM内存", LogEnum.DevConsole,
                                              action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var item = _dicById[message.Source.GetId()];
             if (item != null)
             {
                 bool isSupportDualMine = item.IsSupportDualMine;
                 string args            = item.Args;
                 string dualFullArgs    = item.DualFullArgs;
                 item.Update(message.Source);
                 if (args != item.Args || dualFullArgs != item.DualFullArgs)
                 {
                     CoinViewModel coinVm = MinerProfileViewModel.Current.CoinVm;
                     if (coinVm != null && coinVm.CoinKernel != null && coinVm.CoinKernel.Kernel.KernelInputId == item.Id)
                     {
                         NTMinerRoot.RefreshArgsAssembly.Invoke();
                     }
                 }
                 if (isSupportDualMine != item.IsSupportDualMine)
                 {
                     foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                     {
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.DualCoinGroup));
                     }
                 }
             }
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <KernelInputRemovedEvent>("移除了内核输入后刷新VM内存", LogEnum.DevConsole,
                                              action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChangeds();
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.KernelInputSet)
     {
         _dicById.Add(item.GetId(), new KernelInputViewModel(item));
     }
 }
コード例 #9
0
 public CoinSelectViewModel(
     IEnumerable <CoinViewModel> coins,
     CoinViewModel selected,
     Action <CoinViewModel> onOk,
     bool isPromoteHotCoin = false)
 {
     _coins            = coins;
     _selectedResult   = selected;
     OnOk              = onOk;
     IsPromoteHotCoin  = isPromoteHotCoin;
     this.ClearKeyword = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
コード例 #10
0
 public WalletSelectViewModel(CoinViewModel coin, bool isDualCoin, WalletViewModel selected, Action <WalletViewModel> onSelectedChanged)
 {
     _coin              = coin;
     _isDualCoin        = isDualCoin;
     _selectedResult    = selected;
     _onSelectedChanged = onSelectedChanged;
     if (_isDualCoin)
     {
         this.AddWallet = _coin.CoinProfile.AddDualCoinWallet;
     }
     else
     {
         this.AddWallet = _coin.CoinProfile.AddWallet;
     }
 }
コード例 #11
0
 private MinerClientsViewModel()
 {
     this._mineStatusEnumItem = this.MineStatusEnumItems.FirstOrDefault(a => a.Value == MineStatus.All);
     this._mainCoin           = CoinViewModel.PleaseSelect;
     this._dualCoin           = CoinViewModel.PleaseSelect;
     this._selectedMineWork   = MineWorkViewModel.PleaseSelect;
     this._selectedMinerGroup = MinerGroupViewModel.PleaseSelect;
     this._mainCoinPool       = _mainCoin.OptionPools.First();
     this._dualCoinPool       = _dualCoin.OptionPools.First();
     this._mainCoinWallet     = WalletViewModel.PleaseSelect;
     this._dualCoinWallet     = WalletViewModel.PleaseSelect;
     this.PageUp = new DelegateCommand(() => {
         this.MinerClientPageIndex = this.MinerClientPageIndex - 1;
     });
     this.PageDown = new DelegateCommand(() => {
         this.MinerClientPageIndex = this.MinerClientPageIndex + 1;
     });
     this.PageFirst = new DelegateCommand(() => {
         this.MinerClientPageIndex = 1;
     });
     this.PageLast = new DelegateCommand(() => {
         this.MinerClientPageIndex = MinerClientPageCount;
     });
     this.PageRefresh = new DelegateCommand(() => {
         QueryMinerClients();
     });
     this.ManageCoin = new DelegateCommand <CoinViewModel>((coinVm) => {
         CoinPageViewModel.Current.CurrentCoin = coinVm;
         CoinPage.ShowWindow();
     });
     this.ManagePool = new DelegateCommand <CoinViewModel>((coinVm) => {
         this.ManageCoin.Execute(coinVm);
         CoinPageViewModel.Current.SwitchToPoolTab();
     });
     this.ManageWallet = new DelegateCommand <CoinViewModel>((coinVm) => {
         this.ManageCoin.Execute(coinVm);
         CoinPageViewModel.Current.SwitchToWalletTab();
     });
     System.Timers.Timer t = new System.Timers.Timer(50);
     t.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => {
         if (this._logoRotateTransformAngle > 3600000)
         {
             this._logoRotateTransformAngle = 0;
         }
         this.LogoRotateTransformAngle += 50;
     };
     t.Start();
 }
コード例 #12
0
 private void Init()
 {
     VirtualRoot.On <CoinAddedEvent>("添加了币种后刷新VM内存", LogEnum.DevConsole,
                                     action: (message) => {
         _dicById.Add(message.Source.GetId(), new CoinViewModel(message.Source));
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         AllPropertyChanged();
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinRemovedEvent>("移除了币种后刷新VM内存", LogEnum.DevConsole,
                                       action: message => {
         _dicById.Remove(message.Source.GetId());
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         AllPropertyChanged();
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     VirtualRoot.On <CoinUpdatedEvent>("更新了币种后刷新VM内存", LogEnum.DevConsole,
                                       action: message => {
         CoinViewModel coinVm = _dicById[message.Source.GetId()];
         bool justAsDualCoin  = coinVm.JustAsDualCoin;
         coinVm.Update(message.Source);
         coinVm.TestWalletVm.Address = message.Source.TestWallet;
         coinVm.OnPropertyChanged(nameof(coinVm.Wallets));
         coinVm.OnPropertyChanged(nameof(coinVm.WalletItems));
         if (MinerProfileViewModel.Current.CoinId == message.Source.GetId())
         {
             MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         }
         CoinKernelViewModel coinKernelVm = MinerProfileViewModel.Current.CoinVm.CoinKernel;
         if (coinKernelVm != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin.GetId() == message.Source.GetId())
         {
             coinKernelVm.CoinKernelProfile.OnPropertyChanged(nameof(coinKernelVm.CoinKernelProfile.SelectedDualCoin));
         }
         if (justAsDualCoin != coinVm.JustAsDualCoin)
         {
             OnPropertyChanged(nameof(MainCoins));
         }
     }).AddToCollection(NTMinerRoot.Current.ContextHandlers);
     foreach (var item in NTMinerRoot.Current.CoinSet)
     {
         _dicById.Add(item.GetId(), new CoinViewModel(item));
     }
 }
コード例 #13
0
 public WalletSelectViewModel(CoinViewModel coin, bool isDualCoin, WalletViewModel selected, Action <WalletViewModel> onOk)
 {
     _coin           = coin;
     _isDualCoin     = isDualCoin;
     _selectedResult = selected;
     OnOk            = onOk;
     this.AddWallet  = new DelegateCommand(() => {
         this.HideView.Execute(null);
         if (_isDualCoin)
         {
             _coin.CoinProfile.AddDualCoinWallet.Execute(null);
         }
         else
         {
             _coin.CoinProfile.AddWallet.Execute(null);
         }
     });
 }
コード例 #14
0
        public GpuProfilesPageViewModel(MinerClientsWindowViewModel minerClientsWindowVm)
        {
            _minerClientsWindowVm = minerClientsWindowVm;
            if (minerClientsWindowVm.SelectedMinerClients == null && minerClientsWindowVm.SelectedMinerClients.Length != 1)
            {
                throw new InvalidProgramException();
            }
            _minerClientVm = minerClientsWindowVm.SelectedMinerClients[0];
            if (AppContext.Instance.CoinVms.TryGetCoinVm(_minerClientVm.MainCoinCode, out CoinViewModel outCoinVm))
            {
                this._coinVm = outCoinVm;
            }
            if (this._coinVm == null)
            {
                this._coinVm = CoinVms.MainCoins.FirstOrDefault();
            }
            this.Save = new DelegateCommand(() => {
                if (_data == null)
                {
                    return;
                }
                GpuProfilesJsonDb jsonObj = new GpuProfilesJsonDb()
                {
                    Gpus = _data.Gpus
                };
                foreach (var coinVm in CoinVms.MainCoins)
                {
                    if (coinVm.IsOverClockEnabled)
                    {
                        jsonObj.CoinOverClocks.Add(new CoinOverClockData()
                        {
                            CoinId             = coinVm.Id,
                            IsOverClockEnabled = coinVm.IsOverClockEnabled,
                            IsOverClockGpuAll  = coinVm.IsOverClockGpuAll
                        });
                        if (CoinVm.IsOverClockGpuAll)
                        {
                            jsonObj.GpuProfiles.Add(new GpuProfileData(coinVm.GpuAllProfileVm));
                        }
                        jsonObj.GpuProfiles.AddRange(coinVm.GpuProfileVms.Select(a => new GpuProfileData(a)));
                    }
                }
                string json = VirtualRoot.JsonSerializer.Serialize(jsonObj);
                foreach (var client in minerClientsWindowVm.SelectedMinerClients)
                {
                    Client.NTMinerDaemonService.SaveGpuProfilesJsonAsync(client.MinerIp, json);
                }
                VirtualRoot.Out.ShowSuccess("应用成功,请观察效果");
                CloseWindow?.Invoke();
            });
            Client.NTMinerDaemonService.GetGpuProfilesJsonAsync(_minerClientVm.MinerIp, (data, e) => {
                _data = data;
                if (e != null)
                {
                    Write.UserError(e.Message);
                }
                else if (data != null)
                {
                    string iconName;
                    switch (_minerClientVm.GpuType)
                    {
                    case GpuType.NVIDIA:
                    case GpuType.AMD:
                        iconName    = "Icon_Nvidia";
                        GpuIconFill = "Green";
                        RedText     = "超频有风险,操作需谨慎";
                        IsEnabled   = true;
                        break;

                    case GpuType.Empty:
                    default:
                        iconName    = "Icon_GpuEmpty";
                        GpuIconFill = "Gray";
                        RedText     = "没有矿卡或矿卡未驱动";
                        IsEnabled   = false;
                        break;
                    }
                    GpuIcon = (Geometry)System.Windows.Application.Current.Resources[iconName];
                    foreach (var coinVm in AppContext.Instance.CoinVms.MainCoins)
                    {
                        var coinOverClock = data.CoinOverClocks.FirstOrDefault(a => a.CoinId == coinVm.Id);
                        var gpuProfiles   = data.GpuProfiles.Where(a => a.CoinId == coinVm.Id).ToArray();
                        if (coinOverClock == null)
                        {
                            coinOverClock = new CoinOverClockData()
                            {
                                CoinId             = coinVm.Id,
                                IsOverClockEnabled = false,
                                IsOverClockGpuAll  = true
                            };
                        }
                        coinVm.IsOverClockEnabled = coinOverClock.IsOverClockEnabled;
                        coinVm.IsOverClockGpuAll  = coinOverClock.IsOverClockGpuAll;
                        List <GpuProfileViewModel> gpuProfileVms = new List <GpuProfileViewModel>();
                        GpuProfileViewModel gpuAllProfileVm      = null;
                        #region
                        foreach (var gpu in data.Gpus.OrderBy(a => a.Index))
                        {
                            var gpuProfile = gpuProfiles.FirstOrDefault(a => a.Index == gpu.Index);
                            if (gpuProfile == null)
                            {
                                gpuProfile = new GpuProfileData(coinVm.Id, gpu.Index);
                            }
                            var gpuVm = new GpuViewModel(gpu, data.Gpus);
                            if (gpu.Index == NTMinerRoot.GpuAllId)
                            {
                                gpuAllProfileVm = new GpuProfileViewModel(gpuProfile, gpuVm);
                            }
                            else
                            {
                                gpuProfileVms.Add(new GpuProfileViewModel(gpuProfile, gpuVm));
                            }
                        }
                        if (gpuAllProfileVm == null)
                        {
                            gpuAllProfileVm = new GpuProfileViewModel(
                                new GpuProfileData(coinVm.Id, NTMinerRoot.GpuAllId), new GpuViewModel(new GpuData {
                                Index = NTMinerRoot.GpuAllId,
                                Name  = "All"
                            }, data.Gpus));
                        }
                        #endregion
                        coinVm.GpuAllProfileVm = gpuAllProfileVm;
                        coinVm.GpuProfileVms   = gpuProfileVms;
                    }
                }
            });
        }
コード例 #15
0
ファイル: CoinViewModel.cs プロジェクト: piaoyun/ntminer
        public CoinViewModel(Guid id)
        {
            _id       = id;
            this.Save = new DelegateCommand(() => {
                if (NTMinerRoot.Current.CoinSet.Contains(this.Id))
                {
                    Global.Execute(new UpdateCoinCommand(this));
                }
                else
                {
                    Global.Execute(new AddCoinCommand(this));
                }
                CloseWindow?.Invoke();
            });
            this.ViewCoinInfo = new DelegateCommand(() => {
                Process.Start("https://www.feixiaohao.com/currencies/" + this.EnName + "/");
            });
            this.Edit = new DelegateCommand(() => {
                CoinEdit.ShowEditWindow(this);
            });
            this.Remove = new DelegateCommand(() => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                DialogWindow.ShowDialog(message: $"您确定删除{this.Code}币种吗?", title: "确认", onYes: () => {
                    Global.Execute(new RemoveCoinCommand(this.Id));
                }, icon: "Icon_Confirm");
            });
            this.SortUp = new DelegateCommand(() => {
                CoinViewModel upOne = CoinViewModels.Current.AllCoins.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
                if (upOne != null)
                {
                    int sortNumber   = upOne.SortNumber;
                    upOne.SortNumber = this.SortNumber;
                    Global.Execute(new UpdateCoinCommand(upOne));
                    this.SortNumber = sortNumber;
                    Global.Execute(new UpdateCoinCommand(this));
                    CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.AllCoins));
                }
            });
            this.SortDown = new DelegateCommand(() => {
                CoinViewModel nextOne = CoinViewModels.Current.AllCoins.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
                if (nextOne != null)
                {
                    int sortNumber     = nextOne.SortNumber;
                    nextOne.SortNumber = this.SortNumber;
                    Global.Execute(new UpdateCoinCommand(nextOne));
                    this.SortNumber = sortNumber;
                    Global.Execute(new UpdateCoinCommand(this));
                    CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.AllCoins));
                }
            });

            this.AddPool = new DelegateCommand(() => {
                int sortNumber = this.Pools.Count == 0 ? 1 : this.Pools.Max(a => a.SortNumber) + 1;
                new PoolViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(null);
            });
            this.AddWallet = new DelegateCommand(() => {
                int sortNumber = this.Wallets.Count == 0 ? 1 : this.Wallets.Max(a => a.SortNumber) + 1;
                new WalletViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(null);
            });
            this.AddCoinKernel = new DelegateCommand(() => {
                KernelSelect.ShowWindow(this);
            });
        }
コード例 #16
0
        public MinerClientsWindowViewModel(bool isInDesignMode = true)
        {
            if (Design.IsInDesignMode || isInDesignMode)
            {
                return;
            }
            var  appSettings   = NTMinerRoot.Instance.ServerAppSettingSet;
            Guid columnsShowId = ColumnsShowData.PleaseSelect.Id;

            if (appSettings.TryGetAppSetting("ColumnsShowId", out IAppSetting columnsShowAppSetting) && columnsShowAppSetting.Value != null)
            {
                if (Guid.TryParse(columnsShowAppSetting.Value.ToString(), out Guid guid))
                {
                    columnsShowId = guid;
                }
            }
            if (appSettings.TryGetAppSetting("FrozenColumnCount", out IAppSetting frozenColumnCountAppSetting) && frozenColumnCountAppSetting.Value != null)
            {
                if (int.TryParse(frozenColumnCountAppSetting.Value.ToString(), out int frozenColumnCount))
                {
                    _frozenColumnCount = frozenColumnCount;
                }
            }
            if (appSettings.TryGetAppSetting("MaxTemp", out IAppSetting maxTempAppSetting) && maxTempAppSetting.Value != null)
            {
                if (uint.TryParse(maxTempAppSetting.Value.ToString(), out uint maxTemp))
                {
                    _maxTemp = maxTemp;
                }
            }
            if (appSettings.TryGetAppSetting("MinTemp", out IAppSetting minTempAppSetting) && minTempAppSetting.Value != null)
            {
                if (uint.TryParse(minTempAppSetting.Value.ToString(), out uint minTemp))
                {
                    _minTemp = minTemp;
                }
            }
            if (appSettings.TryGetAppSetting("RejectPercent", out IAppSetting rejectPercentAppSetting) && rejectPercentAppSetting.Value != null)
            {
                if (int.TryParse(rejectPercentAppSetting.Value.ToString(), out int rejectPercent))
                {
                    _rejectPercent = rejectPercent;
                }
            }
            this._columnsShow = this.ColumnsShows.List.FirstOrDefault(a => a.Id == columnsShowId);
            if (this._columnsShow == null)
            {
                this._columnsShow = this.ColumnsShows.List.FirstOrDefault();
            }
            this._mineStatusEnumItem = EnumSet.MineStatusEnumItems.FirstOrDefault(a => a.Value == MineStatus.All);
            this._coinVm             = CoinViewModel.PleaseSelect;
            this._selectedMineWork   = MineWorkViewModel.PleaseSelect;
            this._selectedMinerGroup = MinerGroupViewModel.PleaseSelect;
            this._pool = string.Empty;
            // 至少会有一个PleaseSelect所以可以First
            this._poolVm       = _coinVm.OptionPools.First();
            this._wallet       = string.Empty;
            this.OneKeySetting = new DelegateCommand(() => {
                VirtualRoot.Execute(new ShowMinerClientSettingCommand(new MinerClientSettingViewModel(this.SelectedMinerClients)));
            }, CanCommand);
            this.OneKeyMinerNames = new DelegateCommand(() => {
                if (this.SelectedMinerClients.Length == 1)
                {
                    var selectedMinerClient = this.SelectedMinerClients[0];
                    Wpf.Util.ShowInputDialog("群控矿工名 注意:重新开始挖矿时生效", selectedMinerClient.MinerName, null, minerName => {
                        selectedMinerClient.MinerName = minerName;
                        NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("设置群控矿工名成功,重新开始挖矿时生效。");
                    });
                    return;
                }
                MinerNamesSeterViewModel vm = new MinerNamesSeterViewModel(
                    prefix: "miner",
                    suffix: "01",
                    namesByObjectId: this.SelectedMinerClients.Select(a => new Tuple <string, string>(a.Id, string.Empty)).ToList());
                VirtualRoot.Execute(new ShowMinerNamesSeterCommand(vm));
                if (vm.IsOk)
                {
                    this.CountDown = 10;
                    Server.ControlCenterService.UpdateClientsAsync(nameof(MinerClientViewModel.MinerName), vm.NamesByObjectId.ToDictionary(a => a.Item1, a => (object)a.Item2), callback: (response, e) => {
                        if (!response.IsSuccess())
                        {
                            Write.UserFail(response.ReadMessage(e));
                        }
                        else
                        {
                            foreach (var kv in vm.NamesByObjectId)
                            {
                                var item = this.SelectedMinerClients.FirstOrDefault(a => a.Id == kv.Item1);
                                if (item != null)
                                {
                                    item.UpdateMinerName(kv.Item2);
                                }
                            }
                            QueryMinerClients();
                        }
                    });
                }
            }, CanCommand);
            this.OneKeyWindowsLoginName = new DelegateCommand(() => {
                Wpf.Util.ShowInputDialog("远程桌面用户名", string.Empty, null, loginName => {
                    foreach (var item in SelectedMinerClients)
                    {
                        item.WindowsLoginName = loginName;
                    }
                    NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("设置远程桌面用户名成功,双击矿机可打开远程桌面。");
                });
            }, CanCommand);
            this.OneKeyWindowsLoginPassword = new DelegateCommand(() => {
                Wpf.Util.ShowInputDialog("远程桌面密码", string.Empty, null, password => {
                    foreach (var item in SelectedMinerClients)
                    {
                        item.WindowsPassword = password;
                    }
                    NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("设置远程桌面密码成功,双击矿机可打开远程桌面。");
                });
            }, CanCommand);
            this.EditMineWork = new DelegateCommand(() => {
                this.SelectedMinerClients[0].SelectedMineWork.Edit.Execute(null);
            }, () => OnlySelectedOne() && this.SelectedMinerClients[0].SelectedMineWork != null &&
                                                    this.SelectedMinerClients[0].SelectedMineWork != MineWorkViewModel.PleaseSelect);
            this.OneKeyWork = new DelegateCommand <MineWorkViewModel>((work) => {
                foreach (var item in SelectedMinerClients)
                {
                    item.SelectedMineWork = work;
                }
            });
            this.OneKeyGroup = new DelegateCommand <MinerGroupViewModel>((group) => {
                foreach (var item in SelectedMinerClients)
                {
                    item.SelectedMinerGroup = group;
                }
            });
            this.OneKeyOverClock = new DelegateCommand(() => {
                if (this.SelectedMinerClients.Length == 1)
                {
                    VirtualRoot.Execute(new ShowGpuProfilesPageCommand(this));
                }
            }, OnlySelectedOne);
            this.OneKeyUpgrade = new DelegateCommand <NTMinerFileData>((ntminerFileData) => {
                this.ShowDialog(message: "确定升级到该版本吗?", title: "确认", onYes: () => {
                    foreach (var item in SelectedMinerClients)
                    {
                        Server.MinerClientService.UpgradeNTMinerAsync(item, ntminerFileData.FileName, (response, e) => {
                            if (!response.IsSuccess())
                            {
                                Write.UserFail($"{item.MinerName} {item.MinerIp} {response.ReadMessage(e)}");
                            }
                        });
                    }
                }, icon: IconConst.IconConfirm);
            }, (ntminerFileData) => this.SelectedMinerClients != null && this.SelectedMinerClients.Length != 0);
            this.AddMinerClient = new DelegateCommand(() => {
                VirtualRoot.Execute(new ShowMinerClientAddCommand());
            });
            this.RemoveMinerClients = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    this.ShowDialog(message: $"确定删除选中的矿机吗?", title: "确认", onYes: () => {
                        this.CountDown = 10;
                        Server.ControlCenterService.RemoveClientsAsync(SelectedMinerClients.Select(a => a.Id).ToList(), (response, e) => {
                            if (!response.IsSuccess())
                            {
                                Write.UserFail(response.ReadMessage(e));
                            }
                            else
                            {
                                QueryMinerClients();
                            }
                        });
                    }, icon: IconConst.IconConfirm);
                }
            }, CanCommand);
            this.RefreshMinerClients = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    Server.ControlCenterService.RefreshClientsAsync(SelectedMinerClients.Select(a => a.Id).ToList(), (response, e) => {
                        if (!response.IsSuccess())
                        {
                            Write.UserFail(response.ReadMessage(e));
                        }
                        else
                        {
                            foreach (var data in response.Data)
                            {
                                var item = MinerClients.FirstOrDefault(a => a.Id == data.Id);
                                if (item != null)
                                {
                                    item.Update(data);
                                }
                            }
                        }
                    });
                }
            }, CanCommand);
            this.RestartWindows = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    this.ShowDialog(message: $"确定重启选中的电脑吗?", title: "确认", onYes: () => {
                        foreach (var item in SelectedMinerClients)
                        {
                            Server.MinerClientService.RestartWindowsAsync(item, (response, e) => {
                                if (!response.IsSuccess())
                                {
                                    Write.UserFail(response.ReadMessage(e));
                                }
                            });
                        }
                    }, icon: IconConst.IconConfirm);
                }
            }, CanCommand);
            this.ShutdownWindows = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    this.ShowDialog(message: $"确定关闭选中的电脑吗?", title: "确认", onYes: () => {
                        foreach (var item in SelectedMinerClients)
                        {
                            Server.MinerClientService.ShutdownWindowsAsync(item, (response, e) => {
                                if (!response.IsSuccess())
                                {
                                    Write.UserFail(response.ReadMessage(e));
                                }
                            });
                        }
                    }, icon: IconConst.IconConfirm);
                }
            }, CanCommand);
            this.RestartNTMiner = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    this.ShowDialog(message: $"确定重启选中的挖矿客户端吗?", title: "确认", onYes: () => {
                        foreach (var item in SelectedMinerClients)
                        {
                            Server.MinerClientService.RestartNTMinerAsync(item, (response, e) => {
                                if (!response.IsSuccess())
                                {
                                    Write.UserFail(response.ReadMessage(e));
                                }
                            });
                        }
                    }, icon: IconConst.IconConfirm);
                }
            }, CanCommand);
            this.StartMine = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    foreach (var item in SelectedMinerClients)
                    {
                        item.IsMining = true;
                        Server.MinerClientService.StartMineAsync(item, item.WorkId, (response, e) => {
                            if (!response.IsSuccess())
                            {
                                Write.UserFail($"{item.MinerIp} {response.ReadMessage(e)}");
                            }
                        });
                        Server.ControlCenterService.UpdateClientAsync(item.Id, nameof(item.IsMining), item.IsMining, null);
                    }
                }
            }, CanCommand);
            this.StopMine = new DelegateCommand(() => {
                if (SelectedMinerClients.Length == 0)
                {
                    ShowNoRecordSelected();
                }
                else
                {
                    this.ShowDialog(message: $"确定将选中的矿机停止挖矿吗?", title: "确认", onYes: () => {
                        foreach (var item in SelectedMinerClients)
                        {
                            item.IsMining = false;
                            Server.MinerClientService.StopMineAsync(item, (response, e) => {
                                if (!response.IsSuccess())
                                {
                                    Write.UserFail($"{item.MinerIp} {response.ReadMessage(e)}");
                                }
                            });
                            Server.ControlCenterService.UpdateClientAsync(item.Id, nameof(item.IsMining), item.IsMining, null);
                        }
                    }, icon: IconConst.IconConfirm);
                }
            }, CanCommand);
            this.PageUp = new DelegateCommand(() => {
                this.MinerClientPageIndex = this.MinerClientPageIndex - 1;
            });
            this.PageDown = new DelegateCommand(() => {
                this.MinerClientPageIndex = this.MinerClientPageIndex + 1;
            });
            this.PageFirst = new DelegateCommand(() => {
                this.MinerClientPageIndex = 1;
            });
            this.PageLast = new DelegateCommand(() => {
                this.MinerClientPageIndex = MinerClientPageCount;
            });
            this.PageRefresh = new DelegateCommand(QueryMinerClients);
        }
コード例 #17
0
 private KernelInputViewModels()
 {
     Global.Access <KernelInputAddedEvent>(
         Guid.Parse("7BB2CAD5-333F-4BDD-B6FF-3F0AA50724EA"),
         "添加了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         var vm = new KernelInputViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), vm);
         OnPropertyChanged(nameof(AllKernelInputVms));
         OnPropertyChanged(nameof(PleaseSelectVms));
     });
     Global.Access <KernelInputUpdatedEvent>(
         Guid.Parse("A85F4699-F884-43A3-B6F1-3E7CBCA7D7D6"),
         "更新了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var item = _dicById[message.Source.GetId()];
             if (item != null)
             {
                 bool isSupportDualMine = item.IsSupportDualMine;
                 string args            = item.Args;
                 string dualFullArgs    = item.DualFullArgs;
                 item.Update(message.Source);
                 if (args != item.Args || dualFullArgs != item.DualFullArgs)
                 {
                     CoinViewModel coinVm = MinerProfileViewModel.Current.CoinVm;
                     if (coinVm != null && coinVm.CoinKernel != null && coinVm.CoinKernel.Kernel.KernelInputId == item.Id)
                     {
                         Global.Execute(new RefreshArgsAssemblyCommand());
                     }
                 }
                 if (isSupportDualMine != item.IsSupportDualMine)
                 {
                     foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                     {
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                         coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.DualCoinGroup));
                     }
                 }
             }
         }
     });
     Global.Access <KernelInputRemovedEvent>(
         Guid.Parse("4E0CFBAF-443F-4C09-B86B-3DBC7D7AF875"),
         "移除了内核输入后刷新VM内存",
         LogEnum.None,
         action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChanged(nameof(AllKernelInputVms));
             OnPropertyChanged(nameof(PleaseSelectVms));
         }
     });
     foreach (var item in NTMinerRoot.Current.KernelInputSet)
     {
         _dicById.Add(item.GetId(), new KernelInputViewModel(item));
     }
 }
コード例 #18
0
ファイル: CoinViewModel.cs プロジェクト: oyangjian/ntminer
        public CoinViewModel(Guid id)
        {
            _id = id;
            this.ApplyTemplateOverClock = new DelegateCommand <OverClockDataViewModel>((data) => {
                DialogWindow.ShowDialog(message: data.Tooltip, title: "确定应用该超频设置吗?", onYes: () => {
                    FillOverClock(data);
                    ApplyOverClock();
                }, icon: IconConst.IconConfirm);
            });
            this.ApplyCustomOverClock = new DelegateCommand(() => {
                DialogWindow.ShowDialog(message: $"确定应用您的自定义超频吗?", title: "确认自定义超频", onYes: () => {
                    ApplyOverClock();
                }, icon: IconConst.IconConfirm);
            });
            this.FillOverClockForm = new DelegateCommand <OverClockDataViewModel>((data) => {
                FillOverClock(data);
            });
            this.AddOverClockData = new DelegateCommand(() => {
                new OverClockDataViewModel(Guid.NewGuid())
                {
                    CoinId = this.Id
                }.Edit.Execute(FormType.Add);
            });
            this.Save = new DelegateCommand(() => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                if (NTMinerRoot.Current.CoinSet.Contains(this.Id))
                {
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                }
                else
                {
                    VirtualRoot.Execute(new AddCoinCommand(this));
                }
                CloseWindow?.Invoke();
            });
            this.ViewCoinInfo = new DelegateCommand(() => {
                Process.Start("https://www.feixiaohao.com/currencies/" + this.EnName + "/");
            });
            this.Edit = new DelegateCommand <FormType?>((formType) => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                CoinEdit.ShowWindow(formType ?? FormType.Edit, this);
            });
            this.Remove = new DelegateCommand(() => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                DialogWindow.ShowDialog(message: $"您确定删除{this.Code}币种吗?", title: "确认", onYes: () => {
                    VirtualRoot.Execute(new RemoveCoinCommand(this.Id));
                }, icon: IconConst.IconConfirm);
            });
            this.SortUp = new DelegateCommand(() => {
                CoinViewModel upOne = CoinViewModels.Current.AllCoins.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
                if (upOne != null)
                {
                    int sortNumber   = upOne.SortNumber;
                    upOne.SortNumber = this.SortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(upOne));
                    this.SortNumber = sortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                    CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.AllCoins));
                }
            });
            this.SortDown = new DelegateCommand(() => {
                CoinViewModel nextOne = CoinViewModels.Current.AllCoins.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
                if (nextOne != null)
                {
                    int sortNumber     = nextOne.SortNumber;
                    nextOne.SortNumber = this.SortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(nextOne));
                    this.SortNumber = sortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                    CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.MainCoins));
                    CoinViewModels.Current.OnPropertyChanged(nameof(CoinViewModels.AllCoins));
                }
            });

            this.AddPool = new DelegateCommand(() => {
                int sortNumber = this.Pools.Count == 0 ? 1 : this.Pools.Max(a => a.SortNumber) + 1;
                new PoolViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(FormType.Add);
            });
            this.AddWallet = new DelegateCommand(() => {
                int sortNumber = this.Wallets.Count == 0 ? 1 : this.Wallets.Max(a => a.SortNumber) + 1;
                new WalletViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(FormType.Add);
            });
            this.AddCoinKernel = new DelegateCommand(() => {
                KernelSelect.ShowWindow(this);
            });
        }
コード例 #19
0
 public PoolSelectViewModel(CoinViewModel coin, PoolViewModel selected, Action <PoolViewModel> onSelectedChanged)
 {
     _coin              = coin;
     _selectedResult    = selected;
     _onSelectedChanged = onSelectedChanged;
 }
コード例 #20
0
ファイル: PoolSelectViewModel.cs プロジェクト: vebin/ntminer
 public PoolSelectViewModel(CoinViewModel coin, PoolViewModel selected, Action <PoolViewModel> onOk)
 {
     _coin           = coin;
     _selectedResult = selected;
     OnOk            = onOk;
 }
コード例 #21
0
 public CoinViewModel(CoinViewModel vm) : this((ICoin)vm)
 {
     _iconImageSource = vm.IconImageSource;
 }
コード例 #22
0
 public CoinIncomeViewModel(CoinViewModel coinVm)
 {
     _coinVm = coinVm;
 }
コード例 #23
0
        private KernelViewModels()
        {
            Global.Access <KernelAddedEvent>(
                Guid.Parse("35917be2-7373-440d-b083-8edc1050f2cc"),
                "添加了内核后调整VM内存",
                LogEnum.Log,
                action: (message) => {
                _dicById.Add(message.Source.GetId(), new KernelViewModel(message.Source));
                OnPropertyChanged(nameof(AllKernels));
                foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                {
                    coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                }
            });
            Global.Access <KernelRemovedEvent>(
                Guid.Parse("c8a5fdca-85c3-40ae-8c79-41af2aa1d4da"),
                "删除了内核后调整VM内存",
                LogEnum.Log,
                action: message => {
                _dicById.Remove(message.Source.GetId());
                OnPropertyChanged(nameof(AllKernels));
                foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                {
                    coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                }
            });
            Global.Access <KernelUpdatedEvent>(
                Guid.Parse("98b29a2f-fbcf-466d-81a4-ddbbc4594225"),
                "更新了内核后调整VM内存",
                LogEnum.Log,
                action: message => {
                var entity             = _dicById[message.Source.GetId()];
                int sortNumber         = entity.SortNumber;
                bool isSupportDualMine = entity.IsSupportDualMine;
                string args            = entity.Args;
                string dualFullArgs    = entity.DualFullArgs;
                entity.Update(message.Source);
                if (sortNumber != entity.SortNumber)
                {
                    KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.QueryResults));
                }
                if (args != entity.Args || dualFullArgs != entity.DualFullArgs)
                {
                    CoinViewModel coinVm = MinerProfileViewModel.Current.CoinVm;
                    if (coinVm != null && coinVm.CoinKernel != null && coinVm.CoinKernel.KernelId == entity.Id)
                    {
                        Global.Execute(new RefreshArgsAssemblyCommand());
                    }
                }
                if (isSupportDualMine != entity.IsSupportDualMine)
                {
                    foreach (var coinKernelVm in CoinKernelViewModels.Current.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                    {
                        coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                    }
                }
            });

            foreach (var item in NTMinerRoot.Current.KernelSet)
            {
                _dicById.Add(item.GetId(), new KernelViewModel(item));
            }
        }
コード例 #24
0
ファイル: CoinViewModels.cs プロジェクト: ranchenglou/ntminer
 private CoinViewModels()
 {
     if (Design.IsInDesignMode)
     {
         return;
     }
     Global.Access <CoinAddedEvent>(
         Guid.Parse("1ee6e72d-d98f-42ab-8732-dcee2e42f4b8"),
         "添加了币种后刷新VM内存",
         LogEnum.Log,
         action: (message) => {
         _dicById.Add(message.Source.GetId(), new CoinViewModel(message.Source));
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         OnPropertyChanged(nameof(AllCoins));
         OnPropertyChanged(nameof(MainCoins));
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
         OnPropertyChanged(nameof(PleaseSelect));
         OnPropertyChanged(nameof(DualPleaseSelect));
     });
     Global.Access <CoinRemovedEvent>(
         Guid.Parse("6c966862-6dfa-4473-94b5-1133a16180a1"),
         "移除了币种后刷新VM内存",
         LogEnum.Log,
         action: message => {
         _dicById.Remove(message.Source.GetId());
         MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         OnPropertyChanged(nameof(AllCoins));
         OnPropertyChanged(nameof(MainCoins));
         CoinPageViewModel.Current.OnPropertyChanged(nameof(CoinPageViewModel.List));
         OnPropertyChanged(nameof(PleaseSelect));
         OnPropertyChanged(nameof(DualPleaseSelect));
     });
     Global.Access <CoinUpdatedEvent>(
         Guid.Parse("114c90e5-6a0a-4aa4-9ba8-5ed603286c51"),
         "更新了币种后刷新VM内存",
         LogEnum.Log,
         action: message => {
         CoinViewModel coinVm = _dicById[message.Source.GetId()];
         bool justAsDualCoin  = coinVm.JustAsDualCoin;
         coinVm.Update(message.Source);
         coinVm.TestWalletVm.Address = message.Source.TestWallet;
         coinVm.OnPropertyChanged(nameof(coinVm.Wallets));
         if (MinerProfileViewModel.Current.CoinId == message.Source.GetId())
         {
             MinerProfileViewModel.Current.OnPropertyChanged(nameof(MinerProfileViewModel.Current.CoinVm));
         }
         CoinKernelViewModel coinKernelVm = MinerProfileViewModel.Current.CoinVm.CoinKernel;
         if (coinKernelVm != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin != null &&
             coinKernelVm.CoinKernelProfile.SelectedDualCoin.GetId() == message.Source.GetId())
         {
             coinKernelVm.CoinKernelProfile.OnPropertyChanged(nameof(coinKernelVm.CoinKernelProfile.SelectedDualCoin));
         }
         if (justAsDualCoin != coinVm.JustAsDualCoin)
         {
             OnPropertyChanged(nameof(MainCoins));
         }
     });
     foreach (var item in NTMinerRoot.Current.CoinSet)
     {
         _dicById.Add(item.GetId(), new CoinViewModel(item));
     }
 }
コード例 #25
0
        public CoinViewModel(Guid id)
        {
            _id             = id;
            _coinIncomeVm   = new CoinIncomeViewModel(this);
            this.BrowseIcon = new DelegateCommand(() => {
                if (!DevMode.IsDevMode)
                {
                    return;
                }
                OpenFileDialog openFileDialog = new OpenFileDialog {
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    Filter           = "png (*.png)|*.png",
                    FilterIndex      = 1
                };
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try {
                        string iconFileFullName = openFileDialog.FileName;
                        this.IconImageSource    = new Uri(iconFileFullName, UriKind.Absolute).ToString();
                        string pngFileName      = Path.GetFileName(iconFileFullName);
                        if (AppContext.Instance.CoinVms.AllCoins.Any(a => a.Icon == pngFileName && a.Id != this.Id))
                        {
                            throw new ValidationException("币种图标不能重名");
                        }
                        this.Icon = pngFileName;
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e);
                    }
                }
            });
            this.ApplyTemplateOverClock = new DelegateCommand <OverClockDataViewModel>((data) => {
                this.ShowDialog(message: data.Tooltip, title: "确定应用该超频设置吗?", onYes: () => {
                    FillOverClock(data);
                    ApplyOverClock();
                }, icon: IconConst.IconConfirm);
            });
            this.ApplyCustomOverClock = new DelegateCommand(() => {
                this.ShowDialog(message: $"确定应用您的自定义超频吗?", title: "确认自定义超频", onYes: () => {
                    ApplyOverClock();
                }, icon: IconConst.IconConfirm);
            });
            this.RestoreOverClock = new DelegateCommand(() => {
                this.ShowDialog(message: $"确定恢复默认并禁用超频界面吗?", title: "确认", onYes: () => {
                    NTMinerRoot.Instance.GpuSet.OverClock.Restore();
                    this.IsOverClockEnabled = false;
                }, icon: IconConst.IconConfirm);
            });
            this.FillOverClockForm = new DelegateCommand <OverClockDataViewModel>((data) => {
                FillOverClock(data);
            });
            this.FillOverClockForms = new DelegateCommand(() => {
                this.ShowDialog(message: "确定将统一超频的数据一键填充到每张卡吗?", title: "一键填充表单", onYes: () => {
                    var data = GpuAllProfileVm;
                    foreach (var item in GpuProfileVms)
                    {
                        if (item.Index == NTMinerRoot.GpuAllId)
                        {
                            continue;
                        }
                        item.Update((IOverClockInput)data);
                    }
                }, icon: IconConst.IconConfirm);
            });
            this.AddOverClockData = new DelegateCommand(() => {
                new OverClockDataViewModel(Guid.NewGuid())
                {
                    CoinId = this.Id
                }.Edit.Execute(FormType.Add);
            });
            this.Save = new DelegateCommand(() => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                if (NTMinerRoot.Instance.CoinSet.Contains(this.Id))
                {
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                }
                else
                {
                    VirtualRoot.Execute(new AddCoinCommand(this));
                }
                CloseWindow?.Invoke();
            });
            this.Edit = new DelegateCommand <FormType?>((formType) => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                VirtualRoot.Execute(new CoinEditCommand(formType ?? FormType.Edit, this));
            });
            this.Remove = new DelegateCommand(() => {
                if (this.Id == Guid.Empty)
                {
                    return;
                }
                this.ShowDialog(message: $"您确定删除{this.Code}币种吗?", title: "确认", onYes: () => {
                    VirtualRoot.Execute(new RemoveCoinCommand(this.Id));
                }, icon: IconConst.IconConfirm);
            });
            this.SortUp = new DelegateCommand(() => {
                CoinViewModel upOne = AppContext.Instance.CoinVms.AllCoins.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
                if (upOne != null)
                {
                    int sortNumber   = upOne.SortNumber;
                    upOne.SortNumber = this.SortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(upOne));
                    this.SortNumber = sortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                    AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins));
                    AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.AllCoins));
                }
            });
            this.SortDown = new DelegateCommand(() => {
                CoinViewModel nextOne = AppContext.Instance.CoinVms.AllCoins.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
                if (nextOne != null)
                {
                    int sortNumber     = nextOne.SortNumber;
                    nextOne.SortNumber = this.SortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(nextOne));
                    this.SortNumber = sortNumber;
                    VirtualRoot.Execute(new UpdateCoinCommand(this));
                    AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins));
                    AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.AllCoins));
                }
            });

            this.AddPool = new DelegateCommand(() => {
                int sortNumber = this.Pools.Count == 0 ? 1 : this.Pools.Max(a => a.SortNumber) + 1;
                new PoolViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(FormType.Add);
            });
            this.AddWallet = new DelegateCommand(() => {
                int sortNumber = this.Wallets.Count == 0 ? 1 : this.Wallets.Max(a => a.SortNumber) + 1;
                new WalletViewModel(Guid.NewGuid())
                {
                    CoinId     = Id,
                    SortNumber = sortNumber
                }.Edit.Execute(FormType.Add);
            });
        }
コード例 #26
0
ファイル: CoinViewModels.cs プロジェクト: ranchenglou/ntminer
 public bool TryGetCoinVm(Guid coinId, out CoinViewModel coinVm)
 {
     return(_dicById.TryGetValue(coinId, out coinVm));
 }
コード例 #27
0
ファイル: ChartViewModel.cs プロジェクト: ayxcjqx/ntminer
        public ChartViewModel(CoinViewModel coinVm)
        {
            this.Hide = new DelegateCommand(() => {
                this.IsShow = false;
            });
            _coinVm = coinVm;
            var mapper = Mappers.Xy <MeasureModel>()
                         .X(model => model.DateTime.Ticks) //use DateTime.Ticks as X
                         .Y(model => model.Value);         //use the value property as Y

            //lets save the mapper globally.
            Charting.For <MeasureModel>(mapper);

            string DateTimeFormatter(double value) => new DateTime((long)value).ToString("HH:mm");
            string SpeedFormatter(double value) => value.ToUnitSpeedText();

            //AxisStep forces the distance between each separator in the X axis
            double axisStep = TimeSpan.FromMinutes(1).Ticks;
            //AxisUnit forces lets the axis know that we are plotting Minutes
            //this is not always necessary, but it can prevent wrong labeling
            double axisUnit   = TimeSpan.TicksPerMinute;
            var    axisYSpeed = new Axis()
            {
                LabelFormatter = SpeedFormatter,
                MinValue       = 0,
                Separator      = new Separator(),
                Foreground     = SAxisForeground,
                FontSize       = 13,
                Position       = AxisPosition.RightTop
            };
            var axisYOnlineCount = new Axis()
            {
                LabelFormatter = value => Math.Round(value, 0) + "miner",
                Separator      = new Separator(),
                Foreground     = SAxisForeground,
                MinValue       = 0,
                FontSize       = 11
            };
            var axisYShareCount = new Axis()
            {
                LabelFormatter = value => Math.Round(value, 0) + "share",
                Separator      = new Separator(),
                Foreground     = SAxisForeground,
                MinValue       = 0,
                FontSize       = 11,
                Position       = AxisPosition.RightTop
            };

            this._axisY = new AxesCollection {
                axisYOnlineCount, axisYSpeed, axisYShareCount
            };
            DateTime now = DateTime.Now;

            this._axisX = new AxesCollection()
            {
                new Axis()
                {
                    LabelFormatter = DateTimeFormatter,
                    MaxValue       = now.Ticks,
                    MinValue       = now.Ticks - TimeSpan.FromMinutes(NTMinerRoot.SpeedHistoryLengthByMinute).Ticks,
                    Unit           = axisUnit,
                    Separator      = new Separator()
                    {
                        Step = axisStep
                    },
                    Foreground = SAxisForeground,
                    FontSize   = 12,
                }
            };
            LineSeries mainCoinSpeedLs = new LineSeries {
                Title             = "speed",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 1,
                Values            = new ChartValues <MeasureModel>()
            };
            LineSeries onlineCountLs = new LineSeries {
                Title             = "onlineCount",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 0,
                Fill   = STransparent,
                Stroke = OnlineColor,
                Values = new ChartValues <MeasureModel>()
            };
            LineSeries miningCountLs = new LineSeries {
                Title             = "miningCount",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 0,
                Fill   = STransparent,
                Stroke = MiningColor,
                Values = new ChartValues <MeasureModel>()
            };

            _rejectValues = new ChartValues <MeasureModel>();
            _acceptValues = new ChartValues <MeasureModel>();
            StackedColumnSeries rejectScs = new StackedColumnSeries {
                Title          = "rejectShare",
                Values         = _rejectValues,
                DataLabels     = false,
                ScalesYAt      = 2,
                MaxColumnWidth = 7
            };
            StackedColumnSeries acceptScs = new StackedColumnSeries {
                Title          = "acceptShare",
                Values         = _acceptValues,
                DataLabels     = false,
                ScalesYAt      = 2,
                MaxColumnWidth = 7
            };

            this._series = new SeriesCollection()
            {
                mainCoinSpeedLs, rejectScs, acceptScs, miningCountLs, onlineCountLs
            };
        }
コード例 #28
0
        public ControlCenterChartViewModel(CoinViewModel coinVm)
        {
            _coinVm = coinVm;
            var mapper = Mappers.Xy <MeasureModel>()
                         .X(model => model.DateTime.Ticks) //use DateTime.Ticks as X
                         .Y(model => model.Value);         //use the value property as Y

            //lets save the mapper globally.
            Charting.For <MeasureModel>(mapper);

            Func <double, string> dateTimeFormatter = value => new DateTime((long)value).ToString("HH:mm");
            Func <double, string> speedFormatter    = value => value.ToUnitSpeedText();
            //AxisStep forces the distance between each separator in the X axis
            double axisStep = TimeSpan.FromMinutes(1).Ticks;
            //AxisUnit forces lets the axis know that we are plotting Minutes
            //this is not always necessary, but it can prevent wrong labeling
            double axisUnit   = TimeSpan.TicksPerMinute;
            var    axisYSpeed = new Axis()
            {
                LabelFormatter = speedFormatter,
                MinValue       = 0,
                Separator      = new Separator(),
                Foreground     = black,
                FontSize       = 13,
                Position       = AxisPosition.RightTop
            };
            var axisYOnlineCount = new Axis()
            {
                LabelFormatter = value => Math.Round(value, 0).ToString(),
                Separator      = new Separator(),
                Foreground     = black,
                MinValue       = 0,
                FontSize       = 13
            };

            this._axisY = new AxesCollection {
                axisYOnlineCount, axisYSpeed
            };
            DateTime now = DateTime.Now;

            this._axisX = new AxesCollection()
            {
                new Axis()
                {
                    LabelFormatter = dateTimeFormatter,
                    MaxValue       = now.Ticks,
                    MinValue       = now.Ticks - TimeSpan.FromMinutes(NTMinerRoot.Current.SpeedHistoryLengthByMinute).Ticks,
                    Unit           = axisUnit,
                    Separator      = new Separator()
                    {
                        Step = axisStep
                    },
                    Foreground = black,
                    FontSize   = 13,
                }
            };
            LineSeries mainCoinSpeedLs = new LineSeries {
                Title             = "speed",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 1,
                Values            = new ChartValues <MeasureModel>()
            };
            LineSeries onlineCountLs = new LineSeries {
                Title             = "onlineCount",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 0,
                Fill   = transparent,
                Stroke = OnlineColor,
                Values = new ChartValues <MeasureModel>()
            };
            LineSeries miningCountLs = new LineSeries {
                Title             = "miningCount",
                DataLabels        = false,
                PointGeometrySize = 0,
                StrokeThickness   = 1,
                ScalesYAt         = 0,
                Fill   = transparent,
                Stroke = MiningColor,
                Values = new ChartValues <MeasureModel>()
            };

            this._series = new SeriesCollection()
            {
                mainCoinSpeedLs, onlineCountLs, miningCountLs
            };
        }