"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:
Renaud Paquay
2010-04-07 17:45:08 -07:00
parent d3cd35600b
commit 118920bbab
7 changed files with 66 additions and 2 deletions

View 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);
}
}
}

View File

@@ -129,6 +129,7 @@
<Compile Include="Validation\Argument.cs" /> <Compile Include="Validation\Argument.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Commands\CommandAgent.cs" />
<Compile Include="Commands\OrchardCommandAttribute.cs" /> <Compile Include="Commands\OrchardCommandAttribute.cs" />
<Compile Include="Commands\CommandContext.cs" /> <Compile Include="Commands\CommandContext.cs" />
<Compile Include="Commands\DefaultOrchardCommandHandler.cs" /> <Compile Include="Commands\DefaultOrchardCommandHandler.cs" />

View File

@@ -18,5 +18,10 @@ namespace Orchard.Host {
public void Stop(bool immediate) { public void Stop(bool immediate) {
//TODO //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 });
}
} }
} }

View File

@@ -21,6 +21,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>

View File

@@ -8,5 +8,6 @@ namespace Orchard {
public bool Verbose { get; set; } public bool Verbose { get; set; }
public string VirtualPath { get; set; } public string VirtualPath { get; set; }
public string WorkingDirectory { get; set; } public string WorkingDirectory { get; set; }
public string Tenant { get; set; }
} }
} }

View File

@@ -10,8 +10,9 @@ namespace Orchard {
} }
public class OrchardArgumentsParser : IOrchardArgumentsParser { public class OrchardArgumentsParser : IOrchardArgumentsParser {
public OrchardArguments Parse(ParserResult arguments) { public OrchardArguments Parse(ParserResult arguments) {
OrchardArguments result = new OrchardArguments(); var result = new OrchardArguments();
foreach (var sw in arguments.Switches) { foreach (var sw in arguments.Switches) {
switch (sw.Name.ToLowerInvariant()) { switch (sw.Name.ToLowerInvariant()) {
@@ -29,6 +30,11 @@ namespace Orchard {
case "virtualpath": case "virtualpath":
result.VirtualPath = sw.Value; result.VirtualPath = sw.Value;
break; break;
case "t":
case "tenant":
result.Tenant = sw.Value;
break;
} }
} }

View File

@@ -41,8 +41,16 @@ namespace Orchard {
Console.WriteLine("Detected and using orchard directory \"{0}\"", orchardDirectory.FullName); 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) { private DirectoryInfo GetOrchardDirectory(string directory) {