private static void PickRejectPattern(INTMinerRoot root, string input, IKernel kernel, ICoin coin, bool isDual) { string rejectSharePattern = kernel.RejectSharePattern; if (isDual) { rejectSharePattern = kernel.DualRejectSharePattern; } if (string.IsNullOrEmpty(rejectSharePattern)) { return; } var match = Regex.Match(input, rejectSharePattern); if (match.Success) { string rejectShareText = match.Groups["rejectShare"].Value; int rejectShare; if (int.TryParse(rejectShareText, out rejectShare)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); share.RejectCount = rejectShare; share.ShareOn = DateTime.Now; Global.Happened(new ShareChangedEvent(share)); } } }
private static void PickTotalShare(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string totalSharePattern = kernelOutput.TotalSharePattern; if (isDual) { totalSharePattern = kernelOutput.DualTotalSharePattern; } if (string.IsNullOrEmpty(totalSharePattern)) { return; } Regex regex = VirtualRoot.GetRegex(totalSharePattern); var match = regex.Match(input); if (match.Success) { string totalShareText = match.Groups[NTKeyword.TotalShareGroupName].Value; if (int.TryParse(totalShareText, out int totalShare)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: totalShare - share.RejectShareCount, rejectShareCount: null, now: DateTime.Now); } } }
private static void PickTotalShare(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string totalSharePattern = kernelOutput.TotalSharePattern; if (isDual) { totalSharePattern = kernelOutput.DualTotalSharePattern; } if (string.IsNullOrEmpty(totalSharePattern)) { return; } var match = Regex.Match(input, totalSharePattern, RegexOptions.Compiled); if (match.Success) { string totalShareText = match.Groups["totalShare"].Value; int totalShare; if (int.TryParse(totalShareText, out totalShare)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: totalShare - share.RejectShareCount, rejectShareCount: null, now: DateTime.Now); } } }
private static void PickAcceptShare(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string acceptSharePattern = kernelOutput.AcceptSharePattern; if (isDual) { acceptSharePattern = kernelOutput.DualAcceptSharePattern; } if (string.IsNullOrEmpty(acceptSharePattern)) { return; } var match = Regex.Match(input, acceptSharePattern); if (match.Success) { string acceptShareText = match.Groups["acceptShare"].Value; int acceptShare; if (int.TryParse(acceptShareText, out acceptShare)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); share.AcceptShareCount = acceptShare; share.ShareOn = DateTime.Now; Global.Happened(new ShareChangedEvent(share)); } } }
public void Update(ICoinShare share) { _acceptShareCount = share.AcceptShareCount; _rejectShareCount = share.RejectShareCount; _shareOn = share.ShareOn; OnPropertyChanged(nameof(TotalShareCount)); OnPropertyChanged(nameof(RejectPercent)); OnPropertyChanged(nameof(RejectPercentText)); OnPropertyChanged(nameof(RejectShareCount)); OnPropertyChanged(nameof(ShareOn)); }
private static void PickAcceptOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string acceptOneShare = kernelOutput.AcceptOneShare; if (isDual) { acceptOneShare = kernelOutput.DualAcceptOneShare; } if (string.IsNullOrEmpty(acceptOneShare)) { return; } if (acceptOneShare.Contains("\n")) { input = preline + "\n" + input; } Regex regex = VirtualRoot.GetRegex(acceptOneShare); var match = regex.Match(input); if (match.Success) { if (!isDual) { // 决定不支持双挖的单卡份额统计 string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value; if (!string.IsNullOrEmpty(gpuText)) { if (int.TryParse(gpuText, out int gpuIndex)) { if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg)) { if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length) { gpuIndex = mineContext.UseDevices[gpuIndex]; } } if (string.IsNullOrEmpty(kernelOutput.FoundOneShare)) { root.GpusSpeed.IncreaseFoundShare(gpuIndex); } root.GpusSpeed.IncreaseAcceptShare(gpuIndex); } } } ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: share.AcceptShareCount + 1, rejectShareCount: null, now: DateTime.Now); } }
private static void PickRejectOneShare(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectOneShare = kernelOutput.RejectOneShare; if (isDual) { rejectOneShare = kernelOutput.DualRejectOneShare; } if (string.IsNullOrEmpty(rejectOneShare)) { return; } var match = Regex.Match(input, rejectOneShare, RegexOptions.Compiled); if (match.Success) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), null, share.RejectShareCount + 1, DateTime.Now); } }
private static void PickAcceptOneShare(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string acceptOneShare = kernelOutput.AcceptOneShare; if (isDual) { acceptOneShare = kernelOutput.DualAcceptOneShare; } if (string.IsNullOrEmpty(acceptOneShare)) { return; } var match = Regex.Match(input, acceptOneShare); if (match.Success) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: share.AcceptShareCount + 1, rejectShareCount: null, now: DateTime.Now); } }
private static void PickRejectOneShare(INTMinerRoot root, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectOneShare = kernelOutput.RejectOneShare; if (isDual) { rejectOneShare = kernelOutput.DualRejectOneShare; } if (string.IsNullOrEmpty(rejectOneShare)) { return; } if (rejectOneShare.Contains("\n")) { input = preline + "\n" + input; } var match = Regex.Match(input, rejectOneShare, RegexOptions.Compiled); if (match.Success) { if (!isDual) { // 决定不支持双挖的单卡份额统计 string gpuText = match.Groups[Consts.GpuIndexGroupName].Value; if (!string.IsNullOrEmpty(gpuText)) { if (int.TryParse(gpuText, out int gpuIndex)) { if (string.IsNullOrEmpty(kernelOutput.FoundOneShare)) { root.GpusSpeed.IncreaseFoundShare(gpuIndex); } root.GpusSpeed.IncreaseRejectShare(gpuIndex); } } } ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), null, share.RejectShareCount + 1, DateTime.Now); } }
private static void PickRejectPercent(INTMinerContext root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectPercentPattern = kernelOutput.RejectPercentPattern; if (isDual) { rejectPercentPattern = kernelOutput.DualRejectPercentPattern; } if (string.IsNullOrEmpty(rejectPercentPattern)) { return; } Regex regex = VirtualRoot.GetRegex(rejectPercentPattern); var match = regex.Match(input); string rejectPercentText = match.Groups[NTKeyword.RejectPercentGroupName].Value; if (double.TryParse(rejectPercentText, out double rejectPercent)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: (int)(share.TotalShareCount * rejectPercent), now: DateTime.Now); } }
private static void PickRejectPercent(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectPercentPattern = kernelOutput.RejectPercentPattern; if (isDual) { rejectPercentPattern = kernelOutput.DualRejectPercentPattern; } if (string.IsNullOrEmpty(rejectPercentPattern)) { return; } var match = Regex.Match(input, rejectPercentPattern, RegexOptions.Compiled); string rejectPercentText = match.Groups["rejectPercent"].Value; double rejectPercent; if (double.TryParse(rejectPercentText, out rejectPercent)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), acceptShareCount: null, rejectShareCount: (int)(share.TotalShareCount * rejectPercent), now: DateTime.Now); } }
private static void PickRejectPercent(INTMinerRoot root, string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectPercentPattern = kernelOutput.RejectPercentPattern; if (isDual) { rejectPercentPattern = kernelOutput.DualRejectPercentPattern; } if (string.IsNullOrEmpty(rejectPercentPattern)) { return; } var match = Regex.Match(input, rejectPercentPattern); string rejectPercentText = match.Groups["rejectPercent"].Value; double rejectPercent; if (double.TryParse(rejectPercentText, out rejectPercent)) { ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); share.RejectCount = (int)(share.TotalShareCount * rejectPercent); share.ShareOn = DateTime.Now; Global.Happened(new ShareChangedEvent(share)); } }
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; } }
private static void PickRejectOneShare(INTMinerContext root, IMineContext mineContext, string input, string preline, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string rejectOneShare = kernelOutput.RejectOneShare; if (isDual) { rejectOneShare = kernelOutput.DualRejectOneShare; } if (string.IsNullOrEmpty(rejectOneShare)) { return; } if (rejectOneShare.Contains("\n")) { input = preline + "\n" + input; } Regex regex = VirtualRoot.GetRegex(rejectOneShare); var match = regex.Match(input); if (match.Success) { if (!isDual) { // 决定不支持双挖的单卡份额统计 string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value; if (!string.IsNullOrEmpty(gpuText)) { if (int.TryParse(gpuText, out int gpuIndex)) { if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg)) { if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpuIndex < mineContext.UseDevices.Length) { gpuIndex = mineContext.UseDevices[gpuIndex]; } } if (string.IsNullOrEmpty(kernelOutput.FoundOneShare)) { root.GpusSpeed.IncreaseFoundShare(gpuIndex); } root.GpusSpeed.IncreaseRejectShare(gpuIndex); } } else if (!string.IsNullOrEmpty(kernelOutput.FoundOneShare)) { // 哪个GPU最近找到了一个share就是那个GPU拒绝了一个share var gpuSpeeds = root.GpusSpeed.AsEnumerable(); IGpuSpeed gpuSpeed = null; foreach (var item in gpuSpeeds) { if (gpuSpeed == null) { gpuSpeed = item; } else if (item.FoundShareOn > gpuSpeed.FoundShareOn) { gpuSpeed = item; } } if (gpuSpeed != null) { var gpuIndex = gpuSpeed.Gpu.Index; root.GpusSpeed.IncreaseRejectShare(gpuIndex); } } } ICoinShare share = root.CoinShareSet.GetOrCreate(coin.GetId()); root.CoinShareSet.UpdateShare(coin.GetId(), null, share.RejectShareCount + 1, DateTime.Now); } }
private static void ReportSpeed(INTMinerRoot root) { try { SpeedData data = new SpeedData { MessageId = Guid.NewGuid(), MinerName = root.MinerProfile.MinerName, ClientId = ClientId.Id, Timestamp = DateTime.Now, MainCoinCode = string.Empty, MainCoinShareDelta = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinShareDelta = 0, DualCoinSpeed = 0, IsMining = root.IsMining, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, MainCoinWallet = string.Empty }; ICoin mainCoin; if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; } else { data.MainCoinPool = string.Empty; } data.MainCoinWallet = coinProfile.Wallet; ICoinKernel coinKernel; if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { IKernel kernel; if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { data.Kernel = kernel.FullName; ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { ICoin dualCoin; if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; IPool dualCoinPool; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; } else { data.DualCoinPool = string.Empty; } } } } } } // 如果正在挖矿则报告算力,否则默认报告0算力 if (root.IsMining) { CoinShareData preCoinShare; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.MainCoinShareDelta = share.TotalShareCount; } else { data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } if (root.CurrentMineContext is IDualMineContext dualMineContext) { if (root.IsMining) { coinId = dualMineContext.DualCoin.GetId(); gpuSpeeds = NTMinerRoot.Current.GpusSpeed; totalSpeed = gpuSpeeds.CurrentSpeed(root.GpuAllId); data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value; share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.DualCoinShareDelta = share.TotalShareCount; } else { data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } } } Server.ReportService.ReportSpeed(data); } catch (Exception e) { Global.DebugLine(e.Message, ConsoleColor.Red); Global.DebugLine(e.StackTrace, ConsoleColor.Red); } }
public static SpeedData CreateSpeedData() { INTMinerRoot root = NTMinerRoot.Instance; IWorkProfile workProfile = root.MinerProfile; string macAddress = string.Empty; string localIp = string.Empty; foreach (var item in VirtualRoot.LocalIpSet.AsEnumerable()) { if (macAddress.Length != 0) { macAddress += "," + item.MACAddress; localIp += "," + item.IPAddress; } else { macAddress = item.MACAddress; localIp = item.IPAddress; } } SpeedData data = new SpeedData { LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp, KernelSelfRestartCount = 0, IsAutoBoot = workProfile.IsAutoBoot, IsAutoStart = workProfile.IsAutoStart, AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds, Version = MainAssemblyInfo.CurrentVersion.ToString(4), BootOn = root.CreatedOn, MineStartedOn = null, IsMining = root.IsMining, MineWorkId = Guid.Empty, MineWorkName = string.Empty, MinerName = workProfile.MinerName, GpuInfo = root.GpuSetInfo, ClientId = VirtualRoot.Id, MACAddress = macAddress, LocalIp = localIp, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = root.GpuSet.DriverVersion.ToString(), GpuType = root.GpuSet.GpuType, OSVirtualMemoryMb = NTMinerRoot.OSVirtualMemoryMb, KernelCommandLine = string.Empty, DiskSpace = NTMinerRoot.DiskSpace, IsAutoRestartKernel = workProfile.IsAutoRestartKernel, AutoRestartKernelTimes = workProfile.AutoRestartKernelTimes, IsNoShareRestartKernel = workProfile.IsNoShareRestartKernel, NoShareRestartKernelMinutes = workProfile.NoShareRestartKernelMinutes, IsNoShareRestartComputer = workProfile.IsNoShareRestartComputer, NoShareRestartComputerMinutes = workProfile.NoShareRestartComputerMinutes, IsPeriodicRestartComputer = workProfile.IsPeriodicRestartComputer, PeriodicRestartComputerHours = workProfile.PeriodicRestartComputerHours, IsPeriodicRestartKernel = workProfile.IsPeriodicRestartKernel, PeriodicRestartKernelHours = workProfile.PeriodicRestartKernelHours, PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes, PeriodicRestartKernelMinutes = workProfile.PeriodicRestartKernelMinutes, IsAutoStartByCpu = workProfile.IsAutoStartByCpu, IsAutoStopByCpu = workProfile.IsAutoStopByCpu, CpuGETemperatureSeconds = workProfile.CpuGETemperatureSeconds, CpuLETemperatureSeconds = workProfile.CpuLETemperatureSeconds, CpuStartTemperature = workProfile.CpuStartTemperature, CpuStopTemperature = workProfile.CpuStopTemperature, MainCoinPoolDelay = string.Empty, DualCoinPoolDelay = string.Empty, MinerIp = string.Empty, IsFoundOneGpuShare = false, IsGotOneIncorrectGpuShare = false, IsRejectOneGpuShare = false, CpuPerformance = root.CpuPackage.Performance, CpuTemperature = root.CpuPackage.Temperature, IsRaiseHighCpuEvent = workProfile.IsRaiseHighCpuEvent, HighCpuPercent = workProfile.HighCpuBaseline, HighCpuSeconds = workProfile.HighCpuSeconds, GpuTable = root.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray() }; if (workProfile.MineWork != null) { data.MineWorkId = workProfile.MineWork.GetId(); data.MineWorkName = workProfile.MineWork.Name; } #region 当前选中的币种是什么 if (root.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId()); data.MainCoinWallet = coinProfile.Wallet; if (root.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; if (root.IsMining) { data.MainCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false); } if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId); data.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { data.MainCoinPool = string.Empty; } if (root.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (root.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { data.Kernel = kernel.GetFullName(); if (root.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput)) { data.IsFoundOneGpuShare = !string.IsNullOrEmpty(kernelOutput.FoundOneShare); data.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare); data.IsRejectOneGpuShare = !string.IsNullOrEmpty(kernelOutput.RejectOneShare); } ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (root.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (root.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; if (root.IsMining) { data.DualCoinPoolDelay = root.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true); } if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); data.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { var mineContext = root.LockedMineContext; if (mineContext != null) { data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; data.MineStartedOn = mineContext.CreatedOn; data.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.LockedMineContext.MainCoin) { _sLastSpeedMainCoin = root.LockedMineContext.MainCoin; Guid coinId = root.LockedMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.MainCoinTotalShare = share.TotalShareCount; data.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = root.LockedMineContext.MainCoin; } if (root.LockedMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.DualCoinTotalShare = share.TotalShareCount; data.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(data); }
private void Link() { VirtualRoot.BuildCmdPath <RegCmdHereCommand>(path: message => { try { Cmd.RegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "添加windows右键命令行成功"); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerContext), "添加windows右键命令行失败", OutEnum.Warn); } }, location: this.GetType()); VirtualRoot.BuildCmdPath <UnRegCmdHereCommand>(path: message => { try { Cmd.UnRegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "移除windows右键命令行成功"); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerContext), "移除windows右键命令行失败", OutEnum.Warn); } }, location: this.GetType()); VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None, path: message => { Power.PreventSleep(MinerProfile.IsPreventDisplaySleep); }, location: this.GetType()); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; DateTime highSpeedOn = DateTime.Now; DateTime overClockHighSpeedOn = DateTime.Now; VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole, path: message => { // 将无份额内核重启份额计数置0 shareCount = 0; highSpeedOn = DateTime.Now; overClockHighSpeedOn = DateTime.Now; if (!message.MineContext.IsRestart) { // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑 shareOn = DateTime.Now; } }, location: this.GetType()); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None, path: message => { #region 低算力重启电脑 if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue) { var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId); if (coinProfile.IsLowSpeedRestartComputer && coinProfile.LowSpeed != 0 && coinProfile.LowSpeedRestartComputerMinutes > 0) { IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId); if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) >= message.BornOn) { if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.LowSpeed) >= coinProfile.LowSpeed) { highSpeedOn = message.BornOn; } } if (highSpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) < message.BornOn) { string coinCode = string.Empty; if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin)) { coinCode = coin.Code; } VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedRestartComputerMinutes}分钟低于{coinProfile.LowSpeed}重启电脑", toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } return; } } else { highSpeedOn = message.BornOn; } } #endregion #region 低算力重新应用超频 if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue) { var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId); if (coinProfile.IsLowSpeedReOverClock && coinProfile.OverClockLowSpeed != 0 && coinProfile.LowSpeedReOverClockMinutes > 0) { IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId); if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) >= message.BornOn) { if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.OverClockLowSpeed) >= coinProfile.OverClockLowSpeed) { overClockHighSpeedOn = message.BornOn; } } if (overClockHighSpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) < message.BornOn) { string coinCode = string.Empty; if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin)) { coinCode = coin.Code; } VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedReOverClockMinutes}分钟低于{coinProfile.OverClockLowSpeed}重新应用超频", toConsole: true); VirtualRoot.Execute(new CoinOverClockCommand(MinerProfile.CoinId)); } } else { overClockHighSpeedOn = message.BornOn; } } #endregion #region 周期重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes) { string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue) { DateTime dt = GetKernelRestartBaseOnTime(); if ((DateTime.Now - dt).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 无份额重启内核 try { if (IsMining && this.LockedMineContext.MainCoin != null) { int totalShare = 0; bool restartComputer = MinerProfile.NoShareRestartComputerMinutes > 0 && MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; bool restartKernel = MinerProfile.NoShareRestartKernelMinutes > 0 && MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartComputer || restartKernel) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId()); totalShare = mainCoinShare.TotalShareCount; if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } // 如果份额没有增加 if (shareCount == totalShare) { // 重启电脑,基于MineStartedOn bool isRestartComputerMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; if (restartComputer && isRestartComputerMinutes) { if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true); VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10)); return; // 退出 } // 重启内核,如果MineRestartedOn不是DateTime.MineValue则基于MineRestartedOn DateTime dt = GetKernelRestartBaseOnTime(); bool isRestartKernelMinutes = (DateTime.Now - dt).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartKernel && isRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true); RestartMine(); return; // 退出 } } if (totalShare > shareCount) { shareCount = totalShare; shareOn = DateTime.Now; } }
public SpeedDto CreateSpeedDto() { INTMinerContext ntminerContext = NTMinerContext.Instance; IWorkProfile workProfile = ntminerContext.MinerProfile; string localIps = VirtualRoot.FormatLocalIps(out string macAddress); Guid mineContextId = Guid.Empty; if (ntminerContext.CurrentMineContext != null) { mineContextId = ntminerContext.CurrentMineContext.Id; } SpeedDto speedDto = new SpeedDto { MineContextId = mineContextId, MainCoinSpeedOn = DateTime.MinValue, DualCoinSpeedOn = DateTime.MinValue, IsAutoDisableWindowsFirewall = workProfile.IsAutoDisableWindowsFirewall, IsDisableAntiSpyware = workProfile.IsDisableAntiSpyware, IsDisableUAC = workProfile.IsDisableUAC, IsDisableWAU = workProfile.IsDisableWAU, Is1080PillEnabled = workProfile.Is1080PillEnabled, IsPreventDisplaySleep = workProfile.IsPreventDisplaySleep, IsAutoReboot = workProfile.IsAutoReboot, LocalServerMessageTimestamp = VirtualRoot.LocalServerMessageSetTimestamp, KernelSelfRestartCount = 0, IsAutoBoot = workProfile.IsAutoBoot, IsAutoStart = workProfile.IsAutoStart, AutoStartDelaySeconds = workProfile.AutoStartDelaySeconds, Version = EntryAssemblyInfo.CurrentVersionStr, BootOn = ntminerContext.CreatedOn, MineStartedOn = null, IsMining = ntminerContext.IsMining, MineWorkId = Guid.Empty, MineWorkName = string.Empty, MinerName = workProfile.MinerName, GpuInfo = ntminerContext.GpuSetInfo, ClientId = NTMinerContext.Id, MACAddress = macAddress, LocalIp = localIps, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = ntminerContext.GpuSet.DriverVersion, GpuType = ntminerContext.GpuSet.GpuType, OSVirtualMemoryMb = VirtualRoot.DriveSet.OSVirtualMemoryMb, TotalPhysicalMemoryMb = (int)(Windows.Ram.Instance.TotalPhysicalMemory / NTKeyword.IntM), KernelCommandLine = string.Empty, DiskSpace = VirtualRoot.DriveSet.ToDiskSpaceString(), IsAutoRestartKernel = workProfile.IsAutoRestartKernel, AutoRestartKernelTimes = workProfile.AutoRestartKernelTimes, IsNoShareRestartKernel = workProfile.IsNoShareRestartKernel, NoShareRestartKernelMinutes = workProfile.NoShareRestartKernelMinutes, IsNoShareRestartComputer = workProfile.IsNoShareRestartComputer, NoShareRestartComputerMinutes = workProfile.NoShareRestartComputerMinutes, IsPeriodicRestartComputer = workProfile.IsPeriodicRestartComputer, PeriodicRestartComputerHours = workProfile.PeriodicRestartComputerHours, IsPeriodicRestartKernel = workProfile.IsPeriodicRestartKernel, PeriodicRestartKernelHours = workProfile.PeriodicRestartKernelHours, PeriodicRestartComputerMinutes = workProfile.PeriodicRestartComputerMinutes, PeriodicRestartKernelMinutes = workProfile.PeriodicRestartKernelMinutes, IsAutoStartByCpu = workProfile.IsAutoStartByCpu, IsAutoStopByCpu = workProfile.IsAutoStopByCpu, CpuGETemperatureSeconds = workProfile.CpuGETemperatureSeconds, CpuLETemperatureSeconds = workProfile.CpuLETemperatureSeconds, CpuStartTemperature = workProfile.CpuStartTemperature, CpuStopTemperature = workProfile.CpuStopTemperature, MainCoinPoolDelay = string.Empty, DualCoinPoolDelay = string.Empty, MinerIp = string.Empty, IsFoundOneGpuShare = false, IsGotOneIncorrectGpuShare = false, IsRejectOneGpuShare = false, CpuPerformance = ntminerContext.CpuPackage.Performance, CpuTemperature = ntminerContext.CpuPackage.Temperature, IsRaiseHighCpuEvent = workProfile.IsRaiseHighCpuEvent, HighCpuPercent = workProfile.HighCpuBaseline, HighCpuSeconds = workProfile.HighCpuSeconds, IsOuterUserEnabled = workProfile.IsOuterUserEnabled, ReportOuterUserId = NTMinerRegistry.GetOuterUserId(), IsLowSpeedRestartComputer = false, LowSpeedRestartComputerMinutes = 0, LowSpeed = 0, IsLowSpeedReOverClock = false, LowSpeedReOverClockMinutes = 0, OverClockLowSpeed = 0, GpuTable = ntminerContext.GpusSpeed.AsEnumerable().Where(a => a.Gpu.Index != NTMinerContext.GpuAllId).Select(a => a.ToGpuSpeedData()).ToArray() }; if (workProfile.MineWork != null) { speedDto.MineWorkId = workProfile.MineWork.GetId(); speedDto.MineWorkName = workProfile.MineWork.Name; } #region 当前选中的币种是什么 if (ntminerContext.ServerContext.CoinSet.TryGetCoin(workProfile.CoinId, out ICoin mainCoin)) { speedDto.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = workProfile.GetCoinProfile(mainCoin.GetId()); speedDto.MainCoinWallet = coinProfile.Wallet; speedDto.IsLowSpeedRestartComputer = coinProfile.IsLowSpeedRestartComputer; speedDto.LowSpeed = coinProfile.LowSpeed; speedDto.LowSpeedRestartComputerMinutes = coinProfile.LowSpeedRestartComputerMinutes; speedDto.IsLowSpeedReOverClock = coinProfile.IsLowSpeedReOverClock; speedDto.LowSpeedReOverClockMinutes = coinProfile.LowSpeedReOverClockMinutes; speedDto.OverClockLowSpeed = coinProfile.OverClockLowSpeed; if (ntminerContext.ServerContext.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { speedDto.MainCoinPool = mainCoinPool.Server; if (ntminerContext.IsMining) { speedDto.MainCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(mainCoinPool.GetId(), isDual: false); } if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = workProfile.GetPoolProfile(coinProfile.PoolId); speedDto.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { speedDto.MainCoinPool = string.Empty; } if (ntminerContext.ServerContext.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (ntminerContext.ServerContext.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { speedDto.Kernel = kernel.GetFullName(); if (ntminerContext.ServerContext.KernelOutputSet.TryGetKernelOutput(kernel.KernelOutputId, out IKernelOutput kernelOutput)) { speedDto.IsFoundOneGpuShare = !string.IsNullOrEmpty(kernelOutput.FoundOneShare); speedDto.IsGotOneIncorrectGpuShare = !string.IsNullOrEmpty(kernelOutput.GpuGotOneIncorrectShare); speedDto.IsRejectOneGpuShare = !string.IsNullOrEmpty(kernelOutput.RejectOneShare); } ICoinKernelProfile coinKernelProfile = workProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); speedDto.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (ntminerContext.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { speedDto.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = workProfile.GetCoinProfile(dualCoin.GetId()); speedDto.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (ntminerContext.ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { speedDto.DualCoinPool = dualCoinPool.Server; if (ntminerContext.IsMining) { speedDto.DualCoinPoolDelay = ntminerContext.ServerContext.PoolSet.GetPoolDelayText(dualCoinPool.GetId(), isDual: true); } if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = workProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); speedDto.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { speedDto.DualCoinPool = string.Empty; } } } } } } #endregion if (ntminerContext.IsMining) { var mineContext = ntminerContext.LockedMineContext; if (mineContext != null) { speedDto.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; if (mineContext.MineStartedOn != DateTime.MinValue) { speedDto.MineStartedOn = mineContext.MineStartedOn; } speedDto.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == ntminerContext.LockedMineContext.MainCoin) { _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin; Guid coinId = ntminerContext.LockedMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = ntminerContext.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId); speedDto.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; speedDto.MainCoinSpeedOn = totalSpeed.MainCoinSpeed.SpeedOn; ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId); speedDto.MainCoinTotalShare = share.TotalShareCount; speedDto.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = ntminerContext.LockedMineContext.MainCoin; } if (ntminerContext.LockedMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = ntminerContext.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerContext.GpuAllId); speedDto.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; speedDto.DualCoinSpeedOn = totalSpeed.DualCoinSpeed.SpeedOn; ICoinShare share = ntminerContext.CoinShareSet.GetOrCreate(coinId); speedDto.DualCoinTotalShare = share.TotalShareCount; speedDto.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(speedDto); }
public static SpeedData CreateSpeedData() { INTMinerRoot root = NTMinerRoot.Instance; SpeedData data = new SpeedData { KernelSelfRestartCount = 0, IsAutoBoot = NTMinerRegistry.GetIsAutoBoot(), IsAutoStart = NTMinerRegistry.GetIsAutoStart(), Version = NTMinerRoot.CurrentVersion.ToString(4), BootOn = root.CreatedOn, MineStartedOn = null, IsMining = root.IsMining, MineWorkId = root.MinerProfile.MineWork != null?root.MinerProfile.MineWork.GetId() : Guid.Empty, MinerName = root.MinerProfile.MinerName, GpuInfo = root.GpuSetInfo, ClientId = VirtualRoot.Id, MainCoinCode = string.Empty, MainCoinWallet = string.Empty, MainCoinTotalShare = 0, MainCoinRejectShare = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinTotalShare = 0, DualCoinRejectShare = 0, DualCoinSpeed = 0, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, OSName = Windows.OS.Instance.WindowsEdition, GpuDriver = root.GpuSet.DriverVersion, GpuType = root.GpuSet.GpuType, OSVirtualMemoryMb = NTMinerRoot.OSVirtualMemoryMb, KernelCommandLine = NTMinerRoot.UserKernelCommandLine, DiskSpace = NTMinerRoot.DiskSpace, IsAutoRestartKernel = root.MinerProfile.IsAutoRestartKernel, IsNoShareRestartKernel = root.MinerProfile.IsNoShareRestartKernel, IsPeriodicRestartComputer = root.MinerProfile.IsPeriodicRestartComputer, IsPeriodicRestartKernel = root.MinerProfile.IsPeriodicRestartKernel, NoShareRestartKernelMinutes = root.MinerProfile.NoShareRestartKernelMinutes, PeriodicRestartComputerHours = root.MinerProfile.PeriodicRestartComputerHours, PeriodicRestartKernelHours = root.MinerProfile.PeriodicRestartKernelHours, GpuTable = root.GpusSpeed.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Select(a => new GpuSpeedData { Index = a.Gpu.Index, Name = a.Gpu.Name, TotalMemory = a.Gpu.TotalMemory, MainCoinSpeed = a.MainCoinSpeed.Value, DualCoinSpeed = a.DualCoinSpeed.Value, FanSpeed = a.Gpu.FanSpeed, Temperature = a.Gpu.Temperature, PowerUsage = a.Gpu.PowerUsage, Cool = a.Gpu.Cool, PowerCapacity = a.Gpu.PowerCapacity, CoreClockDelta = a.Gpu.CoreClockDelta, MemoryClockDelta = a.Gpu.MemoryClockDelta, TempLimit = a.Gpu.TempLimit }).ToArray() }; #region 当前选中的币种是什么 if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out ICoin mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.MinerProfile.GetCoinProfile(mainCoin.GetId()); data.MainCoinWallet = coinProfile.Wallet; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; if (mainCoinPool.IsUserMode) { IPoolProfile mainCoinPoolProfile = root.MinerProfile.GetPoolProfile(coinProfile.PoolId); data.MainCoinWallet = mainCoinPoolProfile.UserName; } } else { data.MainCoinPool = string.Empty; } if (root.CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { data.Kernel = kernel.GetFullName(); ICoinKernelProfile coinKernelProfile = root.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.MinerProfile.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; if (dualCoinPool.IsUserMode) { IPoolProfile dualCoinPoolProfile = root.MinerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId); data.DualCoinWallet = dualCoinPoolProfile.UserName; } } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { var mineContext = root.CurrentMineContext; if (mineContext != null) { data.KernelSelfRestartCount = mineContext.KernelSelfRestartCount; data.MineStartedOn = mineContext.CreatedOn; data.KernelCommandLine = mineContext.CommandLine; } // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedMainCoin == null || _sLastSpeedMainCoin == root.CurrentMineContext.MainCoin) { _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.MainCoinTotalShare = share.TotalShareCount; data.MainCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedMainCoin = root.CurrentMineContext.MainCoin; } if (root.CurrentMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_sLastSpeedDualCoin == null || _sLastSpeedDualCoin == dualMineContext.DualCoin) { _sLastSpeedDualCoin = dualMineContext.DualCoin; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); data.DualCoinTotalShare = share.TotalShareCount; data.DualCoinRejectShare = share.RejectShareCount; } else { _sLastSpeedDualCoin = dualMineContext.DualCoin; } } } return(data); }
private void Link() { VirtualRoot.BuildCmdPath <RegCmdHereCommand>(action: message => { try { Windows.Cmd.RegCmdHere(); VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), "windows右键命令行添加成功", OutEnum.Success); } catch (Exception e) { Logger.ErrorDebugLine(e); VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "windows右键命令行添加失败", OutEnum.Warn); } }); VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None, action: message => { Windows.Power.PreventSleep(); }); #region 挖矿开始时将无份额内核重启份额计数置0 int shareCount = 0; DateTime shareOn = DateTime.Now; VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole, action: message => { // 将无份额内核重启份额计数置0 shareCount = 0; if (!message.MineContext.IsRestart) { shareOn = DateTime.Now; } }); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None, action: message => { #region 重启电脑 try { if (MinerProfile.IsPeriodicRestartComputer) { if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes) { string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true); Windows.Power.Restart(60); VirtualRoot.Execute(new CloseNTMinerCommand(content)); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 周期重启内核 try { if (IsMining && MinerProfile.IsPeriodicRestartKernel) { if ((DateTime.Now - LockedMineContext.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes) { VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true); RestartMine(); return; // 退出 } } } catch (Exception e) { Logger.ErrorDebugLine(e); } #endregion #region 无份额重启内核 try { if (IsMining && this.LockedMineContext.MainCoin != null) { int totalShare = 0; bool restartComputer = MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; bool restartKernel = MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartComputer || restartKernel) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId()); totalShare = mainCoinShare.TotalShareCount; if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null) { ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); totalShare += dualCoinShare.TotalShareCount; } // 如果份额没有增加 if (shareCount == totalShare) { if (restartComputer) { if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart) { VirtualRoot.Execute(new SetAutoStartCommand(true, true)); } string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑"; VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true); Windows.Power.Restart(60); VirtualRoot.Execute(new CloseNTMinerCommand(content)); return; // 退出 } // 产生过份额或者已经两倍重启内核时间了 if (restartKernel && (totalShare > 0 || (DateTime.Now - shareOn).TotalMinutes > 2 * MinerProfile.NoShareRestartKernelMinutes)) { VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true); RestartMine(); return; // 退出 } } if (totalShare > shareCount) { shareCount = totalShare; shareOn = DateTime.Now; } }
private void Link() { VirtualRoot.Window <RegCmdHereCommand>("处理注册右键打开windows命令行菜单命令", LogEnum.DevConsole, action: message => { try { RegCmdHere(); 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", LogEnum.DevConsole, action: message => { // 将无份额内核重启份额计数置0 shareCount = 0; if (!message.MineContext.IsRestart) { shareOn = DateTime.Now; } }); #endregion #region 每20秒钟检查是否需要重启 VirtualRoot.On <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None, action: message => { #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(60); VirtualRoot.Execute(new CloseNTMinerCommand()); 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 && this.CurrentMineContext.MainCoin != null) { int totalShare = 0; bool restartComputer = MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes; bool restartKernel = MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes; if (restartComputer || restartKernel) { ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId()); 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) { if (restartComputer) { if (!NTMinerRegistry.GetIsAutoBoot()) { NTMinerRegistry.SetIsAutoBoot(true); } if (!NTMinerRegistry.GetIsAutoStart()) { NTMinerRegistry.SetIsAutoStart(true); } Logger.WarnWriteLine($"{MinerProfile.NoShareRestartComputerMinutes}分钟收益没有增加重启电脑"); Windows.Power.Restart(60); VirtualRoot.Execute(new CloseNTMinerCommand()); return; // 退出 } // 产生过份额或者已经两倍重启内核时间了 if (restartKernel && (totalShare > 0 || (DateTime.Now - shareOn).TotalMinutes > 2 * MinerProfile.NoShareRestartKernelMinutes)) { Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核"); RestartMine(); return; // 退出 } } if (totalShare > shareCount) { shareCount = totalShare; shareOn = DateTime.Now; } }
private static void ReportSpeed(INTMinerRoot root) { try { SpeedData data = new SpeedData { MessageId = Guid.NewGuid(), MinerName = root.MinerProfile.MinerName, ClientId = ClientId.Id, Timestamp = DateTime.Now, MainCoinCode = string.Empty, MainCoinShareDelta = 0, MainCoinSpeed = 0, DualCoinCode = string.Empty, DualCoinShareDelta = 0, DualCoinSpeed = 0, IsMining = root.IsMining, DualCoinPool = string.Empty, DualCoinWallet = string.Empty, IsDualCoinEnabled = false, Kernel = string.Empty, MainCoinPool = string.Empty, MainCoinWallet = string.Empty }; #region 当前选中的币种是什么 ICoin mainCoin; if (root.CoinSet.TryGetCoin(root.MinerProfile.CoinId, out mainCoin)) { data.MainCoinCode = mainCoin.Code; ICoinProfile coinProfile = root.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (root.PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { data.MainCoinPool = mainCoinPool.Server; } else { data.MainCoinPool = string.Empty; } data.MainCoinWallet = coinProfile.Wallet; ICoinKernel coinKernel; if (root.CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { IKernel kernel; if (root.KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { data.Kernel = kernel.FullName; ICoinKernelProfile coinKernelProfile = root.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); data.IsDualCoinEnabled = coinKernelProfile.IsDualCoinEnabled; if (coinKernelProfile.IsDualCoinEnabled) { ICoin dualCoin; if (root.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { data.DualCoinCode = dualCoin.Code; ICoinProfile dualCoinProfile = root.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); data.DualCoinWallet = dualCoinProfile.DualCoinWallet; IPool dualCoinPool; if (root.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { data.DualCoinPool = dualCoinPool.Server; } else { data.DualCoinPool = string.Empty; } } } } } } #endregion if (root.IsMining) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_lastSpeedMainCoin == null || _lastSpeedMainCoin == root.CurrentMineContext.MainCoin) { _lastSpeedMainCoin = root.CurrentMineContext.MainCoin; CoinShareData preCoinShare; Guid coinId = root.CurrentMineContext.MainCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.MainCoinSpeed = (int)totalSpeed.MainCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.MainCoinShareDelta = share.TotalShareCount; } else { data.MainCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } if (root.CurrentMineContext is IDualMineContext dualMineContext) { // 判断上次报告的算力币种和本次报告的是否相同,否则说明刚刚切换了币种默认第一次报告0算力 if (_lastSpeedDualCoin == null || _lastSpeedDualCoin == dualMineContext.DualCoin) { _lastSpeedDualCoin = dualMineContext.DualCoin; CoinShareData preCoinShare; Guid coinId = dualMineContext.DualCoin.GetId(); IGpusSpeed gpuSpeeds = NTMinerRoot.Current.GpusSpeed; IGpuSpeed totalSpeed = gpuSpeeds.CurrentSpeed(NTMinerRoot.GpuAllId); data.DualCoinSpeed = (int)totalSpeed.DualCoinSpeed.Value; ICoinShare share = root.CoinShareSet.GetOrCreate(coinId); if (!_coinShareDic.TryGetValue(coinId, out preCoinShare)) { preCoinShare = new CoinShareData() { TotalShareCount = share.TotalShareCount }; _coinShareDic.Add(coinId, preCoinShare); data.DualCoinShareDelta = share.TotalShareCount; } else { data.DualCoinShareDelta = share.TotalShareCount - preCoinShare.TotalShareCount; } } } } Server.ReportService.ReportSpeed(data); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); } }
public GpusSpeed(INTMinerRoot root) { _root = root; foreach (var gpu in _root.GpuSet) { _currentGpuSpeed.Add(gpu.Index, new GpuSpeed(gpu) { MainCoinSpeed = new Speed() { Value = 0, SpeedOn = DateTime.Now }, DualCoinSpeed = new Speed() { Value = 0, SpeedOn = DateTime.Now } }); } IGpuSpeed totalGpuSpeed = this._currentGpuSpeed[NTMinerRoot.GpuAllId]; var speedExceptTotal = _currentGpuSpeed.Values.Where(a => a != totalGpuSpeed).ToArray(); totalGpuSpeed.MainCoinSpeed.Value = speedExceptTotal.Sum(a => a.MainCoinSpeed.Value); totalGpuSpeed.DualCoinSpeed.Value = speedExceptTotal.Sum(a => a.DualCoinSpeed.Value); foreach (var item in _currentGpuSpeed) { _gpuSpeedHistory.Add(item.Key, new List <IGpuSpeed>()); } Global.Access <Per10MinuteEvent>( Guid.Parse("9A17AE73-34B8-4EBA-BE91-22BBD163A3E8"), "周期清除过期的历史算力", LogEnum.Console, action: message => { ClearOutOfDateHistory(); }); Global.Access <MineStopedEvent>( Guid.Parse("1C79954C-0311-4C94-B001-09B39FC11DC6"), "停止挖矿后产生一次0算力", LogEnum.Console, action: message => { var now = DateTime.Now; foreach (var gpu in _root.GpuSet) { Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu) { MainCoinSpeed = new Speed { Value = 0, SpeedOn = now }, DualCoinSpeed = new Speed { Value = 0, SpeedOn = now } })); if (message.MineContext is IDualMineContext dualMineContext) { Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu) { MainCoinSpeed = new Speed { Value = 0, SpeedOn = now }, DualCoinSpeed = new Speed { Value = 0, SpeedOn = now } })); } } }); Global.Access <MineStartedEvent>( Guid.Parse("997bc22f-9bee-4fd6-afe8-eec7eb664daf"), "挖矿开始时产生一次0算力0份额", LogEnum.Console, action: message => { var now = DateTime.Now; ICoinShare share = _root.CoinShareSet.GetOrCreate(message.MineContext.MainCoin.GetId()); share.AcceptShareCount = 0; share.RejectCount = 0; share.ShareOn = now; Global.Happened(new ShareChangedEvent(share)); foreach (var gpu in _root.GpuSet) { Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: false, gpuSpeed: new GpuSpeed(gpu) { MainCoinSpeed = new Speed { Value = 0, SpeedOn = now }, DualCoinSpeed = new Speed { Value = 0, SpeedOn = now } })); } if (message.MineContext is IDualMineContext dualMineContext) { share = _root.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); share.AcceptShareCount = 0; share.RejectCount = 0; share.ShareOn = now; Global.Happened(new ShareChangedEvent(share)); foreach (var gpu in _root.GpuSet) { Global.Happened(new GpuSpeedChangedEvent(isDualSpeed: true, gpuSpeed: new GpuSpeed(gpu) { MainCoinSpeed = new Speed { Value = 0, SpeedOn = now }, DualCoinSpeed = new Speed { Value = 0, SpeedOn = now } })); } } }); Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
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; } }