Esempio n. 1
0
 /// <summary>
 /// 本机网络调用
 /// </summary>
 public void CloseDaemon()
 {
     try {
         using (HttpClient client = RpcRoot.CreateHttpClient()) {
             client.Timeout = TimeSpan.FromSeconds(2);
             Task <HttpResponseMessage> getHttpResponse = client.PostAsync($"http://localhost:{NTKeyword.NTMinerDaemonPort.ToString()}/api/{_controllerName}/{nameof(INTMinerDaemonController.CloseDaemon)}", null);
             Write.DevDebug($"{nameof(CloseDaemon)} {getHttpResponse.Result.ReasonPhrase}");
         }
     }
     catch (Exception e) {
         Write.DevException(e);
     }
 }
Esempio n. 2
0
 public void ReportSpeedAsync(string host, SpeedData data, Action <ReportResponse> callback)
 {
     Task.Factory.StartNew(() => {
         TimeSpan timeSpan = TimeSpan.FromSeconds(3);
         try {
             using (HttpClient client = RpcRoot.CreateHttpClient()) {
                 // 可能超过3秒钟,查查原因。因为我的网络不稳经常断线。
                 client.Timeout = timeSpan;
                 Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://{host}:{NTKeyword.ControlCenterPort.ToString()}/api/{_controllerName}/{nameof(IReportController.ReportSpeed)}", data);
                 ReportResponse response = getHttpResponse.Result.Content.ReadAsAsync <ReportResponse>().Result;
                 callback?.Invoke(response);
             }
         }
         catch (Exception e) {
             Write.DevException(e);
         }
     });
 }
Esempio n. 3
0
 public void ReportStateAsync(string host, Guid clientId, bool isMining)
 {
     Task.Factory.StartNew(() => {
         TimeSpan timeSpan = TimeSpan.FromSeconds(3);
         try {
             using (HttpClient client = RpcRoot.CreateHttpClient()) {
                 client.Timeout      = timeSpan;
                 ReportState request = new ReportState {
                     ClientId = clientId,
                     IsMining = isMining
                 };
                 Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://{host}:{NTKeyword.ControlCenterPort.ToString()}/api/{_controllerName}/{nameof(IReportController.ReportState)}", request);
                 Write.DevDebug($"{nameof(ReportStateAsync)} {getHttpResponse.Result.ReasonPhrase}");
             }
         }
         catch (Exception e) {
             Write.DevException(e);
         }
     });
 }