Moving interfaces for services to Umbraco.Core.

Adding xml extensions for Content to generate xml for the xml cache.
Adding test for xml generation.
This commit is contained in:
sitereactor
2012-11-06 10:47:14 -01:00
parent f438ad16e0
commit ec9880968f
37 changed files with 247 additions and 97 deletions

View File

@@ -1,14 +1,9 @@
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Caching;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
namespace Umbraco.Core
@@ -138,5 +133,13 @@ namespace Umbraco.Core
if (this.IsReady)
throw new Exception("ApplicationContext has already been initialized.");
}
/// <summary>
/// Gets the current DatabaseContext
/// </summary>
public DatabaseContext DatabaseContext
{
get { return DatabaseContext.Current; }
}
}
}

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core.Models
{
@@ -41,6 +43,44 @@ namespace Umbraco.Core.Models
}
}
//TODO Possibly add a ToXml method, which will generate valid xml for the current Content object
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content)
{
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
var xml = new XElement(nodeName,
new XAttribute("id", content.Id),
new XAttribute("parentID", content.Level > 1 ? content.ParentId : -1),
new XAttribute("level", content.Level),
new XAttribute("writerID", content.Writer.Id),
new XAttribute("creatorID", content.Creator.Id),
new XAttribute("nodeType", content.ContentType.Id),
new XAttribute("template", content.Template),//Template name versus Id
new XAttribute("sortOrder", content.SortOrder),
new XAttribute("createDate", content.CreateDate),
new XAttribute("updateDate", content.UpdateDate),
new XAttribute("nodeName", content.Name),
new XAttribute("urlName", content.UrlName),//Format Url ?
new XAttribute("writerName", content.Writer.Name),
new XAttribute("creatorName", content.Creator.Name),
new XAttribute("path", content.Path));
foreach (var property in content.Properties)
{
if (property == null) continue;
xml.Add(property.ToXml());
if (property.Alias == "umbracoUrlName" && property.Value.ToString().Trim() != string.Empty)
xml.SetAttributeValue("urlName", property.Value);
}
return xml;
}
}
}

View File

@@ -61,6 +61,12 @@ namespace Umbraco.Core.Models
[IgnoreDataMember]
internal DataTypeDatabaseType DataTypeDatabaseType { get { return _propertyType.DataTypeDatabaseType; } }
/// <summary>
/// Returns the PropertyType, which this Property is based on
/// </summary>
[IgnoreDataMember]
internal PropertyType PropertyType { get { return _propertyType; } }
/// <summary>
/// Gets or Sets the version id for the Property
/// </summary>

View File

@@ -0,0 +1,26 @@
using System;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core.Models
{
public static class PropertyExtensions
{
/// <summary>
/// Creates the xml representation for the <see cref="Property"/> object
/// </summary>
/// <param name="property"><see cref="Property"/> to generate xml for</param>
/// <returns>Xml of the property and its value</returns>
public static XElement ToXml(this Property property)
{
string nodeName = property.Alias.ToUmbracoAlias();
var xd = new XmlDocument();
XmlNode xmlNode = xd.CreateNode(XmlNodeType.Element, nodeName, "");
xmlNode.AppendChild(property.PropertyType.DataType(property.Id).Data.ToXMl(xd));
var element = xmlNode.GetXElement();
return element;
}
}
}

View File

