public void StartMiner(bool minimized) { _minimized = minimized; _process = new Process(); DeviceConfig firstDeviceConfig = DeviceConfigs.First(); string minerPath = Helpers.ResolveToFullPath(firstDeviceConfig.MinerPath, Helpers.GetApplicationRoot()); string minerFolderPath = Path.GetDirectoryName(minerPath); _process.StartInfo.FileName = "cmd"; List <string> userDefindedArgs = new List <string>(); if (!String.IsNullOrEmpty(firstDeviceConfig.MinerArguments)) { userDefindedArgs.AddRange(firstDeviceConfig.MinerArguments.Split(" ")); } if (!String.IsNullOrEmpty(firstDeviceConfig.MinerDeviceSpecificArguments)) { userDefindedArgs.AddRange(firstDeviceConfig.MinerDeviceSpecificArguments.Split(" ")); } string args = ""; string space = ""; if (!userDefindedArgs.Contains("-o")) { string address = Pool.PoolUrl.StartsWith("stratum+tcp://", StringComparison.OrdinalIgnoreCase) ? Pool.PoolUrl : "stratum+tcp://" + Pool.PoolUrl; args = $"{space}-o {address}"; space = " "; } if (!userDefindedArgs.Contains("-u")) { args += $"{space}-u {Pool.PoolUser}"; space = " "; } if (!userDefindedArgs.Contains("-p")) { args += $"{space}-p {Pool.PoolPassword}"; space = " "; } if (!userDefindedArgs.Contains("-d")) { string devicesString = string.Join(',', DeviceConfigs.Select(dc => dc.DeviceId)); args += $"{space}-d {devicesString}"; space = " "; } _port = firstDeviceConfig.MinerApiPort > 0 ? firstDeviceConfig.MinerApiPort : Helpers.GetAvailablePort(); if (!userDefindedArgs.Any(a => a.StartsWith("--api_listen={", StringComparison.OrdinalIgnoreCase))) { args += $"{space}--api_listen={_port}"; space = " "; } if (!String.IsNullOrEmpty(firstDeviceConfig.MinerArguments)) { args += space + firstDeviceConfig.MinerArguments; } if (DeviceConfigs.Any(dc => !string.IsNullOrEmpty(dc.MinerDeviceSpecificArguments))) { Dictionary <string, List <string> > combinedArgumentsDictionary = new Dictionary <string, List <string> >(); foreach (DeviceConfig deviceConfig in DeviceConfigs) { var splittedArguments = deviceConfig.MinerDeviceSpecificArguments.Split(" "); foreach (string splittedArgument in splittedArguments) { const string cnConfigArgmument = "--cn_config="; if (splittedArgument.StartsWith(cnConfigArgmument, StringComparison.OrdinalIgnoreCase)) { AddToListInDictionary(combinedArgumentsDictionary, cnConfigArgmument, splittedArgument.Substring(cnConfigArgmument.Length)); } const string ethConfigArgmument = "--eth_config="; if (splittedArgument.StartsWith(ethConfigArgmument, StringComparison.OrdinalIgnoreCase)) { AddToListInDictionary(combinedArgumentsDictionary, ethConfigArgmument, splittedArgument.Substring(ethConfigArgmument.Length)); } } } StringBuilder argumentsBuilder = new StringBuilder(); bool first = true; foreach (var combinedArgument in combinedArgumentsDictionary) { if (!first) { argumentsBuilder.Append(" "); } first = false; argumentsBuilder.Append(combinedArgument.Key); argumentsBuilder.Append(string.Join(',', combinedArgument.Value)); } args += space + argumentsBuilder; } _process.EnableRaisingEvents = true; _process.Exited += ProcessOnExited; _process.StartInfo.Arguments = $"/c \"{Path.GetFileName(minerPath)} {args}\""; _process.StartInfo.UseShellExecute = true; _process.StartInfo.CreateNoWindow = false; _process.StartInfo.RedirectStandardOutput = false; _process.StartInfo.WorkingDirectory = minerFolderPath; _process.StartInfo.WindowStyle = minimized ? ProcessWindowStyle.Minimized : ProcessWindowStyle.Normal; Log.Debug($"Miner Start Info: \"{_process.StartInfo.FileName}\" {_process.StartInfo.Arguments}"); _process.Start(); }
public void StartMiner(bool minimized) { _minimized = minimized; _process = new Process(); DeviceConfig firstDeviceConfig = DeviceConfigs.First(); string minerPath = Helpers.ResolveToFullPath(firstDeviceConfig.MinerPath, Helpers.GetApplicationRoot()); string minerFolderPath = Path.GetDirectoryName(minerPath); _process.StartInfo.FileName = "cmd"; List <string> userDefindedArgs = new List <string>(); if (!String.IsNullOrEmpty(firstDeviceConfig.MinerArguments)) { userDefindedArgs.AddRange(firstDeviceConfig.MinerArguments.Split(" ")); } if (!String.IsNullOrEmpty(firstDeviceConfig.MinerDeviceSpecificArguments)) { userDefindedArgs.AddRange(firstDeviceConfig.MinerDeviceSpecificArguments.Split(" ")); } string args = ""; string space = ""; if (!userDefindedArgs.Contains("-epool")) { args = $"{space}-epool {Pool.PoolUrl}"; space = " "; } if (!userDefindedArgs.Contains("-ewal")) { args += $"{space}-ewal {Pool.PoolUser}"; space = " "; } if (!userDefindedArgs.Contains("-epsw")) { args += $"{space}-epsw {Pool.PoolPassword}"; space = " "; } if (!userDefindedArgs.Contains("-di")) { string devicesString = string.Join("", DeviceConfigs.Select(dc => dc.DeviceId)); args += $"{space}-di {devicesString}"; space = " "; } _port = firstDeviceConfig.MinerApiPort > 0 ? firstDeviceConfig.MinerApiPort : Helpers.GetAvailablePort(); if (!userDefindedArgs.Contains("-mport")) { args += $"{space}-mport -{_port}"; space = " "; } if (!String.IsNullOrEmpty(firstDeviceConfig.MinerArguments)) { args += space + firstDeviceConfig.MinerArguments; } if (DeviceConfigs.Any(dc => !string.IsNullOrEmpty(dc.MinerDeviceSpecificArguments))) { Dictionary <string, List <string> > combinedArgumentsDictionary = new Dictionary <string, List <string> >(); foreach (DeviceConfig deviceConfig in DeviceConfigs) { var splittedArguments = deviceConfig.MinerDeviceSpecificArguments.Split(" "); for (var index = 0; index + 1 < splittedArguments.Length; index += 2) { AddToListInDictionary(combinedArgumentsDictionary, splittedArguments[index], splittedArguments[index + 1]); } } StringBuilder argumentsBuilder = new StringBuilder(); bool first = true; foreach (var combinedArgument in combinedArgumentsDictionary) { if (!first) { argumentsBuilder.Append(" "); } first = false; argumentsBuilder.Append(combinedArgument.Key); argumentsBuilder.Append(" "); argumentsBuilder.Append(string.Join(',', combinedArgument.Value)); } args += space + argumentsBuilder; } _process.EnableRaisingEvents = true; _process.Exited += ProcessOnExited; _process.StartInfo.Arguments = $"/c \"{Path.GetFileName(minerPath)} {args}\""; _process.StartInfo.UseShellExecute = true; _process.StartInfo.CreateNoWindow = false; _process.StartInfo.RedirectStandardOutput = false; _process.StartInfo.WorkingDirectory = minerFolderPath; _process.StartInfo.WindowStyle = minimized ? ProcessWindowStyle.Minimized : ProcessWindowStyle.Normal; Log.Debug($"Miner Start Info: \"{_process.StartInfo.FileName}\" {_process.StartInfo.Arguments}"); _process.Start(); }