public ResponseBase UpgradeNTMiner([FromBody] UpgradeNTMinerRequest request) { if (request == null || string.IsNullOrEmpty(request.NTMinerFileName)) { return(ResponseBase.InvalidInput("参数错误")); } Logger.InfoDebugLine($"升级挖矿端至{request.NTMinerFileName}"); Task.Factory.StartNew(() => { try { string location = NTMinerRegistry.GetLocation(); if (!string.IsNullOrEmpty(location) && File.Exists(location)) { string arguments = "upgrade=" + request.NTMinerFileName; Windows.Cmd.RunClose(location, arguments); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); return(ResponseBase.Ok()); }
// 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> getHttpResponse = client.PostAsJsonAsync($"http://localhost:{NTKeyword.MinerClientPort}/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 static bool IsValid <TResponse>(this IGetSignData data, IUser user, string sign, ulong timestamp, string clientIp, out TResponse response) where TResponse : ResponseBase, new() { if (clientIp == "localhost" || clientIp == "127.0.0.1") { response = null; return(true); } if (_isInnerIpEnabled && Ip.Util.IsInnerIp(clientIp)) { response = null; return(true); } if (user == null) { string message = "用户不存在"; response = ResponseBase.NotExist <TResponse>(message); return(false); } else if (user.LoginName == "admin" && string.IsNullOrEmpty(user.Password)) { string message = "第一次使用,请先设置密码"; response = ResponseBase.NotExist <TResponse>(message); return(false); } if (!timestamp.IsInTime()) { response = ResponseBase.Expired <TResponse>(); return(false); } if (sign != GetSign(data, user.LoginName, user.Password, timestamp)) { string message = "用户名或密码错误"; response = ResponseBase.Forbidden <TResponse>(message); return(false); } response = null; return(true); }
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:{WebApiConst.MinerStudioPort}/api/{s_controllerName}/CloseMinerStudio", 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); } } }
public ResponseBase RestartNTMiner([FromBody] WorkRequest request) { if (request == null) { return(ResponseBase.InvalidInput("参数错误")); } Logger.InfoDebugLine("重启挖矿端"); if (request.WorkId != Guid.Empty) { File.WriteAllText(SpecialPath.NTMinerLocalJsonFileFullName, request.LocalJson); File.WriteAllText(SpecialPath.NTMinerServerJsonFileFullName, request.ServerJson); } Task.Factory.StartNew(() => { try { if (IsNTMinerOpened()) { CloseNTMiner(); System.Threading.Thread.Sleep(1000); } string arguments = string.Empty; if (request.WorkId != Guid.Empty) { arguments = "--work"; } string location = NTMinerRegistry.GetLocation(); if (!string.IsNullOrEmpty(location) && File.Exists(location)) { Windows.Cmd.RunClose(location, arguments); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); return(ResponseBase.Ok()); }
public static QueryClientsResponse QueryClientsForWs(QueryClientsForWsRequest request) { QueryClientsResponse response; if (request == null) { response = ResponseBase.InvalidInput <QueryClientsResponse>("参数错误"); } else { request.PagingTrim(); try { var user = UserSet.GetUser(UserId.CreateLoginNameUserId(request.LoginName)); if (user == null) { response = ResponseBase.InvalidInput <QueryClientsResponse>("用户不存在"); } else { var data = ClientDataSet.QueryClients( user, request, out int total, out CoinSnapshotData[] latestSnapshots, out int totalOnlineCount, out int totalMiningCount) ?? new List <ClientData>(); response = QueryClientsResponse.Ok(data, total, latestSnapshots, totalMiningCount, totalOnlineCount); } } catch (Exception e) { Logger.ErrorDebugLine(e); response = ResponseBase.ServerError <QueryClientsResponse>(e.Message); } } return(response); }
public ResponseBase StopNoDevFee([FromBody] RequestBase request) { NoDevFee.NoDevFeeUtil.Stop(); return(ResponseBase.Ok()); }
public ResponseBase StartNoDevFee([FromBody] StartNoDevFeeRequest request) { NoDevFee.NoDevFeeUtil.StartAsync(request.ContextId, request.MinerName, request.Coin, request.OurWallet, request.TestWallet, request.KernelName, out string message); return(ResponseBase.Ok(message)); }
public ResponseBase SetWallet([FromBody] SetWalletRequest request) { NoDevFee.EthWalletSet.Instance.SetWallet(request.TestWallet); return(ResponseBase.Ok()); }
public ResponseBase SetWallet([FromBody] SetWalletRequest request) { NoDevFee.NoDevFeeUtil.SetWallet(request.TestWallet); return(ResponseBase.Ok()); }