mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Fix bug in dynamic extension loader
When probing for references, if the reference is present in the module "bin" directory, then make sure the virtual path of the reference entry is set. --HG-- branch : dev
This commit is contained in:
parent
dfaab61f43
commit
1b020c6c8a
@ -104,18 +104,23 @@ namespace Orchard.Environment.Extensions {
|
||||
context.AvailableExtensions
|
||||
.Where(e =>
|
||||
context.ReferencesByModule.ContainsKey(extension.Name) &&
|
||||
context.ReferencesByModule[extension.Name].Any(r => StringComparer.OrdinalIgnoreCase.Equals(e.Name, r.Name)));
|
||||
context.ReferencesByModule[extension.Name].Any(r => StringComparer.OrdinalIgnoreCase.Equals(e.Name, r.Name)))
|
||||
.ToList();
|
||||
|
||||
var processedModuleReferences =
|
||||
moduleReferences
|
||||
.Where(e => context.ProcessedExtensions.ContainsKey(e.Name))
|
||||
.Select(e => context.ProcessedExtensions[e.Name]);
|
||||
.Select(e => context.ProcessedExtensions[e.Name])
|
||||
.ToList();
|
||||
|
||||
var activatedExtension = extensionProbes
|
||||
.Where(e => e.Loader.IsCompatibleWithModuleReferences(extension, processedModuleReferences))
|
||||
.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();
|
||||
|
||||
if (activatedExtension == null) {
|
||||
Logger.Warning("No loader found for extension \"{0}\"!", extension.Name);
|
||||
@ -233,8 +238,10 @@ namespace Orchard.Environment.Extensions {
|
||||
|
||||
var bestBinaryReference = references
|
||||
.Where(entry => !string.IsNullOrEmpty(entry.VirtualPath))
|
||||
.Select(entry => new { Entry = entry, LastWriteTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(entry.VirtualPath) })
|
||||
.OrderBy(e => e.LastWriteTimeUtc)
|
||||
.ThenBy(e => e.Name).FirstOrDefault();
|
||||
.ThenBy(e => e.Entry.Name)
|
||||
.FirstOrDefault();
|
||||
|
||||
var bestExtensionReference = context.ProcessedExtensions.ContainsKey(referenceName) ?
|
||||
context.ProcessedExtensions[referenceName] :
|
||||
@ -252,14 +259,14 @@ namespace Orchard.Environment.Extensions {
|
||||
|
||||
// Activate the binary ref
|
||||
if (bestBinaryReference != null) {
|
||||
if (!context.ProcessedReferences.Contains(bestBinaryReference.Name)) {
|
||||
context.ProcessedReferences.Add(bestBinaryReference.Name);
|
||||
bestBinaryReference.Loader.ReferenceActivated(context, bestBinaryReference);
|
||||
if (!context.ProcessedReferences.Contains(bestBinaryReference.Entry.Name)) {
|
||||
context.ProcessedReferences.Add(bestBinaryReference.Entry.Name);
|
||||
bestBinaryReference.Entry.Loader.ReferenceActivated(context, bestBinaryReference.Entry);
|
||||
}
|
||||
activatedReferences.Add(new DependencyReferenceDescriptor {
|
||||
LoaderName = bestBinaryReference.Loader.Name,
|
||||
Name = bestBinaryReference.Name,
|
||||
VirtualPath = bestBinaryReference.VirtualPath
|
||||
LoaderName = bestBinaryReference.Entry.Loader.Name,
|
||||
Name = bestBinaryReference.Entry.Name,
|
||||
VirtualPath = bestBinaryReference.Entry.VirtualPath
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -105,11 +105,19 @@ namespace Orchard.Environment.Extensions.Loaders {
|
||||
Descriptor = descriptor,
|
||||
Loader = this,
|
||||
Name = r.AssemblyName,
|
||||
VirtualPath = null
|
||||
VirtualPath = GetReferenceVirtualPath(projectPath, r.AssemblyName)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private string GetReferenceVirtualPath(string projectPath, string referenceName) {
|
||||
var path = _virtualPathProvider.GetDirectoryName(projectPath);
|
||||
path = _virtualPathProvider.Combine(path, "bin", referenceName + ".dll");
|
||||
if (_virtualPathProvider.FileExists(path))
|
||||
return path;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override Assembly LoadReference(DependencyReferenceDescriptor reference) {
|
||||
return _buildManager.GetCompiledAssembly(reference.VirtualPath);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ namespace Orchard.Environment.Extensions.Loaders {
|
||||
public IExtensionLoader Loader { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string VirtualPath { get; set; }
|
||||
public DateTime LastWriteTimeUtc { get; set; }
|
||||
}
|
||||
|
||||
public interface IExtensionLoader {
|
||||
|
@ -141,9 +141,9 @@ namespace Orchard.Environment.Extensions.Loaders {
|
||||
Descriptor = descriptor,
|
||||
Loader = this,
|
||||
Name = Path.GetFileNameWithoutExtension(path),
|
||||
VirtualPath = path,
|
||||
LastWriteTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(path)
|
||||
} );
|
||||
VirtualPath = path
|
||||
} )
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public override bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) {
|
||||
|
Loading…
Reference in New Issue
Block a user