public LocalJsonDb(INTMinerRoot root, MineWorkData mineWorkData) { var minerProfile = root.MinerProfile; CoinProfileData mainCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(minerProfile.CoinId)); List <CoinProfileData> coinProfiles = new List <CoinProfileData> { mainCoinProfile }; List <PoolProfileData> poolProfiles = new List <PoolProfileData>(); CoinKernelProfileData coinKernelProfile = new CoinKernelProfileData(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId)); PoolProfileData mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId)); poolProfiles.Add(mainCoinPoolProfile); if (mainCoinProfile.PoolId1 != Guid.Empty) { mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId1)); poolProfiles.Add(mainCoinPoolProfile); } if (coinKernelProfile.IsDualCoinEnabled) { CoinProfileData dualCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId)); coinProfiles.Add(dualCoinProfile); PoolProfileData dualCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId)); poolProfiles.Add(dualCoinPoolProfile); } MinerProfile = MinerProfileData.Create(minerProfile); MinerProfile.MinerName = "{{MinerName}}"; MineWork = mineWorkData; CoinProfiles = coinProfiles.ToArray(); CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile }; PoolProfiles = poolProfiles.ToArray(); Pools = root.ServerContext.PoolSet.AsEnumerable().Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData(a)).ToArray(); Wallets = minerProfile.GetWallets().Select(a => new WalletData(a)).ToArray(); TimeStamp = Timestamp.GetTimestamp(); }
private void Init(INTMinerContext root) { var minerProfileRepository = root.ServerContext.CreateLocalRepository <MinerProfileData>(); _data = minerProfileRepository.GetAll().FirstOrDefault(); var mineWorkRepository = root.ServerContext.CreateLocalRepository <MineWorkData>(); MineWork = mineWorkRepository.GetAll().FirstOrDefault(); if (_data == null) { Guid coinId = Guid.Empty; ICoin coin = root.ServerContext.CoinSet.AsEnumerable().OrderBy(a => a.Code).FirstOrDefault(); if (coin != null) { coinId = coin.GetId(); } _data = MinerProfileData.CreateDefaultData(coinId); } else { // 交换到注册表以供守护进程访问 if (ClientAppType.IsMinerClient && !NTMinerContext.IsJsonLocal) { SetIsOuterUserEnabled(_data.IsOuterUserEnabled); SetOuterUserId(_data.OuterUserId); } } if (_coinProfileSet == null) { _coinProfileSet = new CoinProfileSet(root); } else { _coinProfileSet.Refresh(); } if (_coinKernelProfileSet == null) { _coinKernelProfileSet = new CoinKernelProfileSet(root); } else { _coinKernelProfileSet.Refresh(); } if (_poolProfileSet == null) { _poolProfileSet = new PoolProfileSet(root); } else { _poolProfileSet.Refresh(); } if (_walletSet == null) { _walletSet = new WalletSet(root); } else { _walletSet.Refresh(); } }
public void SetMinerProfileProperty(Guid workId, string propertyName, object value) { if (!MinerProfileProperties.ContainsKey(propertyName)) { return; } using (var database = CreateDatabase(workId)) { var col = database.GetCollection <MinerProfileData>(); var data = col.FindAll().FirstOrDefault(); bool exist = true; if (data == null) { exist = false; data = MinerProfileData.CreateDefaultData(); } PropertyInfo propertyInfo = MinerProfileProperties[propertyName]; if (propertyInfo.PropertyType == typeof(Guid)) { value = DictionaryExtensions.ConvertToGuid(value); } propertyInfo.SetValue(data, value, null); if (exist) { data.ModifiedOn = DateTime.Now; col.Update(data); } else { col.Insert(data); } } }
// 从磁盘读取local.json反序列化为LocalJson对象 private static void LocalJsonInit() { if (!_localJsonInited) { lock (_locker) { if (!_localJsonInited) { string localJson = HomePath.ReadLocalJsonFile(); if (!string.IsNullOrEmpty(localJson)) { LocalJsonDb data = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson); _localJson = data ?? new LocalJsonDb(); } else { _localJson = new LocalJsonDb(); } #region 因为是群控作业,将开机启动和自动挖矿设置为true var repository = new LiteDbReadWriteRepository <MinerProfileData>(HomePath.LocalDbFileFullName); MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId); if (localProfile != null) { MinerProfileData.CopyWorkIgnoreValues(localProfile, _localJson.MinerProfile); // 如果是作业模式则必须设置为开机自动重启 if (localProfile.IsAutoStart == false || localProfile.IsAutoBoot == false) { localProfile.IsAutoBoot = true; localProfile.IsAutoStart = true; repository.Update(localProfile); } } _localJson.MinerProfile.IsAutoBoot = true; _localJson.MinerProfile.IsAutoStart = true; #endregion #region 矿机名 // 当用户使用群控作业但没有指定群控矿机名时使用从local.litedb中读取的矿工名 if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName)) { if (localProfile != null) { _localJson.MinerProfile.MinerName = localProfile.MinerName; } // 如果local.litedb中也没有矿机名则使用去除了特殊符号的本机机器名作为矿机名 if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName)) { string minerName = Environment.MachineName; minerName = new string(minerName.ToCharArray().Where(a => !NTKeyword.InvalidMinerNameChars.Contains(a)).ToArray()); _localJson.MinerProfile.MinerName = minerName; } } #endregion _localJsonInited = true; } } } }
private void Init(INTMinerRoot root, MineWorkData mineWorkData) { MineWork = mineWorkData; isUseJson = mineWorkData != null; if (isUseJson) { _data = NTMinerRoot.LocalJson.MinerProfile; } else { IRepository <MinerProfileData> repository = NTMinerRoot.CreateLocalRepository <MinerProfileData>(false); _data = repository.GetAll().FirstOrDefault(); } if (_data == null) { Guid coinId = Guid.Empty; ICoin coin = root.CoinSet.OrderBy(a => a.SortNumber).FirstOrDefault(); if (coin != null) { coinId = coin.GetId(); } _data = MinerProfileData.CreateDefaultData(coinId); } if (_coinProfileSet == null) { _coinProfileSet = new CoinProfileSet(root, mineWorkData); } else { _coinProfileSet.Refresh(mineWorkData); } if (_coinKernelProfileSet == null) { _coinKernelProfileSet = new CoinKernelProfileSet(root, mineWorkData); } else { _coinKernelProfileSet.Refresh(mineWorkData); } if (_poolProfileSet == null) { _poolProfileSet = new PoolProfileSet(root, mineWorkData); } else { _poolProfileSet.Refresh(mineWorkData); } if (_walletSet == null) { _walletSet = new WalletSet(root); } else { _walletSet.Refresh(); } }
public MinerProfile(INTMinerRoot root) { _root = root; _data = GetMinerProfileData(); if (_data == null) { throw new ValidationException("未获取到MinerProfileData数据,请重试"); } Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
public MinerProfile(INTMinerRoot root) { _root = root; _data = GetMinerProfileData(); if (_data == null) { throw new ValidationException("未获取到MinerProfileData数据,请重试"); } BootLog.Log(this.GetType().FullName + "接入总线"); }
// 从磁盘读取local.json反序列化为LocalJson对象 private static void LocalJsonInit() { if (!_localJsonInited) { lock (_localJsonlocker) { if (!_localJsonInited) { string localJson = SpecialPath.ReadLocalJsonFile(); if (!string.IsNullOrEmpty(localJson)) { try { LocalJsonDb data = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson); _localJson = data ?? new LocalJsonDb(); } catch (Exception e) { Logger.ErrorDebugLine(e); } } else { _localJson = new LocalJsonDb(); } // 因为是群控作业,将开机启动和自动挖矿设置为true var repository = new LiteDbReadWriteRepository <MinerProfileData>(VirtualRoot.LocalDbFileFullName); MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId); if (localProfile != null) { if (localProfile.IsAutoStart == false || localProfile.IsAutoBoot == false) { localProfile.IsAutoBoot = true; localProfile.IsAutoStart = true; repository.Update(localProfile); } } _localJson.MinerProfile.IsAutoBoot = true; _localJson.MinerProfile.IsAutoStart = true; // 这里的逻辑是,当用户在主界面填写矿工名时,矿工名会被交换到注册表从而当用户使用群控但没有填写群控矿工名时作为缺省矿工名 // 但是旧版本的挖矿端并没有把矿工名交换到注册表去所以当注册表中没有矿工名时需读取local.litedb中的矿工名 if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName)) { _localJson.MinerProfile.MinerName = NTMinerRegistry.GetMinerName(); if (string.IsNullOrEmpty(_localJson.MinerProfile.MinerName)) { if (localProfile != null) { _localJson.MinerProfile.MinerName = localProfile.MinerName; } } } _localJsonInited = true; } } } }
public LocalJsonDb() { this.CoinKernelProfiles = new CoinKernelProfileData[0]; this.CoinProfiles = new CoinProfileData[0]; this.MinerProfile = MinerProfileData.CreateDefaultData(Guid.Empty); this.MineWork = new MineWorkData(); this.Pools = new PoolData[0]; this.PoolProfiles = new PoolProfileData[0]; this.Wallets = new WalletData[0]; this.TimeStamp = Timestamp.GetTimestamp(); }
public MinerProfileData GetMinerProfile(Guid workId) { using (var database = CreateDatabase(workId)) { var col = database.GetCollection <MinerProfileData>(); var data = col.FindAll().FirstOrDefault(); if (data == null) { data = MinerProfileData.CreateDefaultData(); col.Insert(data); } return(data); } }
private void Init(INTMinerRoot root) { IRepository <MinerProfileData> minerProfileRepository = NTMinerRoot.CreateLocalRepository <MinerProfileData>(); _data = minerProfileRepository.GetAll().FirstOrDefault(); IRepository <MineWorkData> mineWorkRepository = NTMinerRoot.CreateLocalRepository <MineWorkData>(); MineWork = mineWorkRepository.GetAll().FirstOrDefault(); if (_data == null) { Guid coinId = Guid.Empty; ICoin coin = root.CoinSet.OrderBy(a => a.Code).FirstOrDefault(); if (coin != null) { coinId = coin.GetId(); } _data = MinerProfileData.CreateDefaultData(coinId); } if (_coinProfileSet == null) { _coinProfileSet = new CoinProfileSet(root); } else { _coinProfileSet.Refresh(); } if (_coinKernelProfileSet == null) { _coinKernelProfileSet = new CoinKernelProfileSet(root); } else { _coinKernelProfileSet.Refresh(); } if (_poolProfileSet == null) { _poolProfileSet = new PoolProfileSet(root); } else { _poolProfileSet.Refresh(); } if (_walletSet == null) { _walletSet = new WalletSet(root); } else { _walletSet.Refresh(); } }
private MinerProfileData GetMinerProfileData() { if (CommandLineArgs.IsWorker) { return(Server.ProfileService.GetMinerProfile(CommandLineArgs.WorkId)); } else { IRepository <MinerProfileData> repository = NTMinerRoot.CreateLocalRepository <MinerProfileData>(); var result = repository.GetAll().FirstOrDefault(); if (result == null) { result = MinerProfileData.CreateDefaultData(); } return(result); } }
public static void SetAutoStart(bool isAutoBoot, bool isAutoStart) { var db = GetDb(); if (db != null) { using (db) { var col = db.GetCollection <MinerProfileData>(); MinerProfileData data = col.FindById(MinerProfileData.DefaultId); if (data != null) { data.IsAutoBoot = isAutoBoot; data.IsAutoStart = isAutoStart; col.Update(data); } } } }
public static bool GetIsAutoBoot() { var db = GetDb(); if (db != null) { using (db) { MinerProfileData data = db.GetCollection <MinerProfileData>().FindById(MinerProfileData.DefaultId); if (data != null) { return(data.IsAutoBoot); } return(false); } } else { return(false); } }
// 从磁盘读取local.json反序列化为LocalJson对象 private static void LocalJsonInit() { if (!_localJsonInited) { lock (_locker) { if (!_localJsonInited) { string localJson = HomePath.ReadLocalJsonFile(_workType); LocalJsonDb localJsonDb = null; if (!string.IsNullOrEmpty(localJson)) { localJsonDb = VirtualRoot.JsonSerializer.Deserialize <LocalJsonDb>(localJson); } if (localJsonDb == null) { if (ClientAppType.IsMinerClient) { localJsonDb = JsonDb.LocalJsonDb.ConvertFromNTMinerContext(); VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), "当前作业由本机数据自动生成,因为本机没有作业记录,请先在群控端创建或编辑作业。", OutEnum.Warn, toConsole: true); } else { localJsonDb = new LocalJsonDb(); } } _localJsonDb = localJsonDb; if (ClientAppType.IsMinerClient) { #region 因为是群控作业,将开机启动和自动挖矿设置为true var repository = new LiteDbReadWriteRepository <MinerProfileData>(HomePath.LocalDbFileFullName); MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId); if (localProfile != null) { MinerProfileData.CopyWorkIgnoreValues(localProfile, _localJsonDb.MinerProfile); // 如果是作业模式则必须设置为开机自动重启 if (!localProfile.IsAutoBoot) { localProfile.IsAutoBoot = true; repository.Update(localProfile); } } _localJsonDb.MinerProfile.IsAutoBoot = true; NTMinerRegistry.SetIsAutoStart(true); #endregion #region 矿机名 if (!string.IsNullOrEmpty(_workerName)) { _localJsonDb.MinerProfile.MinerName = _workerName; } else { // 当用户使用群控作业但没有指定群控矿机名时使用从local.litedb中读取的矿工名 if (string.IsNullOrEmpty(_localJsonDb.MinerProfile.MinerName)) { if (localProfile != null) { _localJsonDb.MinerProfile.MinerName = localProfile.MinerName; } // 如果local.litedb中也没有矿机名则使用去除了特殊符号的本机机器名作为矿机名 if (string.IsNullOrEmpty(_localJsonDb.MinerProfile.MinerName)) { _localJsonDb.MinerProfile.MinerName = NTKeyword.GetSafeMinerName(ThisPcName); } } } #endregion } _localJsonInited = true; } } } }
public MinerProfileViewModel() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, (int)propertyInfo.GetValue(this, null) + 1, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, Math.Round((double)propertyInfo.GetValue(this, null) + 0.1, 2), null); } #endregion }); this.Down = new DelegateCommand <string>(propertyName => { #region if (!_propertyInfos.TryGetValue(propertyName, out PropertyInfo propertyInfo)) { propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo == null) { Write.DevError(() => $"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); return; } _propertyInfos.Add(propertyName, propertyInfo); } if (propertyInfo.PropertyType == typeof(int)) { int value = (int)propertyInfo.GetValue(this, null); if (value > 0) { propertyInfo.SetValue(this, value - 1, null); } } else if (propertyInfo.PropertyType == typeof(double)) { double value = (double)propertyInfo.GetValue(this, null); if (value > 0.1) { propertyInfo.SetValue(this, Math.Round(value - 0.1, 2), null); } } #endregion }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); bool isRefreshed = false; if (ClientAppType.IsMinerClient) { VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; Write.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { isRefreshed = true; this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open; if (message.WsClientState.ToOut) { VirtualRoot.Out.ShowWarn(message.WsClientState.Description, autoHideSeconds: 3); } if (!message.WsClientState.ToOut || !this.IsWsOnline) { this.WsDescription = message.WsClientState.Description; } if (!this.IsWsOnline) { if (message.WsClientState.LastTryOn != DateTime.MinValue) { this.WsLastTryOn = message.WsClientState.LastTryOn; } if (message.WsClientState.NextTrySecondsDelay > 0) { WsNextTrySecondsDelay = message.WsClientState.NextTrySecondsDelay; } } } #endregion }, this.GetType(), LogEnum.DevConsole); VirtualRoot.AddEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { if (WsNextTrySecondsDelay > 0) { WsNextTrySecondsDelay--; } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); if (IsOuterUserEnabled) { RpcRoot.Client.NTMinerDaemonService.GetWsDaemonStateAsync((WsClientState state, Exception e) => { if (state != null && !isRefreshed) { this.IsWsOnline = state.Status == WsClientStatus.Open; this.WsDescription = state.Description; if (state.NextTrySecondsDelay > 0) { this.WsNextTrySecondsDelay = state.NextTrySecondsDelay; } this.WsLastTryOn = state.LastTryOn; } }); } } NTMinerContext.SetRefreshArgsAssembly((reason) => { Write.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #if DEBUG NTStopwatch.Start(); #endif #region 确保双挖权重在合法的范围内 if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerContext.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } #endregion NTMinerContext.Instance.CurrentMineContext = NTMinerContext.Instance.CreateMineContext(); if (NTMinerContext.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } #if DEBUG var milliseconds = NTStopwatch.Stop(); if (milliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{milliseconds} {this.GetType().Name}.SetRefreshArgsAssembly"); } #endif }); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, location: this.GetType()); AppRoot.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerContext.Instance.ServerContext.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppRoot.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); VirtualRoot.AddEventPath <CoinVmAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); VirtualRoot.AddEventPath <CoinVmRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MinerProfileViewModel() { #if DEBUG NTStopwatch.Start(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { if (propertyInfo.PropertyType == typeof(int)) { propertyInfo.SetValue(this, (int)propertyInfo.GetValue(this, null) + 1, null); } else if (propertyInfo.PropertyType == typeof(double)) { propertyInfo.SetValue(this, Math.Round((double)propertyInfo.GetValue(this, null) + 0.1, 2), null); } } else { Write.DevError($"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); } }); this.Down = new DelegateCommand <string>(propertyName => { PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName); if (propertyInfo != null) { if (propertyInfo.PropertyType == typeof(int)) { int value = (int)propertyInfo.GetValue(this, null); if (value > 0) { propertyInfo.SetValue(this, value - 1, null); } } else if (propertyInfo.PropertyType == typeof(double)) { double value = (double)propertyInfo.GetValue(this, null); if (value > 0.1) { propertyInfo.SetValue(this, Math.Round(value - 0.1, 2), null); } } } else { Write.DevError($"类型{this.GetType().FullName}不具有名称为{propertyName}的属性"); } }); NTMinerRoot.SetRefreshArgsAssembly(() => { #if DEBUG NTStopwatch.Start(); #endif if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } NTMinerRoot.Instance.CurrentMineContext = NTMinerRoot.Instance.CreateMineContext(); if (NTMinerRoot.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerRoot.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } #if DEBUG var milliseconds = NTStopwatch.Stop(); if (milliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{milliseconds} {this.GetType().Name}.SetRefreshArgsAssembly"); } #endif }); VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, location: this.GetType()); AppContext.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerRoot.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppContext.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private static void Upgrade() { if (ClientAppType.IsMinerClient && !NTMinerRegistry.GetIsValueNameExist("IsNoUi")) { try { using (var db = new LiteDatabase($"filename={Path.Combine(HomePath.HomeDirFullName, NTKeyword.LocalDbFileName)}")) { var col = db.GetCollection <MinerProfileData>(); MinerProfileData data = col.FindById(MinerProfileData.DefaultId); if (data != null) { NTMinerRegistry.SetIsNoUi(data.IsNoUi); NTMinerRegistry.SetIsAutoStart(data.IsAutoStart); } } } catch { } } if (ClientAppType.IsMinerClient && HomePath.IsLocalHome && File.Exists(HomePath.RootConfigFileFullName) && !File.Exists(HomePath.RootLockFileFullName)) { #region 迁移 string sharePackagesDir = Path.Combine(TempPath.TempDirFullName, NTKeyword.PackagesDirName); if (Directory.Exists(sharePackagesDir)) { foreach (var fileFullName in Directory.GetFiles(sharePackagesDir)) { string destFileName = Path.Combine(HomePath.PackagesDirFullName, Path.GetFileName(fileFullName)); if (!File.Exists(destFileName)) { File.Copy(fileFullName, destFileName); } } } if (DevMode.IsDevMode) { string shareServerDbFileFullName = Path.Combine(TempPath.TempDirFullName, NTKeyword.ServerDbFileName); if (File.Exists(shareServerDbFileFullName) && !File.Exists(HomePath.ServerDbFileFullName)) { File.Copy(shareServerDbFileFullName, HomePath.ServerDbFileFullName); } } string shareServerJsonFileFullName = Path.Combine(TempPath.TempDirFullName, NTKeyword.ServerJsonFileName); if (File.Exists(shareServerJsonFileFullName) && !File.Exists(HomePath.ServerJsonFileFullName)) { File.Copy(shareServerJsonFileFullName, HomePath.ServerJsonFileFullName); } string shareLocalDbFileFullName = Path.Combine(TempPath.TempDirFullName, NTKeyword.LocalDbFileName); if (File.Exists(shareLocalDbFileFullName) && !File.Exists(HomePath.LocalDbFileFullName)) { File.Copy(shareLocalDbFileFullName, HomePath.LocalDbFileFullName); } string shareGpuProfilesJsonFileFullName = Path.Combine(TempPath.TempDirFullName, NTKeyword.GpuProfilesFileName); if (File.Exists(shareGpuProfilesJsonFileFullName) && !File.Exists(HomePath.GpuProfilesJsonFileFullName)) { File.Copy(shareGpuProfilesJsonFileFullName, HomePath.GpuProfilesJsonFileFullName); } string shareUpdaterFileFullName = Path.Combine(TempPath.TempDirFullName, NTKeyword.UpdaterDirName, NTKeyword.NTMinerUpdaterFileName); if (File.Exists(shareUpdaterFileFullName) && !File.Exists(HomePath.UpdaterFileFullName)) { File.Copy(shareUpdaterFileFullName, HomePath.UpdaterFileFullName); } #endregion File.Move(HomePath.RootConfigFileFullName, HomePath.RootLockFileFullName); } }
public MinerProfileViewModel() { #if DEBUG Write.Stopwatch.Restart(); #endif if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.AutoStartDelaySecondsUp = new DelegateCommand(() => { this.AutoStartDelaySeconds++; }); this.AutoStartDelaySecondsDown = new DelegateCommand(() => { if (this.AutoStartDelaySeconds > 0) { this.AutoStartDelaySeconds--; } }); this.AutoRestartKernelTimesUp = new DelegateCommand(() => { this.AutoRestartKernelTimes++; }); this.AutoRestartKernelTimesDown = new DelegateCommand(() => { if (this.AutoRestartKernelTimes > 0) { this.AutoRestartKernelTimes--; } }); this.NoShareRestartKernelMinutesUp = new DelegateCommand(() => { this.NoShareRestartKernelMinutes++; }); this.NoShareRestartKernelMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartKernelMinutes > 0) { this.NoShareRestartKernelMinutes--; } }); this.NoShareRestartComputerMinutesUp = new DelegateCommand(() => { this.NoShareRestartComputerMinutes++; }); this.NoShareRestartComputerMinutesDown = new DelegateCommand(() => { if (this.NoShareRestartComputerMinutes > 0) { this.NoShareRestartComputerMinutes--; } }); this.PeriodicRestartKernelHoursUp = new DelegateCommand(() => { this.PeriodicRestartKernelHours++; }); this.PeriodicRestartKernelHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelHours > 0) { this.PeriodicRestartKernelHours--; } }); this.PeriodicRestartKernelMinutesUp = new DelegateCommand(() => { this.PeriodicRestartKernelMinutes++; }); this.PeriodicRestartKernelMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartKernelMinutes > 0) { this.PeriodicRestartKernelMinutes--; } }); this.PeriodicRestartComputerHoursUp = new DelegateCommand(() => { this.PeriodicRestartComputerHours++; }); this.PeriodicRestartComputerHoursDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerHours > 0) { this.PeriodicRestartComputerHours--; } }); this.PeriodicRestartComputerMinutesUp = new DelegateCommand(() => { this.PeriodicRestartComputerMinutes++; }); this.PeriodicRestartComputerMinutesDown = new DelegateCommand(() => { if (this.PeriodicRestartComputerMinutes > 0) { this.PeriodicRestartComputerMinutes--; } }); this.CpuGETemperatureSecondsUp = new DelegateCommand(() => { this.CpuGETemperatureSeconds++; }); this.CpuGETemperatureSecondsDown = new DelegateCommand(() => { this.CpuGETemperatureSeconds--; }); this.CpuStopTemperatureUp = new DelegateCommand(() => { this.CpuStopTemperature++; }); this.CpuStopTemperatureDown = new DelegateCommand(() => { this.CpuStopTemperature--; }); this.CpuLETemperatureSecondsUp = new DelegateCommand(() => { this.CpuLETemperatureSeconds++; }); this.CpuLETemperatureSecondsDown = new DelegateCommand(() => { this.CpuLETemperatureSeconds--; }); this.CpuStartTemperatureUp = new DelegateCommand(() => { this.CpuStartTemperature++; }); this.CpuStartTemperatureDown = new DelegateCommand(() => { this.CpuStartTemperature--; }); this.EPriceUp = new DelegateCommand(() => { this.EPrice = Math.Round(this.EPrice + 0.1, 2); }); this.EPriceDown = new DelegateCommand(() => { if (this.EPrice > 0.1) { this.EPrice = Math.Round(this.EPrice - 0.1, 2); } }); this.PowerAppendUp = new DelegateCommand(() => { this.PowerAppend++; }); this.PowerAppendDown = new DelegateCommand(() => { if (this.PowerAppend > 0) { this.PowerAppend--; } }); this.MaxTempUp = new DelegateCommand(() => { this.MaxTemp++; }); this.MaxTempDown = new DelegateCommand(() => { if (this.MaxTemp > 0) { this.MaxTemp--; } }); this.AutoNoUiMinutesUp = new DelegateCommand(() => { this.AutoNoUiMinutes++; }); this.AutoNoUiMinutesDown = new DelegateCommand(() => { if (this.AutoNoUiMinutes > 0) { this.AutoNoUiMinutes--; } }); NTMinerRoot.SetRefreshArgsAssembly(() => { if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } this.ArgsAssembly = NTMinerRoot.Instance.BuildAssembleArgs(out _, out _, out _); }); VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }); AppContext.AppContextCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerRoot.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }); AppContext.AppContextEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); VirtualRoot.BuildEventPath <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public MinerProfileViewModel() { if (WpfUtil.IsInDesignMode) { return; } if (Instance != null) { throw new InvalidProgramException(); } if (this.IsCreateShortcut) { CreateShortcut(); } this.Up = new DelegateCommand <string>(propertyName => { WpfUtil.Up(this, propertyName); }); this.Down = new DelegateCommand <string>(propertyName => { WpfUtil.Down(this, propertyName); }); this.WsRetry = new DelegateCommand(() => { RpcRoot.Client.NTMinerDaemonService.StartOrStopWsAsync(isResetFailCount: true); IsConnecting = true; }); if (ClientAppType.IsMinerClient) { VirtualRoot.AddEventPath <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { IsMining = false; NTMinerConsole.UserError(message.Message); }, location: this.GetType()); // 群控客户端已经有一个执行RefreshWsStateCommand命令的路径了 VirtualRoot.AddCmdPath <RefreshWsStateCommand>(message => { #region if (message.WsClientState != null) { this.IsWsOnline = message.WsClientState.Status == WsClientStatus.Open; if (message.WsClientState.ToOut) { VirtualRoot.Out.ShowWarn(message.WsClientState.Description, autoHideSeconds: 3); } if (!message.WsClientState.ToOut || !this.IsWsOnline) { this.WsDescription = message.WsClientState.Description; } if (!this.IsWsOnline) { if (message.WsClientState.LastTryOn != DateTime.MinValue) { this.WsLastTryOn = message.WsClientState.LastTryOn; } if (message.WsClientState.NextTrySecondsDelay > 0) { WsNextTrySecondsDelay = message.WsClientState.NextTrySecondsDelay; } } } #endregion }, this.GetType(), LogEnum.DevConsole); VirtualRoot.AddEventPath <Per1SecondEvent>("外网群控重试秒表倒计时", LogEnum.None, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { if (WsNextTrySecondsDelay > 0) { WsNextTrySecondsDelay--; } else if (WsLastTryOn == DateTime.MinValue) { RpcRoot.Client.NTMinerDaemonService.GetWsDaemonStateAsync((WsClientState state, Exception e) => { if (state != null) { this.IsWsOnline = state.Status == WsClientStatus.Open; this.WsDescription = state.Description; if (state.NextTrySecondsDelay > 0) { this.WsNextTrySecondsDelay = state.NextTrySecondsDelay; } this.WsLastTryOn = state.LastTryOn; } }); } OnPropertyChanged(nameof(WsLastTryOnText)); } }, this.GetType()); VirtualRoot.AddEventPath <WsServerOkEvent>("服务器Ws服务已可用", LogEnum.DevConsole, action: message => { if (IsOuterUserEnabled && !IsWsOnline) { StartOrStopWs(); } }, this.GetType()); } NTMinerContext.SetRefreshArgsAssembly((reason) => { NTMinerConsole.DevDebug(() => $"RefreshArgsAssembly" + reason, ConsoleColor.Cyan); #region 确保双挖权重在合法的范围内 if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerContext.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } #endregion NTMinerContext.Instance.CurrentMineContext = NTMinerContext.Instance.CreateMineContext(); if (NTMinerContext.Instance.CurrentMineContext != null) { this.ArgsAssembly = NTMinerContext.Instance.CurrentMineContext.CommandLine; } else { this.ArgsAssembly = string.Empty; } }); AppRoot.AddCmdPath <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.DevConsole, action: message => { MinerProfileData data = NTMinerContext.Instance.ServerContext.CreateLocalRepository <MinerProfileData>().GetByKey(this.Id); if (data != null) { this.IsAutoBoot = data.IsAutoBoot; this.IsAutoStart = data.IsAutoStart; } }, location: this.GetType()); AppRoot.AddEventPath <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }, location: this.GetType()); VirtualRoot.AddEventPath <LocalContextReInitedEventHandledEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); if (CoinVm != null) { CoinVm.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.OnPropertyChanged(nameof(CoinVm.Wallets)); CoinVm.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedWallet)); CoinVm.CoinKernel?.CoinKernelProfile.SelectedDualCoin?.CoinProfile?.OnPropertyChanged(nameof(CoinVm.CoinProfile.SelectedDualCoinWallet)); } }, location: this.GetType()); VirtualRoot.AddEventPath <CoinVmAddedEvent>("Vm集添加了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); VirtualRoot.AddEventPath <CoinVmRemovedEvent>("Vm集删除了新币种后刷新MinerProfileVm内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }, this.GetType()); if ((IsAutoStart || CommandLineArgs.IsAutoStart) && IsNoUi) { NTMinerConsole.Disable(); } }