@@ -126,7 +126,7 @@ namespace Umbraco.Core.Models
internal Guid DataTypeControlId
{
get { return _dataTypeControlId; }
private set
set
{
_dataTypeControlId = value;
OnPropertyChanged(DataTypeControlIdSelector);
@@ -140,7 +140,7 @@ namespace Umbraco.Core.Models
internal DataTypeDatabaseType DataTypeDatabaseType
{
get { return _dataTypeDatabaseType; }
private set
set
{
_dataTypeDatabaseType = value;
OnPropertyChanged(DataTypeDatabaseTypeSelector);

View File

@@ -8,6 +8,7 @@ namespace Umbraco.Core.Models
/// Resolves the IDataType for a PropertyType.
/// </summary>
/// <param name="propertyType">PropertyType that references a DataType</param>
/// <param name="propertyId">Id of the Property which references this DataType through its PropertyType</param>
/// <returns><see cref="IDataType"/></returns>
/// <remarks>
/// This extension method is left internal because we don't want to take
@@ -15,11 +16,12 @@ namespace Umbraco.Core.Models
/// be replaced by PropertyEditors. It is however needed to generate xml
/// for a property/propertytype when publishing.
/// </remarks>
internal static IDataType DataType(this PropertyType propertyType)
internal static IDataType DataType(this PropertyType propertyType, int propertyId)
{
Mandate.ParameterNotNull(propertyType, "propertyType");
var dataType = DataTypesResolver.Current.GetById(propertyType.DataTypeControlId);
dataType.DataTypeDefinitionId = propertyType.DataTypeId;
dataType.Data.PropertyId = propertyId;
return dataType;
}
}

View File

@@ -195,10 +195,19 @@ namespace Umbraco.Core.Persistence.Repositories
//Create the PropertyData for this version - cmsPropertyData
var propertyFactory = new PropertyFactory(entity.ContentType, entity.Version, entity.Id);
var propertyDataDtos = propertyFactory.BuildDto(entity.Properties);
var keyDictionary = new Dictionary<int, int>();
//Add Properties
foreach (var propertyDataDto in propertyDataDtos)
{
Database.Insert(propertyDataDto);
var primaryKey = Convert.ToInt32(Database.Insert(propertyDataDto));
keyDictionary.Add(propertyDataDto.PropertyTypeId, primaryKey);
}
//Update Properties with its newly set Id
foreach (var property in entity.Properties)
{
property.Id = keyDictionary[property.PropertyTypeId];
}
((ICanBeDirty)entity).ResetDirtyProperties();

View File

@@ -111,6 +111,11 @@ namespace Umbraco.Core.Persistence.Repositories
var propertyTypeDto = propertyFactory.BuildPropertyTypeDto(propertyGroup.Id, propertyType);
var primaryKey = Convert.ToInt32(Database.Insert(propertyTypeDto));
propertyType.Id = primaryKey;//Set Id on PropertyType
//Update the current PropertyType with correct ControlId and DatabaseType
var dataTypeDto = Database.FirstOrDefault<DataTypeDto>("WHERE nodeId = @Id", new { Id = propertyTypeDto.DataTypeId });
propertyType.DataTypeControlId = dataTypeDto.ControlId;
propertyType.DataTypeDatabaseType = dataTypeDto.DbType.EnumParse<DataTypeDatabaseType>(true);
}
}
}

View File

@@ -47,7 +47,7 @@ namespace Umbraco.Core.Persistence.Repositories
foreach (var contentTypeDto in list)
{
bool result = contentType.AddContentType(Get(contentTypeDto.ParentId));
//Do something if adding fails? (Should hopefully not be possible unless someone create a circular reference)
//Do something if adding fails? (Should hopefully not be possible unless someone created a circular reference)
}
((ICanBeDirty)contentType).ResetDirtyProperties();

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Publishing
{
/// <summary>
/// Abstract class for the implementation of an <see cref="IPublishingStrategy"/>, which provides the events used for publishing/unpublishing.
/// </summary>
public abstract class BasePublishingStrategy : IPublishingStrategy
{
public abstract bool Publish(IContent content, int userId);
public abstract bool PublishWithChildren(IEnumerable<IContent> content, int userId);
public abstract bool UnPublish(IContent content, int userId);
public abstract bool UnPublish(IEnumerable<IContent> content, int userId);
/// <summary>
/// Occurs before publish
/// </summary>
public static event EventHandler<PublishingEventArgs> Publishing;
/// <summary>
/// Raises the <see cref="Publishing"/> event
/// </summary>
/// <param name="content"> </param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected virtual void OnPublish(IContent content, PublishingEventArgs e)
{
if (Publishing != null)
Publishing(content, e);
}
/// <summary>
/// Occurs after publish
/// </summary>
public static event EventHandler<PublishingEventArgs> Published;
/// <summary>
/// Raises the <see cref="Published"/> event
/// </summary>
/// <param name="content"> </param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected virtual void OnPublished(IContent content, PublishingEventArgs e)
{
if (Published != null)
Published(content, e);
}
/// <summary>
/// Occurs before unpublish
/// </summary>
public static event EventHandler<PublishingEventArgs> UnPublishing;
/// <summary>
/// Raises the <see cref="UnPublishing"/> event
/// </summary>
/// <param name="content"> </param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected virtual void OnUnPublish(IContent content, PublishingEventArgs e)
{
if (UnPublishing != null)
UnPublishing(content, e);
}
/// <summary>
/// Occurs after unpublish
/// </summary>
public static event EventHandler<PublishingEventArgs> UnPublished;
/// <summary>
/// Raises the <see cref="UnPublished"/> event
/// </summary>
/// <param name="content"> </param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected virtual void OnUnPublished(IContent content, PublishingEventArgs e)
{
if (UnPublished != null)
UnPublished(content, e);
}
}
}

View File

