Пример #1
0
 private ColumnsShowViewModels()
 {
     this.Add = new DelegateCommand(() => {
         new ColumnsShowViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
     });
     VirtualRoot.On <ColumnsShowAddedEvent>("添加了列显后刷新VM内存", LogEnum.DevConsole,
                                            action: message => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             ColumnsShowViewModel vm = new ColumnsShowViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), vm);
             OnPropertyChanged(nameof(List));
             MinerClientsWindowViewModel.Current.ColumnsShow = vm;
         }
     });
     VirtualRoot.On <ColumnsShowUpdatedEvent>("更新了列显后刷新VM内存", LogEnum.DevConsole,
                                              action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             ColumnsShowViewModel entity = _dicById[message.Source.GetId()];
             entity.Update(message.Source);
         }
     });
     VirtualRoot.On <ColumnsShowRemovedEvent>("移除了列显后刷新VM内存", LogEnum.DevConsole,
                                              action: message => {
         MinerClientsWindowViewModel.Current.ColumnsShow = _dicById.Values.FirstOrDefault();
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(List));
     });
     foreach (var item in NTMinerRoot.Current.ColumnsShowSet)
     {
         _dicById.Add(item.GetId(), new ColumnsShowViewModel(item));
     }
 }
Пример #2
0
 public ColumnItem(PropertyInfo propertyInfo, ColumnsShowViewModel vm)
 {
     this.PropertyInfo = propertyInfo;
     this._vm          = vm;
 }
Пример #3
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);
        }