private void DoInit(bool isWork, Action callback) { this.ServerAppSettingSet = new ServerAppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ServerContextInit(isWork); this.GpuProfileSet = new GpuProfileSet(this); this.WorkerEventSet = new WorkerEventSet(this); this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); IsJsonLocal = isWork; this._minerProfile = new MinerProfile(this); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); if (VirtualRoot.IsMinerClient) { OfficialServer.GetTimeAsync((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Timestamp.DesyncSeconds) { Logger.OkDebugLine("时间同步"); } else { Write.UserWarn($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}"); } }); Report.Init(this); Link(); // 当显卡温度变更时守卫温度防线 TempGruarder.Instance.Init(this); // 因为这里耗时500毫秒左右 Task.Factory.StartNew(() => { Windows.Error.DisableWindowsErrorUI(); if (NTMinerRegistry.GetIsAutoDisableWindowsFirewall()) { Windows.Firewall.DisableFirewall(); } Windows.UAC.DisableUAC(); Windows.WAU.DisableWAUAsync(); Windows.Defender.DisableAntiSpyware(); Windows.Power.PowerCfgOff(); Windows.BcdEdit.IgnoreAllFailures(); }); } callback?.Invoke(); }
private void DoInit(bool isWork, Action callback) { IsJsonServer = !DevMode.IsDebugMode || VirtualRoot.IsMinerStudio || isWork; this.ServerAppSettingSet = new ServerAppSettingSet(); this.CalcConfigSet = new CalcConfigSet(this); this.ServerContext = new ServerContext(); this.GpuProfileSet = new GpuProfileSet(this); this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(); this.MinerGroupSet = new MinerGroupSet(); this.NTMinerWalletSet = new NTMinerWalletSet(); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(); this.ServerMessageSet = new ServerMessageSet(VirtualRoot.LocalDbFileFullName, isServer: false); // 作业和在群控客户端管理作业时 IsJsonLocal = isWork || VirtualRoot.IsMinerStudio; this._minerProfile = new MinerProfile(this); this.CpuPackage = new CpuPackage(_minerProfile); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(MainAssemblyInfo.CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(MainAssemblyInfo.CurrentVersionTag); if (VirtualRoot.IsMinerClient) { VirtualRoot.LocalIpSet.InitOnece(); Report.Init(); Link(); // 当显卡温度变更时守卫温度防线 TempGruarder.Instance.Init(this); // 因为这里耗时500毫秒左右 Task.Factory.StartNew(() => { Windows.Error.DisableWindowsErrorUI(); Windows.UAC.DisableUAC(); Windows.WAU.DisableWAUAsync(); Windows.Defender.DisableAntiSpyware(); Windows.Power.PowerCfgOff(); Windows.BcdEdit.IgnoreAllFailures(); }); } callback?.Invoke(); }
public void Start() { Global.Logger.InfoDebugLine("开始启动Wcf服务"); string baseUrl = $"http://{Global.Localhost}:{Global.ClientPort}/"; ServiceHost minerClientServiceHost = new ServiceHost(typeof(Core.Impl.MinerClientService)); minerClientServiceHost.AddServiceEndpoint(typeof(IMinerClientService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IMinerClientService))); _serviceHosts = new List <ServiceHost> { minerClientServiceHost }; foreach (var serviceHost in _serviceHosts) { ServiceMetadataBehavior serviceMetadata = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (serviceMetadata == null) { serviceMetadata = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(serviceMetadata); } serviceMetadata.HttpGetEnabled = false; serviceHost.Open(); } Global.Logger.OkDebugLine($"服务启动成功: {DateTime.Now}."); Global.Logger.InfoDebugLine("服务列表:"); foreach (var serviceHost in _serviceHosts) { foreach (var endpoint in serviceHost.Description.Endpoints) { Global.Logger.InfoDebugLine(endpoint.Address.Uri.ToString()); } } Global.Logger.OkDebugLine("Wcf服务启动完成"); Server.TimeService.GetTime((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Global.DesyncSeconds) { Global.Logger.OkDebugLine("时间同步"); } else { Global.Logger.WarnDebugLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}"); } }); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Location", ClientId.AppFileFullName); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments", string.Join(" ", CommandLineArgs.Args)); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersion", CurrentVersion.ToString()); Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersionTag", CurrentVersionTag); Report.Init(this); int shareCount = 0; DateTime shareOn = DateTime.Now; #region 挖矿开始时将无份额内核重启份额计数置0 Global.Access <MineStartedEvent>( Guid.Parse("e69e8729-868b-4b5d-b120-2914fffddf90"), "挖矿开始时将无份额内核重启份额计数置0", LogEnum.None, action: message => { shareCount = 0; shareOn = DateTime.Now; }); #endregion #region 每10秒钟检查是否需要重启 Global.Access <Per10SecondEvent>( Guid.Parse("16b3b7b4-5e6c-46b0-97a4-90e085614b78"), "每10秒钟检查是否需要重启", LogEnum.None, action: message => { #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalHours > MinerProfile.PeriodicRestartComputerHours) { Global.Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启电脑"); Windows.Power.Restart(); return; // 退出 } } } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - CurrentMineContext.CreatedOn).TotalHours > MinerProfile.PeriodicRestartKernelHours) { Global.Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启内核"); RestartMine(); return; // 退出 } } } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } #endregion #region 收益没有增加重启内核 try { if (IsMining && MinerProfile.IsNoShareRestartKernel) { if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes) { if (this.CurrentMineContext.MainCoin != null) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId()); int totalShare = mainCoinShare.TotalShareCount; if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } if (shareCount == totalShare) { Global.Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核"); RestartMine(); } else { shareCount = totalShare; shareOn = DateTime.Now; } }
public void Start() { OfficialServer.GetTimeAsync((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Timestamp.DesyncSeconds) { Logger.OkDebugLine("时间同步"); } else { Logger.WarnDebugLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}"); } }); Report.Init(this); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; VirtualRoot.On <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0,应用超频,启动NoDevFee,启动DevConsole,清理除当前外的Temp/Kernel", LogEnum.DevConsole, action: message => { // 将无份额内核重启份额计数置0 shareCount = 0; shareOn = DateTime.Now; Task.Factory.StartNew(() => { try { if (GpuProfileSet.Instance.IsOverClockEnabled(message.MineContext.MainCoin.GetId())) { VirtualRoot.Execute(new CoinOverClockCommand(message.MineContext.MainCoin.GetId())); } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }); StartNoDevFeeAsync(); // 启动DevConsole if (IsUseDevConsole) { string poolIp = CurrentMineContext.MainCoinPool.GetIp(); string consoleTitle = CurrentMineContext.MainCoinPool.Server; DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } // 清理除当前外的Temp/Kernel Cleaner.CleanKernels(); }); #endregion #region 每10秒钟检查是否需要重启 VirtualRoot.On <Per10SecondEvent>("每10秒钟检查是否需要重启", LogEnum.None, action: message => { #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalHours > MinerProfile.PeriodicRestartComputerHours) { Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启电脑"); Windows.Power.Restart(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - CurrentMineContext.CreatedOn).TotalHours > MinerProfile.PeriodicRestartKernelHours) { Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启内核"); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } #endregion #region 收益没有增加重启内核 try { if (IsMining && MinerProfile.IsNoShareRestartKernel) { if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes) { if (this.CurrentMineContext.MainCoin != null) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId()); int totalShare = mainCoinShare.TotalShareCount; if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } if (shareCount == totalShare) { Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核"); RestartMine(); } else { shareCount = totalShare; shareOn = DateTime.Now; } }
public void Start() { OfficialServer.GetTimeAsync((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Timestamp.DesyncSeconds) { Logger.OkDebugLine("时间同步"); } else { Logger.WarnDebugLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}"); } }); Report.Init(this); VirtualRoot.Window <RegCmdHereCommand>("处理注册右键打开windows命令行菜单命令", LogEnum.DevConsole, action: message => { string cmdHere = "SOFTWARE\\Classes\\Directory\\background\\shell\\cmd_here"; string cmdHereCommand = cmdHere + "\\command"; string cmdPrompt = "SOFTWARE\\Classes\\Folder\\shell\\cmdPrompt"; string cmdPromptCommand = cmdPrompt + "\\command"; try { Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHere, "", "命令行"); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHere, "Icon", "cmd.exe"); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHereCommand, "", "\"cmd.exe\""); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdPrompt, "", "命令行"); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdPromptCommand, "", "\"cmd.exe\" \"cd %1\""); cmdHere = "SOFTWARE\\Classes\\Directory\\shell\\cmd_here"; cmdHereCommand = cmdHere + "\\command"; Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHere, "", "命令行"); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHere, "Icon", "cmd.exe"); Windows.WinRegistry.SetValue(Registry.LocalMachine, cmdHereCommand, "", "\"cmd.exe\""); VirtualRoot.Happened(new RegCmdHereEvent(true, "windows右键命令行添加成功")); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.Happened(new RegCmdHereEvent(false, "windows右键命令行添加失败")); } }); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; VirtualRoot.On <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0,应用超频,启动NoDevFee,启动DevConsole,清理除当前外的Temp/Kernel", LogEnum.DevConsole, action: message => { // 将无份额内核重启份额计数置0 shareCount = 0; shareOn = DateTime.Now; try { if (GpuProfileSet.Instance.IsOverClockEnabled(message.MineContext.MainCoin.GetId())) { VirtualRoot.Execute(new CoinOverClockCommand(message.MineContext.MainCoin.GetId())); } } catch (Exception e) { Logger.ErrorDebugLine(e); } StartNoDevFeeAsync(); }); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.On <Per20SecondEvent>("每20秒钟阻止windows系统休眠、检查是否需要重启", LogEnum.None, action: message => { // 阻止windows休眠 Windows.Power.PreventWindowsSleep(); #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes) { Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时{MinerProfile.PeriodicRestartComputerMinutes}分钟重启电脑"); Windows.Power.Restart(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - CurrentMineContext.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes) { Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时{MinerProfile.PeriodicRestartKernelMinutes}分钟重启内核"); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 收益没有增加重启内核 try { if (IsMining && MinerProfile.IsNoShareRestartKernel) { if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes) { if (this.CurrentMineContext.MainCoin != null) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId()); int totalShare = mainCoinShare.TotalShareCount; if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } if (shareCount == totalShare) { Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核"); RestartMine(); return; // 退出 } else { shareCount = totalShare; shareOn = DateTime.Now; } }