@@ -0,0 +1,43 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Publishing
{
/// <summary>
/// Defines the Publishing Strategy
/// </summary>
public interface IPublishingStrategy
{
/// <summary>
/// Publishes a single piece of Content
/// </summary>
/// <param name="content"><see cref="IContent"/> to publish</param>
/// <param name="userId">Id of the User issueing the publish operation</param>
/// <returns>True if the publish operation was successfull and not cancelled, otherwise false</returns>
bool Publish(IContent content, int userId);
/// <summary>
/// Publishes a list of Content
/// </summary>
/// <param name="content">An enumerable list of <see cref="IContent"/></param>
/// <param name="userId">Id of the User issueing the publish operation</param>
/// <returns>True if the publish operation was successfull and not cancelled, otherwise false</returns>
bool PublishWithChildren(IEnumerable<IContent> content, int userId);
/// <summary>
/// Unpublishes a single piece of Content
/// </summary>
/// <param name="content"><see cref="IContent"/> to unpublish</param>
/// <param name="userId">Id of the User issueing the unpublish operation</param>
/// <returns>True if the unpublish operation was successfull and not cancelled, otherwise false</returns>
bool UnPublish(IContent content, int userId);
/// <summary>
/// Unpublishes a list of Content
/// </summary>
/// <param name="content">An enumerable list of <see cref="IContent"/></param>
/// <param name="userId">Id of the User issueing the unpublish operation</param>
/// <returns>True if the unpublish operation was successfull and not cancelled, otherwise false</returns>
bool UnPublish(IEnumerable<IContent> content, int userId);
}
}

View File

@@ -0,0 +1,202 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the ContentService, which is an easy access to operations involving <see cref="IContent"/>
/// </summary>
public interface IContentService : IService
{
/// <summary>
/// Creates an <see cref="IContent"/> object using the alias of the <see cref="IContentType"/>
/// that this Content is based on.
/// </summary>
/// <param name="parentId">Id of Parent for content</param>
/// <param name="contentTypeAlias">Alias of the <see cref="IContentType"/></param>
/// <param name="userId">Optional id of the user creating the content</param>
/// <returns><see cref="IContent"/></returns>
IContent CreateContent(int parentId, string contentTypeAlias, int userId = -1);
//TODO Add CreateNewVersion method? Its currently used in the Document API when Publishing - latest version is published,
//but then a new version is created so latest version is not published.
//IContent CreateNewVersion(int id);
/// <summary>
/// Gets an <see cref="IContent"/> object by Id
/// </summary>
/// <param name="id">Id of the Content to retrieve</param>
/// <returns><see cref="IContent"/></returns>
IContent GetById(int id);
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects by the Id of the <see cref="IContentType"/>
/// </summary>
/// <param name="id">Id of the <see cref="IContentType"/></param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetContentOfContentType(int id);
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects by Level
/// </summary>
/// <param name="level">The level to retrieve Content from</param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetByLevel(int level);
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects by Parent Id
/// </summary>
/// <param name="id">Id of the Parent to retrieve Children from</param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetChildren(int id);
/// <summary>
/// Gets a collection of an <see cref="IContent"/> objects versions by its Id
/// </summary>
/// <param name="id"></param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetVersions(int id);
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which reside at the first level / root
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetRootContent();
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has an expiration date greater then today
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetContentForExpiration();
/// <summary>
/// Gets a collection of <see cref="IContent"/> objects, which has a release date greater then today
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetContentForRelease();
/// <summary>
/// Gets a collection of an <see cref="IContent"/> objects, which resides in the Recycle Bin
/// </summary>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetContentInRecycleBin();
/// <summary>
/// Re-Publishes all Content
/// </summary>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool RePublishAll(int userId = -1);
/// <summary>
/// Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool Publish(IContent content, int userId = -1);
/// <summary>
/// Publishes a <see cref="IContent"/> object and all its children
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish along with its children</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool PublishWithChildren(IContent content, int userId = -1);
/// <summary>
/// UnPublishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <returns>True if unpublishing succeeded, otherwise False</returns>
bool UnPublish(IContent content, int userId = -1);
/// <summary>
/// Saves and Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
bool SaveAndPublish(IContent content, int userId = -1);
/// <summary>
/// Saves a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save</param>
/// <param name="userId">Optional Id of the User saving the Content</param>
void Save(IContent content, int userId = -1);
/// <summary>
/// Saves a collection of <see cref="IContent"/> objects
/// </summary>
/// <param name="contents">Collection of <see cref="IContent"/> to save</param>
/// <param name="userId">Optional Id of the User saving the Content</param>
void Save(IEnumerable<IContent> contents, int userId = -1);
/// <summary>
/// Deletes all content of specified type. All children of deleted content is moved to Recycle Bin.
/// </summary>
/// <remarks>This needs extra care and attention as its potentially a dangerous and extensive operation</remarks>
/// <param name="contentTypeId">Id of the <see cref="IContentType"/></param>
void DeleteContentOfType(int contentTypeId);
/// <summary>
/// Permanently deletes an <see cref="IContent"/> object
/// </summary>
/// <remarks>Please note that this method will completely remove the Content from the database</remarks>
/// <param name="content">The <see cref="IContent"/> to delete</param>
/// <param name="userId">Optional Id of the User deleting the Content</param>
void Delete(IContent content, int userId = -1);
/// <summary>
/// Deletes an <see cref="IContent"/> object by moving it to the Recycle Bin
/// </summary>
/// <remarks>Move an item to the Recycle Bin will result in the item being unpublished</remarks>
/// <param name="content">The <see cref="IContent"/> to delete</param>
/// <param name="userId">Optional Id of the User deleting the Content</param>
void MoveToRecycleBin(IContent content, int userId = -1);
/// <summary>
/// Moves an <see cref="IContent"/> object to a new location
/// </summary>
/// <param name="content">The <see cref="IContent"/> to move</param>
/// <param name="parentId">Id of the Content's new Parent</param>
/// <param name="userId">Optional Id of the User moving the Content</param>
void Move(IContent content, int parentId, int userId = -1);
/// <summary>
/// Empties the Recycle Bin by deleting all <see cref="IContent"/> that resides in the bin
/// </summary>
void EmptyRecycleBin();
/// <summary>
/// Copies an <see cref="IContent"/> object by creating a new Content object of the same type and copies all data from the current
/// to the new copy which is returned.
/// </summary>
/// <param name="content">The <see cref="IContent"/> to copy</param>
/// <param name="parentId">Id of the Content's new Parent</param>
/// <param name="userId">Optional Id of the User copying the Content</param>
/// <returns>The newly created <see cref="IContent"/> object</returns>
IContent Copy(IContent content, int parentId, int userId = -1);
/// <summary>
/// Sends an <see cref="IContent"/> to Publication, which executes handlers and events for the 'Send to Publication' action.
/// </summary>
/// <param name="content">The <see cref="IContent"/> to send to publication</param>
/// <param name="userId">Optional Id of the User issueing the send to publication</param>
/// <returns>True if sending publication was succesfull otherwise false</returns>
bool SendToPublication(IContent content, int userId = -1);
/// <summary>
/// Rollback an <see cref="IContent"/> object to a previous version.
/// This will create a new version, which is a copy of all the old data.
/// </summary>
/// <param name="id">Id of the <see cref="IContent"/>being rolled back</param>
/// <param name="versionId">Id of the version to rollback to</param>
/// <param name="userId">Optional Id of the User issueing the rollback of the Content</param>
/// <returns>The newly created <see cref="IContent"/> object</returns>
IContent Rollback(int id, Guid versionId, int userId = -1);
}
}

