public string GetArguments(WorkerContext context) { var argumentsBuilder = context.Arguments.ExecutableArguments.Aggregate(new StringBuilder(), MergeArguments); if (!string.IsNullOrEmpty(context.Arguments.WorkerPath)) { argumentsBuilder.AppendFormat(" \"{0}\"", context.Arguments.WorkerPath); } context.Arguments.WorkerArguments.Aggregate(argumentsBuilder, MergeArguments); argumentsBuilder.Append(context.GetFormattedArguments()); return(argumentsBuilder.ToString()); }
public virtual Process CreateWorkerProcess(WorkerContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Arguments == null) { throw new ArgumentNullException(nameof(context.Arguments)); } if (context.Arguments.ExecutablePath == null) { throw new ArgumentNullException(nameof(context.Arguments.ExecutablePath)); } var startInfo = new ProcessStartInfo(context.Arguments.ExecutablePath) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false, ErrorDialog = false, WorkingDirectory = context.WorkingDirectory, Arguments = GetArguments(context), }; var processEnvVariables = context.EnvironmentVariables; if (processEnvVariables != null && processEnvVariables.Any()) { foreach (var envVar in processEnvVariables) { startInfo.EnvironmentVariables[envVar.Key] = envVar.Value; startInfo.Arguments = startInfo.Arguments.Replace($"%{envVar.Key}%", envVar.Value); } startInfo.Arguments = SanitizeExpandedArgument(startInfo.Arguments); } ApplyWorkerConcurrencyLimits(startInfo); return(new Process { StartInfo = startInfo }); }
public virtual Process CreateWorkerProcess(WorkerContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Arguments == null) { throw new ArgumentNullException(nameof(context.Arguments)); } if (context.Arguments.ExecutablePath == null) { throw new ArgumentNullException(nameof(context.Arguments.ExecutablePath)); } var startInfo = new ProcessStartInfo(context.Arguments.ExecutablePath) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false, ErrorDialog = false, WorkingDirectory = context.WorkingDirectory, Arguments = GetArguments(context), }; var processEnvVariables = context.EnvironmentVariables; if (processEnvVariables != null && processEnvVariables.Any()) { foreach (var evnVar in processEnvVariables) { startInfo.EnvironmentVariables[evnVar.Key] = evnVar.Value; } } return(new Process { StartInfo = startInfo }); }