示例#1
0
 private static void UserActionHappend()
 {
     if (!DevMode.IsDebugMode)
     {
         VirtualRoot.Happened(new UserActionEvent());
     }
 }
示例#2
0
 private void Init()
 {
     if (_isInited)
     {
         return;
     }
     _isInited = true;
     OfficialServer.OverClockDataService.GetOverClockDatasAsync((response, e) => {
         if (response.IsSuccess())
         {
             IEnumerable <OverClockData> query;
             if (_root.GpuSet.GpuType == GpuType.Empty)
             {
                 query = response.Data;
             }
             else
             {
                 query = response.Data.Where(a => a.GpuType == _root.GpuSet.GpuType);
             }
             foreach (var item in query)
             {
                 if (!_dicById.ContainsKey(item.GetId()))
                 {
                     _dicById.Add(item.GetId(), item);
                 }
             }
         }
         VirtualRoot.Happened(new OverClockDataSetInitedEvent());
     });
 }
示例#3
0
        public void LoadGpuState()
        {
            foreach (Gpu gpu in _gpus.Values)
            {
                int        i          = gpu.Index;
                nvmlDevice nvmlDevice = new nvmlDevice();
                var        nvmlReturn = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
                SetGpuStatus(gpu, nvmlReturn);
                uint power = 0;
                NvmlNativeMethods.nvmlDeviceGetPowerUsage(nvmlDevice, ref power);
                power = (uint)(power / 1000.0);
                uint temp = 0;
                NvmlNativeMethods.nvmlDeviceGetTemperature(nvmlDevice, nvmlTemperatureSensors.Gpu, ref temp);
                uint speed = 0;
                NvmlNativeMethods.nvmlDeviceGetFanSpeed(nvmlDevice, ref speed);
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = (int)temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }
示例#4
0
        public void LoadGpuState(int gpuIndex)
        {
            if (gpuIndex == NTMinerRoot.GpuAllId)
            {
                return;
            }
            var  gpu   = _gpus[gpuIndex];
            uint power = _nvmlHelper.GetPowerUsage(gpuIndex);
            uint temp  = _nvmlHelper.GetTemperature(gpuIndex);
            uint fanSpeed;

            if (!_nvapiHelper.GetFanSpeed(gpu.GetOverClockId(), out fanSpeed))
            {
                fanSpeed = _nvmlHelper.GetFanSpeed(gpuIndex);
            }
            bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != fanSpeed;

            gpu.Temperature = (int)temp;
            gpu.PowerUsage  = power;
            gpu.FanSpeed    = fanSpeed;

            if (isChanged)
            {
                VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
            }
        }
示例#5
0
        public void UpdateShare(Guid coinId, int?acceptShareCount, int?rejectShareCount, DateTime now)
        {
            CoinShare coinShare = (CoinShare)GetOrCreate(coinId);
            bool      isChanged = false;

            if (acceptShareCount.HasValue)
            {
                if (coinShare.AcceptShareCount != acceptShareCount.Value)
                {
                    coinShare.AcceptShareCount = acceptShareCount.Value;
                    isChanged = true;
                }
            }
            if (rejectShareCount.HasValue)
            {
                if (coinShare.RejectShareCount != rejectShareCount.Value)
                {
                    coinShare.RejectShareCount = rejectShareCount.Value;
                    isChanged = true;
                }
            }
            coinShare.ShareOn = now;
            if (isChanged)
            {
                VirtualRoot.Happened(new ShareChangedEvent(coinShare));
            }
        }
示例#6
0
 public void ShowMainWindow(bool isToggle)
 {
     UIThread.Execute(() => {
         if (_mainWindow == null)
         {
             lock (_locker) {
                 if (_mainWindow == null)
                 {
                     _mainWindow = CreateMainWindow();
                     Application.Current.MainWindow = _mainWindow;
                     _mainWindow.Show();
                     AppContext.Enable();
                     NTMinerRoot.IsUiVisible        = true;
                     NTMinerRoot.MainWindowRendedOn = DateTime.Now;
                     VirtualRoot.Happened(new MainWindowShowedEvent());
                     _mainWindow.Closed += (object sender, EventArgs e) => {
                         NTMinerRoot.IsUiVisible = false;
                         _mainWindow             = null;
                     };
                 }
             }
         }
         else
         {
             bool needActive = _mainWindow.WindowState != WindowState.Minimized;
             _mainWindow.ShowWindow(isToggle);
             if (needActive)
             {
                 _mainWindow.Activate();
             }
         }
     });
 }
示例#7
0
 public LocalAppSettingSet(string dbFileFullName)
 {
     _dbFileFullName = dbFileFullName;
     VirtualRoot.Window <ChangeLocalAppSettingCommand>("处理设置AppSetting命令", LogEnum.DevConsole,
                                                       action: message => {
         if (message.AppSetting == null)
         {
             return;
         }
         if (_dicByKey.TryGetValue(message.AppSetting.Key, out AppSettingData entity))
         {
             entity.Value = message.AppSetting.Value;
             using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
                 var col = db.GetCollection <AppSettingData>();
                 col.Update(entity);
             }
         }
         else
         {
             entity = AppSettingData.Create(message.AppSetting);
             _dicByKey.Add(message.AppSetting.Key, entity);
             using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
                 var col = db.GetCollection <AppSettingData>();
                 col.Insert(entity);
             }
         }
         VirtualRoot.Happened(new LocalAppSettingChangedEvent(entity));
     });
 }