View File

@@ -0,0 +1,119 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the ContentTypeService, which is an easy access to operations involving <see cref="IContentType"/>
/// </summary>
public interface IContentTypeService : IService
{
/// <summary>
/// Gets an <see cref="IContentType"/> object by its Id
/// </summary>
/// <param name="id">Id of the <see cref="IContentType"/> to retrieve</param>
/// <returns><see cref="IContentType"/></returns>
IContentType GetContentType(int id);
/// <summary>
/// Gets an <see cref="IContentType"/> object by its Alias
/// </summary>
/// <param name="alias">Alias of the <see cref="IContentType"/> to retrieve</param>
/// <returns><see cref="IContentType"/></returns>
IContentType GetContentType(string alias);
/// <summary>
/// Gets a list of all available <see cref="IContentType"/> objects
/// </summary>
/// <param name="ids">Optional list of ids</param>
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
IEnumerable<IContentType> GetAllContentTypes(params int[] ids);
/// <summary>
/// Gets a list of children for a <see cref="IContentType"/> object
/// </summary>
/// <param name="id">Id of the Parent</param>
/// <returns>An Enumerable list of <see cref="IContentType"/> objects</returns>
IEnumerable<IContentType> GetContentTypeChildren(int id);
/// <summary>
/// Saves a single <see cref="IContentType"/> object
/// </summary>
/// <param name="contentType"><see cref="IContentType"/> to save</param>
void Save(IContentType contentType);
/// <summary>
/// Saves a collection of <see cref="IContentType"/> objects
/// </summary>
/// <param name="contentTypes">Collection of <see cref="IContentType"/> to save</param>
void Save(IEnumerable<IContentType> contentTypes);
/// <summary>
/// Deletes a single <see cref="IContentType"/> object
/// </summary>
/// <param name="contentType"><see cref="IContentType"/> to delete</param>
/// <remarks>Deleting a <see cref="IContentType"/> will delete all the <see cref="IContent"/> objects based on this <see cref="IContentType"/></remarks>
void Delete(IContentType contentType);
/// <summary>
/// Deletes a collection of <see cref="IContentType"/> objects
/// </summary>
/// <param name="contentTypes">Collection of <see cref="IContentType"/> to delete</param>
/// <remarks>Deleting a <see cref="IContentType"/> will delete all the <see cref="IContent"/> objects based on this <see cref="IContentType"/></remarks>
void Delete(IEnumerable<IContentType> contentTypes);
/// <summary>
/// Gets an <see cref="IMediaType"/> object by its Id
/// </summary>
/// <param name="id">Id of the <see cref="IMediaType"/> to retrieve</param>
/// <returns><see cref="IMediaType"/></returns>
IMediaType GetMediaType(int id);
/// <summary>
/// Gets an <see cref="IMediaType"/> object by its Alias
/// </summary>
/// <param name="alias">Alias of the <see cref="IMediaType"/> to retrieve</param>
/// <returns><see cref="IMediaType"/></returns>
IMediaType GetMediaType(string alias);
/// <summary>
/// Gets a list of all available <see cref="IMediaType"/> objects
/// </summary>
/// <param name="ids">Optional list of ids</param>
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
IEnumerable<IMediaType> GetAllMediaTypes(params int[] ids);
/// <summary>
/// Gets a list of children for a <see cref="IMediaType"/> object
/// </summary>
/// <param name="id">Id of the Parent</param>
/// <returns>An Enumerable list of <see cref="IMediaType"/> objects</returns>
IEnumerable<IMediaType> GetMediaTypeChildren(int id);
/// <summary>
/// Saves a single <see cref="IMediaType"/> object
/// </summary>
/// <param name="mediaType"><see cref="IMediaType"/> to save</param>
void Save(IMediaType mediaType);
/// <summary>
/// Saves a collection of <see cref="IMediaType"/> objects
/// </summary>
/// <param name="mediaTypes">Collection of <see cref="IMediaType"/> to save</param>
void Save(IEnumerable<IMediaType> mediaTypes);
/// <summary>
/// Deletes a single <see cref="IMediaType"/> object
/// </summary>
/// <param name="mediaType"><see cref="IMediaType"/> to delete</param>
/// <remarks>Deleting a <see cref="IMediaType"/> will delete all the <see cref="IMedia"/> objects based on this <see cref="IMediaType"/></remarks>
void Delete(IMediaType mediaType);
/// <summary>
/// Deletes a collection of <see cref="IMediaType"/> objects
/// </summary>
/// <param name="mediaTypes">Collection of <see cref="IMediaType"/> to delete</param>
/// <remarks>Deleting a <see cref="IMediaType"/> will delete all the <see cref="IMedia"/> objects based on this <see cref="IMediaType"/></remarks>
void Delete(IEnumerable<IMediaType> mediaTypes);
}
}

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using umbraco.interfaces;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the DataType Service, which is an easy access to operations involving <see cref="IDataType"/> and <see cref="IDataTypeDefinition"/>
/// </summary>
public interface IDataTypeService : IService
{
/// <summary>
/// Gets a <see cref="IDataTypeDefinition"/> by its Id
/// </summary>
/// <param name="id">Id of the <see cref="IDataTypeDefinition"/></param>
/// <returns><see cref="IDataTypeDefinition"/></returns>
IDataTypeDefinition GetDataTypeDefinitionById(int id);
/// <summary>
/// Gets a <see cref="IDataTypeDefinition"/> by its control Id
/// </summary>
/// <param name="id">Id of the DataType control</param>
/// <returns><see cref="IDataTypeDefinition"/></returns>
IDataTypeDefinition GetDataTypeDefinitionById(Guid id);
/// <summary>
/// Gets all <see cref="IDataTypeDefinition"/> objects or those with the ids passed in
/// </summary>
/// <param name="ids">Optional array of Ids</param>
/// <returns>An enumerable list of <see cref="IDataTypeDefinition"/> objects</returns>
IEnumerable<IDataTypeDefinition> GetAllDataTypeDefinitions(params int[] ids);
/// <summary>
/// Saves an <see cref="IDataTypeDefinition"/>
/// </summary>
/// <param name="dataTypeDefinition"><see cref="IDataTypeDefinition"/> to save</param>
/// <param name="userId">Id of the user issueing the save</param>
void Save(IDataTypeDefinition dataTypeDefinition, int userId);
/// <summary>
/// Deletes an <see cref="IDataTypeDefinition"/>
/// </summary>
/// <remarks>
/// Please note that deleting a <see cref="IDataTypeDefinition"/> will remove
/// all the <see cref="PropertyType"/> data that references this <see cref="IDataTypeDefinition"/>.
/// </remarks>
/// <param name="dataTypeDefinition"><see cref="IDataTypeDefinition"/> to delete</param>
/// <param name="userId">Id of the user issueing the deletion</param>
void Delete(IDataTypeDefinition dataTypeDefinition, int userId);
/// <summary>
/// Gets the <see cref="IDataType"/> specified by it's unique ID
/// </summary>
/// <param name="id">Id of the DataType, which corresponds to the Guid Id of the control</param>
/// <returns><see cref="IDataType"/> object</returns>
IDataType GetDataTypeById(Guid id);
/// <summary>
/// Gets a complete list of all registered <see cref="IDataType"/>'s
/// </summary>
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
IEnumerable<IDataType> GetAllDataTypes();
}
}

