diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 8cbb3bf0b5..efb020aac2 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -113,6 +113,9 @@ namespace Umbraco.Core ActionsResolver.Current = new ActionsResolver( PluginManager.Current.ResolveActions()); + MacroPropertyTypeResolver.Current = new MacroPropertyTypeResolver( + PluginManager.Current.ResolveMacroPropertyTypes()); + PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver( new [] { diff --git a/src/Umbraco.Core/DataTypesResolver.cs b/src/Umbraco.Core/DataTypesResolver.cs index 024fecc1ee..c9eba4f074 100644 --- a/src/Umbraco.Core/DataTypesResolver.cs +++ b/src/Umbraco.Core/DataTypesResolver.cs @@ -10,8 +10,6 @@ namespace Umbraco.Core /// internal sealed class DataTypesResolver : LegacyTransientObjectsResolver { - - /// /// Constructor /// diff --git a/src/Umbraco.Core/MacroPropertyTypeResolver.cs b/src/Umbraco.Core/MacroPropertyTypeResolver.cs new file mode 100644 index 0000000000..bc4bc786ae --- /dev/null +++ b/src/Umbraco.Core/MacroPropertyTypeResolver.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using Umbraco.Core.Models; +using Umbraco.Core.ObjectResolution; + +namespace Umbraco.Core +{ + /// + /// A resolver to return all objects + /// + internal sealed class MacroPropertyTypeResolver : ManyObjectsResolverBase + { + /// + /// Constructor + /// + /// + internal MacroPropertyTypeResolver(IEnumerable macroPropertyTypes) + : base(macroPropertyTypes) + { + + } + + /// + /// Gets the implementations. + /// + public IEnumerable MacroPropertyTypes + { + get + { + return Values; + } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/IMacro.cs b/src/Umbraco.Core/Models/IMacro.cs index c46a32c790..a35784aa8b 100644 --- a/src/Umbraco.Core/Models/IMacro.cs +++ b/src/Umbraco.Core/Models/IMacro.cs @@ -89,6 +89,6 @@ namespace Umbraco.Core.Models /// Returns an enum based on the properties on the Macro /// /// - MacroTypes FindMacroType(); + MacroTypes MacroType(); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Macro.cs b/src/Umbraco.Core/Models/Macro.cs index 23d60c0d9e..c5829831ab 100644 --- a/src/Umbraco.Core/Models/Macro.cs +++ b/src/Umbraco.Core/Models/Macro.cs @@ -105,7 +105,7 @@ namespace Umbraco.Core.Models /// Returns an enum based on the properties on the Macro /// /// - public MacroTypes FindMacroType() + public MacroTypes MacroType() { if (!string.IsNullOrEmpty(Xslt)) return MacroTypes.Xslt; diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 5523ecefc6..02e51a0e84 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Text; using System.Threading; using Umbraco.Core.Logging; +using Umbraco.Core.Models; using umbraco.interfaces; namespace Umbraco.Core @@ -103,6 +104,15 @@ namespace Umbraco.Core return ResolveTypes(); } + /// + /// Returns all available IMacroPropertyTypes in application + /// + /// + internal IEnumerable ResolveMacroPropertyTypes() + { + return ResolveTypes(); + } + /// /// Gets/sets which assemblies to scan when type finding, generally used for unit testing, if not explicitly set /// this will search all assemblies known to have plugins and exclude ones known to not have them. diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 3ac230829e..beb813000e 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -71,6 +71,7 @@ + diff --git a/src/Umbraco.Web/Services/FileService.cs b/src/Umbraco.Web/Services/FileService.cs index 7470ec81c8..f9587a05cd 100644 --- a/src/Umbraco.Web/Services/FileService.cs +++ b/src/Umbraco.Web/Services/FileService.cs @@ -6,11 +6,14 @@ using Umbraco.Core.Persistence.UnitOfWork; namespace Umbraco.Web.Services { + /// + /// Represents the File Service, which is an easy access to operations involving objects like Scripts, Stylesheets and Templates + /// public class FileService : IFileService { private readonly IUnitOfWorkProvider _provider; - public FileService() : this(new PetaPocoUnitOfWorkProvider()) + public FileService() : this(new FileUnitOfWorkProvider()) { } diff --git a/src/Umbraco.Web/Services/IMacroService.cs b/src/Umbraco.Web/Services/IMacroService.cs new file mode 100644 index 0000000000..8a5089daba --- /dev/null +++ b/src/Umbraco.Web/Services/IMacroService.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using Umbraco.Core.Models; + +namespace Umbraco.Web.Services +{ + /// + /// Defines the ContentService, which is an easy access to operations involving + /// + public interface IMacroService : IService + { + //TODO Possibly create import macro method and ToXml? + + /// + /// Gets an object by its alias + /// + /// Alias to retrieve an for + /// An object + IMacro GetByAlias(string alias); + + /// + /// Gets a list all available objects + /// + /// Optional array of aliases to limit the results + /// An enumerable list of objects + IEnumerable GetAll(params string[] aliases); + + /// + /// Deletes an + /// + /// to delete + void Delete(IMacro macro); + + /// + /// Saves an + /// + /// to save + void Save(IMacro macro); + + /// + /// Gets a list all available plugins + /// + /// An enumerable list of objects + IEnumerable GetMacroPropertyTypes(); + + /// + /// Gets an by its alias + /// + /// Alias to retrieve an for + /// An object + IMacroPropertyType GetMacroPropertyTypeByAlias(string alias); + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Services/MacroService.cs b/src/Umbraco.Web/Services/MacroService.cs new file mode 100644 index 0000000000..530c1e1e75 --- /dev/null +++ b/src/Umbraco.Web/Services/MacroService.cs @@ -0,0 +1,105 @@ +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Persistence.UnitOfWork; + +namespace Umbraco.Web.Services +{ + /// + /// Represents the Macro Service, which is an easy access to operations involving + /// + public class MacroService : IMacroService + { + private readonly IUnitOfWorkProvider _provider; + + public MacroService() + : this(new FileUnitOfWorkProvider()) + { + } + + public MacroService(IUnitOfWorkProvider provider) + { + _provider = provider; + EnsureMacroCache(); + } + + /// + /// Ensures the macro cache by getting all macros + /// from the repository and thus caching them. + /// + private void EnsureMacroCache() + { + IEnumerable macros = GetAll(); + } + + /// + /// Gets an object by its alias + /// + /// Alias to retrieve an for + /// An object + public IMacro GetByAlias(string alias) + { + var unitOfWork = _provider.GetUnitOfWork(); + var repository = RepositoryResolver.ResolveByType(unitOfWork); + return repository.Get(alias); + } + + /// + /// Gets a list all available objects + /// + /// Optional array of aliases to limit the results + /// An enumerable list of objects + public IEnumerable GetAll(params string[] aliases) + { + var unitOfWork = _provider.GetUnitOfWork(); + var repository = RepositoryResolver.ResolveByType(unitOfWork); + return repository.GetAll(aliases); + } + + /// + /// Deletes an + /// + /// to delete + public void Delete(IMacro macro) + { + var unitOfWork = _provider.GetUnitOfWork(); + var repository = RepositoryResolver.ResolveByType(unitOfWork); + repository.Delete(macro); + unitOfWork.Commit(); + } + + /// + /// Saves an + /// + /// to save + public void Save(IMacro macro) + { + var unitOfWork = _provider.GetUnitOfWork(); + var repository = RepositoryResolver.ResolveByType(unitOfWork); + repository.AddOrUpdate(macro); + unitOfWork.Commit(); + } + + /// + /// Gets a list all available plugins + /// + /// An enumerable list of objects + public IEnumerable GetMacroPropertyTypes() + { + return MacroPropertyTypeResolver.Current.MacroPropertyTypes; + } + + /// + /// Gets an by its alias + /// + /// Alias to retrieve an for + /// An object + public IMacroPropertyType GetMacroPropertyTypeByAlias(string alias) + { + return MacroPropertyTypeResolver.Current.MacroPropertyTypes.FirstOrDefault(x => x.Alias == alias); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Services/ServiceContext.cs b/src/Umbraco.Web/Services/ServiceContext.cs index 6cd7016e3c..0ccade4292 100644 --- a/src/Umbraco.Web/Services/ServiceContext.cs +++ b/src/Umbraco.Web/Services/ServiceContext.cs @@ -34,6 +34,7 @@ namespace Umbraco.Web.Services private void BuildServiceCache() { var provider = new PetaPocoUnitOfWorkProvider(); + var fileProvider = new FileUnitOfWorkProvider(); var publishingStrategy = new PublishingStrategy(); var contentService = new ContentService(provider, publishingStrategy); @@ -42,13 +43,16 @@ namespace Umbraco.Web.Services var mediaService = new MediaService(provider); _cache.AddOrUpdate(typeof(IMediaService).Name, mediaService, (x, y) => mediaService); + var macroService = new MacroService(fileProvider); + _cache.AddOrUpdate(typeof (IMacroService).Name, macroService, (x, y) => macroService); + var contentTypeService = new ContentTypeService(contentService, mediaService, provider); _cache.AddOrUpdate(typeof(IContentTypeService).Name, contentTypeService, (x, y) => contentTypeService); var dataTypeService = new DataTypeService(provider); _cache.AddOrUpdate(typeof(IDataTypeService).Name, dataTypeService, (x, y) => dataTypeService); - var fileService = new FileService(provider); + var fileService = new FileService(fileProvider); _cache.AddOrUpdate(typeof(IFileService).Name, fileService, (x, y) => fileService); var localizationService = new LocalizationService(provider); @@ -102,5 +106,13 @@ namespace Umbraco.Web.Services { get { return _cache[typeof(IMediaService).Name] as IMediaService; } } + + /// + /// Gets the + /// + public IMacroService MacroService + { + get { return _cache[typeof(IMacroService).Name] as IMacroService; } + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Services/ServiceFactory.cs b/src/Umbraco.Web/Services/ServiceFactory.cs new file mode 100644 index 0000000000..db4432d869 --- /dev/null +++ b/src/Umbraco.Web/Services/ServiceFactory.cs @@ -0,0 +1,65 @@ +namespace Umbraco.Web.Services +{ + /// + /// Represents the ServiceFactory, which provides access to the various services in + /// a non-singleton way. + /// + public static class ServiceFactory + { + /// + /// Gets the + /// + public static IContentService ContentService + { + get { return ServiceContext.Current.ContentService; } + } + + /// + /// Gets the + /// + public static IContentTypeService ContentTypeService + { + get { return ServiceContext.Current.ContentTypeService; } + } + + /// + /// Gets the + /// + public static IDataTypeService DataTypeService + { + get { return ServiceContext.Current.DataTypeService; } + } + + /// + /// Gets the + /// + public static IFileService FileService + { + get { return ServiceContext.Current.FileService; } + } + + /// + /// Gets the + /// + public static ILocalizationService LocalizationService + { + get { return ServiceContext.Current.LocalizationService; } + } + + /// + /// Gets the + /// + public static IMediaService MediaService + { + get { return ServiceContext.Current.MediaService; } + } + + /// + /// Gets the + /// + public static IMacroService MacroService + { + get { return ServiceContext.Current.MacroService; } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 9f3080b756..e34bfa989d 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -323,11 +323,14 @@ + + + ASPXCodeBehind