示例#8
0
        public void LoadGpuState()
        {
            for (int i = 0; i < deviceCount; i++)
            {
                nvmlDevice nvmlDevice = new nvmlDevice();
                NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
                uint power = 0;
                NvmlNativeMethods.nvmlDeviceGetPowerUsage(nvmlDevice, ref power);
                power = (uint)(power / 1000.0);
                uint temp = 0;
                NvmlNativeMethods.nvmlDeviceGetTemperature(nvmlDevice, nvmlTemperatureSensors.Gpu, ref temp);
                uint speed = 0;
                NvmlNativeMethods.nvmlDeviceGetFanSpeed(nvmlDevice, ref speed);

                Gpu  gpu       = (Gpu)_gpus[i];
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }
示例#9
0
 public GpuProfileSet(INTMinerRoot root)
 {
     VirtualRoot.Window <AddOrUpdateGpuProfileCommand>("处理添加或更新Gpu超频数据命令", LogEnum.DevConsole,
                                                       action: message => {
         GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index);
         if (data != null)
         {
             data.Update(message.Input);
             Save();
         }
         else
         {
             data = new GpuProfileData(message.Input);
             _data.GpuProfiles.Add(data);
             Save();
         }
         VirtualRoot.Happened(new GpuProfileAddedOrUpdatedEvent(data));
     });
     VirtualRoot.Window <CoinOverClockCommand>("处理币种超频命令", LogEnum.DevConsole,
                                               action: message => {
         Task.Factory.StartNew(() => {
             CoinOverClock(root, message.CoinId);
             VirtualRoot.Happened(new CoinOverClockDoneEvent(message.Id));
         });
     });
 }
