Example #1
0
            public static void CreateProcessAsync(IMineContext mineContext)
            {
                Task.Factory.StartNew(() => {
                    lock (_locker) {
                        try {
#if DEBUG
                            Write.Stopwatch.Restart();
#endif
                            // 清理除当前外的Temp/Kernel
                            Cleaner.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());
                                DelegateHandler <CoinOverClockDoneEvent> callback = null;
                                callback = VirtualRoot.On <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole,
                                                                                   message => {
                                    if (mineContext != Instance.CurrentMineContext)
                                    {
                                        VirtualRoot.UnPath(callback);
                                    }
                                    else if (message.CmdId == cmd.Id)
                                    {
                                        VirtualRoot.UnPath(callback);
                                        Continue(mineContext);
                                    }
                                });
                                VirtualRoot.Execute(cmd);
                            }
                            else
                            {
                                Continue(mineContext);
                            }
                        }
                        catch (Exception e) {
                            Logger.ErrorDebugLine(e);
                            Write.UserFail("挖矿内核启动失败,请联系开发人员解决");
                        }
                    }
                });
            }
            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("挖矿内核启动失败,请联系开发人员解决");
                        }
                    }
                });
            }