public ResponseBase ExportMineWork([FromBody] ExportMineWorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         IUserMineWork mineWork = WebApiRoot.MineWorkSet.GetById(request.MineWorkId);
         if (mineWork == null)
         {
             return(ResponseBase.NotExist());
         }
         if (mineWork.LoginName != User.LoginName)
         {
             return(ResponseBase.Forbidden("无权操作"));
         }
         string localJsonFileFullName  = SpecialPath.GetMineWorkLocalJsonFileFullName(request.MineWorkId);
         string serverJsonFileFullName = SpecialPath.GetMineWorkServerJsonFileFullName(request.MineWorkId);
         File.WriteAllText(localJsonFileFullName, request.LocalJson);
         File.WriteAllText(serverJsonFileFullName, request.ServerJson);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <ResponseBase>(e.Message));
     }
 }
 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 DataResponse <string> GetLocalJson([FromBody] DataRequest <Guid> request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput <DataResponse <string> >("参数错误"));
     }
     try {
         IUserMineWork mineWork = WebApiRoot.MineWorkSet.GetById(request.Data);
         if (mineWork == null)
         {
             return(ResponseBase.NotExist <DataResponse <string> >());
         }
         if (!User.IsAdmin() && mineWork.LoginName != User.LoginName)
         {
             return(ResponseBase.Forbidden <DataResponse <string> >("无权操作"));
         }
         string localJsonFileFullName = SpecialPath.GetMineWorkLocalJsonFileFullName(request.Data);
         string data = string.Empty;
         if (File.Exists(localJsonFileFullName))
         {
             data = File.ReadAllText(localJsonFileFullName);
         }
         return(DataResponse <string> .Ok(data));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <DataResponse <string> >(e.Message));
     }
 }
        public GetWorkJsonResponse GetWorkJson([FromBody] GetWorkJsonRequest request)
        {
            if (request == null)
            {
                return(ResponseBase.InvalidInput <GetWorkJsonResponse>("参数错误"));
            }
            try {
                string workerName = string.Empty;
                // 如果是单机作业
                if (request.WorkId.IsSelfMineWorkId())
                {
                    var clientData = WebApiRoot.ClientDataSet.GetByClientId(request.ClientId);
                    if (clientData != null)
                    {
                        workerName = clientData.WorkerName;
                    }
                    return(GetWorkJsonResponse.Ok(string.Empty, string.Empty, workerName));
                }

                IUserMineWork mineWork = WebApiRoot.MineWorkSet.GetById(request.WorkId);
                if (mineWork == null)
                {
                    return(ResponseBase.NotExist <GetWorkJsonResponse>());
                }
                string localJsonFileFullName = SpecialPath.GetMineWorkLocalJsonFileFullName(request.WorkId);
                string localJson             = string.Empty;
                if (File.Exists(localJsonFileFullName))
                {
                    localJson = File.ReadAllText(localJsonFileFullName);
                    if (!string.IsNullOrEmpty(localJson))
                    {
                        var clientData = WebApiRoot.ClientDataSet.GetByClientId(request.ClientId);
                        if (clientData != null)
                        {
                            workerName = clientData.WorkerName;
                        }
                        localJson = localJson.Replace(NTKeyword.MinerNameParameterName, workerName);
                    }
                }
                string serverJsonFileFullName = SpecialPath.GetMineWorkServerJsonFileFullName(request.WorkId);
                string serverJson             = string.Empty;
                if (File.Exists(serverJsonFileFullName))
                {
                    serverJson = File.ReadAllText(serverJsonFileFullName);
                }
                return(GetWorkJsonResponse.Ok(localJson, serverJson, workerName));
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
                return(ResponseBase.ServerError <GetWorkJsonResponse>(e.Message));
            }
        }
Example #5
0
 public UserMineWorkSet(IOperationMqSender mq)
 {
     VirtualRoot.BuildEventPath <StartMineMqEvent>("收到StartMineMq消息后检查是否是作业挖矿,如果是则处理,否则忽略", LogEnum.None, path: message => {
         #region
         if (IsTooOld(message.Timestamp))
         {
             return;
         }
         Guid workId = message.Data;
         // 只处理作业的
         if (workId != Guid.Empty)
         {
             try {
                 string workerName = string.Empty;
                 WorkRequest request;
                 // 如果是单机作业
                 if (workId.IsSelfMineWorkId())
                 {
                     var clientData = AppRoot.ClientDataSet.GetByClientId(message.ClientId);
                     if (clientData != null)
                     {
                         workerName = clientData.WorkerName;
                     }
                     request = new WorkRequest {
                         WorkId     = workId,
                         WorkerName = workerName,
                         LocalJson  = string.Empty,
                         ServerJson = string.Empty
                     };
                 }
                 else
                 {
                     IUserMineWork mineWork = AppRoot.MineWorkSet.GetById(workId);
                     if (mineWork == null)
                     {
                         return;
                     }
                     string localJsonFileFullName = SpecialPath.GetMineWorkLocalJsonFileFullName(workId);
                     string localJson             = string.Empty;
                     if (File.Exists(localJsonFileFullName))
                     {
                         localJson = File.ReadAllText(localJsonFileFullName);
                         if (!string.IsNullOrEmpty(localJson))
                         {
                             var clientData = AppRoot.ClientDataSet.GetByClientId(message.ClientId);
                             if (clientData != null)
                             {
                                 workerName = clientData.WorkerName;
                             }
                             localJson = localJson.Replace(NTKeyword.MinerNameParameterName, workerName);
                         }
                     }
                     string serverJsonFileFullName = SpecialPath.GetMineWorkServerJsonFileFullName(workId);
                     string serverJson             = string.Empty;
                     if (File.Exists(serverJsonFileFullName))
                     {
                         serverJson = File.ReadAllText(serverJsonFileFullName);
                     }
                     request = new WorkRequest {
                         WorkId     = workId,
                         WorkerName = workerName,
                         LocalJson  = localJson,
                         ServerJson = serverJson
                     };
                 }
                 mq.SendStartWorkMine(message.LoginName, message.ClientId, request);
             }
             catch (Exception e) {
                 Logger.ErrorDebugLine(e);
             }
         }
         #endregion
     }, this.GetType());
 }