示例#10
0
        public void LoadGpuState()
        {
#if DEBUG
            VirtualRoot.Stopwatch.Restart();
#endif
            for (int i = 0; i < Count; i++)
            {
                uint power = adlHelper.GetPowerUsageByIndex(i);
                int  temp  = adlHelper.GetTemperatureByIndex(i);
                uint speed = adlHelper.GetFanSpeedByIndex(i);

                Gpu  gpu       = (Gpu)_gpus[i];
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
#if DEBUG
            Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.{nameof(LoadGpuState)}");
#endif
        }
示例#11
0
 private void RefreshGpuState(IGpu gpu)
 {
     if (gpu.Index == NTMinerRoot.GpuAllId)
     {
         return;
     }
     gpu.PowerCapacity    = _adlHelper.GetPowerLimitByIndex(gpu.Index);
     gpu.TempLimit        = _adlHelper.GetTempLimitByIndex(gpu.Index);
     gpu.MemoryClockDelta = _adlHelper.GetMemoryClockByIndex(gpu.Index);
     gpu.CoreClockDelta   = _adlHelper.GetSystemClockByIndex(gpu.Index);
     _adlHelper.GetClockRangeByIndex(
         gpu.Index,
         out int coreClockDeltaMin, out int coreClockDeltaMax,
         out int memoryClockDeltaMin, out int memoryClockDeltaMax,
         out int powerMin, out int powerMax, out int powerDefault,
         out int tempLimitMin, out int tempLimitMax, out int tempLimitDefault,
         out int fanSpeedMin, out int fanSpeedMax, out int fanSpeedDefault);
     gpu.CoreClockDeltaMin   = coreClockDeltaMin;
     gpu.CoreClockDeltaMax   = coreClockDeltaMax;
     gpu.MemoryClockDeltaMin = memoryClockDeltaMin;
     gpu.MemoryClockDeltaMax = memoryClockDeltaMax;
     gpu.PowerMin            = powerMin;
     gpu.PowerMax            = powerMax;
     gpu.PowerDefault        = powerDefault;
     gpu.TempLimitMin        = tempLimitMin;
     gpu.TempLimitMax        = tempLimitMax;
     gpu.TempLimitDefault    = tempLimitDefault;
     gpu.CoolMin             = fanSpeedMin;
     gpu.CoolMax             = fanSpeedMax;
     VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
 }
示例#12
0
        public void SetCurrentSpeed(int gpuIndex, double speed, bool isDual, DateTime now)
        {
            InitOnece();
            GpuSpeed gpuSpeed;

            if (!_currentGpuSpeed.TryGetValue(gpuIndex, out gpuSpeed))
            {
                return;
            }
            CheckReset();
            lock (_gpuSpeedHistoryValuesLocker) {
                // 将当前的旧算力加入历史列表
                if (_gpuSpeedHistory.TryGetValue(gpuSpeed.Gpu.Index, out List <IGpuSpeed> list))
                {
                    list.Add(gpuSpeed.Clone());
                }
            }
            bool isChanged = false;

            // 如果变化幅度大于等于百分之一或者距离上一次算力记录的时间超过了10分钟则视为算力变化
            if (isDual)
            {
                isChanged = gpuSpeed.DualCoinSpeed.SpeedOn.AddSeconds(10) < now || gpuSpeed.DualCoinSpeed.Value.IsChange(speed, 0.01);
                if (isChanged)
                {
                    gpuSpeed.UpdateDualCoinSpeed(speed, now);
                }
            }
            else
            {
                isChanged = gpuSpeed.MainCoinSpeed.SpeedOn.AddSeconds(10) < now || gpuSpeed.MainCoinSpeed.Value.IsChange(speed, 0.01);
                if (isChanged)
                {
                    gpuSpeed.UpdateMainCoinSpeed(speed, now);
                }
            }
            if (_averageGpuSpeed.TryGetValue(gpuIndex, out AverageSpeedWithHistory averageSpeed))
            {
                if (isDual)
                {
                    var array = _gpuSpeedHistory[gpuIndex].Where(a => a.DualCoinSpeed.Value != 0).ToArray();
                    if (array.Length != 0)
                    {
                        averageSpeed.DualSpeed = array.Average(a => a.DualCoinSpeed.Value);
                    }
                }
                else
                {
                    var array = _gpuSpeedHistory[gpuIndex].Where(a => a.MainCoinSpeed.Value != 0).ToArray();
                    if (array.Length != 0)
                    {
                        averageSpeed.Speed = array.Average(a => a.MainCoinSpeed.Value);
                    }
                }
            }
            if (isChanged)
            {
                VirtualRoot.Happened(new GpuSpeedChangedEvent(isDual: isDual, gpuSpeed: gpuSpeed));
            }
        }
示例#13
0
 public void ResetShare()
 {
     InitOnece();
     foreach (var gpuSpeed in _currentGpuSpeed.Values)
     {
         gpuSpeed.ResetShare();
         VirtualRoot.Happened(new GpuShareChangedEvent(gpuSpeed: gpuSpeed));
     }
 }
示例#14
0
        private LangSet()
        {
            VirtualRoot.Window <RefreshLangSetCommand>("处理刷新语言命令", LogEnum.DevConsole,
                                                       action: message => {
                _isInited = false;
                VirtualRoot.Happened(new LangSetRefreshedEvent());
            });

            VirtualRoot.Window <AddLangCommand>("处理添加语言命令", LogEnum.DevConsole,
                                                action: message => {
                if (_langs.All(a => a.GetId() != message.Input.GetId() && a.Code != message.Input.Code))
                {
                    Lang entity = new Lang().Update(message.Input);
                    _langs.Add(entity);
                    var repository = Repository.CreateLanguageRepository <Lang>();
                    repository.Add(entity);

                    VirtualRoot.Happened(new LangAddedEvent(entity));
                }
            });
            VirtualRoot.Window <UpdateLangCommand>("处理修改语言命令", LogEnum.DevConsole,
                                                   action: message => {
                Lang entity = _langs.FirstOrDefault(a => a.GetId() == message.Input.GetId());
                if (entity != null)
                {
                    entity.Update(message.Input);
                    var repository = Repository.CreateLanguageRepository <Lang>();
                    repository.Update(entity);

                    VirtualRoot.Happened(new LangUpdatedEvent(entity));
                }
            });
            VirtualRoot.Window <RemoveLangCommand>("处理删除语言命令", LogEnum.DevConsole,
                                                   action: message => {
                var entity = _langs.FirstOrDefault(a => a.GetId() == message.EntityId);
                if (entity != null)
                {
                    var toRemoveLangItemIds = new List <Guid>();
                    foreach (var g in LangViewItemSet.Instance.GetLangItems(message.EntityId))
                    {
                        foreach (var langItem in g.Value)
                        {
                            toRemoveLangItemIds.Add(langItem.GetId());
                        }
                    }
                    foreach (var id in toRemoveLangItemIds)
                    {
                        VirtualRoot.Execute(new RemoveLangViewItemCommand(id));
                    }
                    _langs.Remove(entity);
                    var repository = Repository.CreateLanguageRepository <Lang>();
                    repository.Remove(entity.GetId());

                    VirtualRoot.Happened(new LangRemovedEvent(entity));
                }
            });
        }
示例#15
0
        public void SetCurrentSpeed(int gpuIndex, double speed, bool isDual, DateTime now)
        {
            InitOnece();
            GpuSpeed gpuSpeed = _currentGpuSpeed.Values.FirstOrDefault(a => a.Gpu.Index == gpuIndex);

            if (gpuSpeed == null)
            {
                return;
            }
            Guid mainCoinId = _root.MinerProfile.CoinId;

            if (_mainCoinId != mainCoinId)
            {
                _mainCoinId = mainCoinId;
                lock (_gpuSpeedHistoryValuesLocker) {
                    foreach (var item in _gpuSpeedHistory)
                    {
                        item.Value.Clear();
                    }
                }
                foreach (var item in _currentGpuSpeed.Values)
                {
                    item.UpdateMainCoinSpeed(0, now);
                    item.UpdateDualCoinSpeed(0, now);
                }
            }
            lock (_gpuSpeedHistoryValuesLocker) {
                if (_gpuSpeedHistory.ContainsKey(gpuSpeed.Gpu.Index))
                {
                    _gpuSpeedHistory[gpuSpeed.Gpu.Index].Add(gpuSpeed.Clone());
                }
            }
            bool isChanged = false;

            // 如果变化幅度大于等于百分之一
            if (isDual)
            {
                isChanged = gpuSpeed.DualCoinSpeed.SpeedOn.AddSeconds(10) < now || gpuSpeed.DualCoinSpeed.Value.IsChange(speed, 0.01);
                if (isChanged)
                {
                    gpuSpeed.UpdateDualCoinSpeed(speed, now);
                }
            }
            else
            {
                isChanged = gpuSpeed.MainCoinSpeed.SpeedOn.AddSeconds(10) < now || gpuSpeed.MainCoinSpeed.Value.IsChange(speed, 0.01);
                if (isChanged)
                {
                    gpuSpeed.UpdateMainCoinSpeed(speed, now);
                }
            }
            if (isChanged)
            {
                VirtualRoot.Happened(new GpuSpeedChangedEvent(isDualSpeed: isDual, gpuSpeed: gpuSpeed));
            }
        }
示例#16
0
 public void Pick(Guid kernelOutputId, ref string input, IMineContext mineContext)
 {
     try {
         InitOnece();
         if (!_dicById.TryGetValue(kernelOutputId, out KernelOutputData kernelOutput))
         {
             return;
         }
         if (string.IsNullOrEmpty(input))
         {
             return;
         }
         if (!string.IsNullOrEmpty(kernelOutput.KernelRestartKeyword) && input.Contains(kernelOutput.KernelRestartKeyword))
         {
             mineContext.KernelSelfRestartCount = mineContext.KernelSelfRestartCount + 1;
             VirtualRoot.Happened(new KernelSelfRestartedEvent());
         }
         ICoin coin   = mineContext.MainCoin;
         bool  isDual = false;
         // 如果是双挖上下文且当前输入行中没有主币关键字则视为双挖币
         if ((mineContext is IDualMineContext dualMineContext) && !input.Contains(mineContext.MainCoin.Code))
         {
             isDual = true;
             coin   = dualMineContext.DualCoin;
         }
         // 这些方法输出的是事件消息
         PickTotalSpeed(_root, input, kernelOutput, coin, isDual);
         PickGpuSpeed(input, kernelOutput, coin, isDual);
         PickTotalShare(_root, input, kernelOutput, coin, isDual);
         PickAcceptShare(_root, input, kernelOutput, coin, isDual);
         PickAcceptOneShare(_root, input, kernelOutput, coin, isDual);
         PickRejectPattern(_root, input, kernelOutput, coin, isDual);
         PickRejectOneShare(_root, input, kernelOutput, coin, isDual);
         PickRejectPercent(_root, input, kernelOutput, coin, isDual);
         PickPoolDelay(input, kernelOutput, isDual);
         // 如果是像BMiner那样的主币和双挖币的输出在同一行那样的模式则一行输出既要视为主币又要视为双挖币
         if (isDual && kernelOutput.IsDualInSameLine)
         {
             coin   = mineContext.MainCoin;
             isDual = false;
             PickTotalSpeed(_root, input, kernelOutput, coin, isDual);
             PickGpuSpeed(input, kernelOutput, coin, isDual);
             PickTotalShare(_root, input, kernelOutput, coin, isDual);
             PickAcceptShare(_root, input, kernelOutput, coin, isDual);
             PickAcceptOneShare(_root, input, kernelOutput, coin, isDual);
             PickRejectPattern(_root, input, kernelOutput, coin, isDual);
             PickRejectOneShare(_root, input, kernelOutput, coin, isDual);
             PickRejectPercent(_root, input, kernelOutput, coin, isDual);
             PickPoolDelay(input, kernelOutput, isDual);
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
示例#17
0
        public PoolKernelSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            VirtualRoot.Window <AddPoolKernelCommand>("处理添加矿池级内核命令", LogEnum.DevConsole,
                                                      action: message => {
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    var entity = new PoolKernelData().Update(message.Input);
                    _dicById.Add(message.Input.GetId(), entity);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(isUseJson);
                    repository.Add(entity);
                    VirtualRoot.Happened(new PoolKernelAddedEvent(message.Input));
                }
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <RemovePoolKernelCommand>("处理移除矿池级内核命令", LogEnum.DevConsole,
                                                         action: message => {
                if (_dicById.ContainsKey(message.EntityId))
                {
                    var entity = _dicById[message.EntityId];
                    _dicById.Remove(message.EntityId);
                    var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(isUseJson);
                    repository.Remove(message.EntityId);
                    VirtualRoot.Happened(new PoolKernelRemovedEvent(entity));
                }
            }).AddToCollection(root.ContextHandlers);
            VirtualRoot.Window <UpdatePoolKernelCommand>("更新矿池内核", LogEnum.DevConsole,
                                                         action: (message) => {
                InitOnece();
                if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_root.PoolSet.Contains(message.Input.PoolId))
                {
                    throw new ValidationException("there is no pool with id" + message.Input.PoolId);
                }
                if (!_dicById.ContainsKey(message.Input.GetId()))
                {
                    return;
                }
                PoolKernelData entity = _dicById[message.Input.GetId()];
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                entity.Update(message.Input);
                var repository = NTMinerRoot.CreateServerRepository <PoolKernelData>(isUseJson);
                repository.Update(entity);

                VirtualRoot.Happened(new PoolKernelUpdatedEvent(entity));
            }).AddToCollection(root.ContextHandlers);
        }
示例#18
0
        public void IncreaseRejectShare(int gpuIndex)
        {
            InitOnece();
            GpuSpeed gpuSpeed;

            if (!_currentGpuSpeed.TryGetValue(gpuIndex, out gpuSpeed))
            {
                return;
            }
            CheckReset();
            gpuSpeed.IncreaseMainCoinRejectShare();
            VirtualRoot.Happened(new GpuShareChangedEvent(gpuSpeed: gpuSpeed));
        }
示例#19
0
        private void Init()
        {
            DateTime now = DateTime.Now;

            // 如果未显示主界面则收益计算器也不用更新了
            if ((_initedOn == DateTime.MinValue || NTMinerRoot.IsUiVisible) && _initedOn.AddMinutes(10) < now)
            {
                _initedOn = now;
                OfficialServer.GetCalcConfigsAsync(data => {
                    Init(data);
                    VirtualRoot.Happened(new CalcConfigSetInitedEvent());
                });
            }
        }
示例#20
0
        public void Init(bool forceRefresh = false)
        {
            DateTime now = DateTime.Now;

            // 如果未显示主界面则收益计算器也不用更新了
            if ((_initedOn == DateTime.MinValue || NTMinerRoot.IsUiVisible || VirtualRoot.IsMinerStudio) && (forceRefresh || _initedOn.AddMinutes(10) < now))
            {
                _initedOn = now;
                OfficialServer.CalcConfigService.GetCalcConfigsAsync(data => {
                    Init(data);
                    VirtualRoot.Happened(new CalcConfigSetInitedEvent());
                });
            }
        }
示例#21
0
 public void RefreshGpuState(IGpu gpu)
 {
     if (gpu.Index == NTMinerRoot.GpuAllId)
     {
         return;
     }
     try {
         OverClockRange range = _gpuHelper.GetClockRange(gpu.GetOverClockId());
         gpu.UpdateState(range);
     }
     catch (System.Exception e) {
         Logger.ErrorDebugLine(e);
     }
     VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
 }
示例#22
0
 public void Register(INTMinerRoot root)
 {
     VirtualRoot.Window <AddOrUpdateGpuProfileCommand>("处理添加或更新Gpu超频数据命令", LogEnum.DevConsole,
                                                       action: message => {
         GpuProfileData data = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.Input.CoinId && a.Index == message.Input.Index);
         if (data != null)
         {
             data.Update(message.Input);
             Save();
         }
         else
         {
             data = new GpuProfileData(message.Input);
             _data.GpuProfiles.Add(data);
             Save();
         }
         VirtualRoot.Happened(new GpuProfileAddedOrUpdatedEvent(data));
     });
     VirtualRoot.Window <OverClockCommand>("处理超频命令", LogEnum.DevConsole,
                                           action: message => {
         if (root.GpuSet.TryGetGpu(message.Input.Index, out IGpu gpu))
         {
             message.Input.OverClock(gpu.OverClock);
         }
     });
     VirtualRoot.Window <CoinOverClockCommand>("处理币种超频命令", LogEnum.DevConsole,
                                               action: message => {
         if (IsOverClockGpuAll(message.CoinId))
         {
             GpuProfileData overClockData = _data.GpuProfiles.FirstOrDefault(a => a.CoinId == message.CoinId && a.Index == NTMinerRoot.GpuAllId);
             if (overClockData != null)
             {
                 VirtualRoot.Execute(new OverClockCommand(overClockData));
             }
         }
         else
         {
             foreach (var overClockData in _data.GpuProfiles.Where(a => a.CoinId == message.CoinId))
             {
                 if (overClockData.Index != NTMinerRoot.GpuAllId)
                 {
                     VirtualRoot.Execute(new OverClockCommand(overClockData));
                 }
             }
         }
     });
 }
示例#23
0
 public static void BlockWAU() {
     try {
         Task.Factory.StartNew(() => {
             Type type = typeof(WindowsUtil);
             Assembly assembly = type.Assembly;
             string name = "BlockWAU.bat";
             string fileFullName = Path.Combine(SpecialPath.TempDirFullName, name);
             assembly.ExtractManifestResource(type, name, fileFullName);
             Cmd.RunClose(fileFullName, string.Empty, waitForExit: true);
             VirtualRoot.Happened(new BlockWAUEvent(true, "禁用windows系统更新成功"));
         });
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         VirtualRoot.Happened(new BlockWAUEvent(false, "禁用windows系统更新失败"));
     }
 }
示例#24
0
 public static void Win10Optimize() {
     try {
         Task.Factory.StartNew(() => {
             Type type = typeof(WindowsUtil);
             Assembly assembly = type.Assembly;
             string name = "Win10Optimize.reg";
             string fileFullName = Path.Combine(SpecialPath.TempDirFullName, name);
             assembly.ExtractManifestResource(type, name, fileFullName);
             Cmd.RunClose("regedit", $"/s \"{fileFullName}\"", waitForExit: true);
             VirtualRoot.Happened(new Win10OptimizeEvent(true, "优化Windows成功"));
         });
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         VirtualRoot.Happened(new Win10OptimizeEvent(false, "优化Windows失败"));
     }
 }
示例#25
0
        public CoinGroupSet(INTMinerRoot root, bool isUseJson)
        {
            _root      = root;
            _isUseJson = isUseJson;
            _root.ServerContextWindow <AddCoinGroupCommand>("添加币组", 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;
                }
                CoinGroupData entity = new CoinGroupData().Update(message.Input);
                if (ReferenceEquals(entity, message.Input))
                {
                    return;
                }
                _dicById.Add(entity.Id, entity);
                var repository = NTMinerRoot.CreateServerRepository <CoinGroupData>(isUseJson);
                repository.Add(entity);

                VirtualRoot.Happened(new CoinGroupAddedEvent(entity));
            });
            _root.ServerContextWindow <RemoveCoinGroupCommand>("移除币组", LogEnum.DevConsole,
                                                               action: (message) => {
                InitOnece();
                if (message == null || message.EntityId == Guid.Empty)
                {
                    throw new ArgumentNullException();
                }
                if (!_dicById.ContainsKey(message.EntityId))
                {
                    return;
                }
                CoinGroupData entity = _dicById[message.EntityId];
                _dicById.Remove(entity.GetId());
                var repository = NTMinerRoot.CreateServerRepository <CoinGroupData>(isUseJson);
                repository.Remove(message.EntityId);

                VirtualRoot.Happened(new CoinGroupRemovedEvent(entity));
            });
        }
