public void AddOrUpdateMinerGroup(MinerGroupData entity, Action <ResponseBase> callback) { Task.Factory.StartNew(() => { Guid messageId = Guid.NewGuid(); try { entity.ModifiedOn = DateTime.Now; AddOrUpdateMinerGroupRequest request = new AddOrUpdateMinerGroupRequest { MessageId = messageId, LoginName = LoginName, Data = entity, Timestamp = DateTime.Now }; request.SignIt(Password); using (var service = CreateService()) { ResponseBase response = service.AddOrUpdateMinerGroup(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 ResponseBase AddOrUpdateMinerGroup(AddOrUpdateMinerGroupRequest request) { if (request == null) { return(LoadClientResponse.InvalidInput(Guid.Empty, "参数错误")); } try { if (string.IsNullOrEmpty(request.LoginName)) { return(ResponseBase.InvalidInput(request.MessageId, "登录名不能为空")); } if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key)) { return(ResponseBase.Forbidden(request.MessageId)); } if (!request.Timestamp.IsInTime()) { return(ResponseBase.Expired(request.MessageId)); } if (request.Data == null) { return(ResponseBase.InvalidInput(request.MessageId)); } if (request.Sign != request.GetSign(key.Password)) { return(ResponseBase.Forbidden(request.MessageId, "签名验证未通过")); } HostRoot.Current.MinerGroupSet.AddOrUpdate(request.Data); return(ResponseBase.Ok(request.MessageId)); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(request.MessageId, e.Message)); } }