From 1badb1a917e7995b34ab57c5e2387193ad803ff7 Mon Sep 17 00:00:00 2001 From: andrerod Date: Sat, 13 Nov 2010 23:20:25 -0800 Subject: [PATCH] Medium Trust: Replacing usage of GetName() by assemblyName on commandhostenvironment. Extracting DefaultHostEnvironment class to a file outside of the Interface one. --HG-- branch : dev --- .../Commands/CommandHostEnvironment.cs | 3 +- .../Environment/DefaultHostEnvironment.cs | 64 +++++++++++++++++++ src/Orchard/Environment/IHostEnvironment.cs | 56 +--------------- src/Orchard/Orchard.Framework.csproj | 1 + 4 files changed, 69 insertions(+), 55 deletions(-) create mode 100644 src/Orchard/Environment/DefaultHostEnvironment.cs diff --git a/src/Orchard/Commands/CommandHostEnvironment.cs b/src/Orchard/Commands/CommandHostEnvironment.cs index 8a79ff81d..a37339ca9 100644 --- a/src/Orchard/Commands/CommandHostEnvironment.cs +++ b/src/Orchard/Commands/CommandHostEnvironment.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Reflection; using System.Web.Hosting; using Orchard.Environment; using Orchard.Localization; @@ -21,7 +22,7 @@ namespace Orchard.Commands { } public bool IsAssemblyLoaded(string name) { - return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == name); + return AppDomain.CurrentDomain.GetAssemblies().Any(assembly => new AssemblyName(assembly.FullName).Name == name); } public void RestartAppDomain() { diff --git a/src/Orchard/Environment/DefaultHostEnvironment.cs b/src/Orchard/Environment/DefaultHostEnvironment.cs new file mode 100644 index 000000000..d9616b7aa --- /dev/null +++ b/src/Orchard/Environment/DefaultHostEnvironment.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Web; +using System.Web.Hosting; +using Orchard.Services; +using Orchard.Utility.Extensions; + +namespace Orchard.Environment +{ + public class DefaultHostEnvironment : IHostEnvironment + { + private readonly IClock _clock; + + public DefaultHostEnvironment(IClock clock) + { + _clock = clock; + } + + 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() + { + // Touch web.config + File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow); + + // If setting up extensions/modules requires an AppDomain restart, it's very unlikely the + // current request can be processed correctly. So, we redirect to the same URL, so that the + // new request will come to the newly started AppDomain. + if (HttpContext.Current != null) + { + // Don't redirect posts... + if (HttpContext.Current.Request.RequestType == "GET") + { + HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ToUrlString(), true /*endResponse*/); + } + else + { + HttpContext.Current.Response.WriteFile("~/Refresh.html"); + HttpContext.Current.Response.End(); + } + } + } + } +} \ No newline at end of file diff --git a/src/Orchard/Environment/IHostEnvironment.cs b/src/Orchard/Environment/IHostEnvironment.cs index c1cba668a..8b6d668bf 100644 --- a/src/Orchard/Environment/IHostEnvironment.cs +++ b/src/Orchard/Environment/IHostEnvironment.cs @@ -1,13 +1,4 @@ -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Web; -using System.Web.Hosting; -using Orchard.Services; -using Orchard.Utility.Extensions; - -namespace Orchard.Environment { +namespace Orchard.Environment { /// /// Abstraction of the running environment /// @@ -20,47 +11,4 @@ namespace Orchard.Environment { void RestartAppDomain(); void ResetSiteCompilation(); } - - public class DefaultHostEnvironment : IHostEnvironment { - private readonly IClock _clock; - - public DefaultHostEnvironment(IClock clock) { - _clock = clock; - } - - 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() { - // Touch web.config - File.SetLastWriteTimeUtc(MapPath("~/web.config"), _clock.UtcNow); - - // If setting up extensions/modules requires an AppDomain restart, it's very unlikely the - // current request can be processed correctly. So, we redirect to the same URL, so that the - // new request will come to the newly started AppDomain. - if (HttpContext.Current != null) { - // Don't redirect posts... - if (HttpContext.Current.Request.RequestType == "GET") { - HttpContext.Current.Response.Redirect(HttpContext.Current.Request.ToUrlString(), true /*endResponse*/); - } - else { - HttpContext.Current.Response.WriteFile("~/Refresh.html"); - HttpContext.Current.Response.End(); - } - } - } - } -} +} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index c8c95384d..f9c9cffe3 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -174,6 +174,7 @@ +