示例#26
0
 public UserSet(string dbFileFullName)
 {
     _dbFileFullName = dbFileFullName;
     VirtualRoot.Window <AddUserCommand>("处理添加用户命令", LogEnum.DevConsole,
                                         action: message => {
         if (!_dicByLoginName.ContainsKey(message.User.LoginName))
         {
             UserData entity = new UserData(message.User);
             _dicByLoginName.Add(message.User.LoginName, entity);
             using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
                 var col = db.GetCollection <UserData>();
                 col.Insert(entity);
             }
             VirtualRoot.Happened(new UserAddedEvent(entity));
         }
     });
     VirtualRoot.Window <UpdateUserCommand>("处理修改用户命令", LogEnum.DevConsole,
                                            action: message => {
         if (_dicByLoginName.ContainsKey(message.User.LoginName))
         {
             UserData entity = _dicByLoginName[message.User.LoginName];
             entity.Update(message.User);
             using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
                 var col = db.GetCollection <UserData>();
                 col.Update(entity);
             }
             VirtualRoot.Happened(new UserUpdatedEvent(entity));
         }
     });
     VirtualRoot.Window <RemoveUserCommand>("处理删除用户命令", LogEnum.DevConsole,
                                            action: message => {
         if (_dicByLoginName.ContainsKey(message.LoginName))
         {
             UserData entity = _dicByLoginName[message.LoginName];
             _dicByLoginName.Remove(entity.LoginName);
             using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
                 var col = db.GetCollection <UserData>();
                 col.Delete(message.LoginName);
             }
             VirtualRoot.Happened(new UserRemovedEvent(entity));
         }
     });
 }
