Ejemplo n.º 1
0
 public void SetAutoBootStartAsync(IMinerData client, SetAutoBootStartRequest request)
 {
     JsonRpcRoot.FirePostAsync(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.SetAutoBootStart), new Dictionary <string, string> {
         ["autoBoot"]  = request.AutoBoot.ToString(),
         ["autoStart"] = request.AutoStart.ToString()
     }, data: null, callback: null, timeountMilliseconds: 3000);
 }
Ejemplo n.º 2
0
        public bool SaveGpuProfilesJson(string json)
        {
            bool   isSuccess   = false;
            string description = "超频";

            try {
                SpecialPath.SaveGpuProfilesJsonFile(json);
                if (IsNTMinerOpened())
                {
                    JsonRpcRoot.FirePostAsync(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.OverClock), null, data: null);
                }
                else
                {
                    description = "超频,挖矿端未启动,下次启动时生效";
                }
                isSuccess = true;
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
            VirtualRoot.OperationResultSet.Add(new OperationResultData {
                Timestamp    = Timestamp.GetTimestamp(),
                StateCode    = isSuccess ? 200 : 500,
                ReasonPhrase = isSuccess ? "Ok" : "Fail",
                Description  = description
            });
            return(isSuccess);
        }
Ejemplo n.º 3
0
        public ResponseBase StartMine(WorkRequest request)
        {
            ResponseBase response;

            if (request == null)
            {
                response = ResponseBase.InvalidInput("参数错误");
            }
            else
            {
                try {
                    // 单机作业的localJson和serverJson是在编辑单机作业时提前传递到挖矿端的所以不需要在开始挖矿时再传递
                    if (request.WorkId != Guid.Empty && !request.WorkId.IsSelfMineWorkId())
                    {
                        SpecialPath.WriteMineWorkLocalJsonFile(request.LocalJson);
                        SpecialPath.WriteMineWorkServerJsonFile(request.ServerJson);
                    }
                    if (IsNTMinerOpened())
                    {
                        WorkRequest innerRequest = new WorkRequest {
                            WorkId     = request.WorkId,
                            WorkerName = request.WorkerName
                        };
                        JsonRpcRoot.PostAsync <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerClientPort, _minerClientControllerName, nameof(IMinerClientController.StartMine), innerRequest, callback: null, timeountMilliseconds: 3000);
                        response = ResponseBase.Ok("开始挖矿");
                    }
                    else
                    {
                        string location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerClient);
                        if (!string.IsNullOrEmpty(location) && File.Exists(location))
                        {
                            string arguments = NTKeyword.AutoStartCmdParameterName;
                            if (request.WorkId != Guid.Empty)
                            {
                                if (request.WorkId.IsSelfMineWorkId())
                                {
                                    arguments = "--selfWork " + arguments;
                                }
                                else
                                {
                                    arguments = "--work " + arguments;
                                }
                            }
                            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);
        }
Ejemplo n.º 4
0
 public void GetGpuProfilesJsonAsync(IMinerData client)
 {
     JsonRpcRoot.PostAsync <string>(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.GetGpuProfilesJson), null, (json, e) => {
         GpuProfilesJsonDb data = VirtualRoot.JsonSerializer.Deserialize <GpuProfilesJsonDb>(json) ?? new GpuProfilesJsonDb();
         VirtualRoot.RaiseEvent(new GetGpuProfilesResponsedEvent(client.ClientId, data));
     }, timeountMilliseconds: 3000);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 本机同步网络调用
        /// </summary>
        public void CloseMinerStudioAsync(Action callback)
        {
            string location = NTMinerRegistry.GetLocation(NTMinerAppType.MinerStudio);

            if (string.IsNullOrEmpty(location) || !File.Exists(location))
            {
                callback?.Invoke();
                return;
            }
            string processName = Path.GetFileNameWithoutExtension(location);

            if (Process.GetProcessesByName(processName).Length == 0)
            {
                callback?.Invoke();
                return;
            }
            JsonRpcRoot.PostAsync <ResponseBase>(NTKeyword.Localhost, NTKeyword.MinerStudioPort, _controllerName, nameof(IMinerStudioController.CloseMinerStudio), new object(), (response, e) => {
                if (!response.IsSuccess())
                {
                    try {
                        Windows.TaskKill.Kill(processName, waitForExit: true);
                    }
                    catch (Exception ex) {
                        Logger.ErrorDebugLine(ex);
                    }
                }
                callback?.Invoke();
            }, timeountMilliseconds: 2000);
        }
Ejemplo n.º 6
0
 public void UpdateClientsAsync(string propertyName, Dictionary<string, object> values, Action<ResponseBase, Exception> callback) {
     UpdateClientsRequest request = new UpdateClientsRequest {
         PropertyName = propertyName,
         Values = values
     };
     JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IClientDataController.UpdateClients), data: request, callback);
 }
