Ejemplo n.º 1
0
 public ResponseBase StopMine([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         ResponseBase response;
         if (!IsNTMinerOpened())
         {
             return(ResponseBase.Ok());
         }
         try {
             using (HttpClient client = new HttpClient()) {
                 Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://localhost:{Consts.MinerClientPort}/api/MinerClient/StopMine", request);
                 response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
                 return(response);
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
 public ResponseBase StopMine(string clientIp, SignatureRequest request)
 {
     using (HttpClient client = new HttpClient()) {
         Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://{clientIp}:{WebApiConst.MinerClientPort}/api/{s_controllerName}/{nameof(IMinerClientController.StopMine)}", request);
         ResponseBase response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
         return(response);
     }
 }
Ejemplo n.º 3
0
 public ResponseBase ShutdownWindows(string clientIp, SignatureRequest request)
 {
     using (HttpClient client = new HttpClient()) {
         Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://{clientIp}:{Consts.NTMinerDaemonPort}/api/{s_controllerName}/{nameof(INTMinerDaemonController.ShutdownWindows)}", request);
         ResponseBase response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
         return(response);
     }
 }
Ejemplo n.º 4
0
            public void LoginAsync(string loginName, string password, Action <ResponseBase, Exception> callback)
            {
                SignatureRequest request = new SignatureRequest()
                {
                    LoginName = loginName
                };

                request.SignIt(password);
                PostAsync(SControllerName, nameof(IControlCenterController.LoginControlCenter), null, request, callback);
            }
 public void StopMineAsync(string clientIp, SignatureRequest request, Action <ResponseBase, Exception> callback)
 {
     Task.Factory.StartNew(() => {
         try {
             ResponseBase response = StopMine(clientIp, request);
             callback?.Invoke(response, null);
         }
         catch (Exception e) {
             callback?.Invoke(null, e);
         }
     });
 }
Ejemplo n.º 6
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public DataResponse <List <WalletData> > GetWallets()
 {
     try {
         SignatureRequest request = new SignatureRequest {
             LoginName = SingleUser.LoginName
         };
         request.SignIt(SingleUser.PasswordSha1);
         DataResponse <List <WalletData> > response = Post <DataResponse <List <WalletData> > >(SControllerName, nameof(IControlCenterController.Wallets), null, request, timeout: 2000);
         return(response);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(null);
     }
 }
Ejemplo n.º 7
0
 public ResponseBase CloseMinerStudio([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.Execute(new CloseNTMinerCommand());
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Ejemplo n.º 8
0
 public ResponseBase StopMine([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         NTMinerRoot.Instance.StopMineAsync();
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Ejemplo n.º 9
0
 public ResponseBase ShutdownWindows([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         TimeSpan.FromMilliseconds(100).Delay().ContinueWith(t => {
             Windows.Power.Shutdown();
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Ejemplo n.º 10
0
 public ResponseBase CloseMinerStudio([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         TimeSpan.FromMilliseconds(100).Delay().ContinueWith(t => {
             VirtualRoot.Execute(new CloseNTMinerCommand());
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
            public void ShutdownWindowsAsync(IClientData client, Action <ResponseBase, Exception> callback)
            {
                SignatureRequest innerRequest = new SignatureRequest {
                    LoginName = SingleUser.LoginName
                };

                innerRequest.SignIt(SingleUser.GetRemotePassword(client.ClientId));
                WrapperRequest <SignatureRequest> request = new WrapperRequest <SignatureRequest> {
                    ObjectId     = client.GetId(),
                    ClientId     = client.ClientId,
                    LoginName    = SingleUser.LoginName,
                    InnerRequest = innerRequest,
                    ClientIp     = client.MinerIp
                };

                request.SignIt(SingleUser.PasswordSha1);
                PostAsync(SControllerName, nameof(IWrapperMinerClientController.ShutdownWindows), null, request, callback);
            }
Ejemplo n.º 12
0
 // TODO:异步化
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public List <ColumnsShowData> GetColumnsShows()
 {
     try {
         SignatureRequest request = new SignatureRequest {
             LoginName = SingleUser.LoginName
         };
         request.SignIt(SingleUser.PasswordSha1);
         DataResponse <List <ColumnsShowData> > response = Post <DataResponse <List <ColumnsShowData> > >(SControllerName, nameof(IControlCenterController.ColumnsShows), null, request, timeout: 2000);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <ColumnsShowData>());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(new List <ColumnsShowData>());
     }
 }
 /// <summary>
 /// 同步方法
 /// </summary>
 /// <returns></returns>
 public List <PoolData> GetPools()
 {
     try {
         SignatureRequest request = new SignatureRequest {
             LoginName = SingleUser.LoginName
         };
         request.SignIt(SingleUser.PasswordSha1);
         DataResponse <List <PoolData> > response = Post <DataResponse <List <PoolData> > >(SControllerName, nameof(IControlCenterController.Pools), request);
         if (response != null && response.Data != null)
         {
             return(response.Data);
         }
         return(new List <PoolData>());
     }
     catch (Exception e) {
         e = e.GetInnerException();
         Logger.ErrorDebugLine(e.Message, e);
         return(new List <PoolData>());
     }
 }