private GpuProfileViewModels()
 {
     VirtualRoot.On <GpuProfileSetRefreshedEvent>("Gpu超频集合刷新后刷新附着在当前币种上的超频数据", LogEnum.DevConsole,
                                                  action: message => {
         lock (_locker) {
             _listByCoinId.Clear();
             _gpuAllVmDicByCoinId.Clear();
         }
         var coinVm = MinerProfileViewModel.Current.CoinVm;
         if (coinVm != null)
         {
             coinVm.OnOverClockPropertiesChanges();
             VirtualRoot.Execute(new CoinOverClockCommand(coinVm.Id));
         }
     });
     VirtualRoot.On <GpuProfileAddedOrUpdatedEvent>("添加或更新了Gpu超频数据后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
         lock (_locker) {
             List <GpuProfileViewModel> list;
             if (_listByCoinId.TryGetValue(message.Source.CoinId, out list))
             {
                 var vm = list.FirstOrDefault(a => a.Index == message.Source.Index);
                 if (vm != null)
                 {
                     vm.Update(message.Source);
                 }
                 else
                 {
                     if (GpuViewModels.Current.TryGetGpuVm(message.Source.Index, out GpuViewModel gpuVm))
                     {
                         var item = new GpuProfileViewModel(message.Source, gpuVm);
                         list.Add(item);
                         list.Sort(new CompareByGpuIndex());
                         if (item.Index == NTMinerRoot.GpuAllId)
                         {
                             _gpuAllVmDicByCoinId.Add(message.Source.CoinId, item);
                         }
                     }
                 }
             }
             else
             {
                 list = new List <GpuProfileViewModel>();
                 if (GpuViewModels.Current.TryGetGpuVm(message.Source.Index, out GpuViewModel gpuVm))
                 {
                     var item = new GpuProfileViewModel(message.Source, gpuVm);
                     list.Add(item);
                     list.Sort(new CompareByGpuIndex());
                     if (item.Index == NTMinerRoot.GpuAllId)
                     {
                         _gpuAllVmDicByCoinId.Add(message.Source.CoinId, item);
                     }
                 }
                 _listByCoinId.Add(message.Source.CoinId, list);
             }
         }
     });
 }
        public List <GpuProfileViewModel> List(Guid coinId)
        {
            List <GpuProfileViewModel> list;

            if (!_listByCoinId.TryGetValue(coinId, out list))
            {
                lock (_locker) {
                    if (!_listByCoinId.TryGetValue(coinId, out list))
                    {
                        list = new List <GpuProfileViewModel>();
                        foreach (var gpu in GpuViewModels.Current)
                        {
                            GpuProfileViewModel gpuProfileVm = GetGpuProfileVm(coinId, gpu);
                            list.Add(gpuProfileVm);
                        }
                        list.Sort(new CompareByGpuIndex());
                        _listByCoinId.Add(coinId, list);
                    }
                }
            }
            return(list);
        }
