Example #1
0
 /// <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);
     }
 }