diff --git a/src/Orchard/Commands/CommandHostEnvironment.cs b/src/Orchard/Commands/CommandHostEnvironment.cs index a37339ca9..0fc4c4ae8 100644 --- a/src/Orchard/Commands/CommandHostEnvironment.cs +++ b/src/Orchard/Commands/CommandHostEnvironment.cs @@ -1,35 +1,15 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Web.Hosting; using Orchard.Environment; using Orchard.Localization; namespace Orchard.Commands { - internal class CommandHostEnvironment : IHostEnvironment { + internal class CommandHostEnvironment : HostEnvironment { public CommandHostEnvironment() { T = NullLocalizer.Instance; } public Localizer T { get; set; } - public bool IsFullTrust { - 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() { + public override void ResetSiteCompilation() { throw new OrchardCommandHostRetryException(T("A change of configuration requires the session to be restarted.")); } } diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index 4f5c64bad..56f4038fa 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -5,6 +5,7 @@ using NHibernate; using NHibernate.Cfg; using Orchard.Data; using Orchard.Data.Providers; +using Orchard.Environment; using Orchard.Environment.Configuration; using Orchard.Environment.ShellBuilders.Models; using Orchard.FileSystems.AppData; @@ -21,6 +22,7 @@ namespace Orchard.Data { public class SessionFactoryHolder : ISessionFactoryHolder { private readonly ShellSettings _shellSettings; private readonly ShellBlueprint _shellBlueprint; + private readonly IHostEnvironment _hostEnvironment; private readonly IDataServicesProviderFactory _dataServicesProviderFactory; private readonly IAppDataFolder _appDataFolder; private readonly ISessionConfigurationCache _sessionConfigurationCache; @@ -33,12 +35,14 @@ namespace Orchard.Data { ShellBlueprint shellBlueprint, IDataServicesProviderFactory dataServicesProviderFactory, IAppDataFolder appDataFolder, - ISessionConfigurationCache sessionConfigurationCache) { + ISessionConfigurationCache sessionConfigurationCache, + IHostEnvironment hostEnvironment) { _shellSettings = shellSettings; _shellBlueprint = shellBlueprint; _dataServicesProviderFactory = dataServicesProviderFactory; _appDataFolder = appDataFolder; _sessionConfigurationCache = sessionConfigurationCache; + _hostEnvironment = hostEnvironment; T = NullLocalizer.Instance; Logger = NullLogger.Instance; @@ -68,7 +72,7 @@ namespace Orchard.Data { private ISessionFactory BuildSessionFactory() { Logger.Debug("Building session factory"); - if (!(AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted)) + if (!_hostEnvironment.IsFullTrust) NHibernate.Cfg.Environment.UseReflectionOptimizer = false; Configuration config = GetConfiguration(); diff --git a/src/Orchard/Environment/DefaultHostEnvironment.cs b/src/Orchard/Environment/DefaultHostEnvironment.cs index adb6421ee..2412341a9 100644 --- a/src/Orchard/Environment/DefaultHostEnvironment.cs +++ b/src/Orchard/Environment/DefaultHostEnvironment.cs @@ -1,16 +1,12 @@ -using System; -using System.IO; -using System.Linq; -using System.Reflection; +using System.IO; using System.Web; -using System.Web.Hosting; using Orchard.Mvc; using Orchard.Services; using Orchard.Utility.Extensions; namespace Orchard.Environment { - public class DefaultHostEnvironment : IHostEnvironment + public class DefaultHostEnvironment : HostEnvironment { private readonly IClock _clock; private readonly IHttpContextAccessor _httpContextAccessor; @@ -20,27 +16,7 @@ namespace Orchard.Environment _httpContextAccessor = httpContextAccessor; } - public bool IsFullTrust - { - 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() + public override void ResetSiteCompilation() { // Touch web.config File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow); diff --git a/src/Orchard/Environment/HostEnvironment.cs b/src/Orchard/Environment/HostEnvironment.cs new file mode 100644 index 000000000..7cc96ecc9 --- /dev/null +++ b/src/Orchard/Environment/HostEnvironment.cs @@ -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(); + } +} \ No newline at end of file diff --git a/src/Orchard/Logging/LoggingModule.cs b/src/Orchard/Logging/LoggingModule.cs index 93e70e1d8..9474c5671 100644 --- a/src/Orchard/Logging/LoggingModule.cs +++ b/src/Orchard/Logging/LoggingModule.cs @@ -2,11 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Security; -using System.Security.Permissions; using Autofac; using Autofac.Core; using Castle.Core.Logging; +using Orchard.Environment; using Module = Autofac.Module; namespace Orchard.Logging { @@ -16,13 +15,15 @@ namespace Orchard.Logging { // by default, use Orchard's logger that delegates to Castle's logger factory moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); - // Register logger type - if (AppDomain.CurrentDomain.IsHomogenous && AppDomain.CurrentDomain.IsFullyTrusted) { - moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); - } else { - // if security model does not allow it, fall back to null logger factory - moduleBuilder.RegisterType().As().InstancePerLifetimeScope(); - } + moduleBuilder.Register(componentContext => { + IHostEnvironment host = componentContext.Resolve(); + if (host.IsFullTrust) + return new TraceLoggerFactory(); + return new NullLogFactory(); + }) + .As() + .InstancePerLifetimeScope(); + // call CreateLogger in response to the request for an ILogger implementation moduleBuilder.Register(CreateLogger).As().InstancePerDependency(); diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index f5635612a..a264d31e6 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -153,6 +153,7 @@ +