Ejemplo n.º 7
0
        public void RemoveMineWorkAsync(Guid id, Action <ResponseBase, Exception> callback)
        {
            DataRequest <Guid> request = new DataRequest <Guid> {
                Data = id
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMineWorkController.RemoveMineWork), data: request, callback);
        }
Ejemplo n.º 8
0
        public void GetServerMessagesAsync(DateTime timestamp, Action <DataResponse <List <ServerMessageData> >, Exception> callback)
        {
            ServerMessagesRequest request = new ServerMessagesRequest {
                Timestamp = Timestamp.GetTimestamp(timestamp)
            };

            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IServerMessageController.ServerMessages), request, callback);
        }
Ejemplo n.º 9
0
        public void GetLatestSnapshotsAsync(int limit, Action <GetCoinSnapshotsResponse, Exception> callback)
        {
            GetCoinSnapshotsRequest request = new GetCoinSnapshotsRequest {
                Limit = limit
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(ICoinSnapshotController.LatestSnapshots), data: request, callback);
        }
Ejemplo n.º 10
0
        public void RemoveClientsAsync(List <string> objectIds, Action <ResponseBase, Exception> callback)
        {
            var request = new MinerIdsRequest {
                ObjectIds = objectIds
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IClientDataController.RemoveClients), data: request, callback);
        }
Ejemplo n.º 11
0
 public void IsLoginNameExistAsync(string loginName, Action <bool> callback)
 {
     JsonRpcRoot.GetAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserController.IsLoginNameExist), new Dictionary <string, string> {
         ["loginName"] = loginName
     }, (DataResponse <bool> response, Exception e) => {
         callback?.Invoke(response.IsSuccess() && response.Data);
     }, timeountMilliseconds: 5000);
 }
Ejemplo n.º 12
0
        // ReSharper disable once InconsistentNaming
        public void UpgradeNTMinerAsync(IMinerData client, string ntminerFileName)
        {
            UpgradeNTMinerRequest request = new UpgradeNTMinerRequest {
                NTMinerFileName = ntminerFileName
            };

            JsonRpcRoot.PostAsync <ResponseBase>(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.UpgradeNTMiner), request, null, timeountMilliseconds: 3000);
        }
Ejemplo n.º 13
0
        public void GetPackageUrlAsync(string package, Action <string, Exception> callback)
        {
            PackageUrlRequest request = new PackageUrlRequest {
                Package = package
            };

            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IFileUrlController.PackageUrl), request, callback);
        }
Ejemplo n.º 14
0
        // ReSharper disable once InconsistentNaming
        public void GetNTMinerUrlAsync(string fileName, Action <string, Exception> callback)
        {
            NTMinerUrlRequest request = new NTMinerUrlRequest {
                FileName = fileName
            };

            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IFileUrlController.NTMinerUrl), request, callback);
        }
Ejemplo n.º 15
0
 public void UpdateClientAsync(string objectId, string propertyName, object value, Action<ResponseBase, Exception> callback) {
     UpdateClientRequest request = new UpdateClientRequest {
         ObjectId = objectId,
         PropertyName = propertyName,
         Value = value
     };
     JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IClientDataController.UpdateClient), data: request, callback);
 }
Ejemplo n.º 16
0
        public void AddOrUpdateMinerGroupAsync(MinerGroupData entity, Action <ResponseBase, Exception> callback)
        {
            entity.ModifiedOn = DateTime.Now;
            DataRequest <MinerGroupData> request = new DataRequest <MinerGroupData> {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMinerGroupController.AddOrUpdateMinerGroup), data: request, callback);
        }
Ejemplo n.º 17
0
        public void MarkDeleteServerMessageAsync(Guid id, Action <ResponseBase, Exception> callback)
        {
            DataRequest <Guid> request = new DataRequest <Guid>()
            {
                Data = id
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IServerMessageController.MarkDeleteServerMessage), data: request, callback);
        }
Ejemplo n.º 18
0
        public void GetNodeAddressAsync(Guid clientId, string outerUserId, Action <DataResponse <string>, Exception> callback)
        {
            var data = new GetWsServerNodeAddressRequest {
                ClientId = clientId,
                UserId   = outerUserId
            };

            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IWsServerNodeController.GetNodeAddress), data, callback, timeountMilliseconds: 8000);
        }