View File

@@ -0,0 +1,107 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the File Service, which is an easy access to operations involving <see cref="IFile"/> objects like Scripts, Stylesheets and Templates
/// </summary>
public interface IFileService : IService
{
/// <summary>
/// Gets a list of all <see cref="Stylesheet"/> objects
/// </summary>
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
IEnumerable<Stylesheet> GetStylesheets(params string[] names);
/// <summary>
/// Gets a <see cref="Stylesheet"/> object by its name
/// </summary>
/// <param name="name">Name of the stylesheet incl. extension</param>
/// <returns>A <see cref="Stylesheet"/> object</returns>
Stylesheet GetStylesheetByName(string name);
/// <summary>
/// Saves a <see cref="Stylesheet"/>
/// </summary>
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
void SaveStylesheet(Stylesheet stylesheet);
/// <summary>
/// Deletes a stylesheet by its name
/// </summary>
/// <param name="name">Name incl. extension of the Stylesheet to delete</param>
void DeleteStylesheet(string name);
/// <summary>
/// Validates a <see cref="Stylesheet"/>
/// </summary>
/// <param name="stylesheet"><see cref="Stylesheet"/> to validate</param>
/// <returns>True if Stylesheet is valid, otherwise false</returns>
bool ValidateStylesheet(Stylesheet stylesheet);
/// <summary>
/// Gets a list of all <see cref="Script"/> objects
/// </summary>
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
IEnumerable<Script> GetScripts(params string[] names);
/// <summary>
/// Gets a <see cref="Script"/> object by its name
/// </summary>
/// <param name="name">Name of the script incl. extension</param>
/// <returns>A <see cref="Script"/> object</returns>
Script GetScriptByName(string name);
/// <summary>
/// Saves a <see cref="Script"/>
/// </summary>
/// <param name="script"><see cref="Script"/> to save</param>
void SaveScript(Script script);
/// <summary>
/// Deletes a script by its name
/// </summary>
/// <param name="name">Name incl. extension of the Script to delete</param>
void DeleteScript(string name);
/// <summary>
/// Validates a <see cref="Script"/>
/// </summary>
/// <param name="script"><see cref="Script"/> to validate</param>
/// <returns>True if Script is valid, otherwise false</returns>
bool ValidateScript(Script script);
/// <summary>
/// Gets a list of all <see cref="Template"/> objects
/// </summary>
/// <returns>An enumerable list of <see cref="Template"/> objects</returns>
IEnumerable<Template> GetTemplates(params string[] aliases);
/// <summary>
/// Gets a <see cref="Template"/> object by its alias
/// </summary>
/// <param name="alias">Alias of the template</param>
/// <returns>A <see cref="Template"/> object</returns>
Template GetTemplateByAlias(string alias);
/// <summary>
/// Saves a <see cref="Template"/>
/// </summary>
/// <param name="template"><see cref="Template"/> to save</param>
void SaveTemplate(Template template);
/// <summary>
/// Deletes a template by its alias
/// </summary>
/// <param name="alias">Alias of the <see cref="Template"/> to delete</param>
void DeleteTemplate(string alias);
/// <summary>
/// Validates a <see cref="Template"/>
/// </summary>
/// <param name="template"><see cref="Template"/> to validate</param>
/// <returns>True if Script is valid, otherwise false</returns>
bool ValidateTemplate(Template template);
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the Localization Service, which is an easy access to operations involving Languages and Dictionary
/// </summary>
public interface ILocalizationService : IService
{
//Possible to-do list:
//Import DictionaryItem (?)
//RemoveByLanguage (translations)
//Add/Set Text (Insert/Update)
//Remove Text (in translation)
/// <summary>
/// Gets a <see cref="IDictionaryItem"/> by its <see cref="Int32"/> id
/// </summary>
/// <param name="id">Id of the <see cref="IDictionaryItem"/></param>
/// <returns><see cref="IDictionaryItem"/></returns>
IDictionaryItem GetDictionaryItemById(int id);
/// <summary>
/// Gets a <see cref="IDictionaryItem"/> by its <see cref="Guid"/> id
/// </summary>
/// <param name="id">Id of the <see cref="IDictionaryItem"/></param>
/// <returns><see cref="IDictionaryItem"/></returns>
IDictionaryItem GetDictionaryItemById(Guid id);
/// <summary>
/// Gets a <see cref="IDictionaryItem"/> by its key
/// </summary>
/// <param name="key">Key of the <see cref="IDictionaryItem"/></param>
/// <returns><see cref="IDictionaryItem"/></returns>
IDictionaryItem GetDictionaryItemByKey(string key);
/// <summary>
/// Gets a list of children for a <see cref="IDictionaryItem"/>
/// </summary>
/// <param name="parentId">Id of the parent</param>
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
IEnumerable<IDictionaryItem> GetDictionaryItemChildren(Guid parentId);
/// <summary>
/// Gets the root/top <see cref="IDictionaryItem"/> objects
/// </summary>
/// <returns>An enumerable list of <see cref="IDictionaryItem"/> objects</returns>
IEnumerable<IDictionaryItem> GetRootDictionaryItems();
/// <summary>
/// Checks if a <see cref="IDictionaryItem"/> with given key exists
/// </summary>
/// <param name="key">Key of the <see cref="IDictionaryItem"/></param>
/// <returns>True if a <see cref="IDictionaryItem"/> exists, otherwise false</returns>
bool DictionaryItemExists(string key);
/// <summary>
/// Saves a <see cref="IDictionaryItem"/> object
/// </summary>
/// <param name="dictionaryItem"><see cref="IDictionaryItem"/> to save</param>
void Save(IDictionaryItem dictionaryItem);
/// <summary>
/// Deletes a <see cref="IDictionaryItem"/> object and its related translations
/// as well as its children.
/// </summary>
/// <param name="dictionaryItem"><see cref="IDictionaryItem"/> to delete</param>
void Delete(IDictionaryItem dictionaryItem);
/// <summary>
/// Gets a <see cref="ILanguage"/> by its id
/// </summary>
/// <param name="id">Id of the <see cref="ILanguage"/></param>
/// <returns><see cref="ILanguage"/></returns>
ILanguage GetLanguageById(int id);
/// <summary>
/// Gets a <see cref="ILanguage"/> by its culture code
/// </summary>
/// <param name="culture">Culture Code</param>
/// <returns><see cref="ILanguage"/></returns>
ILanguage GetLanguageByCultureCode(string culture);
/// <summary>
/// Gets all available languages
/// </summary>
/// <returns>An enumerable list of <see cref="ILanguage"/> objects</returns>
IEnumerable<ILanguage> GetAllLanguages();
/// <summary>
/// Saves a <see cref="ILanguage"/> object
/// </summary>
/// <param name="language"><see cref="ILanguage"/> to save</param>
void Save(ILanguage language);
/// <summary>
/// Deletes a <see cref="ILanguage"/> by removing it and its usages from the db
/// </summary>
/// <param name="language"><see cref="ILanguage"/> to delete</param>
void Delete(ILanguage language);
}
}

