private static void ContinueCreateProcess(IMineContext mineContext) { Thread.Sleep(1000); if (mineContext != Instance.LockedMineContext) { Write.UserWarn("挖矿停止"); return; } // 解压内核包 if (!mineContext.Kernel.ExtractPackage()) { VirtualRoot.RaiseEvent(new StartingMineFailedEvent("内核解压失败,请卸载内核重试。")); } else { Write.UserOk("内核包解压成功"); } // 执行文件书写器 mineContext.ExecuteFileWriters(); // 分离命令名和参数 GetCmdNameAndArguments(mineContext, out string kernelExeFileFullName, out string arguments); // 这是不应该发生的,如果发生很可能是填写命令的时候拼写错误了 if (!File.Exists(kernelExeFileFullName)) { Write.UserError(kernelExeFileFullName + "文件不存在,可能是被杀软删除导致,请退出杀毒软件重试或者QQ群联系小编,解释:大部分挖矿内核会报毒,不是开源矿工的问题也不是杀软的问题,也不是挖矿内核的问题,是挖矿这件事情的问题,可能是挖矿符合了病毒的定义。"); } if (mineContext.KernelProcessType == KernelProcessType.Logfile) { arguments = arguments.Replace(NTKeyword.LogFileParameterName, mineContext.LogFileFullName); } Write.UserOk($"\"{kernelExeFileFullName}\" {arguments}"); Write.UserInfo($"有请内核上场:{mineContext.KernelProcessType}"); if (mineContext != Instance.LockedMineContext) { Write.UserWarn("挖矿停止"); return; } switch (mineContext.KernelProcessType) { case KernelProcessType.Logfile: CreateLogfileProcess(mineContext, kernelExeFileFullName, arguments); break; case KernelProcessType.Pip: CreatePipProcess(mineContext, kernelExeFileFullName, arguments); break; default: throw new InvalidProgramException(); } VirtualRoot.RaiseEvent(new MineStartedEvent(mineContext)); }
public static void CreateProcessAsync(IMineContext mineContext) { Task.Factory.StartNew(() => { lock (_locker) { try { #if DEBUG Write.Stopwatch.Restart(); #endif // 清理除当前外的Temp/Kernel Cleaner.Instance.Clear(); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(MinerProcess)}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]"); #endif Write.UserOk("场地打扫完毕"); // 应用超频 if (Instance.GpuProfileSet.IsOverClockEnabled(mineContext.MainCoin.GetId())) { Write.UserWarn("应用超频,如果CPU性能较差耗时可能超过1分钟,请耐心等待"); var cmd = new CoinOverClockCommand(mineContext.MainCoin.GetId()); // N卡超频当cpu性能非常差时较耗时,所以这里弄个回调 IMessagePathId callback = null; callback = VirtualRoot.BuildEventPath <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole, message => { if (mineContext != Instance.CurrentMineContext) { VirtualRoot.DeletePath(callback); } else if (message.CmdId == cmd.Id) { VirtualRoot.DeletePath(callback); ContinueCreateProcess(mineContext); } }); VirtualRoot.Execute(cmd); } else { ContinueCreateProcess(mineContext); } } catch (Exception e) { Logger.ErrorDebugLine(e); Write.UserFail("挖矿内核启动失败,请联系开发人员解决"); } } }); }
public static void CreateProcessAsync(IMineContext mineContext) { Task.Factory.StartNew(() => { lock (_locker) { try { #if DEBUG NTStopwatch.Start(); #endif // 清理除当前外的Temp/Kernel Cleaner.Instance.Clear(); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {nameof(MinerProcess)}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]"); } #endif Write.UserOk("场地打扫完毕"); // 应用超频 if (Instance.GpuProfileSet.IsOverClockEnabled(mineContext.MainCoin.GetId())) { Write.UserWarn("应用超频,如果CPU性能较差耗时可能超过1分钟,请耐心等待"); var cmd = new CoinOverClockCommand(mineContext.MainCoin.GetId()); VirtualRoot.AddOnecePath <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole, message => { if (mineContext == Instance.LockedMineContext) { ContinueCreateProcess(mineContext); } }, location: typeof(MinerProcess), pathId: cmd.Id); // 超频是在另一个线程执行的,因为N卡超频当cpu性能非常差时较耗时 VirtualRoot.Execute(cmd); } else { ContinueCreateProcess(mineContext); } } catch (Exception e) { Logger.ErrorDebugLine(e); Write.UserFail("挖矿内核启动失败,请联系开发人员解决"); } } }); }
static void Main() { using (var ws = new WebSocket("ws://localhost:8088/Echo")) { ws.OnOpen += (sender, e) => { Write.UserWarn($"WebSocket Open"); ws.Send("Hi!"); }; ws.OnMessage += (sender, e) => { Write.UserInfo(e.Data); }; ws.OnError += (sender, e) => { Write.UserError(e.Message); }; ws.OnClose += (sender, e) => { Write.UserWarn($"WebSocket Close {e.Code} {e.Reason}"); }; ws.Log.Level = LogLevel.Trace; ws.Connect(); Windows.ConsoleHandler.Register(ws.Close); Console.WriteLine("\nType 'exit' to exit.\n"); while (true) { Console.Write("> "); var msg = Console.ReadLine(); if (msg == "exit") { break; } if (!ws.IsAlive) { ws.Connect(); } // Send a text message. ws.Send(msg); } } }
protected override void OnMessage(MessageEventArgs e) { if (e.IsPing) { WsRoot.MinerStudioSessionSet.ActiveByWsSessionId(base.ID, out _); return; } WsMessage message = e.ToWsMessage <WsMessage>(); if (message == null) { return; } if (!WsRoot.MinerStudioSessionSet.TryGetByWsSessionId(this.ID, out IMinerStudioSession minerSession)) { this.CloseAsync(CloseStatusCode.Normal, "意外,会话不存在,请重新连接"); return; } if (!minerSession.IsValid(message)) { this.CloseAsync(CloseStatusCode.Normal, "意外,签名验证失败,请重新连接"); return; } if (MinerStudioWsMessageHandler.TryGetHandler(message.Type, out Action <string, WsMessage> handler)) { try { handler.Invoke(minerSession.LoginName, message); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } } else { Write.UserWarn($"{_behaviorName} {nameof(OnMessage)} Received InvalidType {e.Data}"); } }
protected override void OnMessage(MessageEventArgs e) { IMinerClientSession minerSession; if (e.IsPing) { if (WsRoot.MinerClientSessionSet.ActiveByWsSessionId(base.ID, out minerSession)) { WsRoot.MinerClientMqSender.SendMinerClientWsBreathed(minerSession.LoginName, minerSession.ClientId); } return; } WsMessage message = e.ToWsMessage <WsMessage>(); if (message == null) { return; } if (!WsRoot.MinerClientSessionSet.TryGetByWsSessionId(this.ID, out minerSession)) { this.CloseAsync(CloseStatusCode.Normal, "意外,会话不存在,请重新连接"); return; } else if (MinerClientWsMessageHandler.TryGetHandler(message.Type, out Action <MinerClientBehavior, string, Guid, WsMessage> handler)) { try { handler.Invoke(this, minerSession.LoginName, minerSession.ClientId, message); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } } else { Write.UserWarn($"{_behaviorName} {nameof(OnMessage)} Received InvalidType {e.Data}"); } }
public void Init(Action callback) { Task.Factory.StartNew(() => { bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase); if (isWork) // 是作业 { DoInit(isWork, callback); if (VirtualRoot.IsMinerClient) { NTMinerRegistry.SetIsLastIsWork(true); } } else // 不是作业 { if (VirtualRoot.IsMinerClient) { NTMinerRegistry.SetIsLastIsWork(false); } // 如果是Debug模式且不是群控客户端则使用本地数据库初始化 bool useLocalDb = DevMode.IsDebugMode && !VirtualRoot.IsMinerStudio; if (useLocalDb) { DoInit(isWork: false, callback: callback); } else { Logger.InfoDebugLine(nameof(GetAliyunServerJson)); GetAliyunServerJson((data) => { // 如果server.json未下载成功则不覆写本地server.json if (data != null && data.Length != 0) { Logger.InfoDebugLine($"{nameof(GetAliyunServerJson)}成功"); var serverJson = Encoding.UTF8.GetString(data); if (!string.IsNullOrEmpty(serverJson)) { SpecialPath.WriteServerJsonFile(serverJson); } OfficialServer.GetJsonFileVersionAsync(MainAssemblyInfo.ServerJsonFileName, serverState => { SetServerJsonVersion(serverState.JsonFileVersion); AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion); if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) < Timestamp.DesyncSeconds) { Logger.OkDebugLine($"本机和服务器时间一致或相差不超过 {Timestamp.DesyncSeconds.ToString()} 秒"); } else { Write.UserWarn($"本机和服务器时间不同步,请调整,本地:{DateTime.Now.ToString()},服务器:{Timestamp.FromTimestamp(serverState.Time).ToString()}。此问题不影响挖矿。"); } }); } else { if (!File.Exists(SpecialPath.ServerJsonFileFullName)) { VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "配置文件下载失败,这是第一次运行开源矿工,配置文件至少需要成功下载一次,请检查网络是否可用", OutEnum.Warn); } else { VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), "配置文件下载失败,使用最近一次成功下载的配置文件", OutEnum.Warn); } } DoInit(isWork, callback); }); #region 发生了用户活动时检查serverJson是否有新版本 VirtualRoot.BuildEventPath <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole, action: message => { RefreshServerJsonFile(); }); #endregion } } VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"启动{VirtualRoot.AppName}"); }); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { var vdsUUDataTask = GetHtmlAsync("https://uupool.cn/api/getAllInfo.php"); var vdsZtDataTask = GetHtmlAsync("https://www.zt.com/api/v1/symbol"); var htmlDataTask = GetHtmlAsync("https://www.f2pool.com/"); byte[] htmlData = null; byte[] vdsUUData = null; byte[] vdsZtData = null; try { Task.WaitAll(new Task[] { vdsUUDataTask, vdsZtDataTask, htmlDataTask }, 30 * 1000); htmlData = htmlDataTask.Result; vdsUUData = vdsUUDataTask.Result; vdsZtData = vdsZtDataTask.Result; } catch { } if (htmlData != null && htmlData.Length != 0) { Write.UserOk($"{DateTime.Now} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); string vdsUUHtml = string.Empty; string vdsZtHtml = string.Empty; if (vdsUUData != null && vdsUUData.Length != 0) { vdsUUHtml = Encoding.UTF8.GetString(vdsUUData); } if (vdsZtData != null && vdsZtData.Length != 0) { vdsZtHtml = Encoding.UTF8.GetString(vdsZtData); } double usdCny = PickUsdCny(html); Write.UserInfo($"usdCny={usdCny}"); List <IncomeItem> incomeItems = PickIncomeItems(html); IncomeItem vdsIncomeItem = PickVDSIncomeItem(vdsUUHtml, vdsZtHtml, usdCny); if (vdsIncomeItem != null && incomeItems.All(a => a.CoinCode != "VDS")) { incomeItems.Add(vdsIncomeItem); } Write.UserInfo($"鱼池首页有{incomeItems.Count}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { Login(); OfficialServer.CalcConfigService.GetCalcConfigsAsync(data => { Write.UserInfo($"NTMiner有{data.Count}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; } } OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => { if (!res.IsSuccess()) { Write.UserFail(res.ReadMessage(e)); } }); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserInfo(incomeItem.ToString()); } foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserOk(incomeItem.ToString()); } Write.UserOk($"更新了{coinCodes.Count}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = data.Count - coinCodes.Count; Write.UserWarn($"{unUpdatedCount}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}"); }); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { Task <byte[]> htmlDataTask = GetHtmlAsync("https://www.f2pool.com/"); byte[] htmlData = null; try { Task.WaitAll(new Task[] { htmlDataTask }, 60 * 1000); htmlData = htmlDataTask.Result; } catch { } if (htmlData != null && htmlData.Length != 0) { Write.UserOk($"{DateTime.Now.ToString()} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); double usdCny = PickUsdCny(html); Write.UserInfo($"usdCny={usdCny.ToString()}"); List <IncomeItem> incomeItems = PickIncomeItems(html); Write.UserInfo($"鱼池首页有{incomeItems.Count.ToString()}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { RpcRoot.SetRpcUser(new RpcUser(ServerRoot.HostConfig.RpcLoginName, HashUtil.Sha1(ServerRoot.HostConfig.RpcPassword)), isOuterNet: false); RpcRoot.OfficialServer.CalcConfigService.GetCalcConfigsAsync(data => { Write.UserInfo($"NTMiner有{data.Count.ToString()}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.NetSpeed = incomeItem.NetSpeed; calcConfigData.NetSpeedUnit = incomeItem.NetSpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; if (calcConfigData.ModifiedOn.AddMinutes(15) > calcConfigData.ModifiedOn.Date.AddDays(1)) { calcConfigData.BaseNetSpeed = calcConfigData.NetSpeed; calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } else if (calcConfigData.BaseNetSpeed != 0) { if (calcConfigData.NetSpeedUnit == calcConfigData.BaseNetSpeedUnit) { calcConfigData.DayWave = (calcConfigData.NetSpeed - calcConfigData.BaseNetSpeed) / calcConfigData.BaseNetSpeed; } else { if (string.IsNullOrEmpty(calcConfigData.BaseNetSpeedUnit)) { calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } var netSpeed = calcConfigData.NetSpeed.FromUnitSpeed(calcConfigData.NetSpeedUnit); var baseNetSpeed = calcConfigData.BaseNetSpeed.FromUnitSpeed(calcConfigData.BaseNetSpeedUnit); calcConfigData.DayWave = (netSpeed - baseNetSpeed) / baseNetSpeed; } } } } RpcRoot.OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => { if (!res.IsSuccess()) { VirtualRoot.Out.ShowError(res.ReadMessage(e), autoHideSeconds: 4); } }); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserInfo(incomeItem.ToString()); } foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserOk(incomeItem.ToString()); } Write.UserOk($"更新了{coinCodes.Count.ToString()}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = data.Count - coinCodes.Count; Write.UserWarn($"{unUpdatedCount.ToString()}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}"); }); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); }
private static void ReadPrintLoopLogFileAsync(IMineContext mineContext, bool isWriteToConsole) { Task.Factory.StartNew(() => { bool isLogFileCreated = true; int n = 0; while (!File.Exists(mineContext.LogFileFullName)) { if (n >= 20) { // 20秒钟都没有建立日志文件,不可能 isLogFileCreated = false; Write.UserFail("呃!意外,竟然20秒钟未产生内核输出,请联系开发人员解决。"); break; } Thread.Sleep(1000); if (n == 0) { Write.UserInfo("等待内核出场"); } if (mineContext != Instance.CurrentMineContext) { Write.UserWarn("挖矿上下文变更,结束内核输出等待。"); isLogFileCreated = false; break; } n++; } if (isLogFileCreated) { Write.UserOk("内核已上场,下面把舞台交给内核。"); StreamReader sreader = null; try { sreader = new StreamReader(File.Open(mineContext.LogFileFullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default); while (mineContext == Instance.CurrentMineContext) { string outline = sreader.ReadLine(); if (string.IsNullOrEmpty(outline) && sreader.EndOfStream) { Thread.Sleep(1000); } else { string input = outline; Guid kernelOutputId = mineContext.Kernel.KernelOutputId; Instance.KernelOutputFilterSet.Filter(kernelOutputId, ref input); ConsoleColor color = ConsoleColor.White; Instance.KernelOutputTranslaterSet.Translate(kernelOutputId, ref input, ref color, isPre: true); // 使用Claymore挖其非ETH币种时它也打印ETH,所以这里需要纠正它 if ("Claymore".Equals(mineContext.Kernel.Code, StringComparison.OrdinalIgnoreCase)) { if (mineContext.MainCoin.Code != "ETH" && input.Contains("ETH")) { input = input.Replace("ETH", mineContext.MainCoin.Code); } } Instance.KernelOutputSet.Pick(kernelOutputId, ref input, mineContext); if (isWriteToConsole) { if (!string.IsNullOrEmpty(input)) { if (IsUiVisible) { Instance.KernelOutputTranslaterSet.Translate(kernelOutputId, ref input, ref color); } if (Instance.KernelOutputSet.TryGetKernelOutput(kernelOutputId, out IKernelOutput kernelOutput)) { if (kernelOutput.PrependDateTime) { Write.UserLine($"{DateTime.Now} {input}", color); } else { Write.UserLine(input, color); } } else { Write.UserLine(input, color); } } } } } } catch (Exception e) { Logger.ErrorDebugLine(e); } finally { sreader?.Close(); sreader?.Dispose(); } Write.UserWarn("内核表演结束"); } }, TaskCreationOptions.LongRunning); }
private static void ReadPrintLoopLogFileAsync(IMineContext mineContext, bool isWriteToConsole) { Task.Factory.StartNew(() => { bool isLogFileCreated = true; int n = 0; while (!File.Exists(mineContext.LogFileFullName)) { if (n >= 20) { // 20秒钟都没有建立日志文件,不可能 isLogFileCreated = false; Write.UserFail("呃!意外,竟然20秒钟未产生内核输出。常见原因:1.挖矿内核被杀毒软件删除; 2.没有磁盘空间了; 3.反馈给开发人员"); break; } Thread.Sleep(1000); if (n == 0) { Write.UserInfo("等待内核出场"); } if (mineContext != Instance.LockedMineContext) { Write.UserWarn("结束内核输出等待。"); isLogFileCreated = false; break; } n++; } if (isLogFileCreated) { StreamReader sreader = null; try { sreader = new StreamReader(File.Open(mineContext.LogFileFullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default); while (mineContext == Instance.LockedMineContext) { string outline = sreader.ReadLine(); if (string.IsNullOrEmpty(outline) && sreader.EndOfStream) { Thread.Sleep(1000); } else { string input = outline; Guid kernelOutputId = Guid.Empty; if (mineContext.KernelOutput != null) { kernelOutputId = mineContext.KernelOutput.GetId(); } // 前译 Instance.ServerContext.KernelOutputTranslaterSet.Translate(kernelOutputId, ref input, isPre: true); Instance.ServerContext.KernelOutputSet.Pick(ref input, mineContext); var kernelOutputKeywords = Instance.KernelOutputKeywordSet.GetKeywords(mineContext.KernelOutput.GetId()); if (kernelOutputKeywords != null && kernelOutputKeywords.Count != 0) { foreach (var keyword in kernelOutputKeywords) { if (input.Contains(keyword.Keyword)) { if (keyword.MessageType.TryParse(out LocalMessageType messageType)) { string content = input; if (!string.IsNullOrEmpty(keyword.Description)) { content += $" 大意:{keyword.Description}"; } VirtualRoot.LocalMessage(LocalMessageChannel.Kernel, nameof(MinerProcess), messageType, content, OutEnum.None, toConsole: false); } } } } if (isWriteToConsole) { if (!string.IsNullOrEmpty(input)) { Write.UserLine(input, ConsoleColor.White); } } } } } catch (Exception e) { Logger.ErrorDebugLine(e); } finally { sreader?.Close(); sreader?.Dispose(); } Write.UserWarn("内核表演结束"); } if (_kernelProcess != null) { lock (_kernelProcessLocker) { if (_kernelProcess != null) { _kernelProcess.Dispose(); _kernelProcess = null; } } } }, TaskCreationOptions.LongRunning); }
private static void ReadPrintLoopLogFileAsync(IMineContext mineContext, bool isWriteToConsole) { Task.Factory.StartNew(() => { bool isLogFileCreated = true; int n = 0; while (!File.Exists(mineContext.LogFileFullName)) { if (n >= 20) { // 20秒钟都没有建立日志文件,不可能 isLogFileCreated = false; Write.UserFail("呃!意外,竟然20秒钟未产生内核输出。常见原因:1.挖矿内核被杀毒软件删除; 2.没有磁盘空间了; 3.反馈给开发人员"); break; } Thread.Sleep(1000); if (n == 0) { Write.UserInfo("等待内核出场"); } if (mineContext != Instance.CurrentMineContext) { Write.UserWarn("结束内核输出等待。"); isLogFileCreated = false; break; } n++; } if (isLogFileCreated) { StreamReader sreader = null; try { sreader = new StreamReader(File.Open(mineContext.LogFileFullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default); while (mineContext == Instance.CurrentMineContext) { string outline = sreader.ReadLine(); if (string.IsNullOrEmpty(outline) && sreader.EndOfStream) { Thread.Sleep(1000); } else { string input = outline; Guid kernelOutputId = Guid.Empty; if (mineContext.KernelOutput != null) { kernelOutputId = mineContext.KernelOutput.GetId(); } Instance.KernelOutputFilterSet.Filter(kernelOutputId, ref input); ConsoleColor color = ConsoleColor.White; // 前译 Instance.KernelOutputTranslaterSet.Translate(kernelOutputId, ref input, ref color, isPre: true); // 使用Claymore挖其非ETH币种时它也打印ETH,所以这里需要纠正它 if ("Claymore".Equals(mineContext.Kernel.Code, StringComparison.OrdinalIgnoreCase)) { if (mineContext.MainCoin.Code != "ETH" && input.Contains("ETH")) { input = input.Replace("ETH", mineContext.MainCoin.Code); } } Instance.KernelOutputSet.Pick(ref input, mineContext); if (isWriteToConsole) { if (!string.IsNullOrEmpty(input)) { Write.UserLine(input, ConsoleColor.White); } } } } } catch (Exception e) { Logger.ErrorDebugLine(e); } finally { sreader?.Close(); sreader?.Dispose(); } Write.UserWarn("内核表演结束"); } if (_kernelProcess != null) { lock (_kernelProcessLocker) { if (_kernelProcess != null) { _kernelProcess.Dispose(); _kernelProcess = null; } } } }, TaskCreationOptions.LongRunning); }
private static void ThisLocalMessage(string provider, LocalMessageType messageType, string content, OutEnum outEnum, bool toConsole) { switch (outEnum) { case OutEnum.None: break; case OutEnum.Info: Out.ShowInfo(content); break; case OutEnum.Warn: Out.ShowWarn(content, delaySeconds: 4); break; case OutEnum.Error: Out.ShowError(content, delaySeconds: 4); break; case OutEnum.Success: Out.ShowSuccess(content); break; case OutEnum.Auto: switch (messageType) { case LocalMessageType.Info: Out.ShowInfo(content); break; case LocalMessageType.Warn: Out.ShowWarn(content, delaySeconds: 4); break; case LocalMessageType.Error: Out.ShowError(content, delaySeconds: 4); break; default: break; } break; default: break; } if (toConsole) { switch (messageType) { case LocalMessageType.Info: Write.UserInfo(content); break; case LocalMessageType.Warn: Write.UserWarn(content); break; case LocalMessageType.Error: Write.UserError(content); break; default: break; } } LocalMessages.Add(LocalMessageChannel.This.GetName(), provider, messageType.GetName(), content); }
public void ShowWarn(string message, string header = "警告", int autoHideSeconds = 0, bool toConsole = false) { Write.UserWarn(message); }
private void DoInit(bool isWork, Action callback) { this.ServerAppSettingSet = new ServerAppSettingSet(this); this.CalcConfigSet = new CalcConfigSet(this); ServerContextInit(isWork); this.GpuProfileSet = new GpuProfileSet(this); 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.NTMinerWalletSet = new NTMinerWalletSet(this); this.OverClockDataSet = new OverClockDataSet(this); this.ColumnsShowSet = new ColumnsShowSet(this); // 作业和在群控客户端管理作业时 IsJsonLocal = isWork || VirtualRoot.IsMinerStudio; this._minerProfile = new MinerProfile(this); // 这几个注册表内部区分挖矿端和群控客户端 NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName); NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args)); NTMinerRegistry.SetCurrentVersion(MainAssemblyInfo.CurrentVersion.ToString()); NTMinerRegistry.SetCurrentVersionTag(MainAssemblyInfo.CurrentVersionTag); if (VirtualRoot.IsMinerClient) { OfficialServer.GetTimeAsync((remoteTime) => { if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Timestamp.DesyncSeconds) { Logger.OkDebugLine("时间同步"); } else { Write.UserWarn($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}"); } }); Report.Init(); Link(); // 当显卡温度变更时守卫温度防线 TempGruarder.Instance.Init(this); // 因为这里耗时500毫秒左右 Task.Factory.StartNew(() => { Windows.Error.DisableWindowsErrorUI(); if (MinerProfile.IsAutoDisableWindowsFirewall) { Windows.Firewall.DisableFirewall(); } Windows.UAC.DisableUAC(); Windows.WAU.DisableWAUAsync(); Windows.Defender.DisableAntiSpyware(); Windows.Power.PowerCfgOff(); Windows.BcdEdit.IgnoreAllFailures(); }); } callback?.Invoke(); }