public static IMineContext CreateMineContext() { INTMinerContext ntminerContext = NTMinerContext.Instance; var minerProfile = ntminerContext.MinerProfile; var serverContext = ntminerContext.ServerContext; var gpuSet = ntminerContext.GpuSet; if (!ntminerContext.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 = 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; bool isTestWallet = false; bool isTestUserName = false; IPoolProfile poolProfile = minerProfile.GetPoolProfile(mainCoinPool.GetId()); if (mainCoinPool.IsUserMode) { password = poolProfile.Password; if (string.IsNullOrEmpty(password)) { password = NTKeyword.PasswordDefaultValue; } userName = poolProfile.UserName; wallet = poolProfile.UserName; isTestUserName = serverContext.PoolSet.TryGetPool(poolProfile.PoolId, out IPool pool) && userName == pool.UserName; } else { userName = wallet; isTestWallet = serverContext.CoinSet.TryGetCoin(mainCoinProfile.CoinId, out ICoin coin) && wallet == coin.TestWallet; } parameters.Add(NTKeyword.UserNameParameterName, userName); parameters.Add(NTKeyword.PasswordParameterName, password); parameters.Add(NTKeyword.WalletParameterName, wallet); string server = mainCoinPool.Server; if (!string.IsNullOrWhiteSpace(poolProfile.Server)) { server = poolProfile.Server; } parameters.Add(NTKeyword.HostParameterName, GetHost(server)); parameters.Add(NTKeyword.PortParameterName, GetPort(server).ToString()); parameters.Add(NTKeyword.PoolParameterName, server); string minerName = $"{mainCoinPool.MinerNamePrefix}{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)) { IPoolProfile poolProfile1 = minerProfile.GetPoolProfile(mainCoinPool1.GetId()); string server1 = mainCoinPool1.Server; if (!string.IsNullOrWhiteSpace(poolProfile1.Server)) { server1 = poolProfile1.Server; } parameters.Add(NTKeyword.Host1ParameterName, GetHost(server1)); parameters.Add(NTKeyword.Port1ParameterName, GetPort(server1).ToString()); parameters.Add(NTKeyword.Pool1ParameterName, server1); if (mainCoinPool1.IsUserMode) { 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 (serverContext.CoinSet.TryGetCoin(coinKernelProfile.DualCoinId, out ICoin dualCoin)) { ICoinProfile dualCoinProfile = 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); IPoolProfile dualPoolProfile = minerProfile.GetPoolProfile(dualCoinPool.GetId()); if (dualCoinPool.IsUserMode) { 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); string dualCoinPoolServer = dualCoinPool.Server; if (!string.IsNullOrWhiteSpace(dualPoolProfile.Server)) { dualCoinPoolServer = dualPoolProfile.Server; } parameters.Add(NTKeyword.DualHostParameterName, GetHost(dualCoinPoolServer)); parameters.Add(NTKeyword.DualPortParameterName, GetPort(dualCoinPoolServer).ToString()); parameters.Add(NTKeyword.DualPoolParameterName, dualCoinPoolServer); 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( minerProfile.MinerName, mainCoin, mainCoinPool, kernel, kernelInput, kernelOutput, mainCoinKernel, wallet, dualSb.ToString(), isTestWallet, isTestUserName, 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( minerProfile.MinerName, mainCoin, mainCoinPool, kernel, kernelInput, kernelOutput, mainCoinKernel, wallet, sb.ToString(), isTestWallet, isTestUserName, parameters, fragments, fileWriters, gpuSet.GetUseDevices())); }
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(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) { 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 = 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 = 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); } 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()); }
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; 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}"); }
public bool TryGetPoolKernel(Guid kernelId, out IPoolKernel kernel) { InitOnece(); var r = _dicById.TryGetValue(kernelId, out PoolKernelData k); kernel = k; return r; }
public PoolKernelViewModel(IPoolKernel data) : this(data.GetId()) { _poolId = data.PoolId; _kernelId = data.KernelId; _args = data.Args; }