From 286e43bc10d7de9f33c7811f760f3bbedc1ecc40 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 22 Mar 2016 12:48:59 +0100 Subject: [PATCH] U4-8222 Remove IMacroEngine - we will only ship with the macro engines we have currently --- .../Macros/MacroEngineFactoryTests.cs | 136 ------------------ src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - .../Macros/PartialViewMacroEngine.cs | 11 +- src/Umbraco.Web/umbraco.presentation/macro.cs | 3 +- src/umbraco.cms/PluginManagerExtensions.cs | 26 ---- .../businesslogic/macro/IMacroEngine.cs | 19 --- .../businesslogic/macro/MacroEngineFactory.cs | 131 ----------------- src/umbraco.cms/umbraco.cms.csproj | 3 - 8 files changed, 3 insertions(+), 327 deletions(-) delete mode 100644 src/Umbraco.Tests/Macros/MacroEngineFactoryTests.cs delete mode 100644 src/umbraco.cms/PluginManagerExtensions.cs delete mode 100644 src/umbraco.cms/businesslogic/macro/IMacroEngine.cs delete mode 100644 src/umbraco.cms/businesslogic/macro/MacroEngineFactory.cs diff --git a/src/Umbraco.Tests/Macros/MacroEngineFactoryTests.cs b/src/Umbraco.Tests/Macros/MacroEngineFactoryTests.cs deleted file mode 100644 index c7211e9fb0..0000000000 --- a/src/Umbraco.Tests/Macros/MacroEngineFactoryTests.cs +++ /dev/null @@ -1,136 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Moq; -using NUnit.Framework; -using umbraco.cms.businesslogic.macro; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Profiling; -using Umbraco.Core.Models; - -namespace Umbraco.Tests.Macros -{ - [TestFixture] - public class MacroEngineFactoryTests - { - [SetUp] - public void Initialize() - { - var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); - - //this ensures its reset - PluginManager.Current = new PluginManager(new ActivatorServiceProvider(), new NullCacheProvider(), - logger, - false) - { - AssembliesToScan = new[] - { - this.GetType().Assembly - } - }; - - //for testing, we'll specify which assemblies are scanned for the PluginTypeResolver - } - - [TearDown] - public void TearDown() - { - PluginManager.Current = null; - } - - [Test] - public void Get_All() - { - var engines = MacroEngineFactory.GetAll(); - Assert.AreEqual(2, engines.Count); - } - - [Test] - public void Get_Engine() - { - var engine1 = MacroEngineFactory.GetEngine("MacroEngine1"); - Assert.IsNotNull(engine1); - } - - [Test] - public void Get_By_Filename() - { - var engine1 = MacroEngineFactory.GetByFilename("test.me1"); - var engine2 = MacroEngineFactory.GetByFilename("test.me2"); - Assert.IsNotNull(engine1); - Assert.IsNotNull(engine2); - Assert.Throws(() => MacroEngineFactory.GetByFilename("test.blah")); - - } - - [Test] - public void Get_By_Extension() - { - var engine1 = MacroEngineFactory.GetByExtension("me1"); - var engine2 = MacroEngineFactory.GetByExtension("me2"); - Assert.IsNotNull(engine1); - Assert.IsNotNull(engine2); - Assert.Throws(() => MacroEngineFactory.GetByExtension("blah")); - } - - #region Classes for tests - public class MacroEngine1 : IMacroEngine - { - public string Name - { - get { return "MacroEngine1"; } - } - - public IEnumerable SupportedExtensions - { - get { return new[] {"me1"}; } - } - - public IEnumerable SupportedUIExtensions - { - get { throw new NotImplementedException(); } - } - - public bool Validate(string code, string tempFileName, IPublishedContent currentPage, out string errorMessage) - { - throw new NotImplementedException(); - } - - public string Execute(MacroModel macro, IPublishedContent currentPage) - { - throw new NotImplementedException(); - } - } - - public class MacroEngine2 : IMacroEngine - { - public string Name - { - get { return "MacroEngine2"; } - } - - public IEnumerable SupportedExtensions - { - get { return new[] { "me2" }; } - } - - public IEnumerable SupportedUIExtensions - { - get { throw new NotImplementedException(); } - } - - public bool Validate(string code, string tempFileName, IPublishedContent currentPage, out string errorMessage) - { - throw new NotImplementedException(); - } - - public string Execute(MacroModel macro, IPublishedContent currentPage) - { - throw new NotImplementedException(); - } - } - #endregion - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 53060d1274..8dd049f1cf 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -509,7 +509,6 @@ - diff --git a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs index 44a60daa6d..aee04cfb29 100644 --- a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs @@ -21,13 +21,11 @@ namespace Umbraco.Web.Macros /// /// A macro engine using MVC Partial Views to execute /// - public class PartialViewMacroEngine : IMacroEngine + public class PartialViewMacroEngine { private readonly Func _getHttpContext; private readonly Func _getUmbracoContext; - - public const string EngineName = "Partial View Macro Engine"; - + public PartialViewMacroEngine() { _getHttpContext = () => @@ -56,11 +54,6 @@ namespace Umbraco.Web.Macros _getUmbracoContext = () => umbracoContext; } - public string Name - { - get { return EngineName; } - } - //NOTE: We do not return any supported extensions because we don't want the MacroEngineFactory to return this // macro engine when searching for engines via extension. Those types of engines are reserved for files that are // stored in the ~/macroScripts folder and each engine must support unique extensions. This is a total Hack until diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index 1ad920cb88..e4234587d5 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -1236,9 +1236,8 @@ namespace umbraco internal PartialViewMacroResult LoadPartialViewMacro(MacroModel macro) { var retVal = new PartialViewMacroResult(); - IMacroEngine engine = null; + var engine = new PartialViewMacroEngine(); - engine = MacroEngineFactory.GetEngine(PartialViewMacroEngine.EngineName); var ret = engine.Execute(macro, UmbracoContext.Current.PublishedContentRequest.PublishedContent); retVal.Result = ret; diff --git a/src/umbraco.cms/PluginManagerExtensions.cs b/src/umbraco.cms/PluginManagerExtensions.cs deleted file mode 100644 index 504a65d9ed..0000000000 --- a/src/umbraco.cms/PluginManagerExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using Umbraco.Core; -using umbraco.cms.businesslogic.macro; -using umbraco.cms.businesslogic.media; - -namespace umbraco.cms -{ - /// - /// Extension methods for the PluginTypeResolver - /// - public static class PluginManagerExtensions - { - - /// - /// Returns all available IDataType in application - /// - /// - /// - internal static IEnumerable ResolveMacroEngines(this PluginManager resolver) - { - return resolver.ResolveTypes(); - } - - } -} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs b/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs deleted file mode 100644 index f79c422968..0000000000 --- a/src/umbraco.cms/businesslogic/macro/IMacroEngine.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Umbraco.Core.Models; - -namespace umbraco.cms.businesslogic.macro -{ - [Obsolete("Get rid of this!! move it and make it good")] - public interface IMacroEngine - { - string Name { get; } - IEnumerable SupportedExtensions { get; } - IEnumerable SupportedUIExtensions { get; } - - bool Validate(string code, string tempFileName, IPublishedContent currentPage, out string errorMessage); - string Execute(MacroModel macro, IPublishedContent currentPage); - } -} diff --git a/src/umbraco.cms/businesslogic/macro/MacroEngineFactory.cs b/src/umbraco.cms/businesslogic/macro/MacroEngineFactory.cs deleted file mode 100644 index 46807bc352..0000000000 --- a/src/umbraco.cms/businesslogic/macro/MacroEngineFactory.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Umbraco.Core; - -namespace umbraco.cms.businesslogic.macro -{ - - //TODO: This class needs to be changed to use the new MultipleResolverBase, doing this will require migrating and cleaning up - // a bunch of types so I have left it existing here under legacy code for now. The IMacroEngine interface also requires fixing - // considering the new macro types of SurfaceControllers. - - public class MacroEngineFactory - { - private static readonly List AllEngines = new List(); - private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim(); - private static volatile bool _isInitialized = false; - - public MacroEngineFactory() - { - EnsureInitialize(); - } - - internal static void EnsureInitialize() - { - using (var lck = new UpgradeableReadLock(Lock)) - { - if (_isInitialized) - return; - - lck.UpgradeToWriteLock(); - - AllEngines.Clear(); - - AllEngines.AddRange( - PluginManager.Current.CreateInstances( - PluginManager.Current.ResolveMacroEngines())); - - _isInitialized = true; - } - } - - /// - /// Returns a collectino of MacroEngineLanguage objects, each of which describes a file extension and an associated macro engine that - /// supports file extension lookups. - /// - /// - /// - /// The PartialViewMacroEngine will never be returned in these results because it does not support searching by file extensions. See - /// the notes in the PartialViewMacroEngine regarding this. - /// - public static IEnumerable GetSupportedUILanguages() - { - var languages = new List(); - foreach (var engine in GetAll()) - { - foreach (string lang in engine.SupportedUIExtensions) - { - if (languages.All(t => t.Extension != lang)) - { - languages.Add(new MacroEngineLanguage(lang, engine.Name)); - } - } - } - return languages.OrderBy(s => s.Extension); - } - - public static List GetAll() - { - EnsureInitialize(); - return AllEngines; - } - - public static IMacroEngine GetEngine(string name) - { - EnsureInitialize(); - var engine = AllEngines.FirstOrDefault(x => x.Name == name); - return engine; - } - - public static IMacroEngine GetByFilename(string filename) - { - if (filename.Contains(".")) - { - string extension = filename.Substring(filename.LastIndexOf(".") + 1); - return GetByExtension(extension); - } - - throw new MacroEngineException(string.Format("No MacroEngine matches the file with extension '{0}'", filename)); - } - - public static IMacroEngine GetByExtension(string extension) - { - var engine = GetAll().Find(t => t.SupportedExtensions.Contains(extension)); - if (engine != null) - { - return engine; - } - - throw new MacroEngineException(string.Format("No MacroEngine found for extension '{0}'", extension)); - } - } - - public class MacroEngineException : Exception - { - public MacroEngineException() : base() { } - - public MacroEngineException(string msg) - : base(msg) - { - - } - } - - public class MacroEngineLanguage - { - public string Extension { get; set; } - public string EngineName { get; set; } - public MacroEngineLanguage() - { - - } - - public MacroEngineLanguage(string extension, string engineName) - { - Extension = extension; - EngineName = engineName; - } - } -} diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index 1858e57393..f8a7bcd716 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -164,8 +164,6 @@ - - @@ -178,7 +176,6 @@ - Code