mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 03:25:23 +08:00
"orchard.exe" can now invoke the CommandAgent
The CommandAgent merely initalizes an Orchard Host and Shell (for now). --HG-- branch : dev
This commit is contained in:
41
src/Orchard/Commands/CommandAgent.cs
Normal file
41
src/Orchard/Commands/CommandAgent.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using Orchard.Environment;
|
||||
|
||||
namespace Orchard.Commands {
|
||||
/// <summary>
|
||||
/// This is the guy instantiated by the orchard.exe host. It is reponsible for
|
||||
/// executing a single command.
|
||||
/// </summary>
|
||||
public class CommandAgent {
|
||||
public void RunSingleCommand(string[] args) {
|
||||
try {
|
||||
Console.WriteLine("Command being run!");
|
||||
|
||||
var host = OrchardStarter.CreateHost(MvcSingletons);
|
||||
host.Initialize();
|
||||
|
||||
var shell = host.
|
||||
}
|
||||
catch (Exception e) {
|
||||
while (e != null) {
|
||||
Console.WriteLine("Error: {0}", e.Message);
|
||||
e = e.InnerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void MvcSingletons(ContainerBuilder builder) {
|
||||
builder.RegisterInstance(ControllerBuilder.Current);
|
||||
builder.RegisterInstance(RouteTable.Routes);
|
||||
builder.RegisterInstance(ModelBinders.Binders);
|
||||
builder.RegisterInstance(ModelMetadataProviders.Current);
|
||||
builder.RegisterInstance(ViewEngines.Engines);
|
||||
}
|
||||
}
|
||||
}
|
@@ -129,6 +129,7 @@
|
||||
<Compile Include="Validation\Argument.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands\CommandAgent.cs" />
|
||||
<Compile Include="Commands\OrchardCommandAttribute.cs" />
|
||||
<Compile Include="Commands\CommandContext.cs" />
|
||||
<Compile Include="Commands\DefaultOrchardCommandHandler.cs" />
|
||||
|
@@ -18,5 +18,10 @@ namespace Orchard.Host {
|
||||
public void Stop(bool immediate) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void RunCommand(string[] args) {
|
||||
var agent = Activator.CreateInstance("Orchard.Framework", "Orchard.Commands.CommandAgent").Unwrap();
|
||||
agent.GetType().GetMethod("RunSingleCommand").Invoke(agent, new object[] { args });
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,6 +21,8 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<UseVSHostingProcess>true</UseVSHostingProcess>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@@ -8,5 +8,6 @@ namespace Orchard {
|
||||
public bool Verbose { get; set; }
|
||||
public string VirtualPath { get; set; }
|
||||
public string WorkingDirectory { get; set; }
|
||||
public string Tenant { get; set; }
|
||||
}
|
||||
}
|
@@ -10,8 +10,9 @@ namespace Orchard {
|
||||
}
|
||||
|
||||
public class OrchardArgumentsParser : IOrchardArgumentsParser {
|
||||
|
||||
public OrchardArguments Parse(ParserResult arguments) {
|
||||
OrchardArguments result = new OrchardArguments();
|
||||
var result = new OrchardArguments();
|
||||
|
||||
foreach (var sw in arguments.Switches) {
|
||||
switch (sw.Name.ToLowerInvariant()) {
|
||||
@@ -29,6 +30,11 @@ namespace Orchard {
|
||||
case "virtualpath":
|
||||
result.VirtualPath = sw.Value;
|
||||
break;
|
||||
|
||||
case "t":
|
||||
case "tenant":
|
||||
result.Tenant = sw.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -41,8 +41,16 @@ namespace Orchard {
|
||||
Console.WriteLine("Detected and using orchard directory \"{0}\"", orchardDirectory.FullName);
|
||||
}
|
||||
|
||||
object host = CreateWorkerAppDomainWithHost(arguments.VirtualPath, orchardDirectory.FullName, typeof(CommandHost));
|
||||
if (arguments.Verbose) {
|
||||
Console.WriteLine("Creating ASP.NET AppDomain for command agent");
|
||||
}
|
||||
var host = (CommandHost)CreateWorkerAppDomainWithHost(arguments.VirtualPath, orchardDirectory.FullName, typeof(CommandHost));
|
||||
|
||||
|
||||
if (arguments.Verbose) {
|
||||
Console.WriteLine("Executing command in ASP.NET AppDomain");
|
||||
}
|
||||
host.RunCommand(_args);
|
||||
}
|
||||
|
||||
private DirectoryInfo GetOrchardDirectory(string directory) {
|
||||
|
Reference in New Issue
Block a user