示例#27
0
 public static void ShowMainWindow()
 {
     UIThread.Execute(() => {
         if (_instance == null)
         {
             lock (_locker) {
                 if (_instance == null)
                 {
                     _instance = new MainWindow();
                     Application.Current.MainWindow = _instance;
                     _instance.Show();
                     NTMinerRoot.IsUiVisible        = true;
                     NTMinerRoot.MainWindowRendedOn = DateTime.Now;
                     VirtualRoot.Happened(new MainWindowShowedEvent());
                 }
             }
         }
     });
 }
示例#28
0
        private static void PickPoolDelay(string input, IKernelOutput kernelOutput, bool isDual)
        {
            string poolDelayPattern = kernelOutput.PoolDelayPattern;

            if (isDual)
            {
                poolDelayPattern = kernelOutput.DualPoolDelayPattern;
            }
            if (string.IsNullOrEmpty(poolDelayPattern))
            {
                return;
            }
            Match match = Regex.Match(input, poolDelayPattern, RegexOptions.Compiled);

            if (match.Success)
            {
                string poolDelayText = match.Groups["poolDelay"].Value;
                VirtualRoot.Happened(new PoolDelayPickedEvent(poolDelayText, isDual));
            }
        }
示例#29
0
        public void LoadGpuState()
        {
            for (int i = 0; i < Count; i++)
            {
                uint power = adlHelper.GetPowerUsageByIndex(i);
                uint temp  = adlHelper.GetTemperatureByIndex(i);
                uint speed = adlHelper.GetFanSpeedByIndex(i);

                Gpu  gpu       = (Gpu)_gpus[i];
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }
示例#30
0
        public void LoadGpuState()
        {
            foreach (Gpu gpu in _gpus.Values)
            {
                int i = gpu.Index;
                if (i == NTMinerRoot.GpuAllId)
                {
                    continue;
                }
                nvmlDevice nvmlDevice = new nvmlDevice();
                var        nvmlReturn = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
                // 显卡重启了,此时nvmlReturn是Unknown
                if (nvmlReturn == nvmlReturn.Unknown && nvmlShutdownRestartCount < 20)
                {
                    nvmlShutdownRestartCount++;
                    NvmlNativeMethods.nvmlShutdown();
                    _isNvmlInited = false;
                    NvmlInit();
                }
                nvmlReturn = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
                SetGpuStatus(gpu, nvmlReturn);
                uint power = 0;
                NvmlNativeMethods.nvmlDeviceGetPowerUsage(nvmlDevice, ref power);
                power = (uint)(power / 1000.0);
                uint temp = 0;
                NvmlNativeMethods.nvmlDeviceGetTemperature(nvmlDevice, nvmlTemperatureSensors.Gpu, ref temp);
                uint speed = 0;
                NvmlNativeMethods.nvmlDeviceGetFanSpeed(nvmlDevice, ref speed);
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = (int)temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }