Beispiel #1
0
        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.WorkerEventSet   = new WorkerEventSet(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.OverClockDataSet = new OverClockDataSet(this);
            this.ColumnsShowSet   = new ColumnsShowSet(this);
            IsJsonLocal           = isWork;
            this._minerProfile    = new MinerProfile(this);

            // 这几个注册表内部区分挖矿端和群控客户端
            NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName);
            NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args));
            NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString());
            NTMinerRegistry.SetCurrentVersionTag(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(this);
                Link();
                // 当显卡温度变更时守卫温度防线
                TempGruarder.Instance.Init(this);
                // 因为这里耗时500毫秒左右
                Task.Factory.StartNew(() => {
                    Windows.Error.DisableWindowsErrorUI();
                    if (NTMinerRegistry.GetIsAutoDisableWindowsFirewall())
                    {
                        Windows.Firewall.DisableFirewall();
                    }
                    Windows.UAC.DisableUAC();
                    Windows.WAU.DisableWAUAsync();
                    Windows.Defender.DisableAntiSpyware();
                    Windows.Power.PowerCfgOff();
                    Windows.BcdEdit.IgnoreAllFailures();
                });
            }

            callback?.Invoke();
        }
Beispiel #2
0
        private void DoInit(bool isWork, Action callback)
        {
            GpuProfileSet.Instance.Register(this);
            this.ServerAppSettingSet = new ServerAppSettingSet(this);
            this.CalcConfigSet       = new CalcConfigSet(this);

            ServerContextInit(isWork);

            this.WorkerEventSet   = new WorkerEventSet(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.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(VirtualRoot.AppFileFullName);
            NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args));
            NTMinerRegistry.SetCurrentVersion(CurrentVersion.ToString());
            NTMinerRegistry.SetCurrentVersionTag(CurrentVersionTag);

            callback?.Invoke();
        }
Beispiel #3
0
        private void DoInit(Action callback)
        {
            this.ReporterDataProvider = new ReportDataProvider();
            this.CalcConfigSet        = new CalcConfigSet(this);
            this.ServerContext        = new ServerContext();
            this.GpuProfileSet        = new GpuProfileSet(this);
            this.KernelProfileSet     = new KernelProfileSet();
            this.GpusSpeed            = new GpusSpeed(this);
            this.CoinShareSet         = new CoinShareSet(this);
            this.OverClockDataSet     = new OverClockDataSet(this);
            this.ServerMessageSet     = new ServerMessageSet(HomePath.LocalDbFileFullName, isServer: false);
            this._minerProfile        = new MinerProfile(this);
            var cpuPackage = new CpuPackage(_minerProfile);

            this.CpuPackage = cpuPackage;

            // 这几个注册表内部区分挖矿端和群控客户端
            NTMinerRegistry.SetLocation(ClientAppType.AppType, VirtualRoot.AppFileFullName);
            NTMinerRegistry.SetArguments(ClientAppType.AppType, string.Join(" ", CommandLineArgs.Args));
            NTMinerRegistry.SetCurrentVersion(ClientAppType.AppType, EntryAssemblyInfo.CurrentVersionStr);
            NTMinerRegistry.SetCurrentVersionTag(ClientAppType.AppType, EntryAssemblyInfo.CurrentVersionTag);

            if (ClientAppType.IsMinerClient)
            {
                Link();
                // 当显卡温度变更时守卫温度防线
                TempGruarder.Instance.Init(this);
            }

            callback?.Invoke();
            cpuPackage.Init();
        }
Beispiel #4
0
        private void DoInit(bool isWork, Action callback)
        {
            IsJsonServer = !DevMode.IsDevMode || VirtualRoot.IsMinerStudio || isWork;
            this.ReporterDataProvider = new ReportDataProvider();
            this.ServerAppSettingSet  = new ServerAppSettingSet();
            this.CalcConfigSet        = new CalcConfigSet(this);
            this.ServerContext        = new ServerContext();
            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.MinerGroupSet    = new MinerGroupSet();
            this.NTMinerWalletSet = new NTMinerWalletSet();
            this.OverClockDataSet = new OverClockDataSet(this);
            this.ColumnsShowSet   = new ColumnsShowSet();
            this.ServerMessageSet = new ServerMessageSet(EntryAssemblyInfo.LocalDbFileFullName, isServer: false);
            // 作业和在群控客户端管理作业时
            IsJsonLocal        = isWork || VirtualRoot.IsMinerStudio;
            this._minerProfile = new MinerProfile(this);
            var cpuPackage = new CpuPackage(_minerProfile);

            this.CpuPackage = cpuPackage;

            // 这几个注册表内部区分挖矿端和群控客户端
            NTMinerRegistry.SetLocation(VirtualRoot.AppFileFullName);
            NTMinerRegistry.SetArguments(string.Join(" ", CommandLineArgs.Args));
            NTMinerRegistry.SetCurrentVersion(EntryAssemblyInfo.CurrentVersion.ToString());
            NTMinerRegistry.SetCurrentVersionTag(EntryAssemblyInfo.CurrentVersionTag);

            if (VirtualRoot.IsMinerClient)
            {
                VirtualRoot.LocalIpSet.InitOnece();
                Link();
                // 当显卡温度变更时守卫温度防线
                TempGruarder.Instance.Init(this);
                // 因为这里耗时500毫秒左右
                Task.Factory.StartNew(() => {
                    Windows.Error.DisableWindowsErrorUI();
                    Windows.UAC.DisableUAC();
                    Windows.WAU.DisableWAUAsync();
                    Windows.Defender.DisableAntiSpyware();
                    Windows.Power.PowerCfgOff();
                    Windows.BcdEdit.IgnoreAllFailures();
                });
            }

            callback?.Invoke();
            cpuPackage.Init();
        }
Beispiel #5
0
        private void DoInit(bool isWork, Action callback)
        {
            IsJsonServer = !DevMode.IsDevMode || ClientAppType.IsMinerStudio || isWork;
            this.ReporterDataProvider = new ReportDataProvider();

            this.CalcConfigSet    = new CalcConfigSet(this);
            this.ServerContext    = new ServerContext();
            this.GpuProfileSet    = new GpuProfileSet(this);
            this.KernelProfileSet = new KernelProfileSet();
            this.GpusSpeed        = new GpusSpeed(this);
            this.CoinShareSet     = new CoinShareSet(this);
            this.OverClockDataSet = new OverClockDataSet(this);
            this.ServerMessageSet = new ServerMessageSet(HomePath.LocalDbFileFullName, isServer: false);
            // 作业和在群控客户端管理作业时
            IsJsonLocal        = isWork || ClientAppType.IsMinerStudio;
            this._minerProfile = new MinerProfile(this);
            var cpuPackage = new CpuPackage(_minerProfile);

            this.CpuPackage = cpuPackage;

            // 这几个注册表内部区分挖矿端和群控客户端
            NTMinerRegistry.SetLocation(ClientAppType.AppType, VirtualRoot.AppFileFullName);
            NTMinerRegistry.SetArguments(ClientAppType.AppType, string.Join(" ", CommandLineArgs.Args));
            NTMinerRegistry.SetCurrentVersion(ClientAppType.AppType, EntryAssemblyInfo.CurrentVersionStr);
            NTMinerRegistry.SetCurrentVersionTag(ClientAppType.AppType, EntryAssemblyInfo.CurrentVersionTag);

            if (ClientAppType.IsMinerClient)
            {
                VirtualRoot.LocalIpSet.InitOnece();
                Link();
                // 当显卡温度变更时守卫温度防线
                TempGruarder.Instance.Init(this);
                // 因为这里耗时500毫秒左右
                Task.Factory.StartNew(() => {
                    Error.DisableWindowsErrorUI();
                    Power.PowerCfgOff();
                    BcdEdit.IgnoreAllFailures();
                });
            }

            callback?.Invoke();
            cpuPackage.Init();
        }
Beispiel #6
0
        private void Link()
        {
            VirtualRoot.BuildCmdPath <RegCmdHereCommand>(path: message => {
                try {
                    Cmd.RegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "添加windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "添加windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.BuildCmdPath <UnRegCmdHereCommand>(path: message => {
                try {
                    Cmd.UnRegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "移除windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "移除windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.BuildEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None,
                                                         path: message => {
                Power.PreventSleep(MinerProfile.IsPreventDisplaySleep);
            }, location: this.GetType());
            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount           = 0;
            DateTime shareOn              = DateTime.Now;
            DateTime highSpeedOn          = DateTime.Now;
            DateTime overClockHighSpeedOn = DateTime.Now;
            VirtualRoot.BuildEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole,
                                                          path: message => {
                // 将无份额内核重启份额计数置0
                shareCount           = 0;
                highSpeedOn          = DateTime.Now;
                overClockHighSpeedOn = DateTime.Now;
                if (!message.MineContext.IsRestart)
                {
                    // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑
                    shareOn = DateTime.Now;
                }
            }, location: this.GetType());
            #endregion
            #region 每20秒钟检查是否需要重启
            VirtualRoot.BuildEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None,
                                                          path: message => {
                #region 低算力重启电脑
                if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue)
                {
                    var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId);
                    if (coinProfile.IsLowSpeedRestartComputer && coinProfile.LowSpeed != 0 && coinProfile.LowSpeedRestartComputerMinutes > 0)
                    {
                        IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId);
                        if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) >= message.BornOn)
                        {
                            if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.LowSpeed) >= coinProfile.LowSpeed)
                            {
                                highSpeedOn = message.BornOn;
                            }
                        }
                        if (highSpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) < message.BornOn)
                        {
                            string coinCode = string.Empty;
                            if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin))
                            {
                                coinCode = coin.Code;
                            }
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedRestartComputerMinutes}分钟低于{coinProfile.LowSpeed}重启电脑", toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;
                        }
                    }
                    else
                    {
                        highSpeedOn = message.BornOn;
                    }
                }
                #endregion

                #region 低算力重新应用超频
                if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue)
                {
                    var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId);
                    if (coinProfile.IsLowSpeedReOverClock && coinProfile.OverClockLowSpeed != 0 && coinProfile.LowSpeedReOverClockMinutes > 0)
                    {
                        IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId);
                        if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) >= message.BornOn)
                        {
                            if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.OverClockLowSpeed) >= coinProfile.OverClockLowSpeed)
                            {
                                overClockHighSpeedOn = message.BornOn;
                            }
                        }
                        if (overClockHighSpeedOn.AddMinutes(coinProfile.LowSpeedReOverClockMinutes) < message.BornOn)
                        {
                            string coinCode = string.Empty;
                            if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin))
                            {
                                coinCode = coin.Code;
                            }
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedReOverClockMinutes}分钟低于{coinProfile.OverClockLowSpeed}重新应用超频", toConsole: true);
                            VirtualRoot.Execute(new CoinOverClockCommand(MinerProfile.CoinId));
                        }
                    }
                    else
                    {
                        overClockHighSpeedOn = message.BornOn;
                    }
                }
                #endregion

                #region 周期重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes)
                        {
                            string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑";
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue)
                    {
                        DateTime dt = GetKernelRestartBaseOnTime();
                        if ((DateTime.Now - dt).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true);
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 无份额重启内核
                try {
                    if (IsMining && this.LockedMineContext.MainCoin != null)
                    {
                        int totalShare       = 0;
                        bool restartComputer = MinerProfile.NoShareRestartComputerMinutes > 0 && MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                        bool restartKernel   = MinerProfile.NoShareRestartKernelMinutes > 0 && MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                        if (restartComputer || restartKernel)
                        {
                            ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId());
                            totalShare = mainCoinShare.TotalShareCount;
                            if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                            {
                                ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                totalShare += dualCoinShare.TotalShareCount;
                            }
                            // 如果份额没有增加
                            if (shareCount == totalShare)
                            {
                                // 重启电脑,基于MineStartedOn
                                bool isRestartComputerMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                                if (restartComputer && isRestartComputerMinutes)
                                {
                                    if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                                    {
                                        VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                                    }
                                    string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑";
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                                    VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                                    return;    // 退出
                                }
                                // 重启内核,如果MineRestartedOn不是DateTime.MineValue则基于MineRestartedOn
                                DateTime dt = GetKernelRestartBaseOnTime();
                                bool isRestartKernelMinutes = (DateTime.Now - dt).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                                if (restartKernel && isRestartKernelMinutes)
                                {
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true);
                                    RestartMine();
                                    return;    // 退出
                                }
                            }
                            if (totalShare > shareCount)
                            {
                                shareCount = totalShare;
                                shareOn    = DateTime.Now;
                            }
                        }
        public IMineContext CreateMineContext()
        {
            if (!GetProfileData(out ICoin mainCoin, out ICoinProfile mainCoinProfile, out IPool mainCoinPool, out ICoinKernel mainCoinKernel, out IKernel kernel,
                                out IKernelInput kernelInput, out IKernelOutput kernelOutput, out string _))
            {
                return(null);
            }
            if (!kernel.IsSupported(mainCoin))
            {
                return(null);
            }
            ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId);
            string             poolKernelArgs    = string.Empty;
            IPoolKernel        poolKernel        = ServerContext.PoolKernelSet.AsEnumerable().FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId());

            if (poolKernel != null)
            {
                poolKernelArgs = poolKernel.Args;
            }
            string kernelArgs     = kernelInput.Args;
            string coinKernelArgs = mainCoinKernel.Args;
            string customArgs     = coinKernelProfile.CustomArgs ?? string.Empty;
            var    parameters     = new Dictionary <string, string>();
            var    fileWriters    = new Dictionary <Guid, string>();
            var    fragments      = new Dictionary <Guid, string>();

            parameters.Add(NTKeyword.MainCoinParameterName, mainCoin.Code);
            string userName = string.Empty;
            string password = NTKeyword.PasswordDefaultValue;
            string wallet   = mainCoinProfile.Wallet;

            if (mainCoinPool.IsUserMode)
            {
                IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId());
                password = poolProfile.Password;
                if (string.IsNullOrEmpty(password))
                {
                    password = NTKeyword.PasswordDefaultValue;
                }
                userName = poolProfile.UserName;
                wallet   = poolProfile.UserName;
            }
            else
            {
                userName = wallet;
            }
            parameters.Add(NTKeyword.UserNameParameterName, userName);
            parameters.Add(NTKeyword.PasswordParameterName, password);
            parameters.Add(NTKeyword.WalletParameterName, wallet);
            parameters.Add(NTKeyword.HostParameterName, mainCoinPool.GetHost());
            parameters.Add(NTKeyword.PortParameterName, mainCoinPool.GetPort().ToString());
            parameters.Add(NTKeyword.PoolParameterName, mainCoinPool.Server);
            string minerName = $"{mainCoinPool.MinerNamePrefix}{this.MinerProfile.MinerName}{mainCoinPool.MinerNamePostfix}";

            parameters.Add(NTKeyword.WorkerParameterName, minerName);
            if (mainCoinKernel.IsSupportPool1 && !mainCoinPool.NoPool1)
            {
                parameters.Add(NTKeyword.Worker1ParameterName, minerName);
                if (ServerContext.PoolSet.TryGetPool(mainCoinProfile.PoolId1, out IPool mainCoinPool1))
                {
                    parameters.Add(NTKeyword.Host1ParameterName, mainCoinPool1.GetHost());
                    parameters.Add(NTKeyword.Port1ParameterName, mainCoinPool1.GetPort().ToString());
                    parameters.Add(NTKeyword.Pool1ParameterName, mainCoinPool1.Server);
                    if (mainCoinPool1.IsUserMode)
                    {
                        IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId());
                        string       password1    = poolProfile1.Password;
                        if (string.IsNullOrEmpty(password1))
                        {
                            password1 = NTKeyword.PasswordDefaultValue;
                        }
                        parameters.Add(NTKeyword.UserName1ParameterName, poolProfile1.UserName);
                        parameters.Add(NTKeyword.Password1ParameterName, password1);
                    }
                    else
                    {
                        parameters.Add(NTKeyword.Wallet1ParameterName, mainCoinProfile.Wallet);
                    }
                }
            }
            string devicesArgs = GetDevicesArgs(kernelInput);

            // 这里不要考虑{logfile},{logfile}往后推迟
            if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine)
            {
                Guid dualCoinGroupId = mainCoinKernel.DualCoinGroupId;
                if (dualCoinGroupId != Guid.Empty)
                {
                    if (this.ServerContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                    {
                        ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId());
                        if (ServerContext.PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                        {
                            string dualUserName = string.Empty;
                            string dualPassword = NTKeyword.PasswordDefaultValue;
                            string dualWallet   = dualCoinProfile.DualCoinWallet;
                            parameters.Add(NTKeyword.DualCoinParameterName, dualCoin.Code);
                            if (dualCoinPool.IsUserMode)
                            {
                                IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId());
                                dualPassword = dualPoolProfile.Password;
                                if (string.IsNullOrEmpty(dualPassword))
                                {
                                    dualPassword = NTKeyword.PasswordDefaultValue;
                                }
                                dualUserName = dualPoolProfile.UserName;
                                dualWallet   = dualPoolProfile.UserName;
                            }
                            else
                            {
                                dualUserName = dualWallet;
                            }
                            parameters.Add(NTKeyword.DualUserNameParameterName, dualUserName);
                            parameters.Add(NTKeyword.DualPasswordParameterName, dualPassword);
                            parameters.Add(NTKeyword.DualWalletParameterName, dualWallet);
                            parameters.Add(NTKeyword.DualHostParameterName, dualCoinPool.GetHost());
                            parameters.Add(NTKeyword.DualPortParameterName, dualCoinPool.GetPort().ToString());
                            parameters.Add(NTKeyword.DualPoolParameterName, dualCoinPool.Server);

                            kernelArgs = mainCoinKernel.DualFullArgs;
                            AssembleArgs(parameters, ref kernelArgs, isDual: true);
                            AssembleArgs(parameters, ref poolKernelArgs, isDual: true);
                            AssembleArgs(parameters, ref customArgs, isDual: true);

                            string dualWeightArg;
                            if (!string.IsNullOrEmpty(kernelInput.DualWeightArg))
                            {
                                if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight)
                                {
                                    dualWeightArg = string.Empty;
                                }
                                else
                                {
                                    dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight).ToString()}";
                                }
                            }
                            else
                            {
                                dualWeightArg = string.Empty;
                            }
                            StringBuilder dualSb = new StringBuilder();
                            dualSb.Append(kernelArgs);
                            if (!string.IsNullOrEmpty(dualWeightArg))
                            {
                                dualSb.Append(" ").Append(dualWeightArg);
                            }
                            if (!string.IsNullOrEmpty(poolKernelArgs))
                            {
                                dualSb.Append(" ").Append(poolKernelArgs);
                            }
                            BuildFragments(ServerContext, mainCoinKernel, parameters, out fileWriters, out fragments);
                            foreach (var fragment in fragments.Values)
                            {
                                dualSb.Append(" ").Append(fragment);
                            }
                            if (!string.IsNullOrEmpty(customArgs))
                            {
                                dualSb.Append(" ").Append(customArgs);
                            }
                            if (!string.IsNullOrEmpty(devicesArgs))
                            {
                                dualSb.Append(" ").Append(devicesArgs);
                            }

                            // 注意:这里退出
                            return(new DualMineContext(
                                       new MineContext(
                                           this.MinerProfile.MinerName,
                                           mainCoin,
                                           mainCoinPool,
                                           kernel,
                                           kernelInput,
                                           kernelOutput,
                                           mainCoinKernel,
                                           wallet,
                                           dualSb.ToString(),
                                           parameters,
                                           fragments,
                                           fileWriters,
                                           GpuSet.GetUseDevices()),
                                       dualCoin,
                                       dualCoinPool,
                                       dualWallet,
                                       coinKernelProfile.DualCoinWeight,
                                       parameters,
                                       fragments,
                                       fileWriters,
                                       GpuSet.GetUseDevices()));
                        }
                    }
                }
            }
            AssembleArgs(parameters, ref kernelArgs, isDual: false);
            AssembleArgs(parameters, ref coinKernelArgs, isDual: false);
            AssembleArgs(parameters, ref poolKernelArgs, isDual: false);
            AssembleArgs(parameters, ref customArgs, isDual: false);
            StringBuilder sb = new StringBuilder();

            sb.Append(kernelArgs);
            if (!string.IsNullOrEmpty(coinKernelArgs))
            {
                sb.Append(" ").Append(coinKernelArgs);
            }
            if (!string.IsNullOrEmpty(poolKernelArgs))
            {
                sb.Append(" ").Append(poolKernelArgs);
            }
            if (!string.IsNullOrEmpty(devicesArgs))
            {
                sb.Append(" ").Append(devicesArgs);
            }
            BuildFragments(ServerContext, mainCoinKernel, parameters, out fileWriters, out fragments);
            foreach (var fragment in fragments.Values)
            {
                sb.Append(" ").Append(fragment);
            }
            if (!string.IsNullOrEmpty(customArgs))
            {
                sb.Append(" ").Append(customArgs);
            }

            return(new MineContext(
                       this.MinerProfile.MinerName,
                       mainCoin,
                       mainCoinPool,
                       kernel,
                       kernelInput,
                       kernelOutput,
                       mainCoinKernel,
                       wallet,
                       sb.ToString(),
                       parameters,
                       fragments,
                       fileWriters,
                       GpuSet.GetUseDevices()));
        }
Beispiel #8
0
        public string BuildAssembleArgs(out Dictionary <string, string> parameters, out Dictionary <Guid, string> fileWriters, out Dictionary <Guid, string> fragments)
        {
            parameters  = new Dictionary <string, string>();
            fileWriters = new Dictionary <Guid, string>();
            fragments   = new Dictionary <Guid, string>();
            if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin))
            {
                return(string.Empty);
            }
            ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId());

            if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
            {
                return(string.Empty);
            }
            if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
            {
                return(string.Empty);
            }
            if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
            {
                return(string.Empty);
            }
            if (!kernel.IsSupported(mainCoin))
            {
                return(string.Empty);
            }
            if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput))
            {
                return(string.Empty);
            }
            ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
            string             poolKernelArgs    = string.Empty;
            IPoolKernel        poolKernel        = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId());

            if (poolKernel != null)
            {
                poolKernelArgs = poolKernel.Args;
            }
            string kernelArgs     = kernelInput.Args;
            string coinKernelArgs = coinKernel.Args;
            string customArgs     = coinKernelProfile.CustomArgs;

            parameters.Add("mainCoin", mainCoin.Code);
            if (mainCoinPool.IsUserMode)
            {
                IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId());
                string       password    = poolProfile.Password;
                if (string.IsNullOrEmpty(password))
                {
                    password = "******";
                }
                parameters.Add("userName", poolProfile.UserName);
                parameters.Add("password", password);
            }
            else
            {
                parameters.Add("wallet", coinProfile.Wallet);
            }
            parameters.Add("host", mainCoinPool.GetHost());
            parameters.Add("port", mainCoinPool.GetPort().ToString());
            parameters.Add("pool", mainCoinPool.Server);
            parameters.Add("worker", this.MinerProfile.MinerName);
            if (coinKernel.IsSupportPool1)
            {
                parameters.Add("worker1", this.MinerProfile.MinerName);
                if (PoolSet.TryGetPool(coinProfile.PoolId1, out IPool mainCoinPool1))
                {
                    parameters.Add("host1", mainCoinPool1.GetHost());
                    parameters.Add("port1", mainCoinPool1.GetPort().ToString());
                    parameters.Add("pool1", mainCoinPool1.Server);
                    if (mainCoinPool1.IsUserMode)
                    {
                        IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId());
                        string       password1    = poolProfile1.Password;
                        if (string.IsNullOrEmpty(password1))
                        {
                            password1 = "x";
                        }
                        parameters.Add("userName1", poolProfile1.UserName);
                        parameters.Add("password1", password1);
                    }
                    else
                    {
                        parameters.Add("wallet1", coinProfile.Wallet);
                    }
                }
            }
            // 这里不要考虑{logfile},{logfile}往后推迟
            if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine)
            {
                Guid dualCoinGroupId = coinKernel.DualCoinGroupId;
                if (dualCoinGroupId == Guid.Empty)
                {
                    dualCoinGroupId = kernelInput.DualCoinGroupId;
                }
                if (dualCoinGroupId != Guid.Empty)
                {
                    if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                    {
                        ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId());
                        if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                        {
                            IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId());
                            string       dualPassword    = dualPoolProfile.Password;
                            if (string.IsNullOrEmpty(dualPassword))
                            {
                                dualPassword = "******";
                            }
                            parameters.Add("dualCoin", dualCoin.Code);
                            parameters.Add("dualWallet", dualCoinProfile.DualCoinWallet);
                            parameters.Add("dualUserName", dualPoolProfile.UserName);
                            parameters.Add("dualPassword", dualPassword);
                            parameters.Add("dualHost", dualCoinPool.GetHost());
                            parameters.Add("dualPort", dualCoinPool.GetPort().ToString());
                            parameters.Add("dualPool", dualCoinPool.Server);

                            kernelArgs = kernelInput.DualFullArgs;
                            AssembleArgs(parameters, ref kernelArgs, isDual: true);
                            AssembleArgs(parameters, ref poolKernelArgs, isDual: true);
                            AssembleArgs(parameters, ref customArgs, isDual: true);

                            string dualWeightArg;
                            if (!string.IsNullOrEmpty(kernelInput.DualWeightArg))
                            {
                                if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight)
                                {
                                    dualWeightArg = string.Empty;
                                }
                                else
                                {
                                    dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}";
                                }
                            }
                            else
                            {
                                dualWeightArg = string.Empty;
                            }
                            StringBuilder dualSb = new StringBuilder();
                            dualSb.Append(kernelArgs);
                            if (!string.IsNullOrEmpty(dualWeightArg))
                            {
                                dualSb.Append(" ").Append(dualWeightArg);
                            }
                            if (!string.IsNullOrEmpty(poolKernelArgs))
                            {
                                dualSb.Append(" ").Append(poolKernelArgs);
                            }
                            BuildFragments(coinKernel, parameters, out fileWriters, out fragments);
                            foreach (var fragment in fragments.Values)
                            {
                                dualSb.Append(" ").Append(fragment);
                            }
                            if (!string.IsNullOrEmpty(customArgs))
                            {
                                dualSb.Append(" ").Append(customArgs);
                            }

                            // 注意:这里退出
                            return(dualSb.ToString());
                        }
                    }
                }
            }
            AssembleArgs(parameters, ref kernelArgs, isDual: false);
            AssembleArgs(parameters, ref coinKernelArgs, isDual: false);
            AssembleArgs(parameters, ref poolKernelArgs, isDual: false);
            AssembleArgs(parameters, ref customArgs, isDual: false);
            string devicesArgs = string.Empty;

            if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg))
            {
                List <int> useDevices = this.GpuSet.GetUseDevices();
                if (useDevices.Count != 0 && useDevices.Count != GpuSet.Count)
                {
                    string separator = kernelInput.DevicesSeparator;
                    if (kernelInput.DevicesSeparator == "space")
                    {
                        separator = " ";
                    }
                    if (string.IsNullOrEmpty(separator))
                    {
                        List <string> gpuIndexes = new List <string>();
                        foreach (var index in useDevices)
                        {
                            int i = index;
                            if (kernelInput.DeviceBaseIndex != 0)
                            {
                                i = index + kernelInput.DeviceBaseIndex;
                            }
                            if (i > 9)
                            {
                                gpuIndexes.Add(gpuIndexChars[i - 10]);
                            }
                            else
                            {
                                gpuIndexes.Add(i.ToString());
                            }
                        }
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes)}";
                    }
                    else
                    {
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, useDevices)}";
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(kernelArgs);
            if (!string.IsNullOrEmpty(coinKernelArgs))
            {
                sb.Append(" ").Append(coinKernelArgs);
            }
            if (!string.IsNullOrEmpty(poolKernelArgs))
            {
                sb.Append(" ").Append(poolKernelArgs);
            }
            if (!string.IsNullOrEmpty(devicesArgs))
            {
                sb.Append(" ").Append(devicesArgs);
            }
            BuildFragments(coinKernel, parameters, out fileWriters, out fragments);
            foreach (var fragment in fragments.Values)
            {
                sb.Append(" ").Append(fragment);
            }
            if (!string.IsNullOrEmpty(customArgs))
            {
                sb.Append(" ").Append(customArgs);
            }

            return(sb.ToString());
        }
        public string BuildAssembleArgs()
        {
            if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin))
            {
                return(string.Empty);
            }
            ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId());

            if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
            {
                return(string.Empty);
            }
            if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
            {
                return(string.Empty);
            }
            if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
            {
                return(string.Empty);
            }
            if (!kernel.IsSupported(mainCoin))
            {
                return(string.Empty);
            }
            if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput))
            {
                return(string.Empty);
            }
            ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
            string             wallet            = coinProfile.Wallet;
            string             pool           = mainCoinPool.Server;
            string             poolKernelArgs = string.Empty;
            IPoolKernel        poolKernel     = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId());

            if (poolKernel != null)
            {
                poolKernelArgs = poolKernel.Args;
            }
            IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId());
            string       userName    = poolProfile.UserName;
            string       password    = poolProfile.Password;

            if (string.IsNullOrEmpty(password))
            {
                password = "******";
            }
            string kernelArgs     = kernelInput.Args;
            string coinKernelArgs = coinKernel.Args;
            string customArgs     = coinKernelProfile.CustomArgs;
            var    argsDic        = new Dictionary <string, string> {
                { "mainCoin", mainCoin.Code },
                { "wallet", wallet },
                { "userName", userName },
                { "password", password },
                { "host", mainCoinPool.GetHost() },
                { "port", mainCoinPool.GetPort().ToString() },
                { "pool", pool },
                { "worker", this.MinerProfile.MinerName }
            };// 这里不要考虑{logfile},{logfile}往后推迟

            if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine)
            {
                Guid dualCoinGroupId = coinKernel.DualCoinGroupId;
                if (dualCoinGroupId == Guid.Empty)
                {
                    dualCoinGroupId = kernelInput.DualCoinGroupId;
                }
                if (dualCoinGroupId != Guid.Empty)
                {
                    if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                    {
                        ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId());
                        if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                        {
                            string       dualWallet      = dualCoinProfile.DualCoinWallet;
                            string       dualPool        = dualCoinPool.Server;
                            IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId());
                            string       dualUserName    = dualPoolProfile.UserName;
                            string       dualPassword    = dualPoolProfile.Password;
                            if (string.IsNullOrEmpty(dualPassword))
                            {
                                dualPassword = "******";
                            }
                            argsDic.Add("dualCoin", dualCoin.Code);
                            argsDic.Add("dualAlgo", dualCoin.Algo);
                            argsDic.Add("dualWallet", dualWallet);
                            argsDic.Add("dualUserName", dualUserName);
                            argsDic.Add("dualPassword", dualPassword);
                            argsDic.Add("dualHost", dualCoinPool.GetHost());
                            argsDic.Add("dualPort", dualCoinPool.GetPort().ToString());
                            argsDic.Add("dualPool", dualPool);

                            kernelArgs = kernelInput.DualFullArgs;
                            AssembleArgs(argsDic, ref kernelArgs, isDual: true);
                            AssembleArgs(argsDic, ref poolKernelArgs, isDual: true);
                            AssembleArgs(argsDic, ref customArgs, isDual: true);

                            string dualWeightArg;
                            if (!string.IsNullOrEmpty(kernelInput.DualWeightArg))
                            {
                                if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight)
                                {
                                    dualWeightArg = string.Empty;
                                }
                                else
                                {
                                    dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}";
                                }
                            }
                            else
                            {
                                dualWeightArg = string.Empty;
                            }

                            return($"{kernelArgs} {dualWeightArg} {poolKernelArgs} {customArgs}");
                        }
                    }
                }
            }
            AssembleArgs(argsDic, ref kernelArgs, isDual: false);
            AssembleArgs(argsDic, ref coinKernelArgs, isDual: false);
            AssembleArgs(argsDic, ref poolKernelArgs, isDual: false);
            AssembleArgs(argsDic, ref customArgs, isDual: false);
            string devicesArgs = string.Empty;

            if (!string.IsNullOrWhiteSpace(kernelInput.DevicesArg))
            {
                List <int> useDevices = GetUseDevices();
                if (useDevices.Count != 0 && useDevices.Count != GpuSet.Count)
                {
                    string separator = kernelInput.DevicesSeparator;
                    if (kernelInput.DevicesSeparator == "space")
                    {
                        separator = " ";
                    }
                    if (string.IsNullOrEmpty(separator))
                    {
                        List <string> gpuIndexes = new List <string>();
                        foreach (var index in useDevices)
                        {
                            int i = index;
                            if (kernelInput.DeviceBaseIndex != 0)
                            {
                                i = index + kernelInput.DeviceBaseIndex;
                            }
                            if (i > 9)
                            {
                                gpuIndexes.Add(gpuIndexChars[i - 10]);
                            }
                            else
                            {
                                gpuIndexes.Add(i.ToString());
                            }
                        }
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, gpuIndexes)}";
                    }
                    else
                    {
                        devicesArgs = $"{kernelInput.DevicesArg} {string.Join(separator, useDevices)}";
                    }
                }
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(kernelArgs);
            if (!string.IsNullOrEmpty(coinKernelArgs))
            {
                sb.Append(" ").Append(coinKernelArgs);
            }
            if (!string.IsNullOrEmpty(poolKernelArgs))
            {
                sb.Append(" ").Append(poolKernelArgs);
            }
            if (!string.IsNullOrEmpty(devicesArgs))
            {
                sb.Append(" ").Append(devicesArgs);
            }
            if (!string.IsNullOrEmpty(customArgs))
            {
                sb.Append(" ").Append(customArgs);
            }
            return(sb.ToString());
        }
Beispiel #10
0
        public string BuildAssembleArgs(out Dictionary <string, string> parameters, out Dictionary <Guid, string> fileWriters, out Dictionary <Guid, string> fragments)
        {
            parameters  = new Dictionary <string, string>();
            fileWriters = new Dictionary <Guid, string>();
            fragments   = new Dictionary <Guid, string>();
            if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin))
            {
                return(string.Empty);
            }
            ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId());

            if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
            {
                return(string.Empty);
            }
            if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
            {
                return(string.Empty);
            }
            if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
            {
                return(string.Empty);
            }
            if (!kernel.IsSupported(mainCoin))
            {
                return(string.Empty);
            }
            if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput))
            {
                return(string.Empty);
            }
            ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
            string             poolKernelArgs    = string.Empty;
            IPoolKernel        poolKernel        = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId());

            if (poolKernel != null)
            {
                poolKernelArgs = poolKernel.Args;
            }
            string kernelArgs     = kernelInput.Args;
            string coinKernelArgs = coinKernel.Args;
            string customArgs     = coinKernelProfile.CustomArgs ?? string.Empty;

            parameters.Add(Consts.MainCoinParameterName, mainCoin.Code);
            if (mainCoinPool.IsUserMode)
            {
                IPoolProfile poolProfile = MinerProfile.GetPoolProfile(mainCoinPool.GetId());
                string       password    = poolProfile.Password;
                if (string.IsNullOrEmpty(password))
                {
                    password = Consts.PasswordDefaultValue;
                }
                parameters.Add(Consts.UserNameParameterName, poolProfile.UserName);
                parameters.Add(Consts.PasswordParameterName, password);
                parameters.Add(Consts.WalletParameterName, poolProfile.UserName);
            }
            else
            {
                parameters.Add(Consts.WalletParameterName, coinProfile.Wallet);
            }
            parameters.Add(Consts.HostParameterName, mainCoinPool.GetHost());
            parameters.Add(Consts.PortParameterName, mainCoinPool.GetPort().ToString());
            parameters.Add(Consts.PoolParameterName, mainCoinPool.Server);
            string minerName = $"{mainCoinPool.MinerNamePrefix}{this.MinerProfile.MinerName}{mainCoinPool.MinerNamePostfix}";

            parameters.Add(Consts.WorkerParameterName, minerName);
            if (coinKernel.IsSupportPool1 && !mainCoinPool.NoPool1)
            {
                parameters.Add(Consts.Worker1ParameterName, minerName);
                if (PoolSet.TryGetPool(coinProfile.PoolId1, out IPool mainCoinPool1))
                {
                    parameters.Add(Consts.Host1ParameterName, mainCoinPool1.GetHost());
                    parameters.Add(Consts.Port1ParameterName, mainCoinPool1.GetPort().ToString());
                    parameters.Add(Consts.Pool1ParameterName, mainCoinPool1.Server);
                    if (mainCoinPool1.IsUserMode)
                    {
                        IPoolProfile poolProfile1 = MinerProfile.GetPoolProfile(mainCoinPool1.GetId());
                        string       password1    = poolProfile1.Password;
                        if (string.IsNullOrEmpty(password1))
                        {
                            password1 = Consts.PasswordDefaultValue;
                        }
                        parameters.Add(Consts.UserName1ParameterName, poolProfile1.UserName);
                        parameters.Add(Consts.Password1ParameterName, password1);
                    }
                    else
                    {
                        parameters.Add(Consts.Wallet1ParameterName, coinProfile.Wallet);
                    }
                }
            }
            string devicesArgs = GetDevicesArgs(kernelInput);

            // 这里不要考虑{logfile},{logfile}往后推迟
            if (coinKernelProfile.IsDualCoinEnabled && kernelInput.IsSupportDualMine)
            {
                Guid dualCoinGroupId = coinKernel.DualCoinGroupId;
                if (dualCoinGroupId != Guid.Empty)
                {
                    if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                    {
                        ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId());
                        if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                        {
                            IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId());
                            string       dualPassword    = dualPoolProfile.Password;
                            if (string.IsNullOrEmpty(dualPassword))
                            {
                                dualPassword = Consts.PasswordDefaultValue;
                            }
                            parameters.Add(Consts.DualCoinParameterName, dualCoin.Code);
                            parameters.Add(Consts.DualWalletParameterName, dualCoinProfile.DualCoinWallet);
                            parameters.Add(Consts.DualUserNameParameterName, dualPoolProfile.UserName);
                            parameters.Add(Consts.DualPasswordParameterName, dualPassword);
                            parameters.Add(Consts.DualHostParameterName, dualCoinPool.GetHost());
                            parameters.Add(Consts.DualPortParameterName, dualCoinPool.GetPort().ToString());
                            parameters.Add(Consts.DualPoolParameterName, dualCoinPool.Server);

                            kernelArgs = coinKernel.DualFullArgs;
                            AssembleArgs(parameters, ref kernelArgs, isDual: true);
                            AssembleArgs(parameters, ref poolKernelArgs, isDual: true);
                            AssembleArgs(parameters, ref customArgs, isDual: true);

                            string dualWeightArg;
                            if (!string.IsNullOrEmpty(kernelInput.DualWeightArg))
                            {
                                if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight)
                                {
                                    dualWeightArg = string.Empty;
                                }
                                else
                                {
                                    dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}";
                                }
                            }
                            else
                            {
                                dualWeightArg = string.Empty;
                            }
                            StringBuilder dualSb = new StringBuilder();
                            dualSb.Append(kernelArgs);
                            if (!string.IsNullOrEmpty(dualWeightArg))
                            {
                                dualSb.Append(" ").Append(dualWeightArg);
                            }
                            if (!string.IsNullOrEmpty(poolKernelArgs))
                            {
                                dualSb.Append(" ").Append(poolKernelArgs);
                            }
                            BuildFragments(coinKernel, parameters, out fileWriters, out fragments);
                            foreach (var fragment in fragments.Values)
                            {
                                dualSb.Append(" ").Append(fragment);
                            }
                            if (!string.IsNullOrEmpty(customArgs))
                            {
                                dualSb.Append(" ").Append(customArgs);
                            }
                            if (!string.IsNullOrEmpty(devicesArgs))
                            {
                                dualSb.Append(" ").Append(devicesArgs);
                            }

                            // 注意:这里退出
                            return(dualSb.ToString());
                        }
                    }
                }
            }
            AssembleArgs(parameters, ref kernelArgs, isDual: false);
            AssembleArgs(parameters, ref coinKernelArgs, isDual: false);
            AssembleArgs(parameters, ref poolKernelArgs, isDual: false);
            AssembleArgs(parameters, ref customArgs, isDual: false);
            StringBuilder sb = new StringBuilder();

            sb.Append(kernelArgs);
            if (!string.IsNullOrEmpty(coinKernelArgs))
            {
                sb.Append(" ").Append(coinKernelArgs);
            }
            if (!string.IsNullOrEmpty(poolKernelArgs))
            {
                sb.Append(" ").Append(poolKernelArgs);
            }
            if (!string.IsNullOrEmpty(devicesArgs))
            {
                sb.Append(" ").Append(devicesArgs);
            }
            BuildFragments(coinKernel, parameters, out fileWriters, out fragments);
            foreach (var fragment in fragments.Values)
            {
                sb.Append(" ").Append(fragment);
            }
            if (!string.IsNullOrEmpty(customArgs))
            {
                sb.Append(" ").Append(customArgs);
            }

            return(sb.ToString());
        }
Beispiel #11
0
        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);

            callback?.Invoke();
        }
Beispiel #12
0
        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();
        }
        public string BuildAssembleArgs()
        {
            if (!CoinSet.TryGetCoin(this.MinerProfile.CoinId, out ICoin mainCoin))
            {
                return(string.Empty);
            }
            ICoinProfile coinProfile = this.MinerProfile.GetCoinProfile(mainCoin.GetId());

            if (!PoolSet.TryGetPool(coinProfile.PoolId, out IPool mainCoinPool))
            {
                return(string.Empty);
            }
            if (!CoinKernelSet.TryGetCoinKernel(coinProfile.CoinKernelId, out ICoinKernel coinKernel))
            {
                return(string.Empty);
            }
            if (!KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel))
            {
                return(string.Empty);
            }
            if (!kernel.IsSupported())
            {
                return(string.Empty);
            }
            if (!KernelInputSet.TryGetKernelInput(kernel.KernelInputId, out IKernelInput kernelInput))
            {
                return(string.Empty);
            }
            ICoinKernelProfile coinKernelProfile = this.MinerProfile.GetCoinKernelProfile(coinProfile.CoinKernelId);
            string             wallet            = coinProfile.Wallet;
            string             pool           = mainCoinPool.Server;
            string             poolKernelArgs = string.Empty;
            IPoolKernel        poolKernel     = PoolKernelSet.FirstOrDefault(a => a.PoolId == mainCoinPool.GetId() && a.KernelId == kernel.GetId());

            if (poolKernel != null)
            {
                poolKernelArgs = poolKernel.Args;
            }
            IPoolProfile poolProfile    = MinerProfile.GetPoolProfile(mainCoinPool.GetId());
            string       userName       = poolProfile.UserName;
            string       password       = poolProfile.Password;
            string       kernelArgs     = kernelInput.Args;
            string       coinKernelArgs = coinKernel.Args;
            string       customArgs     = coinKernelProfile.CustomArgs;
            var          argsDic        = new Dictionary <string, string> {
                { "mainCoin", mainCoin.Code },
                { "mainAlgo", mainCoin.Algo },
                { "wallet", wallet },
                { "userName", userName },
                { "password", password },
                { "host", mainCoinPool.GetHost() },
                { "port", mainCoinPool.GetPort().ToString() },
                { "pool", pool },
                { "worker", this.MinerProfile.MinerName }
            };// 这里不要考虑{logfile},{logfile}往后推迟

            if (coinKernelProfile.IsDualCoinEnabled)
            {
                Guid dualCoinGroupId = coinKernel.DualCoinGroupId;
                if (dualCoinGroupId == Guid.Empty)
                {
                    dualCoinGroupId = kernelInput.DualCoinGroupId;
                }
                if (dualCoinGroupId != Guid.Empty)
                {
                    if (this.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin))
                    {
                        ICoinProfile dualCoinProfile = this.MinerProfile.GetCoinProfile(dualCoin.GetId());
                        if (PoolSet.TryGetPool(dualCoinProfile.DualCoinPoolId, out IPool dualCoinPool))
                        {
                            string       dualWallet      = dualCoinProfile.DualCoinWallet;
                            string       dualPool        = dualCoinPool.Server;
                            IPoolProfile dualPoolProfile = MinerProfile.GetPoolProfile(dualCoinPool.GetId());
                            string       dualUserName    = dualPoolProfile.UserName;
                            string       dualPassword    = dualPoolProfile.Password;
                            argsDic.Add("dualCoin", dualCoin.Code);
                            argsDic.Add("dualAlgo", dualCoin.Algo);
                            argsDic.Add("dualWallet", dualWallet);
                            argsDic.Add("dualUserName", dualUserName);
                            argsDic.Add("dualPassword", dualPassword);
                            argsDic.Add("dualHost", dualCoinPool.GetHost());
                            argsDic.Add("dualPort", dualCoinPool.GetPort().ToString());
                            argsDic.Add("dualPool", dualPool);

                            kernelArgs = kernelInput.DualFullArgs;
                            AssembleArgs(argsDic, ref kernelArgs, isDual: true);
                            AssembleArgs(argsDic, ref poolKernelArgs, isDual: true);
                            AssembleArgs(argsDic, ref customArgs, isDual: true);

                            string dualWeightArg;
                            if (!string.IsNullOrEmpty(kernelInput.DualWeightArg))
                            {
                                if (coinKernelProfile.IsAutoDualWeight && kernelInput.IsAutoDualWeight)
                                {
                                    dualWeightArg = string.Empty;
                                }
                                else
                                {
                                    dualWeightArg = $"{kernelInput.DualWeightArg} {Convert.ToInt32(coinKernelProfile.DualCoinWeight)}";
                                }
                            }
                            else
                            {
                                dualWeightArg = string.Empty;
                            }

                            return($"{kernelArgs} {dualWeightArg} {poolKernelArgs} {customArgs}");
                        }
                    }
                }
            }
            AssembleArgs(argsDic, ref kernelArgs, isDual: false);
            AssembleArgs(argsDic, ref coinKernelArgs, isDual: false);
            AssembleArgs(argsDic, ref poolKernelArgs, isDual: false);
            AssembleArgs(argsDic, ref customArgs, isDual: false);

            return($"{kernelArgs} {coinKernelArgs} {poolKernelArgs} {customArgs}");
        }