mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Remove tenant cache
There was no cache invalidation policy, so remove it --HG-- branch : dev
This commit is contained in:
@@ -18,7 +18,6 @@ namespace Orchard.Commands {
|
||||
/// </summary>
|
||||
public class CommandHostAgent {
|
||||
private IContainer _hostContainer;
|
||||
private Dictionary<string, IStandaloneEnvironment> _tenants;
|
||||
|
||||
public CommandHostAgent() {
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -41,10 +40,44 @@ namespace Orchard.Commands {
|
||||
return StopHost(input, output);
|
||||
}
|
||||
|
||||
public int RunCommand(TextReader input, TextWriter output, string tenant, string[] args, Dictionary<string, string> switches) {
|
||||
try {
|
||||
tenant = tenant ?? "Default";
|
||||
|
||||
using (var env = CreateStandaloneEnvironment(tenant)) {
|
||||
|
||||
var parameters = new CommandParameters {
|
||||
Arguments = args,
|
||||
Switches = switches,
|
||||
Input = input,
|
||||
Output = output
|
||||
};
|
||||
|
||||
env.Resolve<ICommandManager>().Execute(parameters);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (OrchardCommandHostRetryException e) {
|
||||
// Special "Retry" return code for our host
|
||||
output.WriteLine("{0}", e.Message);
|
||||
output.WriteLine("(Retrying...)");
|
||||
return 240;
|
||||
}
|
||||
catch (Exception e) {
|
||||
for (int i = 0; e != null; e = e.InnerException, i++) {
|
||||
if (i > 0) {
|
||||
output.WriteLine("-------------------------------------------------------------------");
|
||||
}
|
||||
output.WriteLine("Error: {0}", e.Message);
|
||||
output.WriteLine("{0}", e.StackTrace);
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public int StartHost(TextReader input, TextWriter output) {
|
||||
try {
|
||||
_hostContainer = CreateHostContainer();
|
||||
_tenants = new Dictionary<string, IStandaloneEnvironment>();
|
||||
return 0;
|
||||
}
|
||||
catch (OrchardCommandHostRetryException e) {
|
||||
@@ -62,6 +95,23 @@ namespace Orchard.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
public int StopHost(TextReader input, TextWriter output) {
|
||||
try {
|
||||
if (_hostContainer != null) {
|
||||
_hostContainer.Dispose();
|
||||
_hostContainer = null;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e) {
|
||||
for (; e != null; e = e.InnerException) {
|
||||
output.WriteLine("Error: {0}", e.Message);
|
||||
output.WriteLine("{0}", e.StackTrace);
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
private IContainer CreateHostContainer() {
|
||||
var hostContainer = OrchardStarter.CreateHostContainer(ContainerRegistrations);
|
||||
|
||||
@@ -71,60 +121,7 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
|
||||
public int StopHost(TextReader input, TextWriter output) {
|
||||
try {
|
||||
foreach (var tenant in _tenants.Values) {
|
||||
tenant.Dispose();
|
||||
}
|
||||
_hostContainer.Dispose();
|
||||
|
||||
_tenants = null;
|
||||
_hostContainer = null;
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e) {
|
||||
for (; e != null; e = e.InnerException) {
|
||||
output.WriteLine("Error: {0}", e.Message);
|
||||
output.WriteLine("{0}", e.StackTrace);
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public int RunCommand(TextReader input, TextWriter output, string tenant, string[] args, Dictionary<string, string> switches) {
|
||||
try {
|
||||
tenant = tenant ?? "Default";
|
||||
|
||||
var env = FindOrCreateTenant(tenant);
|
||||
|
||||
var parameters = new CommandParameters {
|
||||
Arguments = args,
|
||||
Switches = switches,
|
||||
Input = input,
|
||||
Output = output
|
||||
};
|
||||
|
||||
env.Resolve<ICommandManager>().Execute(parameters);
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e) {
|
||||
for (int i = 0; e != null; e = e.InnerException, i++) {
|
||||
if (i > 0) {
|
||||
output.WriteLine("-------------------------------------------------------------------");
|
||||
}
|
||||
output.WriteLine("Error: {0}", e.Message);
|
||||
output.WriteLine("{0}", e.StackTrace);
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public IStandaloneEnvironment FindOrCreateTenant(string tenant) {
|
||||
IStandaloneEnvironment result;
|
||||
if (_tenants.TryGetValue(tenant, out result))
|
||||
return result;
|
||||
|
||||
private IStandaloneEnvironment CreateStandaloneEnvironment(string tenant) {
|
||||
var host = _hostContainer.Resolve<IOrchardHost>();
|
||||
var tenantManager = _hostContainer.Resolve<IShellSettingsManager>();
|
||||
|
||||
@@ -137,9 +134,6 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
var env = host.CreateStandaloneEnvironment(settings);
|
||||
|
||||
// Store in cache for next calls
|
||||
_tenants.Add(tenant, env);
|
||||
return env;
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user