private void Init() { lock (_locker) { if (!_isInited) { string json = SpecialPath.ReadGpuProfilesJsonFile(); if (!string.IsNullOrEmpty(json)) { try { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); _data = data; } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } } else { _data = NewJsonDb(); Save(); } _isInited = true; } } }
private void Init() { lock (_locker) { if (!_isInited) { string json = HomePath.ReadGpuProfilesJsonFile(); if (!string.IsNullOrEmpty(json)) { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); if (data != null) { _data = data; } else { Save(); } } else { Save(); } _isInited = true; } } }
public void GetGpuProfilesJsonAsync(string clientIp, Action <GpuProfilesJsonDb, Exception> callback) { RpcRoot.PostAsync(clientIp, NTKeyword.NTMinerDaemonPort, _controllerName, nameof(INTMinerDaemonController.GetGpuProfilesJson), null, (string json, Exception e) => { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json) ?? new GpuProfilesJsonDb(); callback?.Invoke(data, null); }, timeountMilliseconds: 3000); }
public void GetGpuProfilesJsonAsync(IMinerData client) { JsonRpcRoot.PostAsync <string>(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.GetGpuProfilesJson), null, (json, e) => { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json) ?? new GpuProfilesJsonDb(); VirtualRoot.RaiseEvent(new GetGpuProfilesResponsedEvent(client.ClientId, data)); }, timeountMilliseconds: 3000); }
protected override void Init() { string json = HomePath.ReadGpuProfilesJsonFile(); if (!string.IsNullOrEmpty(json)) { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); if (data != null) { if (!IsGpusModified(data.Gpus)) { _data = data; } else { if (data.GpuProfiles.Any()) { VirtualRoot.ThisLocalWarn(nameof(GpuProfileSet), "检测到本机显卡发生过变更,请重新填写超频数据。", OutEnum.Warn); } Save(); } } else { Save(); } } else { Save(); } }
public GpuProfilesPageViewModel(MinerClientsWindowViewModel minerClientsWindowVm) { if (minerClientsWindowVm.SelectedMinerClients == null || minerClientsWindowVm.SelectedMinerClients.Length == 0) { throw new InvalidProgramException(); } _minerClientVm = minerClientsWindowVm.SelectedMinerClients[0]; _minerClientVms = new ObservableCollection <MinerClientViewModel>(minerClientsWindowVm.SelectedMinerClients); if (AppRoot.CoinVms.TryGetCoinVm(_minerClientVm.MainCoinCode, out CoinViewModel outCoinVm)) { this._coinVm = outCoinVm; } if (this._coinVm == null) { this._coinVm = CoinVms.MainCoins.FirstOrDefault(); } 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().Update(coinVm.GpuAllProfileVm)); } jsonObj.GpuProfiles.AddRange(coinVm.GpuProfileVms.Select(a => new GpuProfileData().Update(a))); } } string json = VirtualRoot.JsonSerializer.Serialize(jsonObj); foreach (var client in minerClientsWindowVm.SelectedMinerClients) { MinerStudioService.Instance.SaveGpuProfilesJsonAsync(client, json); } VirtualRoot.Execute(new CloseWindowCommand(this.Id)); }); }
public void GetGpuProfilesJsonAsync(string clientIp, Action <GpuProfilesJsonDb, Exception> callback) { Task.Factory.StartNew(() => { try { using (HttpClient client = RpcRoot.Create()) { client.Timeout = TimeSpan.FromSeconds(3); Task <HttpResponseMessage> getHttpResponse = client.PostAsync($"http://{clientIp}:{NTKeyword.NTMinerDaemonPort.ToString()}/api/{s_controllerName}/{nameof(INTMinerDaemonController.GetGpuProfilesJson)}", null); string json = getHttpResponse.Result.Content.ReadAsAsync <string>().Result; GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); callback?.Invoke(data, null); return(data); } } catch (Exception e) { callback?.Invoke(null, e); return(null); } }); }
public void GetGpuProfilesJsonAsync(string clientHost, Action <GpuProfilesJsonDb, Exception> callback) { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { client.Timeout = TimeSpan.FromMilliseconds(3000); Task <HttpResponseMessage> message = client.PostAsync($"http://{clientHost}:{WebApiConst.NTMinerDaemonPort}/api/{s_controllerName}/{nameof(INTMinerDaemonController.GetGpuProfilesJson)}", null); string json = message.Result.Content.ReadAsAsync <string>().Result; GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); callback?.Invoke(data, null); return(data); } } catch (Exception e) { e = e.GetInnerException(); callback?.Invoke(null, e); return(null); } }); }
protected override void Init() { string json = HomePath.ReadGpuProfilesJsonFile(); if (!string.IsNullOrEmpty(json)) { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json); if (data != null) { _data = data; } else { Save(); } } else { Save(); } }
public void SetData(GpuProfilesJsonDb data) { _data = data; if (data != null) { string iconName; GpuType gpuType = _minerClientVm.GpuType; if (gpuType == GpuType.Empty) { gpuType = data.GpuType; } IsEnabled = data.Gpus != null && data.Gpus.Length != 0; RedText = "超频有风险,操作需谨慎"; switch (_minerClientVm.GpuType) { case GpuType.NVIDIA: iconName = "Icon_Nvidia"; GpuIconFill = "Red"; break; case GpuType.AMD: iconName = "Icon_Amd"; GpuIconFill = "Green"; break; case GpuType.Empty: default: iconName = "Icon_GpuEmpty"; GpuIconFill = "Gray"; break; } GpuIcon = AppUtil.GetResource <Geometry>(iconName); foreach (var coinVm in AppRoot.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 == NTMinerContext.GpuAllId) { gpuAllProfileVm = new GpuProfileViewModel(gpuProfile, gpuVm); } else { gpuProfileVms.Add(new GpuProfileViewModel(gpuProfile, gpuVm)); } } if (gpuAllProfileVm == null) { gpuAllProfileVm = new GpuProfileViewModel( new GpuProfileData(coinVm.Id, NTMinerContext.GpuAllId), new GpuViewModel(new GpuData { GpuType = gpuType, Index = NTMinerContext.GpuAllId, Name = "All" }, data.Gpus)); } #endregion coinVm.GpuAllProfileVm = gpuAllProfileVm; coinVm.GpuProfileVms = gpuProfileVms; } } }
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(); } } }); }
public void TestMethod1() { GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(""); Assert.IsNull(data); }