public static void CreateProcessAsync(IMineContext mineContext)
            {
                Task.Factory.StartNew(() => {
                    lock (_locker) {
                        try {
                            Write.UserInfo("清理内核进程");
#if DEBUG
                            VirtualRoot.Stopwatch.Restart();
#endif
                            // 清理除当前外的Temp/Kernel
                            Cleaner.Clear();
#if DEBUG
                            Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(MinerProcess)}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]");
#endif
                            Write.UserOk("内核进程清理完毕");
                            Thread.Sleep(1000);
                            Write.UserInfo($"解压内核包{mineContext.Kernel.Package}");
                            // 解压内核包
                            if (!mineContext.Kernel.ExtractPackage())
                            {
                                VirtualRoot.Happened(new StartingMineFailedEvent("内核解压失败,请卸载内核重试。"));
                            }
                            else
                            {
                                Write.UserOk("内核包解压成功");
                            }

                            // 执行文件书写器
                            mineContext.ExecuteFileWriters();

                            Write.UserInfo("总成命令");
                            // 组装命令
                            BuildCmdLine(mineContext, out string kernelExeFileFullName, out string arguments);
                            bool isLogFile = arguments.Contains("{logfile}");
                            // 这是不应该发生的,如果发生很可能是填写命令的时候拼写错误了
                            if (!File.Exists(kernelExeFileFullName))
                            {
                                Write.UserError(kernelExeFileFullName + "文件不存在,可能是小编拼写错误导致,请QQ群联系小编。");
                            }
                            if (isLogFile)
                            {
                                Logger.InfoDebugLine("创建日志文件型进程");
                                // 如果内核支持日志文件
                                // 推迟打印cmdLine,因为{logfile}变量尚未求值
                                CreateLogfileProcess(mineContext, kernelExeFileFullName, arguments);
                            }
                            else
                            {
                                Logger.InfoDebugLine("创建管道型进程");
                                // 如果内核不支持日志文件
                                CreatePipProcess(mineContext, kernelExeFileFullName, arguments);
                            }
                            VirtualRoot.Happened(new MineStartedEvent(mineContext));
                        }
                        catch (Exception e) {
                            Logger.ErrorDebugLine(e);
                            Write.UserFail("挖矿内核启动失败,请联系开发人员解决");
                        }
                    }
                });
            }
Exemplo n.º 2
0
        public void Start()
        {
            OfficialServer.GetTimeAsync((remoteTime) => {
                if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Timestamp.DesyncSeconds)
                {
                    Logger.OkDebugLine("时间同步");
                }
                else
                {
                    Logger.WarnDebugLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}");
                }
            });

            Report.Init(this);

            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount = 0;
            DateTime shareOn    = DateTime.Now;
            VirtualRoot.On <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0,应用超频,启动NoDevFee,启动DevConsole,清理除当前外的Temp/Kernel", LogEnum.DevConsole,
                                              action: message => {
                // 将无份额内核重启份额计数置0
                shareCount = 0;
                shareOn    = DateTime.Now;
                Task.Factory.StartNew(() => {
                    try {
                        if (GpuProfileSet.Instance.IsOverClockEnabled(message.MineContext.MainCoin.GetId()))
                        {
                            VirtualRoot.Execute(new CoinOverClockCommand(message.MineContext.MainCoin.GetId()));
                        }
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e.Message, e);
                    }
                });
                StartNoDevFeeAsync();
                // 清理除当前外的Temp/Kernel
                Cleaner.CleanKernels();
            });
            #endregion
            #region 每10秒钟检查是否需要重启
            VirtualRoot.On <Per10SecondEvent>("每10秒钟检查是否需要重启", LogEnum.None,
                                              action: message => {
                #region 重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalHours > MinerProfile.PeriodicRestartComputerHours)
                        {
                            Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启电脑");
                            Windows.Power.Restart();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e.Message, e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel)
                    {
                        if ((DateTime.Now - CurrentMineContext.CreatedOn).TotalHours > MinerProfile.PeriodicRestartKernelHours)
                        {
                            Logger.WarnWriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启内核");
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e.Message, e);
                }
                #endregion

                #region 收益没有增加重启内核
                try {
                    if (IsMining && MinerProfile.IsNoShareRestartKernel)
                    {
                        if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes)
                        {
                            if (this.CurrentMineContext.MainCoin != null)
                            {
                                ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId());
                                int totalShare           = mainCoinShare.TotalShareCount;
                                if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                                {
                                    ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                    totalShare += dualCoinShare.TotalShareCount;
                                }
                                if (shareCount == totalShare)
                                {
                                    Logger.WarnWriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核");
                                    RestartMine();
                                }
                                else
                                {
                                    shareCount = totalShare;
                                    shareOn    = DateTime.Now;
                                }
                            }