From 6a4e5f1c340cb8058e61d5c613fc08406bf3ca68 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 21 Mar 2011 12:50:19 -0700 Subject: [PATCH 01/14] Making dynamic compilation project hash aware of dependencies. --HG-- branch : dev --- .../Migrations/SchemaCommandGeneratorTests.cs | 2 +- .../ExtensionLoaderCoordinatorTests.cs | 2 +- .../Extensions/ExtensionManagerTests.cs | 2 +- .../Compilers/DefaultProjectFileParser.cs | 24 ++++++++++++++-- .../Compilers/ProjectFileDescriptor.cs | 7 +++++ .../Loaders/DynamicExtensionLoader.cs | 28 ++++++++++++++----- .../Extensions/Loaders/ExtensionLoaderBase.cs | 2 +- .../Extensions/Loaders/IExtensionLoader.cs | 2 +- .../DynamicModuleVirtualPathProvider.cs | 2 +- .../VirtualPath/DefaultVirtualPathProvider.cs | 7 ++++- 10 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs b/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs index 6fa006694..928ce7f7a 100644 --- a/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs +++ b/src/Orchard.Tests.Modules/Migrations/SchemaCommandGeneratorTests.cs @@ -191,7 +191,7 @@ Features: throw new NotImplementedException(); } - public IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath) { + public IEnumerable GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) { throw new NotImplementedException(); } diff --git a/src/Orchard.Tests/Environment/Extensions/ExtensionLoaderCoordinatorTests.cs b/src/Orchard.Tests/Environment/Extensions/ExtensionLoaderCoordinatorTests.cs index 4b32af63c..f2bbbf216 100644 --- a/src/Orchard.Tests/Environment/Extensions/ExtensionLoaderCoordinatorTests.cs +++ b/src/Orchard.Tests/Environment/Extensions/ExtensionLoaderCoordinatorTests.cs @@ -112,7 +112,7 @@ namespace Orchard.Tests.Environment.Extensions { throw new NotImplementedException(); } - public IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath) { + public IEnumerable GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) { throw new NotImplementedException(); } diff --git a/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs b/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs index 14381e75e..557a9e021 100644 --- a/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs +++ b/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs @@ -116,7 +116,7 @@ namespace Orchard.Tests.Environment.Extensions { throw new NotImplementedException(); } - public IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath) { + public IEnumerable GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) { throw new NotImplementedException(); } diff --git a/src/Orchard/Environment/Extensions/Compilers/DefaultProjectFileParser.cs b/src/Orchard/Environment/Extensions/Compilers/DefaultProjectFileParser.cs index 321ed56ce..b4048bfd5 100644 --- a/src/Orchard/Environment/Extensions/Compilers/DefaultProjectFileParser.cs +++ b/src/Orchard/Environment/Extensions/Compilers/DefaultProjectFileParser.cs @@ -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); } diff --git a/src/Orchard/Environment/Extensions/Compilers/ProjectFileDescriptor.cs b/src/Orchard/Environment/Extensions/Compilers/ProjectFileDescriptor.cs index a4387f117..7212935c6 100644 --- a/src/Orchard/Environment/Extensions/Compilers/ProjectFileDescriptor.cs +++ b/src/Orchard/Environment/Extensions/Compilers/ProjectFileDescriptor.cs @@ -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 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; } } } \ No newline at end of file diff --git a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs index cd16d4f0c..eae0ea91f 100644 --- a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs +++ b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs @@ -54,13 +54,13 @@ namespace Orchard.Environment.Extensions.Loaders { return GetDependencies(dependency.VirtualPath); } - public override IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath){ + public override IEnumerable 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 monitor) { @@ -184,17 +184,31 @@ namespace Orchard.Environment.Extensions.Loaders { } private IEnumerable GetDependencies(string projectPath) { - return new[] {projectPath}.Concat(GetSourceFiles(projectPath)); - } + List dependencies = new[] { projectPath }.ToList(); - private IEnumerable 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 = _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) { diff --git a/src/Orchard/Environment/Extensions/Loaders/ExtensionLoaderBase.cs b/src/Orchard/Environment/Extensions/Loaders/ExtensionLoaderBase.cs index e246bfab9..be17465b2 100644 --- a/src/Orchard/Environment/Extensions/Loaders/ExtensionLoaderBase.cs +++ b/src/Orchard/Environment/Extensions/Loaders/ExtensionLoaderBase.cs @@ -58,7 +58,7 @@ namespace Orchard.Environment.Extensions.Loaders { return Enumerable.Empty(); } - public virtual IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath) { + public virtual IEnumerable GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath) { return Enumerable.Empty(); } } diff --git a/src/Orchard/Environment/Extensions/Loaders/IExtensionLoader.cs b/src/Orchard/Environment/Extensions/Loaders/IExtensionLoader.cs index 2b22ebf29..9d681c83a 100644 --- a/src/Orchard/Environment/Extensions/Loaders/IExtensionLoader.cs +++ b/src/Orchard/Environment/Extensions/Loaders/IExtensionLoader.cs @@ -41,6 +41,6 @@ namespace Orchard.Environment.Extensions.Loaders { string GetWebFormAssemblyDirective(DependencyDescriptor dependency); IEnumerable GetWebFormVirtualDependencies(DependencyDescriptor dependency); - IEnumerable GetFileDependencies(DependencyDescriptor dependency, string virtualPath); + IEnumerable GetDynamicModuleDependencies(DependencyDescriptor dependency, string virtualPath); } } \ No newline at end of file diff --git a/src/Orchard/FileSystems/Dependencies/DynamicModuleVirtualPathProvider.cs b/src/Orchard/FileSystems/Dependencies/DynamicModuleVirtualPathProvider.cs index 55b1defd1..b0dda1f0e 100644 --- a/src/Orchard/FileSystems/Dependencies/DynamicModuleVirtualPathProvider.cs +++ b/src/Orchard/FileSystems/Dependencies/DynamicModuleVirtualPathProvider.cs @@ -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().Concat(otherDependencies); diff --git a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs index 9cd99d6c9..cc5261710 100644 --- a/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs +++ b/src/Orchard/FileSystems/VirtualPath/DefaultVirtualPathProvider.cs @@ -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) { From 2b5001be0f2d15718eae39659f0d6847abc155de Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 21 Mar 2011 13:00:38 -0700 Subject: [PATCH 02/14] Renaming OrchardDependencyReplaceAttribute to OrchardSuppressDependencyAttribute. --HG-- branch : dev --- .../Environment/DefaultCompositionStrategyTests.cs | 4 ++-- .../Extensions/OrchardDependencyReplaceAttribute.cs | 8 ++++---- .../Environment/ShellBuilders/CompositionStrategy.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs b/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs index d207155eb..468aa3932 100644 --- a/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs +++ b/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs @@ -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 { } diff --git a/src/Orchard/Environment/Extensions/OrchardDependencyReplaceAttribute.cs b/src/Orchard/Environment/Extensions/OrchardDependencyReplaceAttribute.cs index 7b0a19b74..248a54985 100644 --- a/src/Orchard/Environment/Extensions/OrchardDependencyReplaceAttribute.cs +++ b/src/Orchard/Environment/Extensions/OrchardDependencyReplaceAttribute.cs @@ -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; } } } \ No newline at end of file diff --git a/src/Orchard/Environment/ShellBuilders/CompositionStrategy.cs b/src/Orchard/Environment/ShellBuilders/CompositionStrategy.cs index 4e64d0727..d9e63ac80 100644 --- a/src/Orchard/Environment/ShellBuilders/CompositionStrategy.cs +++ b/src/Orchard/Environment/ShellBuilders/CompositionStrategy.cs @@ -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); } } } From 4c7f24a7bc56167de6693ab55a6ed80f37ac5d2e Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 21 Mar 2011 13:17:12 -0700 Subject: [PATCH 03/14] Removing priority from extensions and making them feature specific. --HG-- branch : dev --- .../Environment/Extensions/ExtensionLoaderCoordinator.cs | 2 +- .../Environment/Extensions/Folders/ExtensionFolders.cs | 4 +--- .../Environment/Extensions/Models/ExtensionDescriptor.cs | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs b/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs index b6ea1504f..256068723 100644 --- a/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs +++ b/src/Orchard/Environment/Extensions/ExtensionLoaderCoordinator.cs @@ -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 { diff --git a/src/Orchard/Environment/Extensions/Folders/ExtensionFolders.cs b/src/Orchard/Environment/Extensions/Folders/ExtensionFolders.cs index 9afe6d7bf..3d78add09 100644 --- a/src/Orchard/Environment/Extensions/Folders/ExtensionFolders.cs +++ b/src/Orchard/Environment/Extensions/Folders/ExtensionFolders.cs @@ -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 { diff --git a/src/Orchard/Environment/Extensions/Models/ExtensionDescriptor.cs b/src/Orchard/Environment/Extensions/Models/ExtensionDescriptor.cs index d264de22f..ef048cefa 100644 --- a/src/Orchard/Environment/Extensions/Models/ExtensionDescriptor.cs +++ b/src/Orchard/Environment/Extensions/Models/ExtensionDescriptor.cs @@ -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 Features { get; set; } } From de0267456d46442607a4c509cc134542301561bc Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 21 Mar 2011 13:39:41 -0700 Subject: [PATCH 04/14] Updating GetReferenceVirtualPath to consider hint paths. --HG-- branch : dev --- .../Loaders/DynamicExtensionLoader.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs index eae0ea91f..03fb8cfb0 100644 --- a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs +++ b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs @@ -101,7 +101,7 @@ namespace Orchard.Environment.Extensions.Loaders { Descriptor = descriptor, Loader = this, Name = r.SimpleName, - VirtualPath = GetReferenceVirtualPath(projectPath, r.SimpleName) + VirtualPath = GetReferenceVirtualPath(projectPath, r.SimpleName, r.Path) }); } } @@ -129,11 +129,21 @@ namespace Orchard.Environment.Extensions.Loaders { } } - private string GetReferenceVirtualPath(string projectPath, string referenceName) { + private string GetReferenceVirtualPath(string projectPath, string referenceName, string hintPath) { var path = _virtualPathProvider.GetDirectoryName(projectPath); + + // Check if hint path is valid + if (!string.IsNullOrEmpty(hintPath)) { + hintPath = _virtualPathProvider.Combine(path, hintPath); + if (_virtualPathProvider.FileExists(hintPath)) + return hintPath; + } + + // Fall back to bin directory path = _virtualPathProvider.Combine(path, "bin", referenceName + ".dll"); if (_virtualPathProvider.FileExists(path)) return path; + return null; } @@ -196,7 +206,9 @@ namespace Orchard.Environment.Extensions.Loaders { // Add Project and Library References foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) { - string path = _virtualPathProvider.Combine(basePath, referenceDescriptor.Path); + string path = referenceDescriptor.ReferenceType == ReferenceType.Library + ? GetReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path) + : _virtualPathProvider.Combine(basePath, referenceDescriptor.Path); if (_virtualPathProvider.FileExists(path)) { dependencies.Add(path); From 14011b7e3946bfb893a41946e115d71c9b8473e0 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 21 Mar 2011 14:50:36 -0700 Subject: [PATCH 05/14] Removing

enclosing --HG-- branch : dev --- .../Orchard.DesignerTools/Services/ObjectDumper.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs index 5af60bf25..23564e577 100644 --- a/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs +++ b/src/Orchard.Web/Modules/Orchard.DesignerTools/Services/ObjectDumper.cs @@ -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) { From 093b6e4f21b0c174a0503e8e10c0686757e55c79 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Mon, 21 Mar 2011 16:34:49 -0700 Subject: [PATCH 06/14] Fixing #17275 --HG-- branch : dev --- .../Core/Containers/Drivers/ContainablePartDriver.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs b/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs index be24ba316..65666c63f 100644 --- a/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs +++ b/src/Orchard.Web/Core/Containers/Drivers/ContainablePartDriver.cs @@ -30,7 +30,7 @@ namespace Orchard.Core.Containers.Drivers { var commonPart = part.As(); 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 From 0099cdd2b7245c735cadb2e71b35ac96416c171f Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 21 Mar 2011 16:11:47 -0700 Subject: [PATCH 07/14] When compiling Razor views for a module/theme, we add assemblies for all modules and themes. This is overkill. Making razor views add only assemblies for the current module, and its references. --HG-- branch : dev --- .../Razor/IRazorCompilationEvents.cs | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs index 44ece4e76..c0933ff0f 100644 --- a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs +++ b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs @@ -1,10 +1,13 @@ -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; using Orchard.Environment.Extensions.Loaders; using Orchard.FileSystems.Dependencies; +using Orchard.FileSystems.VirtualPath; namespace Orchard.Mvc.ViewEngines.Razor { public interface IRazorCompilationEvents { @@ -27,7 +30,12 @@ namespace Orchard.Mvc.ViewEngines.Razor { private readonly IEnumerable _loaders; private readonly IAssemblyLoader _assemblyLoader; - public DefaultRazorCompilationEvents(IDependenciesFolder dependenciesFolder, IBuildManager buildManager, IEnumerable loaders, IAssemblyLoader assemblyLoader) { + public DefaultRazorCompilationEvents( + IDependenciesFolder dependenciesFolder, + IBuildManager buildManager, + IEnumerable loaders, + IAssemblyLoader assemblyLoader) { + _dependenciesFolder = dependenciesFolder; _buildManager = buildManager; _loaders = loaders; @@ -35,8 +43,25 @@ namespace Orchard.Mvc.ViewEngines.Razor { } public void CodeGenerationStarted(RazorBuildProvider provider) { - var descriptors = _dependenciesFolder.LoadDescriptors(); - var entries = descriptors + DependencyDescriptor dependencyDescriptor = GetDependencyDescriptor(provider.VirtualPath); + + IEnumerable dependencyDescriptors = _dependenciesFolder.LoadDescriptors(); + List filteredDependencyDescriptors = new List(); + if (dependencyDescriptor != null) { + // Add module + filteredDependencyDescriptors.Add(dependencyDescriptor); + + // Add module's references + filteredDependencyDescriptors.AddRange(dependencyDescriptor.References + .SelectMany(reference => dependencyDescriptors + .Where(dependency => dependency.Name == reference.Name))); + } + else { + // Fall back that shouldn't usually be called + filteredDependencyDescriptors = dependencyDescriptors.ToList(); + } + + var entries = filteredDependencyDescriptors .SelectMany(descriptor => _loaders .Where(loader => descriptor.LoaderName == loader.Name) .Select(loader => new { @@ -70,6 +95,33 @@ namespace Orchard.Mvc.ViewEngines.Razor { } } + private DependencyDescriptor GetDependencyDescriptor(string virtualPath) { + var appRelativePath = VirtualPathUtility.ToAppRelative(virtualPath); + var prefix = PrefixMatch(appRelativePath, new [] { "~/Modules/", "~/Themes/", "~/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) { } } From f93fe6764978f8b2cd73dd6653b65bca72462000 Mon Sep 17 00:00:00 2001 From: andrerod Date: Mon, 21 Mar 2011 20:37:10 -0700 Subject: [PATCH 08/14] Using hintpath on package builder --HG-- branch : dev --- .../Services/PackageBuilder.cs | 16 ++++++---- .../Loaders/DynamicExtensionLoader.cs | 25 +++------------ src/Orchard/Orchard.Framework.csproj | 1 + .../VirtualPathProviderExtensions.cs | 32 +++++++++++++++++++ 4 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 src/Orchard/Utility/Extensions/VirtualPathProviderExtensions.cs diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs index 9dcc5e7c7..aa6555520 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs @@ -8,14 +8,16 @@ using System.Xml.Linq; using NuGet; 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 static readonly string[] _ignoredThemeExtensions = new[] { "obj", "pdb", "exclude" @@ -31,8 +33,10 @@ namespace Orchard.Packaging.Services { _ignoredThemeExtensions.Contains(Path.GetExtension(filePath) ?? ""); } - public PackageBuilder(IWebSiteFolder webSiteFolder) { + public PackageBuilder(IWebSiteFolder webSiteFolder, + IVirtualPathProvider virtualPathProvider) { _webSiteFolder = webSiteFolder; + _virtualPathProvider = virtualPathProvider; } public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) { @@ -95,7 +99,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 +112,11 @@ 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 = _virtualPathProvider.GetReferenceVirtualPath(context.SourcePath, assemblyName.Name, entry.HintPath != null ? entry.HintPath.Value : null); - string virtualPath = "bin/" + assemblyName.Name + ".dll"; - if (context.SourceFolder.FileExists(context.SourcePath + virtualPath)) { + if (!string.IsNullOrEmpty(virtualPath)) { EmbedVirtualFile(context, virtualPath, MediaTypeNames.Application.Octet); } - else if (hintPath != null) { } } } diff --git a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs index 03fb8cfb0..64dcdebc0 100644 --- a/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs +++ b/src/Orchard/Environment/Extensions/Loaders/DynamicExtensionLoader.cs @@ -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 { @@ -94,14 +95,14 @@ namespace Orchard.Environment.Extensions.Loaders { if (projectPath == null) return Enumerable.Empty(); - 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, r.Path) + VirtualPath = _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, r.SimpleName, r.Path) }); } } @@ -129,24 +130,6 @@ namespace Orchard.Environment.Extensions.Loaders { } } - private string GetReferenceVirtualPath(string projectPath, string referenceName, string hintPath) { - var path = _virtualPathProvider.GetDirectoryName(projectPath); - - // Check if hint path is valid - if (!string.IsNullOrEmpty(hintPath)) { - hintPath = _virtualPathProvider.Combine(path, hintPath); - if (_virtualPathProvider.FileExists(hintPath)) - return hintPath; - } - - // Fall back to bin directory - 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. @@ -207,7 +190,7 @@ namespace Orchard.Environment.Extensions.Loaders { // Add Project and Library References foreach (ReferenceDescriptor referenceDescriptor in projectFile.References.Where(reference => !string.IsNullOrEmpty(reference.Path))) { string path = referenceDescriptor.ReferenceType == ReferenceType.Library - ? GetReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path) + ? _virtualPathProvider.GetProjectReferenceVirtualPath(projectPath, referenceDescriptor.SimpleName, referenceDescriptor.Path) : _virtualPathProvider.Combine(basePath, referenceDescriptor.Path); if (_virtualPathProvider.FileExists(path)) { diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 641a533e1..3e620961c 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -488,6 +488,7 @@ + diff --git a/src/Orchard/Utility/Extensions/VirtualPathProviderExtensions.cs b/src/Orchard/Utility/Extensions/VirtualPathProviderExtensions.cs new file mode 100644 index 000000000..2d7e28906 --- /dev/null +++ b/src/Orchard/Utility/Extensions/VirtualPathProviderExtensions.cs @@ -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; + } + } +} From 3b883c542bc0866a447480464f944d6388394487 Mon Sep 17 00:00:00 2001 From: andrerod Date: Mon, 21 Mar 2011 21:41:14 -0700 Subject: [PATCH 09/14] Caching last written for installed extensions. --HG-- branch : dev --- .../Orchard.Modules/Services/ModuleService.cs | 42 +++++++++++++++---- .../Orchard.Themes/Services/ThemeService.cs | 27 ++++++++---- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Services/ModuleService.cs b/src/Orchard.Web/Modules/Orchard.Modules/Services/ModuleService.cs index 079dbc239..74abca493 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Services/ModuleService.cs +++ b/src/Orchard.Web/Modules/Orchard.Modules/Services/ModuleService.cs @@ -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 { /// /// The extension descriptor. 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); } /// @@ -126,6 +135,23 @@ namespace Orchard.Modules.Services { }; } - private void GenerateWarning(string messageFormat, string featureName, IEnumerable 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())); } + private void GenerateWarning(string messageFormat, string featureName, IEnumerable 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())); + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeService.cs b/src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeService.cs index a5b8452f3..b049f2843 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeService.cs +++ b/src/Orchard.Web/Modules/Orchard.Themes/Services/ThemeService.cs @@ -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 _themeSelectors; private readonly IVirtualPathProvider _virtualPathProvider; + private readonly ICacheManager _cacheManager; public ThemeService( IExtensionManager extensionManager, IFeatureManager featureManager, IEnumerable 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 { /// /// Determines if a theme was recently installed by using the project's last written time. /// - /// The extension descriptor. - 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); - } + /// The extension descriptor. + 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) { From f1353e428a01af8b77bdccefdf8e0552f195890c Mon Sep 17 00:00:00 2001 From: andrerod Date: Mon, 21 Mar 2011 23:32:27 -0700 Subject: [PATCH 10/14] Fixing UT --HG-- branch : dev --- .../Packaging/Services/PackageBuilderTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs b/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs index 2a29d801c..953d35d02 100644 --- a/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs +++ b/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs @@ -4,6 +4,7 @@ using System.IO.Packaging; using Autofac; using NUnit.Framework; using Orchard.Environment.Extensions.Models; +using Orchard.FileSystems.VirtualPath; using Orchard.FileSystems.WebSite; using Orchard.Packaging.Services; using Orchard.Tests.Stubs; @@ -15,6 +16,7 @@ namespace Orchard.Tests.Modules.Packaging.Services { protected override void Register(ContainerBuilder builder) { builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As() .As().InstancePerLifetimeScope(); } From e65709a3a26e798268212a0b75a9b6af2f8c5904 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Tue, 22 Mar 2011 11:34:56 -0700 Subject: [PATCH 11/14] =?UTF-8?q?When=20creating=20a=20nupkg=20file,=20don?= =?UTF-8?q?=E2=80=99t=20include=20assemblies=20that=20are=20part=20of=20th?= =?UTF-8?q?e=20Orchard=20Frx=20(e.g.=20System.Web.Mvc.dll)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : dev --- .../Services/PackageBuilder.cs | 17 +++++++++++++---- .../Environment/IOrchardFrameworkAssemblies.cs | 14 ++++++++++++++ .../Razor/IRazorCompilationEvents.cs | 1 - src/Orchard/Orchard.Framework.csproj | 1 + 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/Orchard/Environment/IOrchardFrameworkAssemblies.cs diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs index aa6555520..2cbbad486 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs @@ -6,6 +6,7 @@ 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; @@ -18,6 +19,7 @@ namespace Orchard.Packaging.Services { 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" @@ -34,9 +36,12 @@ namespace Orchard.Packaging.Services { } public PackageBuilder(IWebSiteFolder webSiteFolder, - IVirtualPathProvider virtualPathProvider) { + IVirtualPathProvider virtualPathProvider, + IOrchardFrameworkAssemblies frameworkAssemblies) { + _webSiteFolder = webSiteFolder; _virtualPathProvider = virtualPathProvider; + _frameworkAssemblies = frameworkAssemblies; } public Stream BuildPackage(ExtensionDescriptor extensionDescriptor) { @@ -112,10 +117,14 @@ namespace Orchard.Packaging.Services { foreach (var entry in entries) { var assemblyName = new AssemblyName(entry.Include.Value); - 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); + // If it is not a core assembly + if (_frameworkAssemblies.GetFrameworkAssemblies().FirstOrDefault(assembly => assembly.FullName.Equals(assemblyName.FullName)) == 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); + } } } } diff --git a/src/Orchard/Environment/IOrchardFrameworkAssemblies.cs b/src/Orchard/Environment/IOrchardFrameworkAssemblies.cs new file mode 100644 index 000000000..2402cfb98 --- /dev/null +++ b/src/Orchard/Environment/IOrchardFrameworkAssemblies.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Reflection; + +namespace Orchard.Environment { + public interface IOrchardFrameworkAssemblies : IDependency { + IEnumerable GetFrameworkAssemblies(); + } + + public class DefaultOrchardFrameworkAssemblies : IOrchardFrameworkAssemblies { + public IEnumerable GetFrameworkAssemblies() { + return typeof (IDependency).Assembly.GetReferencedAssemblies(); + } + } +} diff --git a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs index c0933ff0f..a0d2b3769 100644 --- a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs +++ b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs @@ -7,7 +7,6 @@ using System.Web.WebPages.Razor; using Orchard.Environment; using Orchard.Environment.Extensions.Loaders; using Orchard.FileSystems.Dependencies; -using Orchard.FileSystems.VirtualPath; namespace Orchard.Mvc.ViewEngines.Razor { public interface IRazorCompilationEvents { diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 3e620961c..dc713d2b6 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -185,6 +185,7 @@ + From e3400973787a561b4329fee04c28c55223a4f60d Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Tue, 22 Mar 2011 12:04:42 -0700 Subject: [PATCH 12/14] Using simple name instead of full name. --HG-- branch : dev --- .../Modules/Orchard.Packaging/Services/PackageBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs index 2cbbad486..496f38e90 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Services/PackageBuilder.cs @@ -119,7 +119,7 @@ namespace Orchard.Packaging.Services { var assemblyName = new AssemblyName(entry.Include.Value); // If it is not a core assembly - if (_frameworkAssemblies.GetFrameworkAssemblies().FirstOrDefault(assembly => assembly.FullName.Equals(assemblyName.FullName)) == null) { + 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)) { From aa2d45c0b6e62f6d2302cf72a041a9ab0245351f Mon Sep 17 00:00:00 2001 From: Dave Reed Date: Tue, 22 Mar 2011 12:55:24 -0700 Subject: [PATCH 13/14] Squashed a bug with ResourceManager that sometimes resulted in missing resources. --HG-- branch : dev --- src/Orchard/UI/Resources/ResourceManager.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Orchard/UI/Resources/ResourceManager.cs b/src/Orchard/UI/Resources/ResourceManager.cs index c62faabef..634293830 100644 --- a/src/Orchard/UI/Resources/ResourceManager.cs +++ b/src/Orchard/UI/Resources/ResourceManager.cs @@ -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, RequireSettings> _required = new Dictionary, RequireSettings>(); private readonly List _links = new List(); private readonly Dictionary _metas = new Dictionary { @@ -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 }); From 1e452be3f69c6d475aaed8fe1985e131deca385c Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Tue, 22 Mar 2011 12:59:09 -0700 Subject: [PATCH 14/14] For theme views include all dependencies when compiling to allow theme views to be reference free. --HG-- branch : dev --- .../Packaging/Services/PackageBuilderTests.cs | 2 ++ .../ViewEngines/Razor/IRazorCompilationEvents.cs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs b/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs index 953d35d02..f2b7fa7a6 100644 --- a/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs +++ b/src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs @@ -3,6 +3,7 @@ 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; @@ -17,6 +18,7 @@ namespace Orchard.Tests.Modules.Packaging.Services { protected override void Register(ContainerBuilder builder) { builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType().As() .As().InstancePerLifetimeScope(); } diff --git a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs index a0d2b3769..6ef3ddf89 100644 --- a/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs +++ b/src/Orchard/Mvc/ViewEngines/Razor/IRazorCompilationEvents.cs @@ -42,21 +42,21 @@ namespace Orchard.Mvc.ViewEngines.Razor { } public void CodeGenerationStarted(RazorBuildProvider provider) { - DependencyDescriptor dependencyDescriptor = GetDependencyDescriptor(provider.VirtualPath); + DependencyDescriptor moduleDependencyDescriptor = GetModuleDependencyDescriptor(provider.VirtualPath); IEnumerable dependencyDescriptors = _dependenciesFolder.LoadDescriptors(); - List filteredDependencyDescriptors = new List(); - if (dependencyDescriptor != null) { + List filteredDependencyDescriptors; + if (moduleDependencyDescriptor != null) { // Add module - filteredDependencyDescriptors.Add(dependencyDescriptor); + filteredDependencyDescriptors = new List { moduleDependencyDescriptor }; // Add module's references - filteredDependencyDescriptors.AddRange(dependencyDescriptor.References + filteredDependencyDescriptors.AddRange(moduleDependencyDescriptor.References .SelectMany(reference => dependencyDescriptors .Where(dependency => dependency.Name == reference.Name))); } else { - // Fall back that shouldn't usually be called + // Fall back for themes filteredDependencyDescriptors = dependencyDescriptors.ToList(); } @@ -94,9 +94,9 @@ namespace Orchard.Mvc.ViewEngines.Razor { } } - private DependencyDescriptor GetDependencyDescriptor(string virtualPath) { + private DependencyDescriptor GetModuleDependencyDescriptor(string virtualPath) { var appRelativePath = VirtualPathUtility.ToAppRelative(virtualPath); - var prefix = PrefixMatch(appRelativePath, new [] { "~/Modules/", "~/Themes/", "~/Core/"}); + var prefix = PrefixMatch(appRelativePath, new [] { "~/Modules/", "~/Core/"}); if (prefix == null) return null;