Ejemplo n.º 19
0
        public void GetLocalJsonAsync(Guid workId, Action <DataResponse <string>, Exception> callback)
        {
            DataRequest <Guid> request = new DataRequest <Guid>()
            {
                Data = workId
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMineWorkController.GetLocalJson), data: request, callback);
        }
        public void RemoveKernelOutputKeyword(Guid id, Action <ResponseBase, Exception> callback)
        {
            DataRequest <Guid> request = new DataRequest <Guid>()
            {
                Data = id
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IKernelOutputKeywordController.RemoveKernelOutputKeyword), data: request, callback);
        }
        public void AddOrUpdateKernelOutputKeywordAsync(KernelOutputKeywordData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <KernelOutputKeywordData> request = new DataRequest <KernelOutputKeywordData>()
            {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IKernelOutputKeywordController.AddOrUpdateKernelOutputKeyword), data: request, callback);
        }
Ejemplo n.º 22
0
        public void SetAppSettingAsync(AppSettingData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <AppSettingData> request = new DataRequest <AppSettingData>()
            {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.SetAppSetting), data: request, callback);
        }
Ejemplo n.º 23
0
        public void AddOrUpdateOverClockDataAsync(OverClockData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <OverClockData> request = new DataRequest <OverClockData>()
            {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IOverClockDataController.AddOrUpdateOverClockData), data: request, callback);
        }
Ejemplo n.º 24
0
        // ReSharper disable once InconsistentNaming
        public void AddOrUpdateNTMinerFileAsync(NTMinerFileData entity, Action <ResponseBase, Exception> callback)
        {
            DataRequest <NTMinerFileData> request = new DataRequest <NTMinerFileData>()
            {
                Data = entity
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IFileUrlController.AddOrUpdateNTMinerFile), data: request, callback);
        }
Ejemplo n.º 25
0
        public void ReportStateAsync(Guid clientId, bool isMining)
        {
            ReportState request = new ReportState {
                ClientId = clientId,
                IsMining = isMining
            };

            JsonRpcRoot.FirePostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IReportController.ReportState), null, request, null, 5000);
        }
Ejemplo n.º 26
0
        public void GetWorkJsonAsync(Guid workId, Guid clientId, Action <GetWorkJsonResponse, Exception> callback)
        {
            GetWorkJsonRequest request = new GetWorkJsonRequest()
            {
                WorkId   = workId,
                ClientId = clientId
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMineWorkController.GetWorkJson), data: request, callback);
        }
Ejemplo n.º 27
0
        public void GetJsonFileVersionAsync(string key, Action <ServerStateResponse> callback)
        {
            AppSettingRequest request = new AppSettingRequest {
                Key = key
            };

            JsonRpcRoot.PostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IAppSettingController.GetJsonFileVersion), request, (string line, Exception e) => {
                callback?.Invoke(ServerStateResponse.FromLine(line));
            }, timeountMilliseconds: 10 * 1000);
        }
Ejemplo n.º 28
0
        public void ExportMineWorkAsync(Guid workId, string localJson, string serverJson, Action <ResponseBase, Exception> callback)
        {
            ExportMineWorkRequest request = new ExportMineWorkRequest {
                MineWorkId = workId,
                LocalJson  = localJson,
                ServerJson = serverJson
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IUserMineWorkController.ExportMineWork), data: request, callback);
        }
Ejemplo n.º 29
0
 public void GetOperationResultsAsync(IMinerData client, long afterTime)
 {
     JsonRpcRoot.GetAsync <List <OperationResultData> >(client.GetLocalIp(), NTKeyword.NTMinerDaemonPort, _daemonControllerName, nameof(INTMinerDaemonController.GetOperationResults), new Dictionary <string, string> {
         ["afterTime"] = afterTime.ToString()
     }, (data, e) => {
         if (data != null && data.Count > 0)
         {
             VirtualRoot.RaiseEvent(new ClientOperationResultsEvent(client.ClientId, data));
         }
     }, timeountMilliseconds: 3000);
 }
Ejemplo n.º 30
0
        public void SaveCalcConfigsAsync(List <CalcConfigData> configs, Action <ResponseBase, Exception> callback)
        {
            if (configs == null || configs.Count == 0)
            {
                return;
            }
            SaveCalcConfigsRequest request = new SaveCalcConfigsRequest {
                Data = configs
            };

            JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(ICalcConfigController.SaveCalcConfigs), data: request, callback);
        }