예제 #1
0
        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);
        }
예제 #2
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public DataResponse <List <WalletData> > GetWallets()
 {
     try {
         SignRequest request = new SignRequest {
         };
         DataResponse <List <WalletData> > response = RpcRoot.Post <DataResponse <List <WalletData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IWalletController.Wallets), request, request, timeout: 2000);
         return(response);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(null);
     }
 }
예제 #3
0
        public ResponseBase StartMine(WorkRequest request)
        {
            ResponseBase response;

            if (request == null)
            {
                response = ResponseBase.InvalidInput("参数错误");
            }
            else
            {
                try {
                    if (request.WorkId != Guid.Empty)
                    {
                        File.WriteAllText(SpecialPath.NTMinerLocalJsonFileFullName, request.LocalJson);
                        File.WriteAllText(SpecialPath.NTMinerServerJsonFileFullName, request.ServerJson);
                    }
                    string location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerClient);
                    if (IsNTMinerOpened())
                    {
                        WorkRequest innerRequest = new WorkRequest {
                            WorkId = request.WorkId
                        };
                        response             = RpcRoot.Post <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.StartMine), innerRequest);
                        response.Description = "开始挖矿";
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(location) && File.Exists(location))
                        {
                            string arguments = NTKeyword.AutoStartCmdParameterName;
                            if (request.WorkId != Guid.Empty)
                            {
                                arguments += " --work";
                            }
                            Windows.Cmd.RunClose(location, arguments);
                            response = ResponseBase.Ok("开始挖矿");
                        }
                        else
                        {
                            response = ResponseBase.ServerError("开始挖矿,未找到挖矿端程序");
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    response = ResponseBase.ServerError(e.Message);
                }
            }
            VirtualRoot.OperationResultSet.Add(response.ToOperationResult());
            return(response);
        }
예제 #4
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public List <MineWorkData> GetMineWorks()
 {
     try {
         SignRequest request = new SignRequest {
         };
         DataResponse <List <MineWorkData> > response = RpcRoot.Post <DataResponse <List <MineWorkData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IMineWorkController.MineWorks), request, request, timeout: 2000);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <MineWorkData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <MineWorkData>());
     }
 }
예제 #5
0
 public List <AppSettingData> GetAppSettings()
 {
     try {
         AppSettingsRequest request = new AppSettingsRequest {
         };
         DataResponse <List <AppSettingData> > response = RpcRoot.Post <DataResponse <List <AppSettingData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IAppSettingController.AppSettings), request);
         if (response.IsSuccess())
         {
             return(response.Data);
         }
         return(new List <AppSettingData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <AppSettingData>());
     }
 }
예제 #6
0
 public string GetLocalJson(Guid workId)
 {
     try {
         DataRequest <Guid> request = new DataRequest <Guid>()
         {
             Data = workId
         };
         var response = RpcRoot.Post <DataResponse <string> >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IMineWorkController.GetLocalJson), request, request);
         if (response != null)
         {
             return(response.Data);
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
     return(string.Empty);
 }
예제 #7
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <param name="clientId"></param>
 /// <returns></returns>
 public List <UserData> GetUsers(Guid?clientId)
 {
     try {
         DataRequest <Guid?> request = new DataRequest <Guid?> {
             Data = clientId
         };
         DataResponse <List <UserData> > response = RpcRoot.Post <DataResponse <List <UserData> > >(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IUserController.Users), request, request, timeout: 2000);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <UserData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <UserData>());
     }
 }
예제 #8
0
        private static void CloseNTMiner()
        {
            bool         isClosed = false;
            ResponseBase response = RpcRoot.Post <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.CloseNTMiner), new SignRequest {
            });

            isClosed = response.IsSuccess();
            if (!isClosed)
            {
                try {
                    string location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerClient);
                    if (!string.IsNullOrEmpty(location) && File.Exists(location))
                    {
                        string processName = Path.GetFileNameWithoutExtension(location);
                        Windows.TaskKill.Kill(processName);
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            }
        }
예제 #9
0
        public ResponseBase StopMine()
        {
            ResponseBase response;

            try {
                if (!IsNTMinerOpened())
                {
                    response = ResponseBase.Ok();
                }
                else
                {
                    RpcRoot.Post <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.StopMine), new SignRequest());
                    response = ResponseBase.Ok("停止挖矿");
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
                response = ResponseBase.ServerError(e.Message);
            }
            VirtualRoot.OperationResultSet.Add(response.ToOperationResult());
            return(response);
        }