--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2011-03-22 13:15:45 -07:00
27 changed files with 272 additions and 86 deletions

View File

@@ -191,7 +191,7 @@ Features:
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -3,7 +3,9 @@ using System.IO;
using System.IO.Packaging;
using Autofac;
using NUnit.Framework;
using Orchard.Environment;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;
@@ -15,6 +17,8 @@ namespace Orchard.Tests.Modules.Packaging.Services {
protected override void Register(ContainerBuilder builder) {
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
builder.RegisterType<DefaultVirtualPathProvider>().As<IVirtualPathProvider>();
builder.RegisterType<DefaultOrchardFrameworkAssemblies>().As<IOrchardFrameworkAssemblies>();
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
.As<InMemoryWebSiteFolder>().InstancePerLifetimeScope();
}

View File

@@ -313,13 +313,13 @@ namespace Orchard.Tests.Environment {
Assert.That(blueprint.Dependencies.FirstOrDefault(dependency => dependency.Type.Equals(typeof(StubNestedType))), Is.Not.Null);
}
[OrchardDependencyReplace("Orchard.Tests.Environment.DefaultCompositionStrategyTests+ReplacedStubNestedType")]
[OrchardSuppressDependency("Orchard.Tests.Environment.DefaultCompositionStrategyTests+ReplacedStubNestedType")]
internal class StubNestedType : IDependency {}
internal class ReplacedStubNestedType : IDependency {}
}
[OrchardDependencyReplace("Orchard.Tests.Environment.ReplacedStubType")]
[OrchardSuppressDependency("Orchard.Tests.Environment.ReplacedStubType")]
internal class StubType : IDependency { }
internal class ReplacedStubType : IDependency { }

View File

@@ -112,7 +112,7 @@ namespace Orchard.Tests.Environment.Extensions {
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -116,7 +116,7 @@ namespace Orchard.Tests.Environment.Extensions {
throw new NotImplementedException();
}
public IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -30,7 +30,7 @@ namespace Orchard.Core.Containers.Drivers {
var commonPart = part.As<ICommonPart>();
var model = new ContainableViewModel();
if (commonPart.Container != null) {
if (commonPart != null && commonPart.Container != null) {
model.ContainerId = commonPart.Container.Id;
}
@@ -38,7 +38,9 @@ namespace Orchard.Core.Containers.Drivers {
var oldContainerId = model.ContainerId;
updater.TryUpdateModel(model, "Containable", null, null);
if (oldContainerId != model.ContainerId)
commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest);
if (commonPart != null) {
commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest);
}
}
// note: string.isnullorempty not being recognized by linq-to-nhibernate hence the inline or

View File

@@ -62,19 +62,15 @@ namespace Orchard.DesignerTools.Services {
private void DumpValue(object o, string name) {
string formatted = FormatValue(o);
_node.Add(
new XElement("h3",
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "value"), formatted)
)
);
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "value"), formatted)
);
}
private void DumpObject(object o, string name) {
_node.Add(
new XElement("h3",
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "type"), FormatType(o.GetType()))
)
new XElement("div", new XAttribute("class", "name"), name),
new XElement("div", new XAttribute("class", "type"), FormatType(o.GetType()))
);
if (_parents.Count >= _levels) {

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Caching;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Descriptor;
@@ -16,19 +17,23 @@ namespace Orchard.Modules.Services {
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly IExtensionManager _extensionManager;
private readonly IShellDescriptorManager _shellDescriptorManager;
private readonly ICacheManager _cacheManager;
public ModuleService(
IFeatureManager featureManager,
IOrchardServices orchardServices,
IVirtualPathProvider virtualPathProvider,
IExtensionManager extensionManager,
IShellDescriptorManager shellDescriptorManager) {
IShellDescriptorManager shellDescriptorManager,
ICacheManager cacheManager) {
Services = orchardServices;
_featureManager = featureManager;
_virtualPathProvider = virtualPathProvider;
_extensionManager = extensionManager;
_shellDescriptorManager = shellDescriptorManager;
_cacheManager = cacheManager;
if (_featureManager.FeatureDependencyNotification == null) {
_featureManager.FeatureDependencyNotification = GenerateWarning;
@@ -95,13 +100,17 @@ namespace Orchard.Modules.Services {
/// </summary>
/// <param name="extensionDescriptor">The extension descriptor.</param>
public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
string projectFile = GetManifestPath(extensionDescriptor);
if (!string.IsNullOrEmpty(projectFile)) {
// If project file was modified less than 24 hours ago, the module was recently deployed
return DateTime.UtcNow.Subtract(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)) < new TimeSpan(1, 0, 0, 0);
}
DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => {
string projectFile = GetManifestPath(extensionDescriptor);
if (!string.IsNullOrEmpty(projectFile)) {
// If project file was modified less than 24 hours ago, the module was recently deployed
return _virtualPathProvider.GetFileLastWriteTimeUtc(projectFile);
}
return false;
return DateTime.UtcNow;
});
return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
}
/// <summary>
@@ -126,6 +135,23 @@ namespace Orchard.Modules.Services {
};
}
private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
if (featuresInQuestion.Count() < 1)
return;
Services.Notifier.Warning(T(
messageFormat,
featureName,
featuresInQuestion.Count() > 1
? string.Join("",
featuresInQuestion.Select(
(fn, i) =>
T(i == featuresInQuestion.Count() - 1
? "{0}"
: (i == featuresInQuestion.Count() - 2
? "{0} and "
: "{0}, "), fn).ToString()).ToArray())
: featuresInQuestion.First()));
}
}
}

