mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
@@ -1,35 +1,15 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Web.Hosting;
|
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Commands {
|
namespace Orchard.Commands {
|
||||||
internal class CommandHostEnvironment : IHostEnvironment {
|
internal class CommandHostEnvironment : HostEnvironment {
|
||||||
public CommandHostEnvironment() {
|
public CommandHostEnvironment() {
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public bool IsFullTrust {
|
public override void ResetSiteCompilation() {
|
||||||
get { return AppDomain.CurrentDomain.IsFullyTrusted; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string MapPath(string virtualPath) {
|
|
||||||
return HostingEnvironment.MapPath(virtualPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsAssemblyLoaded(string name) {
|
|
||||||
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RestartAppDomain() {
|
|
||||||
ResetSiteCompilation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetSiteCompilation() {
|
|
||||||
throw new OrchardCommandHostRetryException(T("A change of configuration requires the session to be restarted."));
|
throw new OrchardCommandHostRetryException(T("A change of configuration requires the session to be restarted."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ using NHibernate;
|
|||||||
using NHibernate.Cfg;
|
using NHibernate.Cfg;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Data.Providers;
|
using Orchard.Data.Providers;
|
||||||
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.ShellBuilders.Models;
|
using Orchard.Environment.ShellBuilders.Models;
|
||||||
using Orchard.FileSystems.AppData;
|
using Orchard.FileSystems.AppData;
|
||||||
@@ -21,6 +22,7 @@ namespace Orchard.Data {
|
|||||||
public class SessionFactoryHolder : ISessionFactoryHolder {
|
public class SessionFactoryHolder : ISessionFactoryHolder {
|
||||||
private readonly ShellSettings _shellSettings;
|
private readonly ShellSettings _shellSettings;
|
||||||
private readonly ShellBlueprint _shellBlueprint;
|
private readonly ShellBlueprint _shellBlueprint;
|
||||||
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
||||||
private readonly IAppDataFolder _appDataFolder;
|
private readonly IAppDataFolder _appDataFolder;
|
||||||
private readonly ISessionConfigurationCache _sessionConfigurationCache;
|
private readonly ISessionConfigurationCache _sessionConfigurationCache;
|
||||||
@@ -33,12 +35,14 @@ namespace Orchard.Data {
|
|||||||
ShellBlueprint shellBlueprint,
|
ShellBlueprint shellBlueprint,
|
||||||
IDataServicesProviderFactory dataServicesProviderFactory,
|
IDataServicesProviderFactory dataServicesProviderFactory,
|
||||||
IAppDataFolder appDataFolder,
|
IAppDataFolder appDataFolder,
|
||||||
ISessionConfigurationCache sessionConfigurationCache) {
|
ISessionConfigurationCache sessionConfigurationCache,
|
||||||
|
IHostEnvironment hostEnvironment) {
|
||||||
_shellSettings = shellSettings;
|
_shellSettings = shellSettings;
|
||||||
_shellBlueprint = shellBlueprint;
|
_shellBlueprint = shellBlueprint;
|
||||||
_dataServicesProviderFactory = dataServicesProviderFactory;
|
_dataServicesProviderFactory = dataServicesProviderFactory;
|
||||||
_appDataFolder = appDataFolder;
|
_appDataFolder = appDataFolder;
|
||||||
_sessionConfigurationCache = sessionConfigurationCache;
|
_sessionConfigurationCache = sessionConfigurationCache;
|
||||||
|
_hostEnvironment = hostEnvironment;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -68,7 +72,7 @@ namespace Orchard.Data {
|
|||||||
private ISessionFactory BuildSessionFactory() {
|
private ISessionFactory BuildSessionFactory() {
|
||||||
Logger.Debug("Building session factory");
|
Logger.Debug("Building session factory");
|
||||||
|
|
||||||
if (!(AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted))
|
if (!_hostEnvironment.IsFullTrust)
|
||||||
NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
|
NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
|
||||||
|
|
||||||
Configuration config = GetConfiguration();
|
Configuration config = GetConfiguration();
|
||||||
|
@@ -1,16 +1,12 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Hosting;
|
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Environment
|
namespace Orchard.Environment
|
||||||
{
|
{
|
||||||
public class DefaultHostEnvironment : IHostEnvironment
|
public class DefaultHostEnvironment : HostEnvironment
|
||||||
{
|
{
|
||||||
private readonly IClock _clock;
|
private readonly IClock _clock;
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
@@ -20,27 +16,7 @@ namespace Orchard.Environment
|
|||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFullTrust
|
public override void ResetSiteCompilation()
|
||||||
{
|
|
||||||
get { return AppDomain.CurrentDomain.IsFullyTrusted; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string MapPath(string virtualPath)
|
|
||||||
{
|
|
||||||
return HostingEnvironment.MapPath(virtualPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsAssemblyLoaded(string name)
|
|
||||||
{
|
|
||||||
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RestartAppDomain()
|
|
||||||
{
|
|
||||||
ResetSiteCompilation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetSiteCompilation()
|
|
||||||
{
|
{
|
||||||
// Touch web.config
|
// Touch web.config
|
||||||
File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow);
|
File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow);
|
||||||
|
26
src/Orchard/Environment/HostEnvironment.cs
Normal file
26
src/Orchard/Environment/HostEnvironment.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Web.Hosting;
|
||||||
|
|
||||||
|
namespace Orchard.Environment {
|
||||||
|
public abstract class HostEnvironment : IHostEnvironment {
|
||||||
|
public bool IsFullTrust {
|
||||||
|
get { return AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string MapPath(string virtualPath) {
|
||||||
|
return HostingEnvironment.MapPath(virtualPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAssemblyLoaded(string name) {
|
||||||
|
return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RestartAppDomain() {
|
||||||
|
ResetSiteCompilation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void ResetSiteCompilation();
|
||||||
|
}
|
||||||
|
}
|
@@ -2,11 +2,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Security;
|
|
||||||
using System.Security.Permissions;
|
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Core;
|
using Autofac.Core;
|
||||||
using Castle.Core.Logging;
|
using Castle.Core.Logging;
|
||||||
|
using Orchard.Environment;
|
||||||
using Module = Autofac.Module;
|
using Module = Autofac.Module;
|
||||||
|
|
||||||
namespace Orchard.Logging {
|
namespace Orchard.Logging {
|
||||||
@@ -16,13 +15,15 @@ namespace Orchard.Logging {
|
|||||||
// by default, use Orchard's logger that delegates to Castle's logger factory
|
// by default, use Orchard's logger that delegates to Castle's logger factory
|
||||||
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
|
moduleBuilder.RegisterType<CastleLoggerFactory>().As<ILoggerFactory>().InstancePerLifetimeScope();
|
||||||
|
|
||||||
// Register logger type
|
moduleBuilder.Register<Castle.Core.Logging.ILoggerFactory>(componentContext => {
|
||||||
if (AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted) {
|
IHostEnvironment host = componentContext.Resolve<IHostEnvironment>();
|
||||||
moduleBuilder.RegisterType<TraceLoggerFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
|
if (host.IsFullTrust)
|
||||||
} else {
|
return new TraceLoggerFactory();
|
||||||
// if security model does not allow it, fall back to null logger factory
|
return new NullLogFactory();
|
||||||
moduleBuilder.RegisterType<NullLogFactory>().As<Castle.Core.Logging.ILoggerFactory>().InstancePerLifetimeScope();
|
})
|
||||||
}
|
.As<Castle.Core.Logging.ILoggerFactory>()
|
||||||
|
.InstancePerLifetimeScope();
|
||||||
|
|
||||||
|
|
||||||
// call CreateLogger in response to the request for an ILogger implementation
|
// call CreateLogger in response to the request for an ILogger implementation
|
||||||
moduleBuilder.Register(CreateLogger).As<ILogger>().InstancePerDependency();
|
moduleBuilder.Register(CreateLogger).As<ILogger>().InstancePerDependency();
|
||||||
|
@@ -153,6 +153,7 @@
|
|||||||
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />
|
<Compile Include="DisplayManagement\Implementation\IShapeDisplayEvents.cs" />
|
||||||
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
|
<Compile Include="DisplayManagement\Implementation\IShapeFactoryEvents.cs" />
|
||||||
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
<Compile Include="DisplayManagement\Shapes\ITagBuilderFactory.cs" />
|
||||||
|
<Compile Include="Environment\HostEnvironment.cs" />
|
||||||
<Compile Include="Environment\DefaultHostEnvironment.cs" />
|
<Compile Include="Environment\DefaultHostEnvironment.cs" />
|
||||||
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
|
<Compile Include="Environment\Extensions\Loaders\RawThemeExtensionLoader.cs" />
|
||||||
<Compile Include="Environment\Features\FeatureManager.cs" />
|
<Compile Include="Environment\Features\FeatureManager.cs" />
|
||||||
|
Reference in New Issue
Block a user