public CoinProfileViewModel(ICoinProfile innerProfile) { _inner = innerProfile; this.CopyWallet = new DelegateCommand(() => { string wallet = this.Wallet ?? "无"; Clipboard.SetDataObject(wallet); NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage(wallet, "复制成功"); }); this.CopyDualCoinWallet = new DelegateCommand(() => { string wallet = this.DualCoinWallet ?? "无"; Clipboard.SetDataObject(wallet); NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage(wallet, "复制成功"); }); this.HideWallet = new DelegateCommand(() => { this.IsHideWallet = true; }); this.ShowWallet = new DelegateCommand(() => { this.IsHideWallet = false; }); this.HideDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = true; }); this.ShowDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = false; }); this.AddWallet = new DelegateCommand(() => { if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm)) { Guid id = Guid.NewGuid(); var wallets = coinVm.Wallets.Where(a => a.IsTestWallet).ToArray(); int sortNumber = wallets.Length == 0 ? 1 : wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(id) { CoinId = CoinId, SortNumber = sortNumber }.Edit.Execute(FormType.Add); if (NTMinerRoot.Instance.MinerProfile.TryGetWallet(id, out IWallet wallet)) { this.SelectedWallet = AppContext.Instance.WalletVms.WalletList.FirstOrDefault(a => a.Id == id); } } }); this.AddDualCoinWallet = new DelegateCommand(() => { if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm)) { Guid id = Guid.NewGuid(); var wallets = coinVm.Wallets.Where(a => a.IsTestWallet).ToArray(); int sortNumber = wallets.Length == 0 ? 1 : wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(id) { CoinId = CoinId, SortNumber = sortNumber }.Edit.Execute(FormType.Add); if (NTMinerRoot.Instance.MinerProfile.TryGetWallet(id, out IWallet wallet)) { this.SelectedDualCoinWallet = AppContext.Instance.WalletVms.WalletList.FirstOrDefault(a => a.Id == id); } } }); }
public CoinProfileData(ICoinProfile data) { this.PoolId = data.PoolId; this.Wallet = data.Wallet; this.CoinId = data.CoinId; this.CoinKernelId = data.CoinKernelId; this.IsHideWallet = data.IsHideWallet; this.DualCoinPoolId = data.DualCoinPoolId; this.DualCoinWallet = data.DualCoinWallet; this.IsDualCoinHideWallet = data.IsDualCoinHideWallet; }
public CoinProfileViewModel(ICoinProfile innerProfile) { _inner = innerProfile; this.Up = new DelegateCommand <string>(propertyName => { WpfUtil.Up(this, propertyName); }); this.Down = new DelegateCommand <string>(propertyName => { WpfUtil.Down(this, propertyName); }); this.CopyWallet = new DelegateCommand(() => { string wallet = this.Wallet ?? "无"; Clipboard.SetDataObject(wallet, true); VirtualRoot.Out.ShowSuccess(wallet, header: "复制成功"); }, () => { return(this.SelectedWallet != null && !string.IsNullOrEmpty(this.SelectedWallet.Address)); }); this.CopyDualCoinWallet = new DelegateCommand(() => { string wallet = this.DualCoinWallet ?? "无"; Clipboard.SetDataObject(wallet, true); VirtualRoot.Out.ShowSuccess(wallet, header: "复制成功"); }, () => { return(this.SelectedDualCoinWallet != null && !string.IsNullOrEmpty(this.SelectedDualCoinWallet.Address)); }); this.HideWallet = new DelegateCommand(() => { this.IsHideWallet = true; }); this.ShowWallet = new DelegateCommand(() => { this.IsHideWallet = false; }); this.HideDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = true; }); this.ShowDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = false; }); this.AddWallet = new DelegateCommand(() => { if (AppRoot.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm)) { Guid id = Guid.NewGuid(); var wallets = coinVm.Wallets.Where(a => a.IsTestWallet).ToArray(); int sortNumber = wallets.Length == 0 ? 1 : wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(id) { CoinId = CoinId, SortNumber = sortNumber, AfterClose = () => { if (NTMinerContext.Instance.MinerProfile.TryGetWallet(id, out IWallet wallet)) { this.SelectedWallet = AppRoot.WalletVms.WalletList.FirstOrDefault(a => a.Id == id); } } }.Edit.Execute(FormType.Add); }
public IMineContext CreateMineContext() { if (!GetProfileData(out ICoin mainCoin, out ICoinProfile mainCoinProfile, out IPool mainCoinPool, out ICoinKernel mainCoinKernel, out IKernel kernel, out IKernelInput kernelInput, out IKernelOutput kernelOutput, out string _)) { return(null); } if (!kernel.IsSupported(mainCoin)) { return(null); } ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId); string poolKernelArgs = string.Empty; IPoolKernel poolKernel = ServerContext.PoolKernelSet.AsEnumerable().FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId()); if (poolKernel != null) { poolKernelArgs = poolKernel.Args; } string kernelArgs = kernelInput.Args; string coinKernelArgs = mainCoinKernel.Args; string customArgs = coinKernelProfile.CustomArgs ?? string.Empty; var parameters = new Dictionary <string, string>(); var fileWriters = new Dictionary <Guid, string>(); var fragments = new Dictionary <Guid, string>(); parameters.Add(NTKeyword.MainCoinParameterName, mainCoin.Code); string userName = string.Empty; string password = NTKeyword.PasswordDefaultValue; string wallet = mainCoinProfile.Wallet; if (mainCoinPool.IsUserMode) { IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId()); password = poolProfile.Password; if (string.IsNullOrEmpty(password)) { password = NTKeyword.PasswordDefaultValue; } userName = poolProfile.UserName; wallet = poolProfile.UserName; } else { userName = wallet; } parameters.Add(NTKeyword.UserNameParameterName, userName); parameters.Add(NTKeyword.PasswordParameterName, password); parameters.Add(NTKeyword.WalletParameterName, wallet); parameters.Add(NTKeyword.HostParameterName, mainCoinPool.GetHost()); parameters.Add(NTKeyword.PortParameterName, mainCoinPool.GetPort().ToString()); parameters.Add(NTKeyword.PoolParameterName, mainCoinPool.Server); string minerName = $"{mainCoinPool.MinerNamePrefix}{this.MinerProfile.MinerName}{mainCoinPool.MinerNamePostfix}"; parameters.Add(NTKeyword.WorkerParameterName, minerName); if (mainCoinKernel.IsSupportPool1 && !mainCoinPool.NoPool1) { parameters.Add(NTKeyword.Worker1ParameterName, minerName); if (ServerContext.PoolSet.TryGetPool(mainCoinProfile.PoolId1, out IPool mainCoinPool1)) { parameters.Add(NTKeyword.Host1ParameterName, mainCoinPool1.GetHost()); parameters.Add(NTKeyword.Port1ParameterName, mainCoinPool1.GetPort().ToString()); parameters.Add(NTKeyword.Pool1ParameterName, mainCoinPool1.Server); if (mainCoinPool1.IsUserMode) { IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId()); string password1 = poolProfile1.Password; if (string.IsNullOrEmpty(password1)) { password1 = NTKeyword.PasswordDefaultValue; } parameters.Add(NTKeyword.UserName1ParameterName, poolProfile1.UserName); parameters.Add(NTKeyword.Password1ParameterName, password1); } else { parameters.Add(NTKeyword.Wallet1ParameterName, mainCoinProfile.Wallet); } } } string devicesArgs = GetDevicesArgs(kernelInput); // 这里不要考虑{logfile},{logfile}往后推迟 if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine) { Guid dualCoinGroupId = mainCoinKernel.DualCoinGroupId; if (dualCoinGroupId != Guid.Empty) { if (this.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId()); if (ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { string dualUserName = string.Empty; string dualPassword = NTKeyword.PasswordDefaultValue; string dualWallet = dualCoinProfile.DualCoinWallet; parameters.Add(NTKeyword.DualCoinParameterName, dualCoin.Code); if (dualCoinPool.IsUserMode) { IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId()); dualPassword = dualPoolProfile.Password; if (string.IsNullOrEmpty(dualPassword)) { dualPassword = NTKeyword.PasswordDefaultValue; } dualUserName = dualPoolProfile.UserName; dualWallet = dualPoolProfile.UserName; } else { dualUserName = dualWallet; } parameters.Add(NTKeyword.DualUserNameParameterName, dualUserName); parameters.Add(NTKeyword.DualPasswordParameterName, dualPassword); parameters.Add(NTKeyword.DualWalletParameterName, dualWallet); parameters.Add(NTKeyword.DualHostParameterName, dualCoinPool.GetHost()); parameters.Add(NTKeyword.DualPortParameterName, dualCoinPool.GetPort().ToString()); parameters.Add(NTKeyword.DualPoolParameterName, dualCoinPool.Server); kernelArgs = mainCoinKernel.DualFullArgs; AssembleArgs(parameters, ref kernelArgs, isDual: true); AssembleArgs(parameters, ref poolKernelArgs, isDual: true); AssembleArgs(parameters, ref customArgs, isDual: true); string dualWeightArg; if (!string.IsNullOrEmpty(kernelInput.DualWeightArg)) { if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight) { dualWeightArg = string.Empty; } else { dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight).ToString()}"; } } else { dualWeightArg = string.Empty; } StringBuilder dualSb = new StringBuilder(); dualSb.Append(kernelArgs); if (!string.IsNullOrEmpty(dualWeightArg)) { dualSb.Append(" ").Append(dualWeightArg); } if (!string.IsNullOrEmpty(poolKernelArgs)) { dualSb.Append(" ").Append(poolKernelArgs); } BuildFragments(ServerContext, mainCoinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { dualSb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { dualSb.Append(" ").Append(customArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { dualSb.Append(" ").Append(devicesArgs); } // 注意:这里退出 return(new DualMineContext( new MineContext( this.MinerProfile.MinerName, mainCoin, mainCoinPool, kernel, kernelInput, kernelOutput, mainCoinKernel, wallet, dualSb.ToString(), parameters, fragments, fileWriters, GpuSet.GetUseDevices()), dualCoin, dualCoinPool, dualWallet, coinKernelProfile.DualCoinWeight, parameters, fragments, fileWriters, GpuSet.GetUseDevices())); } } } } AssembleArgs(parameters, ref kernelArgs, isDual: false); AssembleArgs(parameters, ref coinKernelArgs, isDual: false); AssembleArgs(parameters, ref poolKernelArgs, isDual: false); AssembleArgs(parameters, ref customArgs, isDual: false); StringBuilder sb = new StringBuilder(); sb.Append(kernelArgs); if (!string.IsNullOrEmpty(coinKernelArgs)) { sb.Append(" ").Append(coinKernelArgs); } if (!string.IsNullOrEmpty(poolKernelArgs)) { sb.Append(" ").Append(poolKernelArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { sb.Append(" ").Append(devicesArgs); } BuildFragments(ServerContext, mainCoinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { sb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { sb.Append(" ").Append(customArgs); } return(new MineContext( this.MinerProfile.MinerName, mainCoin, mainCoinPool, kernel, kernelInput, kernelOutput, mainCoinKernel, wallet, sb.ToString(), parameters, fragments, fileWriters, GpuSet.GetUseDevices())); }
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); }
public string BuildAssembleArgs(out Dictionary <string, string> parameters, out Dictionary <Guid, string> fileWriters, out Dictionary <Guid, string> fragments) { parameters = new Dictionary <string, string>(); fileWriters = new Dictionary <Guid, string>(); fragments = new Dictionary <Guid, string>(); if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin)) { return(string.Empty); } ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId()); if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { return(string.Empty); } if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { return(string.Empty); } if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { return(string.Empty); } if (!kernel.IsSupported(mainCoin)) { return(string.Empty); } if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput)) { return(string.Empty); } ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); string poolKernelArgs = string.Empty; IPoolKernel poolKernel = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId()); if (poolKernel != null) { poolKernelArgs = poolKernel.Args; } string kernelArgs = kernelInput.Args; string coinKernelArgs = coinKernel.Args; string customArgs = coinKernelProfile.CustomArgs; parameters.Add("mainCoin", mainCoin.Code); if (mainCoinPool.IsUserMode) { IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId()); string password = poolProfile.Password; if (string.IsNullOrEmpty(password)) { password = "******"; } parameters.Add("userName", poolProfile.UserName); parameters.Add("password", password); } else { parameters.Add("wallet", coinProfile.Wallet); } parameters.Add("host", mainCoinPool.GetHost()); parameters.Add("port", mainCoinPool.GetPort().ToString()); parameters.Add("pool", mainCoinPool.Server); parameters.Add("worker", this.MinerProfile.MinerName); if (coinKernel.IsSupportPool1) { parameters.Add("worker1", this.MinerProfile.MinerName); if (PoolSet.TryGetPool(coinProfile.PoolId1, out IPool mainCoinPool1)) { parameters.Add("host1", mainCoinPool1.GetHost()); parameters.Add("port1", mainCoinPool1.GetPort().ToString()); parameters.Add("pool1", mainCoinPool1.Server); if (mainCoinPool1.IsUserMode) { IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId()); string password1 = poolProfile1.Password; if (string.IsNullOrEmpty(password1)) { password1 = "x"; } parameters.Add("userName1", poolProfile1.UserName); parameters.Add("password1", password1); } else { parameters.Add("wallet1", coinProfile.Wallet); } } } // 这里不要考虑{logfile},{logfile}往后推迟 if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine) { Guid dualCoinGroupId = coinKernel.DualCoinGroupId; if (dualCoinGroupId == Guid.Empty) { dualCoinGroupId = kernelInput.DualCoinGroupId; } if (dualCoinGroupId != Guid.Empty) { if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId()); if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId()); string dualPassword = dualPoolProfile.Password; if (string.IsNullOrEmpty(dualPassword)) { dualPassword = "******"; } parameters.Add("dualCoin", dualCoin.Code); parameters.Add("dualWallet", dualCoinProfile.DualCoinWallet); parameters.Add("dualUserName", dualPoolProfile.UserName); parameters.Add("dualPassword", dualPassword); parameters.Add("dualHost", dualCoinPool.GetHost()); parameters.Add("dualPort", dualCoinPool.GetPort().ToString()); parameters.Add("dualPool", dualCoinPool.Server); kernelArgs = kernelInput.DualFullArgs; AssembleArgs(parameters, ref kernelArgs, isDual: true); AssembleArgs(parameters, ref poolKernelArgs, isDual: true); AssembleArgs(parameters, ref customArgs, isDual: true); string dualWeightArg; if (!string.IsNullOrEmpty(kernelInput.DualWeightArg)) { if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight) { dualWeightArg = string.Empty; } else { dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}"; } } else { dualWeightArg = string.Empty; } StringBuilder dualSb = new StringBuilder(); dualSb.Append(kernelArgs); if (!string.IsNullOrEmpty(dualWeightArg)) { dualSb.Append(" ").Append(dualWeightArg); } if (!string.IsNullOrEmpty(poolKernelArgs)) { dualSb.Append(" ").Append(poolKernelArgs); } BuildFragments(coinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { dualSb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { dualSb.Append(" ").Append(customArgs); } // 注意:这里退出 return(dualSb.ToString()); } } } } AssembleArgs(parameters, ref kernelArgs, isDual: false); AssembleArgs(parameters, ref coinKernelArgs, isDual: false); AssembleArgs(parameters, ref poolKernelArgs, isDual: false); AssembleArgs(parameters, ref customArgs, isDual: false); string devicesArgs = string.Empty; if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg)) { List <int> useDevices = this.GpuSet.GetUseDevices(); if (useDevices.Count != 0 && useDevices.Count != GpuSet.Count) { string separator = kernelInput.DevicesSeparator; if (kernelInput.DevicesSeparator == "space") { separator = " "; } if (string.IsNullOrEmpty(separator)) { List <string> gpuIndexes = new List <string>(); foreach (var index in useDevices) { int i = index; if (kernelInput.DeviceBaseIndex != 0) { i = index + kernelInput.DeviceBaseIndex; } if (i > 9) { gpuIndexes.Add(gpuIndexChars[i - 10]); } else { gpuIndexes.Add(i.ToString()); } } devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes)}"; } else { devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, useDevices)}"; } } } StringBuilder sb = new StringBuilder(); sb.Append(kernelArgs); if (!string.IsNullOrEmpty(coinKernelArgs)) { sb.Append(" ").Append(coinKernelArgs); } if (!string.IsNullOrEmpty(poolKernelArgs)) { sb.Append(" ").Append(poolKernelArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { sb.Append(" ").Append(devicesArgs); } BuildFragments(coinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { sb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { sb.Append(" ").Append(customArgs); } return(sb.ToString()); }
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 string BuildAssembleArgs() { if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin)) { return(string.Empty); } ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId()); if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { return(string.Empty); } if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { return(string.Empty); } if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { return(string.Empty); } if (!kernel.IsSupported(mainCoin)) { return(string.Empty); } if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput)) { return(string.Empty); } ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); string wallet = coinProfile.Wallet; string pool = mainCoinPool.Server; string poolKernelArgs = string.Empty; IPoolKernel poolKernel = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId()); if (poolKernel != null) { poolKernelArgs = poolKernel.Args; } IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId()); string userName = poolProfile.UserName; string password = poolProfile.Password; if (string.IsNullOrEmpty(password)) { password = "******"; } string kernelArgs = kernelInput.Args; string coinKernelArgs = coinKernel.Args; string customArgs = coinKernelProfile.CustomArgs; var argsDic = new Dictionary <string, string> { { "mainCoin", mainCoin.Code }, { "wallet", wallet }, { "userName", userName }, { "password", password }, { "host", mainCoinPool.GetHost() }, { "port", mainCoinPool.GetPort().ToString() }, { "pool", pool }, { "worker", this.MinerProfile.MinerName } };// 这里不要考虑{logfile},{logfile}往后推迟 if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine) { Guid dualCoinGroupId = coinKernel.DualCoinGroupId; if (dualCoinGroupId == Guid.Empty) { dualCoinGroupId = kernelInput.DualCoinGroupId; } if (dualCoinGroupId != Guid.Empty) { if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId()); if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { string dualWallet = dualCoinProfile.DualCoinWallet; string dualPool = dualCoinPool.Server; IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId()); string dualUserName = dualPoolProfile.UserName; string dualPassword = dualPoolProfile.Password; if (string.IsNullOrEmpty(dualPassword)) { dualPassword = "******"; } argsDic.Add("dualCoin", dualCoin.Code); argsDic.Add("dualAlgo", dualCoin.Algo); argsDic.Add("dualWallet", dualWallet); argsDic.Add("dualUserName", dualUserName); argsDic.Add("dualPassword", dualPassword); argsDic.Add("dualHost", dualCoinPool.GetHost()); argsDic.Add("dualPort", dualCoinPool.GetPort().ToString()); argsDic.Add("dualPool", dualPool); kernelArgs = kernelInput.DualFullArgs; AssembleArgs(argsDic, ref kernelArgs, isDual: true); AssembleArgs(argsDic, ref poolKernelArgs, isDual: true); AssembleArgs(argsDic, ref customArgs, isDual: true); string dualWeightArg; if (!string.IsNullOrEmpty(kernelInput.DualWeightArg)) { if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight) { dualWeightArg = string.Empty; } else { dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}"; } } else { dualWeightArg = string.Empty; } return($"{kernelArgs} {dualWeightArg} {poolKernelArgs} {customArgs}"); } } } } AssembleArgs(argsDic, ref kernelArgs, isDual: false); AssembleArgs(argsDic, ref coinKernelArgs, isDual: false); AssembleArgs(argsDic, ref poolKernelArgs, isDual: false); AssembleArgs(argsDic, ref customArgs, isDual: false); string devicesArgs = string.Empty; if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg)) { List <int> useDevices = GetUseDevices(); if (useDevices.Count != 0 && useDevices.Count != GpuSet.Count) { string separator = kernelInput.DevicesSeparator; if (kernelInput.DevicesSeparator == "space") { separator = " "; } if (string.IsNullOrEmpty(separator)) { List <string> gpuIndexes = new List <string>(); foreach (var index in useDevices) { int i = index; if (kernelInput.DeviceBaseIndex != 0) { i = index + kernelInput.DeviceBaseIndex; } if (i > 9) { gpuIndexes.Add(gpuIndexChars[i - 10]); } else { gpuIndexes.Add(i.ToString()); } } devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes)}"; } else { devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, useDevices)}"; } } } StringBuilder sb = new StringBuilder(); sb.Append(kernelArgs); if (!string.IsNullOrEmpty(coinKernelArgs)) { sb.Append(" ").Append(coinKernelArgs); } if (!string.IsNullOrEmpty(poolKernelArgs)) { sb.Append(" ").Append(poolKernelArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { sb.Append(" ").Append(devicesArgs); } if (!string.IsNullOrEmpty(customArgs)) { sb.Append(" ").Append(customArgs); } return(sb.ToString()); }
public string BuildAssembleArgs(out Dictionary <string, string> parameters, out Dictionary <Guid, string> fileWriters, out Dictionary <Guid, string> fragments) { parameters = new Dictionary <string, string>(); fileWriters = new Dictionary <Guid, string>(); fragments = new Dictionary <Guid, string>(); if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin)) { return(string.Empty); } ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId()); if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool)) { return(string.Empty); } if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel)) { return(string.Empty); } if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel)) { return(string.Empty); } if (!kernel.IsSupported(mainCoin)) { return(string.Empty); } if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput)) { return(string.Empty); } ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId); string poolKernelArgs = string.Empty; IPoolKernel poolKernel = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId()); if (poolKernel != null) { poolKernelArgs = poolKernel.Args; } string kernelArgs = kernelInput.Args; string coinKernelArgs = coinKernel.Args; string customArgs = coinKernelProfile.CustomArgs ?? string.Empty; parameters.Add(Consts.MainCoinParameterName, mainCoin.Code); if (mainCoinPool.IsUserMode) { IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId()); string password = poolProfile.Password; if (string.IsNullOrEmpty(password)) { password = Consts.PasswordDefaultValue; } parameters.Add(Consts.UserNameParameterName, poolProfile.UserName); parameters.Add(Consts.PasswordParameterName, password); parameters.Add(Consts.WalletParameterName, poolProfile.UserName); } else { parameters.Add(Consts.WalletParameterName, coinProfile.Wallet); } parameters.Add(Consts.HostParameterName, mainCoinPool.GetHost()); parameters.Add(Consts.PortParameterName, mainCoinPool.GetPort().ToString()); parameters.Add(Consts.PoolParameterName, mainCoinPool.Server); string minerName = $"{mainCoinPool.MinerNamePrefix}{this.MinerProfile.MinerName}{mainCoinPool.MinerNamePostfix}"; parameters.Add(Consts.WorkerParameterName, minerName); if (coinKernel.IsSupportPool1 && !mainCoinPool.NoPool1) { parameters.Add(Consts.Worker1ParameterName, minerName); if (PoolSet.TryGetPool(coinProfile.PoolId1, out IPool mainCoinPool1)) { parameters.Add(Consts.Host1ParameterName, mainCoinPool1.GetHost()); parameters.Add(Consts.Port1ParameterName, mainCoinPool1.GetPort().ToString()); parameters.Add(Consts.Pool1ParameterName, mainCoinPool1.Server); if (mainCoinPool1.IsUserMode) { IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId()); string password1 = poolProfile1.Password; if (string.IsNullOrEmpty(password1)) { password1 = Consts.PasswordDefaultValue; } parameters.Add(Consts.UserName1ParameterName, poolProfile1.UserName); parameters.Add(Consts.Password1ParameterName, password1); } else { parameters.Add(Consts.Wallet1ParameterName, coinProfile.Wallet); } } } string devicesArgs = GetDevicesArgs(kernelInput); // 这里不要考虑{logfile},{logfile}往后推迟 if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine) { Guid dualCoinGroupId = coinKernel.DualCoinGroupId; if (dualCoinGroupId != Guid.Empty) { if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId()); if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool)) { IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId()); string dualPassword = dualPoolProfile.Password; if (string.IsNullOrEmpty(dualPassword)) { dualPassword = Consts.PasswordDefaultValue; } parameters.Add(Consts.DualCoinParameterName, dualCoin.Code); parameters.Add(Consts.DualWalletParameterName, dualCoinProfile.DualCoinWallet); parameters.Add(Consts.DualUserNameParameterName, dualPoolProfile.UserName); parameters.Add(Consts.DualPasswordParameterName, dualPassword); parameters.Add(Consts.DualHostParameterName, dualCoinPool.GetHost()); parameters.Add(Consts.DualPortParameterName, dualCoinPool.GetPort().ToString()); parameters.Add(Consts.DualPoolParameterName, dualCoinPool.Server); kernelArgs = coinKernel.DualFullArgs; AssembleArgs(parameters, ref kernelArgs, isDual: true); AssembleArgs(parameters, ref poolKernelArgs, isDual: true); AssembleArgs(parameters, ref customArgs, isDual: true); string dualWeightArg; if (!string.IsNullOrEmpty(kernelInput.DualWeightArg)) { if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight) { dualWeightArg = string.Empty; } else { dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}"; } } else { dualWeightArg = string.Empty; } StringBuilder dualSb = new StringBuilder(); dualSb.Append(kernelArgs); if (!string.IsNullOrEmpty(dualWeightArg)) { dualSb.Append(" ").Append(dualWeightArg); } if (!string.IsNullOrEmpty(poolKernelArgs)) { dualSb.Append(" ").Append(poolKernelArgs); } BuildFragments(coinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { dualSb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { dualSb.Append(" ").Append(customArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { dualSb.Append(" ").Append(devicesArgs); } // 注意:这里退出 return(dualSb.ToString()); } } } } AssembleArgs(parameters, ref kernelArgs, isDual: false); AssembleArgs(parameters, ref coinKernelArgs, isDual: false); AssembleArgs(parameters, ref poolKernelArgs, isDual: false); AssembleArgs(parameters, ref customArgs, isDual: false); StringBuilder sb = new StringBuilder(); sb.Append(kernelArgs); if (!string.IsNullOrEmpty(coinKernelArgs)) { sb.Append(" ").Append(coinKernelArgs); } if (!string.IsNullOrEmpty(poolKernelArgs)) { sb.Append(" ").Append(poolKernelArgs); } if (!string.IsNullOrEmpty(devicesArgs)) { sb.Append(" ").Append(devicesArgs); } BuildFragments(coinKernel, parameters, out fileWriters, out fragments); foreach (var fragment in fragments.Values) { sb.Append(" ").Append(fragment); } if (!string.IsNullOrEmpty(customArgs)) { sb.Append(" ").Append(customArgs); } return(sb.ToString()); }
public string BuildAssembleArgs() { ICoin mainCoin; if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out mainCoin)) { return(string.Empty); } ICoinProfile coinProfile = this.CoinProfileSet.GetCoinProfile(mainCoin.GetId()); IPool mainCoinPool; if (!PoolSet.TryGetPool(coinProfile.PoolId, out mainCoinPool)) { return(string.Empty); } ICoinKernel coinKernel; if (!CoinKernelSet.TryGetKernel(coinProfile.CoinKernelId, out coinKernel)) { return(string.Empty); } IKernel kernel; if (!KernelSet.TryGetKernel(coinKernel.KernelId, out kernel)) { return(string.Empty); } if (!kernel.IsSupported()) { return(string.Empty); } ICoinKernelProfile coinKernelProfile = this.CoinKernelProfileSet.GetCoinKernelProfile(coinProfile.CoinKernelId); string wallet = coinProfile.Wallet; string pool = mainCoinPool.Server; string kernelArgs = kernel.Args; string coinKernelArgs = coinKernel.Args; string customArgs = coinKernelProfile.CustomArgs; var argsDic = new Dictionary <string, string> { { "mainCoin", mainCoin.Code }, { "mainAlgo", mainCoin.Algo }, { "wallet", wallet }, { "host", mainCoinPool.GetHost() }, { "port", mainCoinPool.GetPort().ToString() }, { "pool", pool }, { "worker", this.MinerProfile.MinerName } };// 这里不要考虑{logfile},{logfile}往后推迟 if (coinKernelProfile.IsDualCoinEnabled) { Guid dualCoinGroupId = coinKernel.DualCoinGroupId; if (dualCoinGroupId == Guid.Empty) { dualCoinGroupId = kernel.DualCoinGroupId; } if (dualCoinGroupId != Guid.Empty) { ICoin dualCoin; if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out dualCoin)) { ICoinProfile dualCoinProfile = this.CoinProfileSet.GetCoinProfile(dualCoin.GetId()); IPool dualCoinPool; if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out dualCoinPool)) { string dualWallet = dualCoinProfile.DualCoinWallet; string dualPool = dualCoinPool.Server; argsDic.Add("dualCoin", dualCoin.Code); argsDic.Add("dualAlgo", dualCoin.Algo); argsDic.Add("dualWallet", dualWallet); argsDic.Add("dualHost", dualCoinPool.GetHost()); argsDic.Add("dualPort", dualCoinPool.GetPort().ToString()); argsDic.Add("dualPool", dualPool); kernelArgs = kernel.DualFullArgs; AssembleArgs(argsDic, ref kernelArgs, isDual: true); AssembleArgs(argsDic, ref customArgs, isDual: true); string dualWeightArg; if (!string.IsNullOrEmpty(kernel.DualWeightArg)) { if (coinKernelProfile.IsAutoDualWeight && kernel.IsAutoDualWeight) { dualWeightArg = string.Empty; } else { dualWeightArg = $"{kernel.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}"; } } else { dualWeightArg = string.Empty; } return($"{kernelArgs} {dualWeightArg} {customArgs}"); } } } } AssembleArgs(argsDic, ref kernelArgs, isDual: false); AssembleArgs(argsDic, ref coinKernelArgs, isDual: false); AssembleArgs(argsDic, ref customArgs, isDual: false); return($"{kernelArgs} {coinKernelArgs} {customArgs}"); }
public CoinProfileViewModel(ICoinProfile innerProfile) { _inner = innerProfile; this.CopyWallet = new DelegateCommand(() => { string wallet = this.Wallet ?? "无"; Clipboard.SetDataObject(wallet); MainWindowViewModel.Current.Manager.CreateMessage() .Accent("#1751C3") .Background("#333") .HasBadge("Info") .HasMessage("复制成功:" + wallet) .Dismiss() .WithDelay(TimeSpan.FromSeconds(2)) .Queue(); }); this.CopyDualCoinWallet = new DelegateCommand(() => { string wallet = this.DualCoinWallet ?? "无"; Clipboard.SetDataObject(wallet); MainWindowViewModel.Current.Manager.CreateMessage() .Accent("#1751C3") .Background("#333") .HasBadge("Info") .HasMessage("复制成功:" + wallet) .Dismiss() .WithDelay(TimeSpan.FromSeconds(2)) .Queue(); }); this.HideWallet = new DelegateCommand(() => { this.IsHideWallet = true; }); this.ShowWallet = new DelegateCommand(() => { this.IsHideWallet = false; }); this.HideDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = true; }); this.ShowDualCoinWallet = new DelegateCommand(() => { this.IsDualCoinHideWallet = false; }); this.AddWallet = new DelegateCommand(() => { CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(this.CoinId, out coinVm)) { Guid id = Guid.NewGuid(); var wallets = coinVm.Wallets.Where(a => a.IsTestWallet).ToArray(); int sortNumber = wallets.Length == 0 ? 1 : wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(id) { CoinId = CoinId, SortNumber = sortNumber }.Edit.Execute(null); IWallet wallet; if (NTMinerRoot.Current.WalletSet.TryGetWallet(id, out wallet)) { this.SelectedWallet = WalletViewModels.Current.WalletList.FirstOrDefault(a => a.Id == id); } } }); this.AddDualCoinWallet = new DelegateCommand(() => { CoinViewModel coinVm; if (CoinViewModels.Current.TryGetCoinVm(this.CoinId, out coinVm)) { Guid id = Guid.NewGuid(); var wallets = coinVm.Wallets.Where(a => a.IsTestWallet).ToArray(); int sortNumber = wallets.Length == 0 ? 1 : wallets.Max(a => a.SortNumber) + 1; new WalletViewModel(id) { CoinId = CoinId, SortNumber = sortNumber }.Edit.Execute(null); IWallet wallet; if (NTMinerRoot.Current.WalletSet.TryGetWallet(id, out wallet)) { this.SelectedDualCoinWallet = WalletViewModels.Current.WalletList.FirstOrDefault(a => a.Id == id); } } }); }
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 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); } }