View File

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.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);
}
}

View File

@@ -0,0 +1,103 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the Media Service, which is an easy access to operations involving <see cref="IMedia"/>
/// </summary>
public interface IMediaService : IService
{
/// <summary>
/// Gets an <see cref="IMedia"/> object by Id
/// </summary>
/// <param name="id">Id of the Content to retrieve</param>
/// <returns><see cref="IMedia"/></returns>
IMedia GetById(int id);
/// <summary>
/// Gets a collection of <see cref="IMedia"/> objects by Parent Id
/// </summary>
/// <param name="id">Id of the Parent to retrieve Children from</param>
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
IEnumerable<IMedia> GetChildren(int id);
/// <summary>
/// Gets descendants of a <see cref="IMedia"/> object by its Id
/// </summary>
/// <param name="id">Id of the Parent to retrieve descendants from</param>
/// <returns>An Enumerable flat list of <see cref="IMedia"/> objects</returns>
IEnumerable<IMedia> GetDescendants(int id);
/// <summary>
/// Gets a collection of <see cref="IMedia"/> objects by the Id of the <see cref="IContentType"/>
/// </summary>
/// <param name="id">Id of the <see cref="IMediaType"/></param>
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
IEnumerable<IMedia> GetMediaOfMediaType(int id);
/// <summary>
/// Gets a collection of <see cref="IMedia"/> objects, which reside at the first level / root
/// </summary>
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
IEnumerable<IMedia> GetRootMedia();
/// <summary>
/// Gets a collection of an <see cref="IMedia"/> objects, which resides in the Recycle Bin
/// </summary>
/// <returns>An Enumerable list of <see cref="IMedia"/> objects</returns>
IEnumerable<IMedia> GetMediaInRecycleBin();
/// <summary>
/// Moves an <see cref="IMedia"/> object to a new location
/// </summary>
/// <param name="media">The <see cref="IMedia"/> to move</param>
/// <param name="parentId">Id of the Media's new Parent</param>
/// <param name="userId">Id of the User moving the Media</param>
void Move(IMedia media, int parentId, int userId);
/// <summary>
/// Deletes an <see cref="IMedia"/> object by moving it to the Recycle Bin
/// </summary>
/// <param name="media">The <see cref="IMedia"/> to delete</param>
/// <param name="userId">Id of the User deleting the Media</param>
void MoveToRecycleBin(IMedia media, int userId);
/// <summary>
/// Empties the Recycle Bin by deleting all <see cref="IMedia"/> that resides in the bin
/// </summary>
void EmptyRecycleBin();
/// <summary>
/// Deletes all media of specified type. All children of deleted media is moved to Recycle Bin.
/// </summary>
/// <remarks>This needs extra care and attention as its potentially a dangerous and extensive operation</remarks>
/// <param name="mediaTypeId">Id of the <see cref="IMediaType"/></param>
void DeleteMediaOfType(int mediaTypeId);
/// <summary>
/// Permanently deletes an <see cref="IMedia"/> object
/// </summary>
/// <remarks>
/// Please note that this method will completely remove the Media from the database,
/// but current not from the file system.
/// </remarks>
/// <param name="media">The <see cref="IMedia"/> to delete</param>
/// <param name="userId">Id of the User deleting the Media</param>
void Delete(IMedia media, int userId);
/// <summary>
/// Saves a single <see cref="IMedia"/> object
/// </summary>
/// <param name="media">The <see cref="IMedia"/> to save</param>
/// <param name="userId">Id of the User saving the Content</param>
void Save(IMedia media, int userId);
/// <summary>
/// Saves a collection of <see cref="IMedia"/> objects
/// </summary>
/// <param name="medias">Collection of <see cref="IMedia"/> to save</param>
/// <param name="userId">Id of the User saving the Content</param>
void Save(IEnumerable<IMedia> medias, int userId);
}
}

