/// <summary> /// Executes the specified legacy command. /// </summary> /// <param name="tenantName">The name of the tenant on which the command will be executed.</param> /// <param name="args">Command name and arguments.</param> /// <param name="switches">Command switches.</param> /// <param name="directConsole"> /// <c>true</c> to force orchard output directly into <see cref="Console.Out"/>; otherwise, <c>false</c>. /// </param> /// <returns>The command's output.</returns> public string ExecuteCommand( string tenantName, string[] args, Dictionary<string, string> switches, bool directConsole) { var agent = new CommandHostAgent(); agent.StartHost(Console.In, Console.Out); try { if (directConsole) { agent.RunCommand(Console.In, Console.Out, tenantName, args, switches); return null; } else { using (TextWriter writer = new StringWriter(CultureInfo.CurrentCulture)) { agent.RunCommand(Console.In, writer, tenantName, args, switches); return writer.ToString(); } } } finally { agent.StopHost(Console.In, Console.Out); } }
public void WhenIExecute(string commandLine) { var details = new RequestDetails(); Binding<WebAppHosting>().Host.Execute(() => { var args = commandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var parameters = new CommandParametersParser().Parse(args); var agent = new CommandHostAgent(); var input = new StringReader(""); var output = new StringWriter(); details.StatusCode = agent.RunSingleCommand( input, output, "Default", parameters.Arguments.ToArray(), parameters.Switches.ToDictionary(kv => kv.Key, kv => kv.Value)); details.StatusDescription = details.StatusCode.ToString(); details.ResponseText = output.ToString(); }); Binding<WebAppHosting>().Details = details; }