public KernelOutputTranslaterSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow<AddKernelOutputTranslaterCommand>("添加内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId)) { _dicByKernelOutputId.Add(entity.KernelOutputId, new List<KernelOutputTranslaterData>()); } _dicByKernelOutputId[entity.KernelOutputId].Add(entity); var repository = NTMinerRoot.CreateServerRepository<KernelOutputTranslaterData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelOutputTranslaterAddedEvent(entity)); }); _root.ServerContextWindow<UpdateKernelOutputTranslaterCommand>("更新内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } string regexPattern = entity.RegexPattern; string color = entity.Color; entity.Update(message.Input); if (entity.RegexPattern != regexPattern) { _regexDic.Remove(entity); } if (entity.Color != color) { _colorDic.Remove(entity); } _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository<KernelOutputTranslaterData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelOutputTranslaterUpdatedEvent(entity)); }); _root.ServerContextWindow<RemoveKernelOutputTranslaterCommand>("移除内核输出翻译器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputTranslaterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelOutputId[entity.KernelOutputId].Remove(entity); _colorDic.Remove(entity); _regexDic.Remove(entity); _dicByKernelOutputId[entity.KernelOutputId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository<KernelOutputTranslaterData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelOutputTranslaterRemovedEvent(entity)); }); _root.ServerContextOn<SysDicItemUpdatedEvent>("LogColor字典项更新后刷新翻译器内存", LogEnum.DevConsole, action: message => { if (!_root.SysDicSet.TryGetSysDic("LogColor", out ISysDic dic)) { return; } if (message.Source.DicId != dic.GetId()) { return; } foreach (var entity in _dicById.Values) { if (entity.Color == message.Source.Code) { _colorDic.Remove(entity); } } }); }
public NTMinerWalletSet(INTMinerRoot root) { _root = root; VirtualRoot.BuildCmdPath <AddNTMinerWalletCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Wallet)) { throw new ValidationException("NTMinerWallet Wallet can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } NTMinerWalletData entity = new NTMinerWalletData().Update(message.Input); OfficialServer.NTMinerWalletService.AddOrUpdateNTMinerWalletAsync(entity, (response, e) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.RaiseEvent(new NTMinerWalletAddedEvent(entity)); } else { Write.UserFail(response.ReadMessage(e)); } }); }); VirtualRoot.BuildCmdPath <UpdateNTMinerWalletCommand>(action: (message) => { if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Wallet)) { throw new ValidationException("minerGroup Wallet can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } NTMinerWalletData entity = _dicById[message.Input.GetId()]; NTMinerWalletData oldValue = new NTMinerWalletData().Update(entity); entity.Update(message.Input); OfficialServer.NTMinerWalletService.AddOrUpdateNTMinerWalletAsync(entity, (response, e) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.RaiseEvent(new NTMinerWalletUpdatedEvent(entity)); Write.UserFail(response.ReadMessage(e)); } }); VirtualRoot.RaiseEvent(new NTMinerWalletUpdatedEvent(entity)); }); VirtualRoot.BuildCmdPath <RemoveNTMinerWalletCommand>(action: (message) => { if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } NTMinerWalletData entity = _dicById[message.EntityId]; OfficialServer.NTMinerWalletService.RemoveNTMinerWalletAsync(entity.Id, (response, e) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.RaiseEvent(new NTMinerWalletRemovedEvent(entity)); } else { Write.UserFail(response.ReadMessage(e)); } }); }); }
public CoinKernelProfileSet(INTMinerRoot root, MineWorkData mineWorkData) { _root = root; _mineWorkData = mineWorkData; }
public CoinProfileSet(INTMinerRoot root) { _root = root; Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
public WalletSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddWalletCommand>("添加钱包", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet code and Address can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = new WalletData().Update(message.Input); _dicById.Add(entity.Id, entity); AddWallet(entity); VirtualRoot.Happened(new WalletAddedEvent(entity)); }); VirtualRoot.Window <UpdateWalletCommand>("更新钱包", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet Address can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("wallet name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); UpdateWallet(entity); VirtualRoot.Happened(new WalletUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveWalletCommand>("移除钱包", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WalletData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); RemoveWallet(entity.Id); VirtualRoot.Happened(new WalletRemovedEvent(entity)); }); }
public void ReInit(INTMinerRoot root, MineWorkData mineWorkData) { Init(root, mineWorkData); }
public NVIDIAGpuSet(INTMinerRoot root) { _root = root; this.Properties = new List <GpuSetProperty>(); if (NvmlInit()) { NvmlNativeMethods.nvmlDeviceGetCount(ref deviceCount); for (int i = 0; i < deviceCount; i++) { Gpu gpu = Gpu.Create(i, string.Empty, string.Empty); nvmlDevice nvmlDevice = new nvmlDevice(); var nvmlReturn = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice); SetGpuStatus(gpu, nvmlReturn); NvmlNativeMethods.nvmlDeviceGetName(nvmlDevice, out string name); nvmlMemory memory = new nvmlMemory(); NvmlNativeMethods.nvmlDeviceGetMemoryInfo(nvmlDevice, ref memory); // short gpu name if (!string.IsNullOrEmpty(name)) { name = name.Replace("GeForce GTX ", string.Empty); name = name.Replace("GeForce ", string.Empty); } nvmlPciInfo pci = new nvmlPciInfo(); NvmlNativeMethods.nvmlDeviceGetPciInfo(nvmlDevice, ref pci); gpu.Name = name; gpu.BusId = pci.bus.ToString(); gpu.TotalMemory = memory.total; _gpus.Add(i, gpu); } if (deviceCount > 0) { NvmlNativeMethods.nvmlSystemGetDriverVersion(out _driverVersion); NvmlNativeMethods.nvmlSystemGetNVMLVersion(out string nvmlVersion); this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", _driverVersion)); try { if (double.TryParse(_driverVersion, out double driverVersionNum)) { var item = root.SysDicItemSet.GetSysDicItems("CudaVersion") .Select(a => new { Version = double.Parse(a.Value), a }) .OrderByDescending(a => a.Version) .FirstOrDefault(a => driverVersionNum >= a.Version); if (item != null) { this.Properties.Add(new GpuSetProperty("CudaVersion", "Cuda版本", item.a.Code)); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } this.Properties.Add(new GpuSetProperty("NVMLVersion", "NVML版本", nvmlVersion)); Dictionary <string, string> kvs = new Dictionary <string, string> { { "CUDA_DEVICE_ORDER", "PCI_BUS_ID" } }; foreach (var kv in kvs) { var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value); this.Properties.Add(property); } Task.Factory.StartNew(() => { foreach (var gpu in _gpus.Values) { OverClock.RefreshGpuState(gpu.Index); } // 这里会耗时5秒 foreach (var kv in kvs) { Environment.SetEnvironmentVariable(kv.Key, kv.Value); } }); } } }
public static SpeedData CreateSpeedData() { INTMinerRoot root = NTMinerRoot.Current; SpeedData data = new SpeedData { IsAutoBoot = NTMinerRegistry.GetIsAutoBoot(), IsAutoStart = NTMinerRegistry.GetIsAutoStart(), Version = NTMinerRoot.CurrentVersion.ToString(4), BootOn = root.CreatedOn, MineStartedOn = null, IsMining = root.IsMining, MinerName = root.MinerProfile.MinerName, GpuInfo = root.GpuSetInfo, ClientId = ClientId.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.Current.WindowsEdition, GpuDriver = root.GpuSet.GetProperty("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, MainCoinSpeed = a.MainCoinSpeed.Value, DualCoinSpeed = a.DualCoinSpeed.Value, FanSpeed = a.Gpu.FanSpeed, Temperature = a.Gpu.Temperature, PowerUsage = a.Gpu.PowerUsage, Cool = a.Gpu.Cool, Power = a.Gpu.Power, CoreClockDelta = a.Gpu.CoreClockDelta, MemoryClockDelta = a.Gpu.MemoryClockDelta }).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.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.Current.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.Current.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 CoinSet(INTMinerRoot root) { _root = root; _root.ServerContextCmdPath <AddCoinCommand>("添加币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("coin code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicByCode.ContainsKey(message.Input.Code)) { throw new ValidationException("编码重复"); } CoinData entity = new CoinData().Update(message.Input); _dicById.Add(entity.Id, entity); _dicByCode.Add(entity.Code, entity); var repository = NTMinerRoot.CreateServerRepository <CoinData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new CoinAddedEvent(entity)); }); _root.ServerContextCmdPath <UpdateCoinCommand>("更新币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("coin code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } CoinData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <CoinData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new CoinUpdatedEvent(message.Input)); }); _root.ServerContextCmdPath <RemoveCoinCommand>("移除币种", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinData entity = _dicById[message.EntityId]; Guid[] toRemoves = root.PoolSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemovePoolCommand(id)); } toRemoves = root.CoinKernelSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinKernelCommand(id)); } toRemoves = root.MinerProfile.GetWallets().Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveWalletCommand(id)); } toRemoves = root.CoinGroupSet.Where(a => a.CoinId == entity.Id).Select(a => a.GetId()).ToArray(); foreach (var id in toRemoves) { VirtualRoot.Execute(new RemoveCoinGroupCommand(id)); } _dicById.Remove(entity.Id); if (_dicByCode.ContainsKey(entity.Code)) { _dicByCode.Remove(entity.Code); } var repository = NTMinerRoot.CreateServerRepository <CoinData>(); repository.Remove(entity.Id); VirtualRoot.RaiseEvent(new CoinRemovedEvent(entity)); }); }
public FragmentWriterSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <AddFragmentWriterCommand>("添加命令行片段书写器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (string.IsNullOrEmpty(message.Input.Body)) { throw new ValidationException("FragmentWriter body can't be null or empty"); } FragmentWriterData entity = new FragmentWriterData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>(); repository.Add(entity); VirtualRoot.Happened(new FragmentWriterAddedEvent(entity)); }); _root.ServerContextWindow <UpdateFragmentWriterCommand>("更新命令行片段书写器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Body)) { throw new ValidationException("FragmentWriter body can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } FragmentWriterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>(); repository.Update(entity); VirtualRoot.Happened(new FragmentWriterUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveFragmentWriterCommand>("移除组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } FragmentWriterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <FragmentWriterData>(); repository.Remove(message.EntityId); VirtualRoot.Happened(new FragmentWriterRemovedEvent(entity)); }); }
public CoinKernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; VirtualRoot.Window <AddCoinKernelCommand>("添加币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } if (_dicById.Values.Any(a => a.CoinId == message.Input.CoinId && a.KernelId == message.Input.KernelId)) { return; } CoinKernelData entity = new CoinKernelData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new CoinKernelAddedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(message.Input.CoinId, out coin)) { IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { Guid poolKernelId = Guid.NewGuid(); var poolKernel = new PoolKernelData() { Id = poolKernelId, Args = string.Empty, Description = string.Empty, KernelId = message.Input.KernelId, PoolId = pool.GetId() }; VirtualRoot.Execute(new AddPoolKernelCommand(poolKernel)); } } }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <UpdateCoinKernelCommand>("更新币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is no coin with id" + message.Input.CoinId); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } CoinKernelData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new CoinKernelUpdatedEvent(entity)); }).AddToCollection(root.ContextHandlers); VirtualRoot.Window <RemoveCoinKernelCommand>("移除币种内核", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } CoinKernelData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); var repository = NTMinerRoot.CreateServerRepository <CoinKernelData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new CoinKernelRemovedEvent(entity)); ICoin coin; if (root.CoinSet.TryGetCoin(entity.CoinId, out coin)) { List <Guid> toRemoves = new List <Guid>(); IPool[] pools = root.PoolSet.Where(a => a.CoinId == coin.GetId()).ToArray(); foreach (IPool pool in pools) { foreach (PoolKernelData poolKernel in root.PoolKernelSet.Where(a => a.PoolId == pool.GetId() && a.KernelId == entity.KernelId)) { toRemoves.Add(poolKernel.Id); } } foreach (Guid poolKernelId in toRemoves) { VirtualRoot.Execute(new RemovePoolKernelCommand(poolKernelId)); } } }).AddToCollection(root.ContextHandlers); }
public PoolProfileSet(INTMinerRoot root, MineWorkData mineWorkData) { _root = root; _mineWorkData = mineWorkData; }
public void Init(INTMinerRoot root) { if (_isInited) { return; } _isInited = true; VirtualRoot.On <GpuStateChangedEvent>("当显卡温度变更时守卫温度防线", LogEnum.None, action: message => { IGpu gpu = message.Source; if (gpu.Index == NTMinerRoot.GpuAllId || root.MinerProfile.CoinId == Guid.Empty) { return; } IGpuProfile gpuProfile; if (NTMinerRoot.Instance.GpuProfileSet.IsOverClockGpuAll(root.MinerProfile.CoinId)) { gpuProfile = NTMinerRoot.Instance.GpuProfileSet.GetGpuProfile(root.MinerProfile.CoinId, NTMinerRoot.GpuAllId); } else { gpuProfile = NTMinerRoot.Instance.GpuProfileSet.GetGpuProfile(root.MinerProfile.CoinId, gpu.Index); } if (!gpuProfile.IsAutoFanSpeed) { return; } // 显卡温度抵达防御温度的时间 if (!_fightedOnDic.TryGetValue(gpu.Index, out DateTime fightedOn)) { fightedOn = DateTime.Now; _fightedOnDic.Add(gpu.Index, fightedOn); } if (gpu.FanSpeed == 100 && gpu.Temperature > _guardTemp) { Write.DevDebug($"GPU{gpu.Index} 温度{gpu.Temperature}大于防线温度{_guardTemp},但风扇转速已达100%"); } else if (gpu.Temperature < _guardTemp) { if (!_preTempDic.ContainsKey(gpu.Index)) { _preTempDic.Add(gpu.Index, 0); } // 如果当前温度比上次的温度大 if (gpu.Temperature > _preTempDic[gpu.Index]) { fightedOn = DateTime.Now; _fightedOnDic[gpu.Index] = fightedOn; } _preTempDic[gpu.Index] = gpu.Temperature; // 如果距离抵达防御温度的时间已经很久了则降速风扇 if (fightedOn.AddSeconds(_fanSpeedDownSeconds) < DateTime.Now) { int cool = (int)(gpu.FanSpeed - _fanSpeedDownStep); // 如果温度低于50度则直接将风扇设为驱动默认的最小转速 if (gpu.Temperature < 50) { cool = gpu.CoolMin; } if (cool >= gpu.CoolMin) { _fightedOnDic[gpu.Index] = DateTime.Now; root.GpuSet.OverClock.SetFanSpeed(gpu.Index, cool); Write.DevDebug($"GPU{gpu.Index} 风扇转速由{gpu.FanSpeed}%调低至{cool}%"); } } } else if (gpu.Temperature > _guardTemp) { uint cool; uint len; // 防线突破可能是由于小量降低风扇转速造成的 if (fightedOn.AddSeconds(_fanSpeedDownSeconds) < DateTime.Now) { _fightedOnDic[gpu.Index] = DateTime.Now; len = 100 - gpu.FanSpeed; } else { len = _fanSpeedDownStep; } cool = gpu.FanSpeed + (uint)Math.Ceiling(len / 2.0); if (cool > 100) { cool = 100; } if (cool <= 100) { root.GpuSet.OverClock.SetFanSpeed(gpu.Index, (int)cool); Write.DevDebug($"GPU{gpu.Index} 风扇转速由{gpu.FanSpeed}%调高至{cool}%"); } } }); }
public CalcConfigSet(INTMinerRoot root) { _root = root; }
public KernelOutputSet(INTMinerRoot root) { _root = root; #region 接线 _root.ServerContextCmdPath <AddKernelOutputCommand>("添加内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputData entity = new KernelOutputData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(); repository.Add(entity); VirtualRoot.RaiseEvent(new KernelOutputAddedEvent(entity)); }); _root.ServerContextCmdPath <UpdateKernelOutputCommand>("更新内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException($"{nameof(message.Input.Name)} can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(); repository.Update(entity); VirtualRoot.RaiseEvent(new KernelOutputUpdatedEvent(entity)); }); _root.ServerContextCmdPath <RemoveKernelOutputCommand>("移除内核输出组", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } IKernel[] outputUsers = root.KernelSet.Where(a => a.KernelOutputId == message.EntityId).ToArray(); if (outputUsers.Length != 0) { throw new ValidationException($"这些内核在使用该内核输出组,删除前请先解除使用:{string.Join(",", outputUsers.Select(a => a.GetFullName()))}"); } KernelOutputData entity = _dicById[message.EntityId]; List <Guid> kernelOutputFilterIds = root.KernelOutputFilterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); List <Guid> kernelOutputTranslaterIds = root.KernelOutputTranslaterSet.Where(a => a.KernelOutputId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var kernelOutputFilterId in kernelOutputFilterIds) { VirtualRoot.Execute(new RemoveKernelOutputFilterCommand(kernelOutputFilterId)); } foreach (var kernelOutputTranslaterId in kernelOutputTranslaterIds) { VirtualRoot.Execute(new RemoveKernelOutputTranslaterCommand(kernelOutputTranslaterId)); } _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputData>(); repository.Remove(message.EntityId); VirtualRoot.RaiseEvent(new KernelOutputRemovedEvent(entity)); }); #endregion }
public OverClockDataSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddOverClockDataCommand>("添加超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("OverClockData name can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } OverClockData entity = new OverClockData().Update(message.Input); OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new OverClockDataAddedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); VirtualRoot.Window <UpdateOverClockDataCommand>("更新超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("minerGroup name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } OverClockData entity = _dicById[message.Input.GetId()]; OverClockData oldValue = new OverClockData().Update(entity); entity.Update(message.Input); OfficialServer.OverClockDataService.AddOrUpdateOverClockDataAsync(entity, (response, e) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new OverClockDataUpdatedEvent(entity)); if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } } }); VirtualRoot.Happened(new OverClockDataUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveOverClockDataCommand>("移除超频建议", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } OverClockData entity = _dicById[message.EntityId]; OfficialServer.OverClockDataService.RemoveOverClockDataAsync(entity.Id, (response, e) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new OverClockDataRemovedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); }
private static void PickGpuSpeed(INTMinerRoot root, IMineContext mineContext, string input, IKernelOutput kernelOutput, bool isDual) { string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { return; } var now = DateTime.Now; bool hasGpuId = gpuSpeedPattern.Contains($"?<{VirtualRoot.GpuIndexGroupName}>"); Regex regex = VirtualRoot.GetRegex(gpuSpeedPattern); MatchCollection matches = regex.Matches(input); if (matches.Count > 0) { IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; string gpuSpeedText = match.Groups[VirtualRoot.GpuSpeedGroupName].Value; string gpuSpeedUnit = match.Groups[VirtualRoot.GpuSpeedUnitGroupName].Value; if (string.IsNullOrEmpty(gpuSpeedUnit)) { if (isDual) { gpuSpeedUnit = kernelOutput.DualSpeedUnit; } else { gpuSpeedUnit = kernelOutput.SpeedUnit; } } int gpu = i; if (hasGpuId) { string gpuText = match.Groups[VirtualRoot.GpuIndexGroupName].Value; if (!int.TryParse(gpuText, out gpu)) { gpu = i; } else { gpu = gpu - kernelOutput.GpuBaseIndex; if (gpu < 0) { continue; } } } if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg)) { if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpu < mineContext.UseDevices.Length) { gpu = mineContext.UseDevices[gpu]; } } if (double.TryParse(gpuSpeedText, out double gpuSpeed)) { double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit); gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now); } } string totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { // 求和分算力 double speed = isDual? gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.DualCoinSpeed.Value) : gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.MainCoinSpeed.Value); gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, speed, isDual, now); } } }
public MineWorkSet(INTMinerRoot root) { _root = root; ICoin coin = root.CoinSet.FirstOrDefault(); Global.Access <AddMineWorkCommand>( Guid.Parse("2ce02224-8ddf-4499-9d1d-7439ba5ca2fc"), "添加工作", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = new MineWorkData().Update(message.Input); _dicById.Add(entity.Id, entity); Server.ControlCenterService.AddOrUpdateMineWork(entity, isSuccess => { Global.Happened(new MineWorkAddedEvent(entity)); }); }); Global.Access <UpdateMineWorkCommand>( Guid.Parse("21140dbe-c9be-48d6-ae92-4d0ebc666a25"), "更新工作", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } MineWorkData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); Server.ControlCenterService.AddOrUpdateMineWork(entity, isSuccess => { Global.Happened(new MineWorkUpdatedEvent(entity)); }); }); Global.Access <RemoveMineWorkCommand>( Guid.Parse("cec3ccf4-9700-4e38-b786-8ceefe5209fb"), "移除工作", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MineWorkData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); Server.ControlCenterService.RemoveMineWork(entity.Id, isSuccess => { Global.Happened(new MineWorkRemovedEvent(entity)); }); }); BootLog.Log(this.GetType().FullName + "接入总线"); }
public PoolProfileSet(INTMinerRoot root) { _root = root; }
public WalletSet(INTMinerRoot root) { _root = root; Global.Access <AddWalletCommand>( Guid.Parse("d050de9d-7356-471b-b9c7-19d685aa770a"), "添加钱包", LogEnum.Log, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet code and Address can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = new WalletData().Update(message.Input); _dicById.Add(entity.Id, entity); AddWallet(entity); Global.Happened(new WalletAddedEvent(entity)); }); Global.Access <UpdateWalletCommand>( Guid.Parse("658f0e61-8c86-493f-a147-d66da2ed194d"), "更新钱包", LogEnum.Log, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet Address can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("wallet name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); UpdateWallet(entity); Global.Happened(new WalletUpdatedEvent(entity)); }); Global.Access <RemoveWalletCommand>( Guid.Parse("bd70fe34-7575-43d0-a8e5-d8e9566d8d56"), "移除钱包", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WalletData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); RemoveWallet(entity.Id); Global.Happened(new WalletRemovedEvent(entity)); }); Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
public KernelOutputTranslaterSet(INTMinerRoot root) { _root = root; Global.Access <AddKernelOutputTranslaterCommand>( Guid.Parse("d9da43ad-8fb7-4d6b-a8c7-ac0c1bbc4dd3"), "添加内核输出翻译器", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = new KernelOutputTranslaterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelId.ContainsKey(entity.KernelId)) { _dicByKernelId.Add(entity.KernelId, new List <KernelOutputTranslaterData>()); } _dicByKernelId[entity.KernelId].Add(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(); repository.Add(entity); Global.Happened(new KernelOutputTranslaterAddedEvent(entity)); }); Global.Access <UpdateKernelOutputTranslaterCommand>( Guid.Parse("9e22fc7d-41da-4291-8dde-d8282f81d188"), "更新内核输出翻译器", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException("ConsoleTranslater RegexPattern can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputTranslaterData entity = _dicById[message.Input.GetId()]; string regexPattern = entity.RegexPattern; string color = entity.Color; entity.Update(message.Input); if (entity.RegexPattern != regexPattern) { _regexDic.Remove(entity); } if (entity.Color != color) { _colorDic.Remove(entity); } _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(); repository.Update(entity); Global.Happened(new KernelOutputTranslaterUpdatedEvent(entity)); }); Global.Access <RemoveKernelOutputTranslaterCommand>( Guid.Parse("7e76b569-aa52-492a-ae41-f2e0a22ffa9b"), "移除内核输出翻译器", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputTranslaterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelId[entity.KernelId].Remove(entity); _colorDic.Remove(entity); _regexDic.Remove(entity); _dicByKernelId[entity.KernelId].Sort(new SortNumberComparer()); var repository = NTMinerRoot.CreateServerRepository <KernelOutputTranslaterData>(); repository.Remove(entity.Id); Global.Happened(new KernelOutputTranslaterRemovedEvent(entity)); }); Global.Access <SysDicItemUpdatedEvent>( Guid.Parse("de662262-bd05-4cae-ba6e-843f18541966"), "LogColor字典项更新后刷新翻译器内存", LogEnum.None, action: message => { ISysDic dic; if (!_root.SysDicSet.TryGetSysDic("LogColor", out dic)) { return; } if (message.Source.DicId != dic.GetId()) { return; } foreach (var entity in _dicById.Values) { if (entity.Color == message.Source.Code) { _colorDic.Remove(entity); } } }); Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
public GroupSet(INTMinerRoot root) { _root = root; Global.Access <AddGroupCommand>( Guid.Parse("e0c313ff-2550-41f8-9403-8575638c7faf"), "添加组", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } GroupData entity = new GroupData().Update(message.Input); _dicById.Add(entity.Id, entity); var repository = NTMinerRoot.CreateServerRepository <GroupData>(); repository.Add(entity); Global.Happened(new GroupAddedEvent(entity)); }); Global.Access <UpdateGroupCommand>( Guid.Parse("b2d190dd-b60d-41f9-8e93-65902c318a78"), "更新组", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("Group name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } GroupData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <GroupData>(); repository.Update(entity); Global.Happened(new GroupUpdatedEvent(entity)); }); Global.Access <RemoveGroupCommand>( Guid.Parse("7dede0b5-be81-4fc1-bee1-cdeb6afa7b72"), "移除组", LogEnum.Log, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } GroupData entity = _dicById[message.EntityId]; Guid[] toRemoves = root.CoinGroupSet.GetGroupCoinIds(entity.Id).ToArray(); foreach (var id in toRemoves) { Global.Execute(new RemoveCoinGroupCommand(id)); } _dicById.Remove(entity.GetId()); var repository = NTMinerRoot.CreateServerRepository <GroupData>(); repository.Remove(message.EntityId); Global.Happened(new GroupRemovedEvent(entity)); }); Global.Logger.InfoDebugLine(this.GetType().FullName + "接入总线"); }
private CoinProfile(INTMinerRoot root) { _root = root; }
public KernelSet(INTMinerRoot root, bool isUseJson) { _root = root; _isUseJson = isUseJson; _root.ServerContextWindow <AddKernelCommand>("添加内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("Kernel code can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelData entity = new KernelData().Update(message.Input); _dicById.Add(entity.Id, entity); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Add(entity); VirtualRoot.Happened(new KernelAddedEvent(entity)); }); _root.ServerContextWindow <UpdateKernelCommand>("更新内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.Code)) { throw new ValidationException("Kernel code can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Update(entity); VirtualRoot.Happened(new KernelUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveKernelCommand>("移除内核", LogEnum.DevConsole, action: message => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelData entity = _dicById[message.EntityId]; List <Guid> coinKernelIds = root.CoinKernelSet.Where(a => a.KernelId == entity.Id).Select(a => a.GetId()).ToList(); foreach (var coinKernelId in coinKernelIds) { VirtualRoot.Execute(new RemoveCoinKernelCommand(coinKernelId)); } _dicById.Remove(entity.Id); IRepository <KernelData> repository = NTMinerRoot.CreateServerRepository <KernelData>(isUseJson); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelRemovedEvent(entity)); }); }
public KernelOutputFilterSet(INTMinerRoot root) { _root = root; _root.ServerContextWindow <AddKernelOutputFilterCommand>("添加内核输出过滤器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputFilterData entity = new KernelOutputFilterData().Update(message.Input); _dicById.Add(entity.Id, entity); if (!_dicByKernelOutputId.ContainsKey(entity.KernelOutputId)) { _dicByKernelOutputId.Add(entity.KernelOutputId, new List <KernelOutputFilterData>()); } _dicByKernelOutputId[entity.KernelOutputId].Add(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(); repository.Add(entity); VirtualRoot.Happened(new KernelOutputFilterAddedEvent(entity)); }); _root.ServerContextWindow <UpdateKernelOutputFilterCommand>("更新内核输出过滤器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(message.Input.RegexPattern)) { throw new ValidationException($"{nameof(message.Input.RegexPattern)} can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } KernelOutputFilterData entity = _dicById[message.Input.GetId()]; if (ReferenceEquals(entity, message.Input)) { return; } entity.Update(message.Input); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(); repository.Update(entity); VirtualRoot.Happened(new KernelOutputFilterUpdatedEvent(entity)); }); _root.ServerContextWindow <RemoveKernelOutputFilterCommand>("移除内核输出过滤器", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } KernelOutputFilterData entity = _dicById[message.EntityId]; _dicById.Remove(entity.Id); _dicByKernelOutputId[entity.KernelOutputId].Remove(entity); var repository = NTMinerRoot.CreateServerRepository <KernelOutputFilterData>(); repository.Remove(entity.Id); VirtualRoot.Happened(new KernelOutputFilterRemovedEvent(entity)); }); }
public WalletSet(INTMinerRoot root) { _root = root; VirtualRoot.AddCmdPath <AddWalletCommand>(action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.ServerContext.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet code and Address can't be null or empty"); } if (_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = new WalletData().Update(message.Input); _dicById.Add(entity.Id, entity); AddWallet(entity); VirtualRoot.RaiseEvent(new WalletAddedEvent(message.MessageId, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <UpdateWalletCommand>(action: message => { InitOnece(); if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) { throw new ArgumentNullException(); } if (!_root.ServerContext.CoinSet.Contains(message.Input.CoinId)) { throw new ValidationException("there is not coin with id " + message.Input.CoinId); } if (string.IsNullOrEmpty(message.Input.Address)) { throw new ValidationException("wallet Address can't be null or empty"); } if (string.IsNullOrEmpty(message.Input.Name)) { throw new ValidationException("wallet name can't be null or empty"); } if (!_dicById.ContainsKey(message.Input.GetId())) { return; } WalletData entity = _dicById[message.Input.GetId()]; entity.Update(message.Input); UpdateWallet(entity); VirtualRoot.RaiseEvent(new WalletUpdatedEvent(message.MessageId, entity)); }, location: this.GetType()); VirtualRoot.AddCmdPath <RemoveWalletCommand>(action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } WalletData entity = _dicById[message.EntityId]; _dicById.Remove(entity.GetId()); RemoveWallet(entity.Id); VirtualRoot.RaiseEvent(new WalletRemovedEvent(message.MessageId, entity)); }, location: this.GetType()); }
public ServerAppSettingSet(INTMinerRoot root) { _root = root; VirtualRoot.BuildCmdPath <ChangeServerAppSettingCommand>(action: message => { if (message.AppSetting == null) { return; } AppSettingData oldValue; if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity)) { oldValue = new AppSettingData { Key = entity.Key, Value = entity.Value }; entity.Value = message.AppSetting.Value; } else { entity = AppSettingData.Create(message.AppSetting); oldValue = null; _dicByKey.Add(message.AppSetting.Key, entity); } Server.AppSettingService.SetAppSettingAsync(entity, (response, exception) => { if (!response.IsSuccess()) { if (oldValue == null) { _dicByKey.Remove(message.AppSetting.Key); } else { entity.Value = oldValue.Value; } Write.UserFail(response.ReadMessage(exception)); VirtualRoot.RaiseEvent(new ServerAppSettingChangedEvent(entity)); } }); VirtualRoot.RaiseEvent(new ServerAppSettingChangedEvent(entity)); }); VirtualRoot.BuildCmdPath <ChangeServerAppSettingsCommand>(action: message => { if (message.AppSettings == null) { return; } foreach (var item in message.AppSettings) { AppSettingData oldValue; if (_dicByKey.TryGetValue(item.Key, out AppSettingData entity)) { oldValue = new AppSettingData { Key = entity.Key, Value = entity.Value }; entity.Value = item.Value; } else { entity = AppSettingData.Create(item); oldValue = null; _dicByKey.Add(item.Key, entity); } VirtualRoot.RaiseEvent(new ServerAppSettingChangedEvent(entity)); } Server.AppSettingService.SetAppSettingsAsync(message.AppSettings.Select(a => AppSettingData.Create(a)).ToList(), (response, exception) => { }); }); }
public 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 = EntryAssemblyInfo.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); }
public MinerProfile(INTMinerRoot root, MineWorkData mineWorkData) { _root = root; Init(root, mineWorkData); }
private PoolProfile(INTMinerRoot root) { _root = root; }