Пример #1
0
        private void CloseNTMiner()
        {
            bool isClosed = false;

            try {
                using (HttpClient client = new HttpClient()) {
                    Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://localhost:{Consts.MinerClientPort}/api/MinerClient/CloseNTMiner", new SignatureRequest {
                    });
                    ResponseBase response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
                    isClosed = response.IsSuccess();
                }
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
            if (!isClosed)
            {
                try {
                    string location = NTMinerRegistry.GetLocation();
                    if (!string.IsNullOrEmpty(location) && File.Exists(location))
                    {
                        string processName = Path.GetFileNameWithoutExtension(location);
                        Windows.TaskKill.Kill(processName);
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
            }
        }
            // ReSharper disable once InconsistentNaming
            public void CloseNTMiner()
            {
                string location = NTMinerRegistry.GetLocation();

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

                if (Process.GetProcessesByName(processName).Length == 0)
                {
                    return;
                }
                bool isClosed = false;

                try {
                    using (HttpClient client = new HttpClient()) {
                        client.Timeout = TimeSpan.FromMilliseconds(2000);
                        Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://localhost:{WebApiConst.MinerClientPort}/api/MinerClient/CloseNTMiner", new SignatureRequest {
                        });
                        ResponseBase response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
                        isClosed = response.IsSuccess();
                    }
                }
                catch (Exception e) {
                    e = e.GetInnerException();
                    Logger.ErrorDebugLine(e.Message, e);
                }
                if (!isClosed)
                {
                    try {
                        Windows.TaskKill.Kill(processName);
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e.Message, e);
                    }
                }
            }
            // ReSharper disable once InconsistentNaming
            public void CloseNTMiner()
            {
                string location = NTMinerRegistry.GetLocation();

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

                if (Process.GetProcessesByName(processName).Length == 0)
                {
                    return;
                }
                bool isClosed = false;

                try {
                    using (HttpClient client = RpcRoot.Create()) {
                        client.Timeout = TimeSpan.FromSeconds(2);
                        Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://localhost:{NTKeyword.MinerClientPort.ToString()}/api/{s_controllerName}/{nameof(IMinerClientController.CloseNTMiner)}", new SignRequest {
                        });
                        ResponseBase response = getHttpResponse.Result.Content.ReadAsAsync <ResponseBase>().Result;
                        isClosed = response.IsSuccess();
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                if (!isClosed)
                {
                    try {
                        Windows.TaskKill.Kill(processName);
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e);
                    }
                }
            }
            public void CloseMinerStudio()
            {
                string location = NTMinerRegistry.GetLocation();

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

                if (Process.GetProcessesByName(processName).Length == 0)
                {
                    return;
                }
                bool isClosed = false;

                try {
                    using (HttpClient client = new HttpClient()) {
                        Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://localhost:{Consts.MinerStudioPort}/api/{s_controllerName}/{nameof(IMinerStudioController.CloseMinerStudio)}", new SignRequest {
                        });
                        ResponseBase response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
                        isClosed = response.IsSuccess();
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                if (!isClosed)
                {
                    try {
                        Windows.TaskKill.Kill(processName);
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e);
                    }
                }
            }