Example #3
0
        public GpuProfilesPageViewModel(MinerClientsWindowViewModel minerClientsWindowVm)
        {
            _minerClientsWindowVm = minerClientsWindowVm;
            if (minerClientsWindowVm.SelectedMinerClients == null && minerClientsWindowVm.SelectedMinerClients.Length != 1)
            {
                throw new InvalidProgramException();
            }
            _minerClientVm = minerClientsWindowVm.SelectedMinerClients[0];
            this.Save      = new DelegateCommand(() => {
                if (_data == null)
                {
                    return;
                }
                GpuProfilesJsonDb jsonObj = new GpuProfilesJsonDb()
                {
                    Gpus = _data.Gpus
                };
                foreach (var coinVm in CoinVms.MainCoins)
                {
                    if (coinVm.IsOverClockEnabled)
                    {
                        jsonObj.CoinOverClocks.Add(new CoinOverClockData()
                        {
                            CoinId             = coinVm.Id,
                            IsOverClockEnabled = coinVm.IsOverClockEnabled,
                            IsOverClockGpuAll  = coinVm.IsOverClockGpuAll
                        });
                        if (CoinVm.IsOverClockGpuAll)
                        {
                            jsonObj.GpuProfiles.Add(new GpuProfileData(coinVm.GpuAllProfileVm));
                        }
                        jsonObj.GpuProfiles.AddRange(coinVm.GpuProfileVms.Select(a => new GpuProfileData(a)));
                    }
                }
                string json = VirtualRoot.JsonSerializer.Serialize(jsonObj);
                foreach (var client in minerClientsWindowVm.SelectedMinerClients)
                {
                    Client.NTMinerDaemonService.SaveGpuProfilesJsonAsync(client.MinerIp, json);
                }
                NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("应用成功,请观察效果");
                CloseWindow?.Invoke();
            });
            Client.NTMinerDaemonService.GetGpuProfilesJsonAsync(_minerClientVm.MinerIp, (data, e) => {
                _data = data;
                if (e != null)
                {
                    Write.UserError(e.Message);
                }
                else if (data != null)
                {
                    string iconName;
                    switch (_minerClientVm.GpuType)
                    {
                    case GpuType.NVIDIA:
                    case GpuType.AMD:
                        iconName    = "Icon_Nvidia";
                        GpuIconFill = "Green";
                        RedText     = "超频有风险,操作需谨慎";
                        IsEnabled   = true;
                        break;

                    case GpuType.Empty:
                    default:
                        iconName    = "Icon_GpuEmpty";
                        GpuIconFill = "Gray";
                        RedText     = "没有矿卡或矿卡未驱动";
                        IsEnabled   = false;
                        break;
                    }
                    GpuIcon = (Geometry)System.Windows.Application.Current.Resources[iconName];
                    foreach (var coinVm in AppContext.Instance.CoinVms.MainCoins)
                    {
                        var coinOverClock = data.CoinOverClocks.FirstOrDefault(a => a.CoinId == coinVm.Id);
                        var gpuProfiles   = data.GpuProfiles.Where(a => a.CoinId == coinVm.Id).ToArray();
                        if (coinOverClock == null)
                        {
                            coinOverClock = new CoinOverClockData()
                            {
                                CoinId             = coinVm.Id,
                                IsOverClockEnabled = false,
                                IsOverClockGpuAll  = true
                            };
                        }
                        coinVm.IsOverClockEnabled = coinOverClock.IsOverClockEnabled;
                        coinVm.IsOverClockGpuAll  = coinOverClock.IsOverClockGpuAll;
                        List <GpuProfileViewModel> gpuProfileVms = new List <GpuProfileViewModel>();
                        GpuProfileViewModel gpuAllProfileVm      = null;
                        #region
                        foreach (var gpu in data.Gpus.OrderBy(a => a.Index))
                        {
                            var gpuProfile = gpuProfiles.FirstOrDefault(a => a.Index == gpu.Index);
                            if (gpuProfile == null)
                            {
                                gpuProfile = new GpuProfileData(coinVm.Id, gpu.Index);
                            }
                            var gpuVm = new GpuViewModel(gpu, data.Gpus);
                            if (gpu.Index == NTMinerRoot.GpuAllId)
                            {
                                gpuAllProfileVm = new GpuProfileViewModel(gpuProfile, gpuVm);
                            }
                            else
                            {
                                gpuProfileVms.Add(new GpuProfileViewModel(gpuProfile, gpuVm));
                            }
                        }
                        if (gpuAllProfileVm == null)
                        {
                            gpuAllProfileVm = new GpuProfileViewModel(
                                new GpuProfileData(coinVm.Id, NTMinerRoot.GpuAllId), new GpuViewModel(new GpuData {
                                Index = NTMinerRoot.GpuAllId,
                                Name  = "All"
                            }, data.Gpus));
                        }
                        #endregion
                        coinVm.GpuAllProfileVm = gpuAllProfileVm;
                        coinVm.GpuProfileVms   = gpuProfileVms;
                    }
                    this.CoinVm = CoinVms.MainCoins.FirstOrDefault(a => a.IsOverClockEnabled);
                    if (this.CoinVm == null)
                    {
                        this.CoinVm = CoinVms.MainCoins.FirstOrDefault();
                    }
                }
            });
        }