mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Small refactorings
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -68,7 +68,7 @@ namespace Orchard.Tests.Environment.Extensions {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
public bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -68,7 +68,7 @@ namespace Orchard.Tests.Environment.Extensions {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
public bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
|
|
||||||
@@ -12,6 +13,10 @@ namespace Orchard.Commands {
|
|||||||
return HostingEnvironment.MapPath(virtualPath);
|
return HostingEnvironment.MapPath(virtualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsAssemblyLoaded(string name) {
|
||||||
|
return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == name);
|
||||||
|
}
|
||||||
|
|
||||||
public void RestartAppDomain() {
|
public void RestartAppDomain() {
|
||||||
//Don't restart AppDomain in command line environment
|
//Don't restart AppDomain in command line environment
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
@@ -112,7 +112,7 @@ namespace Orchard.Environment.Extensions {
|
|||||||
.Select(e => context.ProcessedExtensions[e.Name]);
|
.Select(e => context.ProcessedExtensions[e.Name]);
|
||||||
|
|
||||||
var activatedExtension = extensionProbes
|
var activatedExtension = extensionProbes
|
||||||
.Where(e => e.Loader.IsCompatibleWithReferences(extension, processedModuleReferences))
|
.Where(e => e.Loader.IsCompatibleWithModuleReferences(extension, processedModuleReferences))
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
var previousDependency = context.PreviousDependencies.Where(d => StringComparer.OrdinalIgnoreCase.Equals(d.Name, extension.Name)).FirstOrDefault();
|
var previousDependency = context.PreviousDependencies.Where(d => StringComparer.OrdinalIgnoreCase.Equals(d.Name, extension.Name)).FirstOrDefault();
|
||||||
|
@@ -25,7 +25,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
public virtual bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,9 +57,5 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
public virtual IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency) {
|
public virtual IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency) {
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static bool IsAssemblyLoaded(string moduleName) {
|
|
||||||
return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == moduleName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
@@ -29,7 +29,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
Assembly LoadReference(DependencyReferenceDescriptor reference);
|
Assembly LoadReference(DependencyReferenceDescriptor reference);
|
||||||
void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry);
|
void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry);
|
||||||
void ReferenceDeactivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry);
|
void ReferenceDeactivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry);
|
||||||
bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references);
|
bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references);
|
||||||
|
|
||||||
ExtensionProbeEntry Probe(ExtensionDescriptor descriptor);
|
ExtensionProbeEntry Probe(ExtensionDescriptor descriptor);
|
||||||
ExtensionEntry Load(ExtensionDescriptor descriptor);
|
ExtensionEntry Load(ExtensionDescriptor descriptor);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -15,16 +15,19 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
/// extension directory.
|
/// extension directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PrecompiledExtensionLoader : ExtensionLoaderBase {
|
public class PrecompiledExtensionLoader : ExtensionLoaderBase {
|
||||||
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
||||||
|
|
||||||
public PrecompiledExtensionLoader(IDependenciesFolder dependenciesFolder,
|
public PrecompiledExtensionLoader(
|
||||||
|
IHostEnvironment hostEnvironment,
|
||||||
|
IDependenciesFolder dependenciesFolder,
|
||||||
IAssemblyProbingFolder assemblyProbingFolder,
|
IAssemblyProbingFolder assemblyProbingFolder,
|
||||||
IVirtualPathProvider virtualPathProvider,
|
IVirtualPathProvider virtualPathProvider,
|
||||||
IVirtualPathMonitor virtualPathMonitor)
|
IVirtualPathMonitor virtualPathMonitor)
|
||||||
: base(dependenciesFolder) {
|
: base(dependenciesFolder) {
|
||||||
|
_hostEnvironment = hostEnvironment;
|
||||||
_assemblyProbingFolder = assemblyProbingFolder;
|
_assemblyProbingFolder = assemblyProbingFolder;
|
||||||
_virtualPathProvider = virtualPathProvider;
|
_virtualPathProvider = virtualPathProvider;
|
||||||
_virtualPathMonitor = virtualPathMonitor;
|
_virtualPathMonitor = virtualPathMonitor;
|
||||||
@@ -53,7 +56,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(dependency.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(dependency.Name)) {
|
||||||
Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
|
Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
|
||||||
ctx.RestartAppDomain = true;
|
ctx.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
@@ -72,7 +75,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
ctx.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(extension.Name, sourceFileName));
|
ctx.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(extension.Name, sourceFileName));
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(extension.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(extension.Name)) {
|
||||||
Logger.Information("ExtensionRemoved: Module \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
Logger.Information("ExtensionRemoved: Module \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
||||||
ctx.RestartAppDomain = true;
|
ctx.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
@@ -88,7 +91,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(extension.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(extension.Name)) {
|
||||||
Logger.Information("ExtensionDeactivated: Module \"{0}\" is deactivated and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
Logger.Information("ExtensionDeactivated: Module \"{0}\" is deactivated and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
||||||
ctx.RestartAppDomain = true;
|
ctx.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
@@ -110,7 +113,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(referenceEntry.Name, sourceFileName));
|
context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(referenceEntry.Name, sourceFileName));
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(referenceEntry.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(referenceEntry.Name)) {
|
||||||
Logger.Information("ReferenceActivated: Reference \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", referenceEntry.Name);
|
Logger.Information("ReferenceActivated: Reference \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", referenceEntry.Name);
|
||||||
context.RestartAppDomain = true;
|
context.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
@@ -143,7 +146,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
public override bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||||
// A pre-compiled module is _not_ compatible with a dynamically loaded module
|
// A pre-compiled module is _not_ compatible with a dynamically loaded module
|
||||||
// because a pre-compiled module usually references a pre-compiled assembly binary
|
// because a pre-compiled module usually references a pre-compiled assembly binary
|
||||||
// which will have a different identity (i.e. name) from the dynamic module.
|
// which will have a different identity (i.e. name) from the dynamic module.
|
||||||
|
@@ -10,12 +10,17 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
/// file can be found in the "App_Data/Dependencies" folder.
|
/// file can be found in the "App_Data/Dependencies" folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProbingExtensionLoader : ExtensionLoaderBase {
|
public class ProbingExtensionLoader : ExtensionLoaderBase {
|
||||||
|
private readonly IHostEnvironment _hostEnvironment;
|
||||||
private readonly IDependenciesFolder _dependenciesFolder;
|
private readonly IDependenciesFolder _dependenciesFolder;
|
||||||
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
private readonly IAssemblyProbingFolder _assemblyProbingFolder;
|
||||||
|
|
||||||
public ProbingExtensionLoader(IDependenciesFolder dependenciesFolder, IAssemblyProbingFolder assemblyProbingFolder)
|
public ProbingExtensionLoader(
|
||||||
|
IHostEnvironment hostEnvironment,
|
||||||
|
IDependenciesFolder dependenciesFolder,
|
||||||
|
IAssemblyProbingFolder assemblyProbingFolder)
|
||||||
: base(dependenciesFolder) {
|
: base(dependenciesFolder) {
|
||||||
|
|
||||||
|
_hostEnvironment = hostEnvironment;
|
||||||
_dependenciesFolder = dependenciesFolder;
|
_dependenciesFolder = dependenciesFolder;
|
||||||
_assemblyProbingFolder = assemblyProbingFolder;
|
_assemblyProbingFolder = assemblyProbingFolder;
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
@@ -42,7 +47,7 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(dependency.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(dependency.Name)) {
|
||||||
Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
|
Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
|
||||||
ctx.RestartAppDomain = true;
|
ctx.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
@@ -58,14 +63,14 @@ namespace Orchard.Environment.Extensions.Loaders {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// We need to restart the appDomain if the assembly is loaded
|
// We need to restart the appDomain if the assembly is loaded
|
||||||
if (IsAssemblyLoaded(extension.Name)) {
|
if (_hostEnvironment.IsAssemblyLoaded(extension.Name)) {
|
||||||
Logger.Information("ExtensionDeactivated: Module \"{0}\" is deactivated and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
Logger.Information("ExtensionDeactivated: Module \"{0}\" is deactivated and its assembly is loaded, forcing AppDomain restart", extension.Name);
|
||||||
ctx.RestartAppDomain = true;
|
ctx.RestartAppDomain = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsCompatibleWithReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
public override bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||||
// A pre-compiled module is _not_ compatible with a dynamically loaded module
|
// A pre-compiled module is _not_ compatible with a dynamically loaded module
|
||||||
// because a pre-compiled module usually references a pre-compiled assembly binary
|
// because a pre-compiled module usually references a pre-compiled assembly binary
|
||||||
// which will have a different identity (i.e. name) from the dynamic module.
|
// which will have a different identity (i.e. name) from the dynamic module.
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
@@ -13,6 +14,8 @@ namespace Orchard.Environment {
|
|||||||
bool IsFullTrust { get; }
|
bool IsFullTrust { get; }
|
||||||
string MapPath(string virtualPath);
|
string MapPath(string virtualPath);
|
||||||
|
|
||||||
|
bool IsAssemblyLoaded(string name);
|
||||||
|
|
||||||
void RestartAppDomain();
|
void RestartAppDomain();
|
||||||
void ResetSiteCompilation();
|
void ResetSiteCompilation();
|
||||||
}
|
}
|
||||||
@@ -32,6 +35,10 @@ namespace Orchard.Environment {
|
|||||||
return HostingEnvironment.MapPath(virtualPath);
|
return HostingEnvironment.MapPath(virtualPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsAssemblyLoaded(string name) {
|
||||||
|
return AppDomain.CurrentDomain.GetAssemblies().Any(a => a.GetName().Name == name);
|
||||||
|
}
|
||||||
|
|
||||||
public void RestartAppDomain() {
|
public void RestartAppDomain() {
|
||||||
ResetSiteCompilation();
|
ResetSiteCompilation();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user