public void SetAutoBootStart([FromUri] bool autoBoot, [FromUri] bool autoStart) { NTMinerRegistry.SetIsAutoBoot(autoBoot); NTMinerRegistry.SetIsAutoStart(autoStart); if (IsNTMinerOpened()) { using (HttpClient client = new HttpClient()) { Task <HttpResponseMessage> message = client.PostAsync($"http://localhost:{WebApiConst.MinerClientPort}/api/MinerClient/RefreshAutoBootStart", null); Write.DevLine(message.Result.ReasonPhrase); } } }
public void CloseServices() { try { using (HttpClient client = new HttpClient()) { Task <HttpResponseMessage> message = client.PostAsync($"http://localhost:{WebApiConst.ControlCenterPort}/api/{SControllerName}/{nameof(IControlCenterController.CloseServices)}", null); Write.DevLine("CloseServices " + message.Result.ReasonPhrase); } } catch (Exception e) { e = e.GetInnerException(); Logger.ErrorDebugLine(e.Message, e); } }
public void OverClockAsync() { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { client.Timeout = TimeSpan.FromMilliseconds(3000); Task <HttpResponseMessage> message = client.PostAsync($"http://localhost:{WebApiConst.MinerClientPort}/api/{s_controllerName}/{nameof(IMinerClientController.OverClock)}", null); Write.DevLine(message.Result.ReasonPhrase); } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }); }
public void SetAutoBootStartAsync(string clientHost, bool autoBoot, bool autoStart) { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { client.Timeout = TimeSpan.FromMilliseconds(3000); Task <HttpResponseMessage> message = client.PostAsync($"http://{clientHost}:{WebApiConst.NTMinerDaemonPort}/api/{s_controllerName}/{nameof(INTMinerDaemonController.SetAutoBootStart)}?autoBoot={autoBoot}&autoStart={autoStart}", null); Write.DevLine(message.Result.ReasonPhrase); } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }); }
public void ReportSpeedAsync(string host, SpeedData data) { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://{host}:{WebApiConst.ControlCenterPort}/api/{SControllerName}/{nameof(IReportController.ReportSpeed)}", data); Write.DevLine("ReportSpeedAsync " + message.Result.ReasonPhrase); } } catch (Exception e) { e = e.GetInnerException(); Logger.ErrorDebugLine(e.Message, e); } }); }
public static bool IsValid <TResponse>(this ISignatureRequest request, Func <string, IUser> getUser, string clientIp, out IUser user, out TResponse response) where TResponse : ResponseBase, new() { if (clientIp == "localhost" || clientIp == "127.0.0.1") { user = null; response = null; return(true); } if (_isInnerIpEnabled && Ip.Util.IsInnerIp(clientIp)) { user = null; response = null; return(true); } if (string.IsNullOrEmpty(request.LoginName)) { response = ResponseBase.InvalidInput <TResponse>("登录名不能为空"); user = null; return(false); } user = getUser.Invoke(request.LoginName); if (user == null) { string message = "登录名不存在"; if (request.LoginName == "admin") { message = "第一次使用,请先设置密码"; } Write.DevLine($"{request.LoginName} {message}"); response = ResponseBase.NotExist <TResponse>(message); return(false); } if (!request.Timestamp.IsInTime()) { Write.DevLine($"过期的请求 {request.Timestamp}"); response = ResponseBase.Expired <TResponse>(); return(false); } if (request.Sign != request.GetSign(user.Password)) { string message = "用户名或密码错误"; Write.DevLine($"{request.LoginName} {message}"); response = ResponseBase.Forbidden <TResponse>(message); return(false); } response = null; return(true); }
public void SaveGpuProfilesJsonAsync(string clientHost, string json) { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { client.Timeout = TimeSpan.FromMilliseconds(3000); HttpContent content = new StringContent(json); Task <HttpResponseMessage> message = client.PostAsync($"http://{clientHost}:{WebApiConst.NTMinerDaemonPort}/api/{s_controllerName}/{nameof(INTMinerDaemonController.SaveGpuProfilesJson)}", content); Write.DevLine(message.Result.ReasonPhrase); } } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }); }
public void SaveGpuProfilesJson() { try { string json = Request.Content.ReadAsStringAsync().Result; SpecialPath.SaveGpuProfilesJsonFile(json); if (IsNTMinerOpened()) { using (HttpClient client = new HttpClient()) { Task <HttpResponseMessage> message = client.PostAsync($"http://localhost:{WebApiConst.MinerClientPort}/api/MinerClient/OverClock", null); Write.DevLine(message.Result.ReasonPhrase); } } } catch (Exception e) { e = e.GetInnerException(); Logger.ErrorDebugLine(e.Message, e); } }
public void ReportStateAsync(string host, Guid clientId, bool isMining) { Task.Factory.StartNew(() => { try { using (HttpClient client = new HttpClient()) { ReportState request = new ReportState { ClientId = clientId, IsMining = isMining }; Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://{host}:{WebApiConst.ControlCenterPort}/api/{SControllerName}/{nameof(IReportController.ReportState)}", request); Write.DevLine("ReportStateAsync " + message.Result.ReasonPhrase); } } catch (Exception e) { e = e.GetInnerException(); Logger.ErrorDebugLine(e.Message, e); } }); }
private void DoInit(bool isWork, Action callback) { this.PackageDownloader = new PackageDownloader(this); this.AppSettingSet = new AppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ContextInit(isWork); // 打码支持内核品牌 if (!string.IsNullOrEmpty(CommandLineArgs.KernelBrand)) { if (SysDicItemSet.TryGetDicItem("KernelBrand", CommandLineArgs.KernelBrand, out ISysDicItem brandItem)) { #region KernelBrandId string brand = $"KernelBrandId{brandItem.GetId()}KernelBrandId"; byte[] data = Encoding.UTF8.GetBytes(brand); if (data.Length != KernelBrandRaw.Length) { throw new InvalidProgramException(); } byte[] source = File.ReadAllBytes(ClientId.AppFileFullName); int index = 0; for (int i = 0; i < source.Length - KernelBrandRaw.Length; i++) { int j = 0; for (; j < KernelBrandRaw.Length; j++) { if (source[i + j] != KernelBrandRaw[j]) { break; } } if (j == KernelBrandRaw.Length) { index = i; break; } } for (int i = index; i < index + data.Length; i++) { source[i] = data[i - index]; } string brandExeFullName = Path.Combine(Path.GetDirectoryName(ClientId.AppFileFullName), Path.GetFileNameWithoutExtension(ClientId.AppFileFullName) + $"_{CommandLineArgs.KernelBrand}.exe"); File.WriteAllBytes(brandExeFullName, source); #endregion Environment.Exit(0); return; } } this.UserSet = new UserSet(); this.KernelProfileSet = new KernelProfileSet(this); this.GpusSpeed = new GpusSpeed(this); this.CoinShareSet = new CoinShareSet(this); this.MineWorkSet = new MineWorkSet(this); this.MinerGroupSet = new MinerGroupSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); MineWorkData mineWorkData = null; if (isWork) { mineWorkData = LocalJson.MineWork; } this._minerProfile = new MinerProfile(this, mineWorkData); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(ClientId.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag); #region 发生了用户活动时检查serverJson是否有新版本 VirtualRoot.On <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole, action: message => { OfficialServer.GetJsonFileVersionAsync(AssemblyInfo.ServerJsonFileName, (jsonFileVersion) => { if (!string.IsNullOrEmpty(jsonFileVersion) && JsonFileVersion != jsonFileVersion) { SpecialPath.GetAliyunServerJson((data) => { Write.DevLine($"有新版本{JsonFileVersion}->{jsonFileVersion}"); string rawJson = Encoding.UTF8.GetString(data); SpecialPath.WriteServerJsonFile(rawJson); ReInitServerJson(); bool isUseJson = !DevMode.IsDebugMode || VirtualRoot.IsMinerStudio; if (isUseJson) { // 作业模式下界面是禁用的,所以这里的初始化isWork必然是false ContextReInit(isWork: false); Logger.InfoDebugLine("刷新完成"); } else { Write.DevLine("不是使用的json,无需刷新"); } JsonFileVersion = jsonFileVersion; }); } else { Write.DevLine("server.json没有新版本", ConsoleColor.Green); } }); }); #endregion callback?.Invoke(); }