public LocalJsonDb(INTMinerRoot root, MineWorkData mineWorkData) { var minerProfile = root.MinerProfile; CoinProfileData mainCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(minerProfile.CoinId)); List <CoinProfileData> coinProfiles = new List <CoinProfileData> { mainCoinProfile }; List <PoolProfileData> poolProfiles = new List <PoolProfileData>(); CoinKernelProfileData coinKernelProfile = new CoinKernelProfileData(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId)); PoolProfileData mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId)); poolProfiles.Add(mainCoinPoolProfile); if (mainCoinProfile.PoolId1 != Guid.Empty) { mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId1)); poolProfiles.Add(mainCoinPoolProfile); } if (coinKernelProfile.IsDualCoinEnabled) { CoinProfileData dualCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId)); coinProfiles.Add(dualCoinProfile); PoolProfileData dualCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId)); poolProfiles.Add(dualCoinPoolProfile); } MinerProfile = MinerProfileData.Create(minerProfile); MinerProfile.MinerName = "{{MinerName}}"; MineWork = mineWorkData; CoinProfiles = coinProfiles.ToArray(); CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile }; PoolProfiles = poolProfiles.ToArray(); Pools = root.ServerContext.PoolSet.AsEnumerable().Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData(a)).ToArray(); Wallets = minerProfile.GetWallets().Select(a => new WalletData(a)).ToArray(); TimeStamp = Timestamp.GetTimestamp(); }
public void AddOrUpdateMineWork(MineWorkData entity, Action <ResponseBase> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { entity.ModifiedOn = DateTime.Now; AddOrUpdateMineWorkRequest request = new AddOrUpdateMineWorkRequest { MessageId = messageId, LoginName = LoginName, Timestamp = DateTime.Now, Data = entity }; request.SignIt(Password); using (var service = CreateService()) { ResponseBase response = service.AddOrUpdateMineWork(request); callback?.Invoke(response); } } catch (CommunicationException e) { Global.DebugLine(e.Message, ConsoleColor.Red); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } catch (Exception e) { Global.Logger.Error(e.Message, e); callback?.Invoke(ResponseBase.ClientError(messageId, e.Message)); } }); }
public static CoinProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid coinId) { if (root.CoinSet.TryGetCoin(coinId, out ICoin coin)) { var data = GetCoinProfileData(mineWorkData, coin.GetId()); if (data == null) { Guid poolId = Guid.Empty; IPool pool = root.PoolSet.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId); if (pool != null) { poolId = pool.GetId(); } string wallet = coin.TestWallet; Guid coinKernelId = Guid.Empty; ICoinKernel coinKernel = root.CoinKernelSet.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId); if (coinKernel != null) { coinKernelId = coinKernel.GetId(); } data = CoinProfileData.CreateDefaultData(coinId, poolId, wallet, coinKernelId); } CoinProfile coinProfile = new CoinProfile(mineWorkData, data); return(coinProfile); } else { return(Empty); } }
private void DoInit(bool isWork, Action callback) { GpuProfileSet.Instance.Register(this); this.ServerAppSettingSet = new ServerAppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ServerContextInit(isWork); this.WorkerEventSet = new WorkerEventSet(this); this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); MineWorkData mineWorkData = null; if (isWork) { mineWorkData = LocalJson.MineWork; } this._minerProfile = new MinerProfile(this, mineWorkData); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); callback?.Invoke(); }
private static CoinProfileData GetCoinProfileData(MineWorkData mineWorkData, Guid coinId) { bool isUseJson = mineWorkData != null; IRepository <CoinProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinProfileData>(isUseJson); var result = repository.GetByKey(coinId); return(result); }
public static void ReInitLocalJson(MineWorkData mineWorkData = null) { _localJsonInited = false; if (mineWorkData != null) { LocalJsonInit(); _localJson.MineWork = mineWorkData; } }
public void AddOrUpdateMineWorkAsync(MineWorkData entity, Action <ResponseBase, Exception> callback) { entity.ModifiedOn = DateTime.Now; DataRequest <MineWorkData> request = new DataRequest <MineWorkData> { Data = entity }; RpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMineWorkController.AddOrUpdateMineWork), data: request, callback); }
private void Init(INTMinerRoot root, MineWorkData mineWorkData) { MineWork = mineWorkData; isUseJson = mineWorkData != null; if (isUseJson) { _data = NTMinerRoot.LocalJson.MinerProfile; } else { IRepository <MinerProfileData> repository = NTMinerRoot.CreateLocalRepository <MinerProfileData>(false); _data = repository.GetAll().FirstOrDefault(); } if (_data == null) { Guid coinId = Guid.Empty; ICoin coin = root.CoinSet.OrderBy(a => a.SortNumber).FirstOrDefault(); if (coin != null) { coinId = coin.GetId(); } _data = MinerProfileData.CreateDefaultData(coinId); } if (_coinProfileSet == null) { _coinProfileSet = new CoinProfileSet(root, mineWorkData); } else { _coinProfileSet.Refresh(mineWorkData); } if (_coinKernelProfileSet == null) { _coinKernelProfileSet = new CoinKernelProfileSet(root, mineWorkData); } else { _coinKernelProfileSet.Refresh(mineWorkData); } if (_poolProfileSet == null) { _poolProfileSet = new PoolProfileSet(root, mineWorkData); } else { _poolProfileSet.Refresh(mineWorkData); } if (_walletSet == null) { _walletSet = new WalletSet(root); } else { _walletSet.Refresh(); } }
public ResponseBase AddOrUpdateMineWork(MineWorkData entity) { entity.ModifiedOn = DateTime.Now; DataRequest <MineWorkData> request = new DataRequest <MineWorkData> { Data = entity }; ResponseBase response = RpcRoot.Post <ResponseBase>(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IMineWorkController.AddOrUpdateMineWork), request, request); return(response); }
public ResponseBase AddOrUpdateMineWork(MineWorkData entity) { entity.ModifiedOn = DateTime.Now; DataRequest <MineWorkData> request = new DataRequest <MineWorkData> { Data = entity }; ResponseBase response = Post <ResponseBase>(SControllerName, nameof(IMineWorkController.AddOrUpdateMineWork), request.ToQuery(SingleUser.LoginName, SingleUser.PasswordSha1), request); return(response); }
private static CoinKernelProfileData GetCoinKernelProfileData(MineWorkData mineWorkData, Guid coinKernelId) { bool isUseJson = mineWorkData != null; IRepository <CoinKernelProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinKernelProfileData>(isUseJson); var result = repository.GetByKey(coinKernelId); if (result == null) { result = CoinKernelProfileData.CreateDefaultData(coinKernelId); } return(result); }
public void AddOrUpdateMineWorkAsync(MineWorkData entity, Action <ResponseBase, Exception> callback) { Task.Factory.StartNew(() => { try { var response = AddOrUpdateMineWork(entity); callback?.Invoke(response, null); } catch (Exception e) { callback?.Invoke(null, e); } }); }
public ResponseBase AddOrUpdateMineWork(MineWorkData entity) { entity.ModifiedOn = DateTime.Now; DataRequest <MineWorkData> request = new DataRequest <MineWorkData> { LoginName = SingleUser.LoginName, Data = entity }; request.SignIt(SingleUser.PasswordSha1); ResponseBase response = Post <ResponseBase>(SControllerName, nameof(IControlCenterController.AddOrUpdateMineWork), null, request); return(response); }
public static void ExportWorkJson(MineWorkData mineWorkData, out string localJson, out string serverJson) { localJson = string.Empty; serverJson = string.Empty; try { LocalJsonDb localJsonObj = new LocalJsonDb(Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(Instance, localJsonObj); localJson = VirtualRoot.JsonSerializer.Serialize(localJsonObj); serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }
public void ExportWorkJson(MineWorkData mineWorkData, out string localJson, out string serverJson) { localJson = string.Empty; serverJson = string.Empty; try { LocalJsonDb localJsonObj = new LocalJsonDb(this, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(this, localJsonObj); localJson = VirtualRoot.JsonSerializer.Serialize(localJsonObj); serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); mineWorkData.ServerJsonSha1 = HashUtil.Sha1(serverJson); } catch (Exception e) { Logger.ErrorDebugLine(e); } }
private static PoolProfileData GetPoolProfileData(INTMinerRoot root, MineWorkData mineWorkData, Guid poolId) { bool isUseJson = mineWorkData != null; IRepository <PoolProfileData> repository = NTMinerRoot.CreateLocalRepository <PoolProfileData>(isUseJson); var result = repository.GetByKey(poolId); if (result == null) { if (root.PoolSet.TryGetPool(poolId, out IPool pool)) { // 如果本地未设置用户名密码则使用默认的测试用户名密码 result = PoolProfileData.CreateDefaultData(pool); } } return(result); }
public static PoolProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid poolIdId) { if (root.PoolSet.TryGetPool(poolIdId, out IPool pool)) { var data = GetPoolProfileData(root, mineWorkData, pool.GetId()); if (data == null) { data = PoolProfileData.CreateDefaultData(pool); } PoolProfile coinProfile = new PoolProfile(mineWorkData, data); return(coinProfile); } else { return(Empty); } }
public static CoinKernelProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid coinKernelId) { if (root.CoinKernelSet.TryGetCoinKernel(coinKernelId, out ICoinKernel coinKernel)) { var data = GetCoinKernelProfileData(mineWorkData, coinKernel.GetId()); if (data == null) { data = CoinKernelProfileData.CreateDefaultData(coinKernel.GetId()); } CoinKernelProfile coinProfile = new CoinKernelProfile(mineWorkData, data); return(coinProfile); } else { return(Empty); } }
public MineWorkSet() { VirtualRoot.BuildEventPath <MinerStudioServiceSwitchedEvent>("切换了群口后台服务类型后刷新内存", LogEnum.DevConsole, path: message => { _dicById.Clear(); base.Refresh(); // 初始化以触发MineWorkSetInitedEvent事件 InitOnece(); }, this.GetType()); VirtualRoot.BuildCmdPath <AddMineWorkCommand>(path: message => { InitOnece(); if (!_dicById.ContainsKey(message.Input.Id)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); var data = new MineWorkData().Update(message.Input); data.CreatedOn = DateTime.Now; _dicById.Add(data.Id, data); repository.Add(data); VirtualRoot.RaiseEvent(new MineWorkAddedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.BuildCmdPath <UpdateMineWorkCommand>(path: message => { InitOnece(); if (_dicById.TryGetValue(message.Input.Id, out MineWorkData data)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); data.Update(message.Input); data.ModifiedOn = DateTime.Now; repository.Update(data); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.BuildCmdPath <RemoveMineWorkCommand>(path: message => { InitOnece(); if (_dicById.TryGetValue(message.EntityId, out MineWorkData entity)) { _dicById.Remove(message.EntityId); var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); repository.Remove(message.EntityId); MinerStudioPath.DeleteMineWorkFiles(message.EntityId); VirtualRoot.RaiseEvent(new MineWorkRemovedEvent(message.MessageId, entity)); } }, this.GetType()); }
public void AddOrUpdate(MineWorkData data) { InitOnece(); lock (_locker) { using (LiteDatabase db = HostRoot.CreateLocalDb()) { var col = db.GetCollection <MineWorkData>(); if (_dicById.ContainsKey(data.Id)) { data.ModifiedOn = DateTime.Now; _dicById[data.Id].Update(data); col.Update(_dicById[data.Id]); } else { data.CreatedOn = DateTime.Now; _dicById.Add(data.Id, data); col.Insert(data); } } } }
private void EditJson(FormType?formType, WorkType workType, string json) { if (workType == WorkType.None) { throw new InvalidProgramException(); } if (workType == WorkType.SelfWork) { if (!string.IsNullOrEmpty(json)) { File.WriteAllText(HomePath.SelfWorkLocalJsonFileFullName, json); } else { File.Delete(HomePath.SelfWorkLocalJsonFileFullName); } } else { if (!string.IsNullOrEmpty(json)) { File.WriteAllText(HomePath.MineWorkLocalJsonFileFullName, json); } else { File.Delete(HomePath.MineWorkLocalJsonFileFullName); } } NTMinerContext.Instance.ReInitMinerProfile(workType); this.Sha1 = NTMinerContext.Instance.MinerProfile.GetSha1(); MineWorkData mineWorkData = new MineWorkData().Update(this); LocalJsonDb localJsonObj = new LocalJsonDb(NTMinerContext.Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(NTMinerContext.Instance, localJsonObj); var serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); this.ServerJsonSha1 = HashUtil.Sha1(serverJson); VirtualRoot.Execute(new EditMineWorkCommand(formType ?? FormType.Edit, new MineWorkViewModel(this))); }
public MineWorkSet() { VirtualRoot.AddCmdPath <AddMineWorkCommand>(action: message => { InitOnece(); if (!_dicById.ContainsKey(message.Input.Id)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); var data = new MineWorkData().Update(message.Input); data.CreatedOn = DateTime.Now; _dicById.Add(data.Id, data); repository.Add(data); VirtualRoot.RaiseEvent(new MineWorkAddedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <UpdateMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.Input.Id, out MineWorkData data)) { var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); data.Update(message.Input); data.ModifiedOn = DateTime.Now; repository.Update(data); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(message.MessageId, data)); } }, this.GetType()); VirtualRoot.AddCmdPath <RemoveMineWorkCommand>(action: message => { InitOnece(); if (_dicById.TryGetValue(message.EntityId, out MineWorkData entity)) { _dicById.Remove(message.EntityId); var repository = VirtualRoot.CreateLocalRepository <MineWorkData>(); repository.Remove(message.EntityId); MinerStudioPath.DeleteMineWorkFiles(message.EntityId); VirtualRoot.RaiseEvent(new MineWorkRemovedEvent(message.MessageId, entity)); } }, this.GetType()); }
public CoinProfileSet(INTMinerRoot root, MineWorkData mineWorkData) { _root = root; _mineWorkData = mineWorkData; }
private void DoSave() { if (string.IsNullOrEmpty(this.Name)) { VirtualRoot.Out.ShowError("作业名称是必须的", autoHideSeconds: 4); } bool isMinerProfileChanged = false; // 表示是否随后打开编辑界面,如果是新建的作业则保存后随即会打开作业编辑界面 bool isShowEdit = false; MineWorkData mineWorkData = new MineWorkData().Update(this); if (MinerStudioRoot.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel vm)) { string sha1 = NTMinerContext.Instance.MinerProfile.GetSha1(); // 如果作业设置变更了则一定变更了 if (this.Sha1 != sha1) { isMinerProfileChanged = true; } else { // 如果作业设置没变更但作业引用的服务器数据库记录状态变更了则变更了 LocalJsonDb localJsonObj = new LocalJsonDb(NTMinerContext.Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(NTMinerContext.Instance, localJsonObj); var serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); sha1 = HashUtil.Sha1(serverJson); if (sha1 != this.ServerJsonSha1) { isMinerProfileChanged = true; } } } else { isMinerProfileChanged = true; isShowEdit = true; NTMinerConsole.UserInfo("保存作业。"); } if (RpcRoot.IsOuterNet) { if (!this.Id.IsSelfMineWorkId()) { RpcRoot.OfficialServer.UserMineWorkService.AddOrUpdateMineWorkAsync(new MineWorkData().Update(this), (r, ex) => { if (r.IsSuccess()) { if (isMinerProfileChanged) { NTMinerContext.Instance.ExportWorkJson(mineWorkData, out string localJson, out string serverJson); if (!string.IsNullOrEmpty(localJson) && !string.IsNullOrEmpty(serverJson)) { RpcRoot.OfficialServer.UserMineWorkService.ExportMineWorkAsync(this.Id, localJson, serverJson, (response, e) => { if (response.IsSuccess()) { if (isShowEdit) { VirtualRoot.RaiseEvent(new MineWorkAddedEvent(Guid.Empty, this)); } else { VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(Guid.Empty, this)); } if (isShowEdit) { this.Edit.Execute(FormType.Edit); } } else { VirtualRoot.Out.ShowError(response.ReadMessage(e), autoHideSeconds: 4); } }); } if (mineWorkData.ServerJsonSha1 != this.ServerJsonSha1) { this.ServerJsonSha1 = mineWorkData.ServerJsonSha1; } } } else { VirtualRoot.Out.ShowError(r.ReadMessage(ex), autoHideSeconds: 4); } });
public MineWorkSet(INTMinerRoot root) { _root = root; VirtualRoot.Window <AddMineWorkCommand>("添加工作", 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; } MineWorkData entity = new MineWorkData().Update(message.Input); var response = Server.ControlCenterService.AddOrUpdateMineWork(entity); if (response.IsSuccess()) { _dicById.Add(entity.Id, entity); VirtualRoot.Happened(new MineWorkAddedEvent(entity)); } else { Write.UserLine(response?.Description, ConsoleColor.Red); } }); VirtualRoot.Window <UpdateMineWorkCommand>("更新工作", 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; } MineWorkData entity = _dicById[message.Input.GetId()]; MineWorkData oldValue = new MineWorkData().Update(entity); entity.Update(message.Input); Server.ControlCenterService.AddOrUpdateMineWorkAsync(entity, (response, exception) => { if (!response.IsSuccess()) { entity.Update(oldValue); VirtualRoot.Happened(new MineWorkUpdatedEvent(entity)); if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } } }); VirtualRoot.Happened(new MineWorkUpdatedEvent(entity)); }); VirtualRoot.Window <RemoveMineWorkCommand>("移除工作", LogEnum.DevConsole, action: (message) => { InitOnece(); if (message == null || message.EntityId == Guid.Empty) { throw new ArgumentNullException(); } if (!_dicById.ContainsKey(message.EntityId)) { return; } MineWorkData entity = _dicById[message.EntityId]; Server.ControlCenterService.RemoveMineWorkAsync(entity.Id, (response, exception) => { if (response.IsSuccess()) { _dicById.Remove(entity.Id); VirtualRoot.Happened(new MineWorkRemovedEvent(entity)); } else if (response != null) { Write.UserLine(response.Description, ConsoleColor.Red); } }); }); }
public void Refresh(MineWorkData mineWorkData) { _mineWorkData = mineWorkData; _dicById.Clear(); }
public void ReInit(INTMinerRoot root, MineWorkData mineWorkData) { Init(root, mineWorkData); }
private CoinProfile(MineWorkData mineWorkData, CoinProfileData data) { _mineWorkData = mineWorkData; _data = data ?? throw new ArgumentNullException(nameof(data)); }
public MineWorkViewModel(Guid id) { _id = id; this.Save = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } if (string.IsNullOrEmpty(this.Name)) { VirtualRoot.Out.ShowError("作业名称是必须的"); } bool isMineWorkChanged = false; bool isMinerProfileChanged = false; MineWorkData mineWorkData = new MineWorkData(this); if (NTMinerRoot.Instance.MineWorkSet.TryGetMineWork(this.Id, out IMineWork entity)) { string sha1 = NTMinerRoot.Instance.MinerProfile.GetSha1(); // 如果作业设置变更了则一定变更了 if (this.Sha1 != sha1) { isMinerProfileChanged = true; } else { // 如果作业设置没变更但作业引用的服务器数据库记录状态变更了则变更了 LocalJsonDb localJsonObj = new LocalJsonDb(NTMinerRoot.Instance, mineWorkData); ServerJsonDb serverJsonObj = new ServerJsonDb(NTMinerRoot.Instance, localJsonObj); var serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); sha1 = HashUtil.Sha1(serverJson); if (sha1 != this.ServerJsonSha1) { isMinerProfileChanged = true; } } if (entity.Name != this.Name || entity.Description != this.Description) { isMineWorkChanged = true; } } else { isMinerProfileChanged = true; VirtualRoot.Execute(new AddMineWorkCommand(this)); this.Edit.Execute(FormType.Edit); } if (isMinerProfileChanged) { Write.DevDebug("检测到MinerProfile状态变更"); NTMinerRoot.ExportWorkJson(mineWorkData, out string localJson, out string serverJson); if (!string.IsNullOrEmpty(localJson) && !string.IsNullOrEmpty(serverJson)) { RpcRoot.Server.MineWorkService.ExportMineWorkAsync(this.Id, localJson, serverJson, callback: null); } if (mineWorkData.ServerJsonSha1 != this.ServerJsonSha1) { this.ServerJsonSha1 = mineWorkData.ServerJsonSha1; isMineWorkChanged = true; } } if (isMineWorkChanged) { VirtualRoot.Execute(new UpdateMineWorkCommand(mineWorkData)); } }); this.Edit = new DelegateCommand <FormType?>((formType) => { if (this.Id == Guid.Empty) { return; } if (!AppContext.Instance.MineWorkVms.TryGetMineWorkVm(this.Id, out MineWorkViewModel mineWorkVm)) { WpfUtil.ShowInputDialog("作业名称", string.Empty, workName => { if (string.IsNullOrEmpty(workName)) { return("作业名称是必须的"); } return(string.Empty); }, onOk: workName => { new MineWorkViewModel(this) { Name = workName }.Save.Execute(null); }); } else { // 编辑作业前切换上下文 // 根据workId下载json保存到本地并调用LocalJson.Instance.ReInit() string json = RpcRoot.Server.MineWorkService.GetLocalJson(this.Id); if (!string.IsNullOrEmpty(json)) { File.WriteAllText(SpecialPath.LocalJsonFileFullName, json); } else { File.Delete(SpecialPath.LocalJsonFileFullName); } NTMinerRoot.Instance.ReInitMinerProfile(); this.Sha1 = NTMinerRoot.Instance.MinerProfile.GetSha1(); VirtualRoot.Execute(new MineWorkEditCommand(formType ?? FormType.Edit, new MineWorkViewModel(this))); } }, formType => { if (this == PleaseSelect) { return(false); } return(true); }); this.Remove = new DelegateCommand(() => { if (this.Id == Guid.Empty) { return; } this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除吗?", title: "确认", onYes: () => { VirtualRoot.Execute(new RemoveMineWorkCommand(this.Id)); })); }, () => { if (this == PleaseSelect) { return(false); } return(true); }); }
private void DoInit(bool isWork, Action callback) { this.PackageDownloader = new PackageDownloader(this); this.AppSettingSet = new AppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ContextInit(isWork); if (!string.IsNullOrEmpty(CommandLineArgs.KernelBrand)) { if (SysDicItemSet.TryGetDicItem("KernelBrand", CommandLineArgs.KernelBrand, out ISysDicItem brandItem)) { #region KernelBrandId string brand = $"KernelBrandId{brandItem.GetId()}KernelBrandId"; byte[] data = Encoding.UTF8.GetBytes(brand); if (data.Length != KernelBrandRaw.Length) { throw new InvalidProgramException(); } byte[] source = File.ReadAllBytes(ClientId.AppFileFullName); int index = 0; for (int i = 0; i < source.Length - KernelBrandRaw.Length; i++) { int j = 0; for (; j < KernelBrandRaw.Length; j++) { if (source[i + j] != KernelBrandRaw[j]) { break; } } if (j == KernelBrandRaw.Length) { index = i; break; } } for (int i = index; i < index + data.Length; i++) { source[i] = data[i - index]; } string brandExeFullName = Path.Combine(Path.GetDirectoryName(ClientId.AppFileFullName), Path.GetFileNameWithoutExtension(ClientId.AppFileFullName) + $"_{CommandLineArgs.KernelBrand}.exe"); File.WriteAllBytes(brandExeFullName, source); #endregion Environment.Exit(0); return; } } this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); MineWorkData mineWorkData = null; if (isWork) { mineWorkData = LocalJson.MineWork; } this._minerProfile = new MinerProfile(this, mineWorkData); NTMinerRegistry.SetLocation(ClientId.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); callback?.Invoke(); }