public ResponseBase RemoveMineWork([FromBody] DataRequest <Guid> request) { if (request == null || request.Data == Guid.Empty) { return(ResponseBase.InvalidInput("参数错误")); } try { IUserMineWork mineWork = WebApiRoot.MineWorkSet.GetById(request.Data); if (mineWork == null) { return(ResponseBase.Ok()); } if (mineWork.LoginName != User.LoginName) { return(ResponseBase.Forbidden("无权操作")); } if (WebApiRoot.ClientDataSet.IsAnyClientInWork(request.Data)) { return(ResponseBase.ClientError($"作业{mineWork.Name}下有矿机,请先移除矿机再做删除操作")); } WebApiRoot.MineWorkSet.RemoveById(request.Data); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase RemoveMinerGroup([FromBody] DataRequest <Guid> request) { if (request == null || request.Data == Guid.Empty) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!request.IsValid(User, Sign, Timestamp, base.ClientIp, out ResponseBase response)) { return(response); } IMinerGroup minerGroup = HostRoot.Instance.MinerGroupSet.GetMinerGroup(request.Data); if (minerGroup == null) { return(ResponseBase.Ok()); } if (HostRoot.Instance.ClientSet.IsAnyClientInGroup(request.Data)) { return(ResponseBase.ClientError($"组{minerGroup.Name}下有矿机,请先移除矿机再做删除操作")); } HostRoot.Instance.MinerGroupSet.Remove(request.Data); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase ChangePassword([FromBody] ChangePasswordRequest request) { if (request == null || string.IsNullOrEmpty(request.LoginName) || string.IsNullOrEmpty(request.OldPassword) || string.IsNullOrEmpty(request.NewPassword)) { return(ResponseBase.InvalidInput("参数错误")); } try { IUser user = HostRoot.Instance.UserSet.GetUser(request.LoginName); if (user == null) { return(ResponseBase.ClientError($"登录名不存在")); } if (user.Password == request.NewPassword) { return(ResponseBase.Ok()); } if (user.Password != request.OldPassword) { return(ResponseBase.ClientError($"旧密码不正确")); } VirtualRoot.Execute(new ChangePasswordCommand(request.LoginName, request.OldPassword, request.NewPassword, request.Description)); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase RemoveMineWork([FromBody] DataRequest <Guid> request) { if (request == null || request.Data == Guid.Empty) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!request.IsValid(HostRoot.Current.UserSet.GetUser, ClientIp, out ResponseBase response)) { return(response); } IMineWork mineWork = HostRoot.Current.MineWorkSet.GetMineWork(request.Data); if (mineWork == null) { return(ResponseBase.Ok()); } if (HostRoot.Current.ClientSet.IsAnyClientInWork(request.Data)) { return(ResponseBase.ClientError($"作业{mineWork.Name}下有矿机,请先移除矿机再做删除操作")); } HostRoot.Current.MineWorkSet.Remove(request.Data); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase RemoveMinerGroup([FromBody] DataRequest <Guid> request) { if (request == null || request.Data == Guid.Empty) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!IsValidUser(request, out ResponseBase response, out UserData user)) { return(response); } IUserMinerGroup minerGroup = WebApiRoot.MinerGroupSet.GetById(request.Data); if (minerGroup == null) { return(ResponseBase.Ok()); } if (minerGroup.LoginName != user.LoginName) { return(ResponseBase.Forbidden("无权操作")); } if (WebApiRoot.ClientDataSet.IsAnyClientInGroup(request.Data)) { return(ResponseBase.ClientError($"组{minerGroup.Name}下有矿机,请先移除矿机再做删除操作")); } WebApiRoot.MinerGroupSet.RemoveById(request.Data); return(ResponseBase.Ok()); } catch (Exception e) { Logger.ErrorDebugLine(e); return(ResponseBase.ServerError(e.Message)); } }
public ResponseBase StartMine([FromBody] WrapperRequest <WorkRequest> request) { if (request == null || request.InnerRequest == null || string.IsNullOrEmpty(request.ClientIp)) { return(ResponseBase.InvalidInput("参数错误")); } try { if (!request.IsValid(HostRoot.Current.UserSet.GetUser, ClientIp, out ResponseBase response)) { return(response); } IClientData clientData = HostRoot.Current.ClientSet.GetByObjectId(request.ObjectId); if (clientData == null) { return(ResponseBase.ClientError("给定标识的矿机不存在")); } string localJson = string.Empty, serverJson = string.Empty; Guid workId = request.InnerRequest.WorkId; if (workId != Guid.Empty) { localJson = SpecialPath.ReadMineWorkLocalJsonFile(workId).Replace("{{MinerName}}", clientData.MinerName); serverJson = SpecialPath.ReadMineWorkServerJsonFile(workId); } WorkRequest innerRequest = new WorkRequest { Timestamp = request.InnerRequest.Timestamp, WorkId = workId, LocalJson = localJson, ServerJson = serverJson }; response = Client.NTMinerDaemonService.StartMine(request.ClientIp, innerRequest); return(response); } catch (Exception e) { e = e.GetInnerException(); Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(e.Message)); } }