View File

@@ -0,0 +1,10 @@
namespace Umbraco.Core.Services
{
/// <summary>
/// Marker interface for services, which is used to store difference services in a list or dictionary
/// </summary>
public interface IService
{
}
}

View File

@@ -0,0 +1,16 @@
using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Services
{
/// <summary>
/// Defines the UserService, which is an easy access to operations involving <see cref="IProfile"/> and eventually Users and Members.
/// </summary>
public interface IUserService : IService
{
/// <summary>
/// Gets an <see cref="IProfile"/> for the current BackOffice User
/// </summary>
/// <returns><see cref="IProfile"/> containing the Name and Id of the logged in BackOffice User</returns>
IProfile GetCurrentBackOfficeUser();
}
}

View File

@@ -104,6 +104,7 @@
<Compile Include="Models\Membership\Profile.cs" />
<Compile Include="Models\Membership\User.cs" />
<Compile Include="Models\Membership\UserProfile.cs" />
<Compile Include="Models\PropertyExtensions.cs" />
<Compile Include="Models\PropertyTypeExtensions.cs" />
<Compile Include="Models\Rdbms\ContentType2ContentTypeDto.cs" />
<Compile Include="Models\Rdbms\PropertyTypeGroupDto.cs" />
@@ -376,6 +377,8 @@
<Compile Include="ObjectResolution\Resolution.cs" />
<Compile Include="ObjectResolution\ResolverBase.cs" />
<Compile Include="ObjectResolution\SingleObjectResolverBase.cs" />
<Compile Include="Publishing\BasePublishingStrategy.cs" />
<Compile Include="Publishing\IPublishingStrategy.cs" />
<Compile Include="RenderingEngine.cs" />
<Compile Include="Serialization\AbstractSerializationService.cs" />
<Compile Include="Serialization\Formatter.cs" />
@@ -387,6 +390,15 @@
<Compile Include="Serialization\ServiceStackJsonSerializer.cs" />
<Compile Include="Serialization\ServiceStackXmlSerializer.cs" />
<Compile Include="Serialization\StreamedResult.cs" />
<Compile Include="Services\IContentService.cs" />
<Compile Include="Services\IContentTypeService.cs" />
<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\IUserService.cs" />
<Compile Include="TypeExtensions.cs" />
<Compile Include="ReadLock.cs" />
<Compile Include="TypeFinder.cs" />

View File

@@ -1,15 +1,14 @@
using System;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core
{
/// <summary>
/// Extension methods for xml objects
/// </summary>
internal static class XmlExtensions
{
public static T AttributeValue<T>(this XmlNode xml, string attributeName)
{
if (xml == null) throw new ArgumentNullException("xml");
@@ -26,5 +25,22 @@ namespace Umbraco.Core
return default(T);
}
public static XElement GetXElement(this XmlNode node)
{
XDocument xDoc = new XDocument();
using (XmlWriter xmlWriter = xDoc.CreateWriter())
node.WriteTo(xmlWriter);
return xDoc.Root;
}
public static XmlNode GetXmlNode(this XElement element)
{
using (XmlReader xmlReader = element.CreateReader())
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
return xmlDoc;
}
}
}
}