Implements a basic version of the MacroService for U4-940
Adding a static ServiceFactory class for easy access to the various services in a non-singleton way. Adding a Resolver for MacroPropertyTypes. Updating the CoreBootManager and PluginManager to include the MacroPropertyTypeResolver.
This commit is contained in:
@@ -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 []
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
internal sealed class DataTypesResolver : LegacyTransientObjectsResolver<DataTypesResolver, IDataType>
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
|
||||
34
src/Umbraco.Core/MacroPropertyTypeResolver.cs
Normal file
34
src/Umbraco.Core/MacroPropertyTypeResolver.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// A resolver to return all <see cref="IMacroPropertyType"/> objects
|
||||
/// </summary>
|
||||
internal sealed class MacroPropertyTypeResolver : ManyObjectsResolverBase<MacroPropertyTypeResolver, IMacroPropertyType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="macroPropertyTypes"></param>
|
||||
internal MacroPropertyTypeResolver(IEnumerable<Type> macroPropertyTypes)
|
||||
: base(macroPropertyTypes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroPropertyType"/> implementations.
|
||||
/// </summary>
|
||||
public IEnumerable<IMacroPropertyType> MacroPropertyTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return Values;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,6 @@ namespace Umbraco.Core.Models
|
||||
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
|
||||
/// </summary>
|
||||
/// <returns><see cref="MacroTypes"/></returns>
|
||||
MacroTypes FindMacroType();
|
||||
MacroTypes MacroType();
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace Umbraco.Core.Models
|
||||
/// Returns an enum <see cref="MacroTypes"/> based on the properties on the Macro
|
||||
/// </summary>
|
||||
/// <returns><see cref="MacroTypes"/></returns>
|
||||
public MacroTypes FindMacroType()
|
||||
public MacroTypes MacroType()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Xslt))
|
||||
return MacroTypes.Xslt;
|
||||
|
||||
@@ -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<IAction>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all available IMacroPropertyTypes in application
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<Type> ResolveMacroPropertyTypes()
|
||||
{
|
||||
return ResolveTypes<IMacroPropertyType>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
<Compile Include="Dictionary\CultureDictionaryFactoryResolver.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
||||
<Compile Include="EventArgs.cs" />
|
||||
<Compile Include="MacroPropertyTypeResolver.cs" />
|
||||
<Compile Include="Models\ContentBase.cs" />
|
||||
<Compile Include="Models\ContentExtensions.cs" />
|
||||
<Compile Include="Enum.cs" />
|
||||
|
||||
@@ -6,11 +6,14 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the File Service, which is an easy access to operations involving <see cref="IFile"/> objects like Scripts, Stylesheets and Templates
|
||||
/// </summary>
|
||||
public class FileService : IFileService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
|
||||
public FileService() : this(new PetaPocoUnitOfWorkProvider())
|
||||
public FileService() : this(new FileUnitOfWorkProvider())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
52
src/Umbraco.Web/Services/IMacroService.cs
Normal file
52
src/Umbraco.Web/Services/IMacroService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the ContentService, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
public interface IMacroService : IService
|
||||
{
|
||||
//TODO Possibly create import macro method and ToXml?
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacro"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacro"/> for</param>
|
||||
/// <returns>An <see cref="IMacro"/> object</returns>
|
||||
IMacro GetByAlias(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacro"/> objects
|
||||
/// </summary>
|
||||
/// <param name="aliases">Optional array of aliases to limit the results</param>
|
||||
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns>
|
||||
IEnumerable<IMacro> GetAll(params string[] aliases);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to delete</param>
|
||||
void Delete(IMacro macro);
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to save</param>
|
||||
void Save(IMacro macro);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacroPropertyType"/> plugins
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IMacroPropertyType"/> objects</returns>
|
||||
IEnumerable<IMacroPropertyType> GetMacroPropertyTypes();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacroPropertyType"/> by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacroPropertyType"/> for</param>
|
||||
/// <returns>An <see cref="IMacroPropertyType"/> object</returns>
|
||||
IMacroPropertyType GetMacroPropertyTypeByAlias(string alias);
|
||||
}
|
||||
}
|
||||
105
src/Umbraco.Web/Services/MacroService.cs
Normal file
105
src/Umbraco.Web/Services/MacroService.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Macro Service, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
public class MacroService : IMacroService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
|
||||
public MacroService()
|
||||
: this(new FileUnitOfWorkProvider())
|
||||
{
|
||||
}
|
||||
|
||||
public MacroService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
EnsureMacroCache();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the macro cache by getting all macros
|
||||
/// from the repository and thus caching them.
|
||||
/// </summary>
|
||||
private void EnsureMacroCache()
|
||||
{
|
||||
IEnumerable<IMacro> macros = GetAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacro"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacro"/> for</param>
|
||||
/// <returns>An <see cref="IMacro"/> object</returns>
|
||||
public IMacro GetByAlias(string alias)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IMacroRepository, IMacro, string>(unitOfWork);
|
||||
return repository.Get(alias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacro"/> objects
|
||||
/// </summary>
|
||||
/// <param name="aliases">Optional array of aliases to limit the results</param>
|
||||
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns>
|
||||
public IEnumerable<IMacro> GetAll(params string[] aliases)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IMacroRepository, IMacro, string>(unitOfWork);
|
||||
return repository.GetAll(aliases);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to delete</param>
|
||||
public void Delete(IMacro macro)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IMacroRepository, IMacro, string>(unitOfWork);
|
||||
repository.Delete(macro);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
/// <param name="macro"><see cref="IMacro"/> to save</param>
|
||||
public void Save(IMacro macro)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IMacroRepository, IMacro, string>(unitOfWork);
|
||||
repository.AddOrUpdate(macro);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list all available <see cref="IMacroPropertyType"/> plugins
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IMacroPropertyType"/> objects</returns>
|
||||
public IEnumerable<IMacroPropertyType> GetMacroPropertyTypes()
|
||||
{
|
||||
return MacroPropertyTypeResolver.Current.MacroPropertyTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacroPropertyType"/> by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias to retrieve an <see cref="IMacroPropertyType"/> for</param>
|
||||
/// <returns>An <see cref="IMacroPropertyType"/> object</returns>
|
||||
public IMacroPropertyType GetMacroPropertyTypeByAlias(string alias)
|
||||
{
|
||||
return MacroPropertyTypeResolver.Current.MacroPropertyTypes.FirstOrDefault(x => x.Alias == alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroService"/>
|
||||
/// </summary>
|
||||
public IMacroService MacroService
|
||||
{
|
||||
get { return _cache[typeof(IMacroService).Name] as IMacroService; }
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/Umbraco.Web/Services/ServiceFactory.cs
Normal file
65
src/Umbraco.Web/Services/ServiceFactory.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the ServiceFactory, which provides access to the various services in
|
||||
/// a non-singleton way.
|
||||
/// </summary>
|
||||
public static class ServiceFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IContentService"/>
|
||||
/// </summary>
|
||||
public static IContentService ContentService
|
||||
{
|
||||
get { return ServiceContext.Current.ContentService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IContentTypeService"/>
|
||||
/// </summary>
|
||||
public static IContentTypeService ContentTypeService
|
||||
{
|
||||
get { return ServiceContext.Current.ContentTypeService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IDataTypeService"/>
|
||||
/// </summary>
|
||||
public static IDataTypeService DataTypeService
|
||||
{
|
||||
get { return ServiceContext.Current.DataTypeService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IFileService"/>
|
||||
/// </summary>
|
||||
public static IFileService FileService
|
||||
{
|
||||
get { return ServiceContext.Current.FileService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ILocalizationService"/>
|
||||
/// </summary>
|
||||
public static ILocalizationService LocalizationService
|
||||
{
|
||||
get { return ServiceContext.Current.LocalizationService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMediaService"/>
|
||||
/// </summary>
|
||||
public static IMediaService MediaService
|
||||
{
|
||||
get { return ServiceContext.Current.MediaService; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IMacroService"/>
|
||||
/// </summary>
|
||||
public static IMacroService MacroService
|
||||
{
|
||||
get { return ServiceContext.Current.MacroService; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,11 +323,14 @@
|
||||
<Compile Include="Services\IDataTypeService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\IMacroService.cs" />
|
||||
<Compile Include="Services\IMediaService.cs" />
|
||||
<Compile Include="Services\IService.cs" />
|
||||
<Compile Include="Services\LocalizationService.cs" />
|
||||
<Compile Include="Services\MacroService.cs" />
|
||||
<Compile Include="Services\MediaService.cs" />
|
||||
<Compile Include="Services\ServiceContext.cs" />
|
||||
<Compile Include="Services\ServiceFactory.cs" />
|
||||
<Compile Include="Templates\TemplateUtilities.cs" />
|
||||
<Compile Include="umbraco.presentation\Default.aspx.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
|
||||
Reference in New Issue
Block a user