View File

@@ -6,16 +6,20 @@ using System.Net.Mime;
using System.Reflection;
using System.Xml.Linq;
using NuGet;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Utility.Extensions;
using NuGetPackageBuilder = NuGet.PackageBuilder;
namespace Orchard.Packaging.Services {
[OrchardFeature("PackagingServices")]
public class PackageBuilder : IPackageBuilder {
private readonly IWebSiteFolder _webSiteFolder;
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly IOrchardFrameworkAssemblies _frameworkAssemblies;
private static readonly string[] _ignoredThemeExtensions = new[] {
"obj", "pdb", "exclude"
@@ -31,8 +35,13 @@ namespace Orchard.Packaging.Services {
_ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? "");
}
public PackageBuilder(IWebSiteFolder webSiteFolder) {
public PackageBuilder(IWebSiteFolder webSiteFolder,
IVirtualPathProvider virtualPathProvider,
IOrchardFrameworkAssemblies frameworkAssemblies) {
_webSiteFolder = webSiteFolder;
_virtualPathProvider = virtualPathProvider;
_frameworkAssemblies = frameworkAssemblies;
}
public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) {
@@ -95,7 +104,7 @@ namespace Orchard.Packaging.Services {
}
}
private static void EmbedReferenceFiles(CreateContext context) {
private void EmbedReferenceFiles(CreateContext context) {
var entries = context.Project
.Elements(Ns("Project"))
.Elements(Ns("ItemGroup"))
@@ -108,13 +117,15 @@ namespace Orchard.Packaging.Services {
foreach (var entry in entries) {
var assemblyName = new AssemblyName(entry.Include.Value);
string hintPath = entry.HintPath != null ? entry.HintPath.Value : null;
string virtualPath = "bin/" + assemblyName.Name + ".dll";
if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) {
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
// If it is not a core assembly
if (_frameworkAssemblies.GetFrameworkAssemblies().FirstOrDefault(assembly => assembly.Name.Equals(assemblyName.Name)) == null) {
string virtualPath = _virtualPathProvider.GetReferenceVirtualPath(context.SourcePath, assemblyName.Name, entry.HintPath != null ? entry.HintPath.Value : null);
if (!string.IsNullOrEmpty(virtualPath)) {
EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet);
}
}
else if (hintPath != null) { }
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using JetBrains.Annotations;
using Orchard.Caching;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.Environment.Features;
@@ -17,16 +18,20 @@ namespace Orchard.Themes.Services {
private readonly IFeatureManager _featureManager;
private readonly IEnumerable<IThemeSelector> _themeSelectors;
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly ICacheManager _cacheManager;
public ThemeService(
IExtensionManager extensionManager,
IFeatureManager featureManager,
IEnumerable<IThemeSelector> themeSelectors,
IVirtualPathProvider virtualPathProvider) {
IVirtualPathProvider virtualPathProvider,
ICacheManager cacheManager) {
_extensionManager = extensionManager;
_featureManager = featureManager;
_themeSelectors = themeSelectors;
_virtualPathProvider = virtualPathProvider;
_cacheManager = cacheManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
@@ -116,15 +121,19 @@ namespace Orchard.Themes.Services {
/// <summary>
/// Determines if a theme was recently installed by using the project's last written time.
/// </summary>
/// <param name="descriptor">The extension descriptor.</param>
public bool IsRecentlyInstalled(ExtensionDescriptor descriptor) {
string projectFile = GetManifestPath(descriptor);
if (!string.IsNullOrEmpty(projectFile)) {
// If project file was modified less than 24 hours ago, the module was recently deployed
return DateTime.UtcNow.Subtract(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)) < new TimeSpan(1, 0, 0, 0);
}
/// <param name="extensionDescriptor">The extension descriptor.</param>
public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => {
string projectFile = GetManifestPath(extensionDescriptor);
if (!string.IsNullOrEmpty(projectFile)) {
// If project file was modified less than 24 hours ago, the module was recently deployed
return _virtualPathProvider.GetFileLastWriteTimeUtc(projectFile);
}
return false;
return DateTime.UtcNow;
});
return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
}
private string GetManifestPath(ExtensionDescriptor descriptor) {

View File

@@ -39,15 +39,33 @@ namespace Orchard.Environment.Extensions.Compilers {
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("Reference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor { SimpleName = ExtractAssemblyName(c.Value), FullName = c.Value });
.Where(c => c.Attribute("Include") != null)
.Select(c => {
string path = null;
XElement attribute = c.Elements(ns("HintPath")).FirstOrDefault();
if (attribute != null) {
path = attribute.Value;
}
return new ReferenceDescriptor {
SimpleName = ExtractAssemblyName(c.Attribute("Include").Value),
FullName = c.Attribute("Include").Value,
Path = path,
ReferenceType = ReferenceType.Library
};
});
var projectReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("ProjectReference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor { SimpleName = Path.GetFileNameWithoutExtension(c.Value), FullName = Path.GetFileNameWithoutExtension(c.Value) });
.Select(c => new ReferenceDescriptor {
SimpleName = Path.GetFileNameWithoutExtension(c.Value),
FullName = Path.GetFileNameWithoutExtension(c.Value),
Path = c.Value,
ReferenceType = ReferenceType.Project
});
return assemblyReferences.Union(projectReferences);
}

View File

@@ -1,6 +1,11 @@
using System.Collections.Generic;
namespace Orchard.Environment.Extensions.Compilers {
public enum ReferenceType {
Library,
Project
}
public class ProjectFileDescriptor {
public string AssemblyName { get; set; }
public IEnumerable<string> SourceFilenames { get; set; }
@@ -9,5 +14,7 @@ namespace Orchard.Environment.Extensions.Compilers {
public class ReferenceDescriptor {
public string SimpleName { get; set; }
public string FullName { get; set; }
public string Path { get; set; }
public ReferenceType ReferenceType { get; set; }
}
}

View File

@@ -202,7 +202,7 @@ namespace Orchard.Environment.Extensions {
availableExtensions.OrderByDependenciesAndPriorities(
(item, dep) => referencesByModule.ContainsKey(item.Id) &&
referencesByModule[item.Id].Any(r => StringComparer.OrdinalIgnoreCase.Equals(dep.Id, r.Name)),
(item) => item.Priority)
(item) => 0)
.ToList();
return new ExtensionLoadingContext {

View File

@@ -100,7 +100,6 @@ namespace Orchard.Environment.Extensions.Folders {
AntiForgery = GetValue(manifest, "AntiForgery"),
Zones = GetValue(manifest, "Zones"),
BaseTheme = GetValue(manifest, "BaseTheme"),
Priority = int.Parse(GetValue(manifest, "Priority") ?? "0")
};
extensionDescriptor.Features = GetFeaturesForExtension(manifest, extensionDescriptor);
@@ -204,7 +203,7 @@ namespace Orchard.Environment.Extensions.Folders {
FeatureDescriptor defaultFeature = new FeatureDescriptor {
Id = extensionDescriptor.Id,
Name = extensionDescriptor.Name,
Priority = extensionDescriptor.Priority,
Priority = GetValue(manifest, "Priority") != null ? int.Parse(GetValue(manifest, "Priority")) : 0,
Description = GetValue(manifest, "FeatureDescription") ?? GetValue(manifest, "Description") ?? string.Empty,
Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, "Dependencies")),
Extension = extensionDescriptor,
@@ -234,7 +233,6 @@ namespace Orchard.Environment.Extensions.Folders {
if (featureDescriptorId == extensionDescriptor.Id) {
featureDescriptor = defaultFeature;
featureDescriptor.Name = extensionDescriptor.Name;
featureDescriptor.Priority = extensionDescriptor.Priority;
}
else {
featureDescriptor = new FeatureDescriptor {

View File

@@ -9,6 +9,7 @@ using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.Dependencies;
using Orchard.FileSystems.VirtualPath;
using Orchard.Logging;
using Orchard.Utility.Extensions;
namespace Orchard.Environment.Extensions.Loaders {
public class DynamicExtensionLoader : ExtensionLoaderBase {
@@ -54,13 +55,13 @@ namespace Orchard.Environment.Extensions.Loaders {
return GetDependencies(dependency.VirtualPath);
}
public override IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath){
public override IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
virtualPath = _virtualPathProvider.ToAppRelative(virtualPath);
if (StringComparer.OrdinalIgnoreCase.Equals(virtualPath, dependency.VirtualPath)) {
return GetSourceFiles(virtualPath);
return GetDependencies(virtualPath);
}
return base.GetFileDependencies(dependency, virtualPath);
return base.GetDynamicModuleDependencies(dependency, virtualPath);
}
public override void Monitor(ExtensionDescriptor descriptor, Action<IVolatileToken> monitor) {
@@ -94,14 +95,14 @@ namespace Orchard.Environment.Extensions.Loaders {
if (projectPath == null)
return Enumerable.Empty<ExtensionReferenceProbeEntry>();
using(var stream = _virtualPathProvider.OpenFile(projectPath)) {
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
var projectFile = _projectFileParser.Parse(stream);
return projectFile.References.Select(r => new ExtensionReferenceProbeEntry {
Descriptor = descriptor,
Loader = this,
Name = r.SimpleName,
VirtualPath = GetReferenceVirtualPath(projectPath, r.SimpleName)
VirtualPath = _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, r.SimpleName, r.Path)
});
}
}
@@ -129,14 +130,6 @@ namespace Orchard.Environment.Extensions.Loaders {
}
}
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) {
// DynamicExtensionLoader has 2 types of references: assemblies from module bin directory
// and .csproj.
@@ -184,17 +177,33 @@ namespace Orchard.Environment.Extensions.Loaders {
}
private IEnumerable<string> GetDependencies(string projectPath) {
return new[] {projectPath}.Concat(GetSourceFiles(projectPath));
}
List<string> dependencies = new[] { projectPath }.ToList();
private IEnumerable<string> GetSourceFiles(string projectPath) {
var basePath = _virtualPathProvider.GetDirectoryName(projectPath);
using (var stream = _virtualPathProvider.OpenFile(projectPath)) {
var projectFile = _projectFileParser.Parse(stream);
return projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f));
// Add source files
dependencies.AddRange(projectFile.SourceFilenames.Select(f => _virtualPathProvider.Combine(basePath, f)));
// Add Project and Library References
foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) {
string path = referenceDescriptor.ReferenceType == ReferenceType.Library
? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path)
: _virtualPathProvider.Combine(basePath, referenceDescriptor.Path);
if (_virtualPathProvider.FileExists(path)) {
dependencies.Add(path);
if (referenceDescriptor.ReferenceType == ReferenceType.Project) {
dependencies.AddRange(GetDependencies(path));
}
}
}
}
return dependencies;
}
private string GetProjectPath(ExtensionDescriptor descriptor) {

View File

@@ -58,7 +58,7 @@ namespace Orchard.Environment.Extensions.Loaders {
return Enumerable.Empty<string>();
}
public virtual IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath) {
public virtual IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) {
return Enumerable.Empty<string>();
}
}

View File

@@ -41,6 +41,6 @@ namespace Orchard.Environment.Extensions.Loaders {
string GetWebFormAssemblyDirective(DependencyDescriptor dependency);
IEnumerable<string> GetWebFormVirtualDependencies(DependencyDescriptor dependency);
IEnumerable<string> GetFileDependencies(DependencyDescriptor dependency, string virtualPath);
IEnumerable<string> GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath);
}
}

View File

@@ -29,7 +29,6 @@ namespace Orchard.Environment.Extensions.Models {
public string AntiForgery { get; set; }
public string Zones { get; set; }
public string BaseTheme { get; set; }
public int Priority { get; set; }
public IEnumerable<FeatureDescriptor> Features { get; set; }
}

View File

@@ -2,11 +2,11 @@
namespace Orchard.Environment.Extensions {
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class OrchardDependencyReplaceAttribute : Attribute {
public OrchardDependencyReplaceAttribute(string dependency) {
Dependency = dependency;
public class OrchardSuppressDependencyAttribute : Attribute {
public OrchardSuppressDependencyAttribute(string fullName) {
FullName = fullName;
}
public string Dependency { get; set; }
public string FullName { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Reflection;
namespace Orchard.Environment {
public interface IOrchardFrameworkAssemblies : IDependency {
IEnumerable<AssemblyName> GetFrameworkAssemblies();
}
public class DefaultOrchardFrameworkAssemblies : IOrchardFrameworkAssemblies {
public IEnumerable<AssemblyName> GetFrameworkAssemblies() {
return typeof (IDependency).Assembly.GetReferencedAssemblies();
}
}
}

View File

@@ -77,8 +77,8 @@ namespace Orchard.Environment.ShellBuilders {
// Identify replaced types
foreach(Feature feature in features) {
foreach (Type type in feature.ExportedTypes) {
foreach (OrchardDependencyReplaceAttribute replacedType in type.GetCustomAttributes(typeof(OrchardDependencyReplaceAttribute), false)) {
excludedTypes.Add(replacedType.Dependency);
foreach (OrchardSuppressDependencyAttribute replacedType in type.GetCustomAttributes(typeof(OrchardSuppressDependencyAttribute), false)) {
excludedTypes.Add(replacedType.FullName);
}
}
}

View File

@@ -47,7 +47,7 @@ namespace Orchard.FileSystems.Dependencies {
var loader = _loaders.Where(l => l.Name == desc.LoaderName).FirstOrDefault();
if (loader != null) {
var otherDependencies = loader.GetFileDependencies(desc, virtualPath);
var otherDependencies = loader.GetDynamicModuleDependencies(desc, virtualPath);
if (otherDependencies.Any()) {
var allDependencies = virtualPathDependencies.OfType<string>().Concat(otherDependencies);

View File

@@ -58,7 +58,12 @@ namespace Orchard.FileSystems.VirtualPath {
}
public bool FileExists(string virtualPath) {
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
try {
return HostingEnvironment.VirtualPathProvider.FileExists(virtualPath);
} catch {
// Medium Trust or invalid mappings that fall outside the app folder
return false;
}
}
public bool DirectoryExists(string virtualPath) {

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Razor.Generator;
using System.Web.WebPages.Razor;
using Orchard.Environment;
@@ -27,7 +29,12 @@ namespace Orchard.Mvc.ViewEngines.Razor {
private readonly IEnumerable<IExtensionLoader> _loaders;
private readonly IAssemblyLoader _assemblyLoader;
public DefaultRazorCompilationEvents(IDependenciesFolder dependenciesFolder, IBuildManager buildManager, IEnumerable<IExtensionLoader> loaders, IAssemblyLoader assemblyLoader) {
public DefaultRazorCompilationEvents(
IDependenciesFolder dependenciesFolder,
IBuildManager buildManager,
IEnumerable<IExtensionLoader> loaders,
IAssemblyLoader assemblyLoader) {
_dependenciesFolder = dependenciesFolder;
_buildManager = buildManager;
_loaders = loaders;
@@ -35,8 +42,25 @@ namespace Orchard.Mvc.ViewEngines.Razor {
}
public void CodeGenerationStarted(RazorBuildProvider provider) {
var descriptors = _dependenciesFolder.LoadDescriptors();
var entries = descriptors
DependencyDescriptor moduleDependencyDescriptor = GetModuleDependencyDescriptor(provider.VirtualPath);
IEnumerable<DependencyDescriptor> dependencyDescriptors = _dependenciesFolder.LoadDescriptors();
List<DependencyDescriptor> filteredDependencyDescriptors;
if (moduleDependencyDescriptor != null) {
// Add module
filteredDependencyDescriptors = new List<DependencyDescriptor> { moduleDependencyDescriptor };
// Add module's references
filteredDependencyDescriptors.AddRange(moduleDependencyDescriptor.References
.SelectMany(reference => dependencyDescriptors
.Where(dependency => dependency.Name == reference.Name)));
}
else {
// Fall back for themes
filteredDependencyDescriptors = dependencyDescriptors.ToList();
}
var entries = filteredDependencyDescriptors
.SelectMany(descriptor => _loaders
.Where(loader => descriptor.LoaderName == loader.Name)
.Select(loader => new {
@@ -70,6 +94,33 @@ namespace Orchard.Mvc.ViewEngines.Razor {
}
}
private DependencyDescriptor GetModuleDependencyDescriptor(string virtualPath) {
var appRelativePath = VirtualPathUtility.ToAppRelative(virtualPath);
var prefix = PrefixMatch(appRelativePath, new [] { "~/Modules/", "~/Core/"});
if (prefix == null)
return null;
var moduleName = ModuleMatch(appRelativePath, prefix);
if (moduleName == null)
return null;
return _dependenciesFolder.GetDescriptor(moduleName);
}
private static string ModuleMatch(string virtualPath, string prefix) {
var index = virtualPath.IndexOf('/', prefix.Length, virtualPath.Length - prefix.Length);
if (index < 0)
return null;
var moduleName = virtualPath.Substring(prefix.Length, index - prefix.Length);
return (string.IsNullOrEmpty(moduleName) ? null : moduleName);
}
private static string PrefixMatch(string virtualPath, params string[] prefixes) {
return prefixes
.FirstOrDefault(p => virtualPath.StartsWith(p, StringComparison.OrdinalIgnoreCase));
}
public void CodeGenerationCompleted(RazorBuildProvider provider, CodeGenerationCompleteEventArgs e) {
}
}

View File

@@ -185,6 +185,7 @@
<Compile Include="Environment\Features\FeatureManager.cs" />
<Compile Include="Environment\IAssemblyLoader.cs" />
<Compile Include="Environment\HostComponentsConfigModule.cs" />
<Compile Include="Environment\IOrchardFrameworkAssemblies.cs" />
<Compile Include="Environment\ViewsBackgroundCompilation.cs" />
<Compile Include="Environment\Warmup\StartupResult.cs" />
<Compile Include="Environment\Warmup\WarmupUtility.cs" />
@@ -488,6 +489,7 @@
<Compile Include="Messaging\Services\IMessagingChannel.cs" />
<Compile Include="IWorkContextAccessor.cs" />
<Compile Include="Utility\Extensions\ControllerExtensions.cs" />
<Compile Include="Utility\Extensions\VirtualPathProviderExtensions.cs" />
<Compile Include="Validation\PathValidation.cs" />
<Compile Include="WorkContextExtensions.cs" />
<Compile Include="Mvc\ViewEngines\Razor\RazorCompilationEventsShim.cs" />

View File

@@ -11,7 +11,7 @@ using Autofac.Features.Metadata;
using Orchard.Environment.Extensions.Models;
namespace Orchard.UI.Resources {
public class ResourceManager : IResourceManager {
public class ResourceManager : IResourceManager, IUnitOfWorkDependency {
private readonly Dictionary<Tuple<String, String>, RequireSettings> _required = new Dictionary<Tuple<String, String>, RequireSettings>();
private readonly List<LinkEntry> _links = new List<LinkEntry>();
private readonly Dictionary<string, MetaEntry> _metas = new Dictionary<string, MetaEntry> {
@@ -234,11 +234,14 @@ namespace Orchard.UI.Resources {
if (resource == null) {
return;
}
if (allResources.Contains(resource)) {
settings = ((RequireSettings) allResources[resource]).Combine(settings);
}
settings.Type = resource.Type;
settings.Name = resource.Name;
// Settings is given so they can cascade down into dependencies. For example, if Foo depends on Bar, and Foo's required
// location is Head, so too should Bar's location.
// forge the effective require settings for this resource
// (1) If a require exists for the resource, combine with it. Last settings in gets preference for its specified values.
// (2) If no require already exists, form a new settings object based on the given one but with its own type/name.
settings = allResources.Contains(resource)
? ((RequireSettings)allResources[resource]).Combine(settings)
: new RequireSettings { Type = resource.Type, Name = resource.Name }.Combine(settings);
if (resource.Dependencies != null) {
var dependencies = from d in resource.Dependencies
select FindResource(new RequireSettings { Type = resource.Type, Name = d });

View File

@@ -0,0 +1,32 @@
using Orchard.FileSystems.VirtualPath;
namespace Orchard.Utility.Extensions {
public static class VirtualPathProviderExtensions {
public static string GetProjectReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string projectPath, string referenceName, string hintPath) {
string basePath = virtualPathProvider.GetDirectoryName(projectPath);
string virtualPath = virtualPathProvider.GetReferenceVirtualPath(basePath, referenceName, hintPath);
if (!string.IsNullOrEmpty(virtualPath)) {
return virtualPathProvider.Combine(basePath, virtualPath);
}
return null;
}
public static string GetReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string basePath, string referenceName, string hintPath) {
// Check if hint path is valid
if (!string.IsNullOrEmpty(hintPath)) {
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, hintPath)))
return hintPath;
}
// Fall back to bin directory
string relativePath = virtualPathProvider.Combine("bin", referenceName + ".dll");
if (virtualPathProvider.FileExists(virtualPathProvider.Combine(basePath, relativePath)))
return relativePath;
return null;
}
}
}