public MineWorkSet(INTMinerRoot root) { _root = root; VirtualRoot.BuildCmdPath <AddMineWorkCommand>(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.RaiseEvent(new MineWorkAddedEvent(entity)); } else { Write.UserFail(response?.Description); } }); VirtualRoot.BuildCmdPath <UpdateMineWorkCommand>(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.RaiseEvent(new MineWorkUpdatedEvent(entity)); Write.UserFail(response.ReadMessage(exception)); } }); VirtualRoot.RaiseEvent(new MineWorkUpdatedEvent(entity)); }); VirtualRoot.BuildCmdPath <RemoveMineWorkCommand>(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.RaiseEvent(new MineWorkRemovedEvent(entity)); } else { Write.UserFail(response.ReadMessage(exception)); } }); }); }
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 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 + "接入总线"); }