using System; using System.Collections.Generic; using System.ComponentModel; using System.Xml.Linq; using Umbraco.Core.Configuration; using System.IO; using Umbraco.Core.Models; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services { /// /// A temporary interface until we are in v8, this is used to return a different result for the same method and this interface gets implemented /// explicitly. These methods will replace the normal ones in IContentService in v8 and this will be removed. /// public interface IMediaServiceOperations { //TODO: Remove this class in v8 //TODO: There's probably more that needs to be added like the EmptyRecycleBin, etc... /// /// Deletes an object by moving it to the Recycle Bin /// /// The to delete /// Id of the User deleting the Media Attempt MoveToRecycleBin(IMedia media, int userId = 0); /// /// Permanently deletes an object /// /// /// Please note that this method will completely remove the Media from the database, /// but current not from the file system. /// /// The to delete /// Id of the User deleting the Media Attempt Delete(IMedia media, int userId = 0); /// /// Saves a single object /// /// The to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. Attempt Save(IMedia media, int userId = 0, bool raiseEvents = true); /// /// Saves a collection of objects /// /// Collection of to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. Attempt Save(IEnumerable medias, int userId = 0, bool raiseEvents = true); } /// /// Defines the Media Service, which is an easy access to operations involving /// public interface IMediaService : IContentServiceBase { int CountNotTrashed(string contentTypeAlias = null); int Count(string mediaTypeAlias = null); int CountChildren(int parentId, string mediaTypeAlias = null); int CountDescendants(int parentId, string mediaTypeAlias = null); IEnumerable GetByIds(IEnumerable ids); IEnumerable GetByIds(IEnumerable ids); /// /// Creates an object using the alias of the /// that this Media should based on. /// /// /// Note that using this method will simply return a new IMedia without any identity /// as it has not yet been persisted. It is intended as a shortcut to creating new media objects /// that does not invoke a save operation against the database. /// /// Name of the Media object /// Id of Parent for the new Media item /// Alias of the /// Optional id of the user creating the media item /// IMedia CreateMedia(string name, Guid parentId, string mediaTypeAlias, int userId = 0); /// /// Creates an object using the alias of the /// that this Media should based on. /// /// /// Note that using this method will simply return a new IMedia without any identity /// as it has not yet been persisted. It is intended as a shortcut to creating new media objects /// that does not invoke a save operation against the database. /// /// Name of the Media object /// Id of Parent for the new Media item /// Alias of the /// Optional id of the user creating the media item /// IMedia CreateMedia(string name, int parentId, string mediaTypeAlias, int userId = 0); /// /// Creates an object using the alias of the /// that this Media should based on. /// /// /// Note that using this method will simply return a new IMedia without any identity /// as it has not yet been persisted. It is intended as a shortcut to creating new media objects /// that does not invoke a save operation against the database. /// /// Name of the Media object /// Parent for the new Media item /// Alias of the /// Optional id of the user creating the media item /// IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = 0); /// /// Gets an object by Id /// /// Id of the Content to retrieve /// IMedia GetById(int id); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Children from /// An Enumerable list of objects IEnumerable GetChildren(int id); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Children from /// Page number /// Page size /// Total records query would return without paging /// Field to order by /// Direction to order by /// Search text filter /// An Enumerable list of objects IEnumerable GetPagedChildren(int id, long pageIndex, int pageSize, out long totalRecords, string orderBy = "SortOrder", Direction orderDirection = Direction.Ascending, string filter = ""); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Children from /// Page number /// Page size /// Total records query would return without paging /// Field to order by /// Direction to order by /// Flag to indicate when ordering by system field /// /// An Enumerable list of objects IEnumerable GetPagedChildren(int id, long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, bool orderBySystemField, IQuery filter); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Children from /// Page number /// Page size /// Total records query would return without paging /// Field to order by /// Direction to order by /// Flag to indicate when ordering by system field /// Search text filter /// A list of content type Ids to filter the list by /// An Enumerable list of objects IEnumerable GetPagedChildren(int id, long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, bool orderBySystemField, string filter, int[] contentTypeFilter); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Descendants from /// Page number /// Page size /// Total records query would return without paging /// Field to order by /// Direction to order by /// Search text filter /// An Enumerable list of objects IEnumerable GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords, string orderBy = "path", Direction orderDirection = Direction.Ascending, string filter = ""); /// /// Gets a collection of objects by Parent Id /// /// Id of the Parent to retrieve Descendants from /// Page number /// Page size /// Total records query would return without paging /// Field to order by /// Direction to order by /// Flag to indicate when ordering by system field /// /// An Enumerable list of objects IEnumerable GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, bool orderBySystemField, IQuery filter); /// /// Gets descendants of a object by its Id /// /// Id of the Parent to retrieve descendants from /// An Enumerable flat list of objects IEnumerable GetDescendants(int id); /// /// Gets a collection of objects by the Id of the /// /// Id of the /// An Enumerable list of objects IEnumerable GetMediaOfMediaType(int id); /// /// Gets a collection of objects, which reside at the first level / root /// /// An Enumerable list of objects IEnumerable GetRootMedia(); /// /// Gets a collection of an objects, which resides in the Recycle Bin /// /// An Enumerable list of objects IEnumerable GetMediaInRecycleBin(); /// /// Moves an object to a new location /// /// The to move /// Id of the Media's new Parent /// Id of the User moving the Media void Move(IMedia media, int parentId, int userId = 0); /// /// Deletes an object by moving it to the Recycle Bin /// /// The to delete /// Id of the User deleting the Media void MoveToRecycleBin(IMedia media, int userId = 0); /// /// Empties the Recycle Bin by deleting all that resides in the bin /// OperationResult EmptyRecycleBin(); /// /// Deletes all media of specified type. All children of deleted media is moved to Recycle Bin. /// /// This needs extra care and attention as its potentially a dangerous and extensive operation /// Id of the /// Optional Id of the user deleting Media void DeleteMediaOfType(int mediaTypeId, int userId = 0); /// /// Deletes all media of the specified types. All Descendants of deleted media that is not of these types is moved to Recycle Bin. /// /// This needs extra care and attention as its potentially a dangerous and extensive operation /// Ids of the s /// Optional Id of the user issueing the delete operation void DeleteMediaOfTypes(IEnumerable mediaTypeIds, int userId = 0); /// /// Permanently deletes an object /// /// /// Please note that this method will completely remove the Media from the database, /// but current not from the file system. /// /// The to delete /// Id of the User deleting the Media void Delete(IMedia media, int userId = 0); /// /// Saves a single object /// /// The to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. void Save(IMedia media, int userId = 0, bool raiseEvents = true); /// /// Saves a collection of objects /// /// Collection of to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. void Save(IEnumerable medias, int userId = 0, bool raiseEvents = true); /// /// Gets an object by its 'UniqueId' /// /// Guid key of the Media to retrieve /// IMedia GetById(Guid key); /// /// Gets a collection of objects by Level /// /// The level to retrieve Media from /// An Enumerable list of objects IEnumerable GetByLevel(int level); /// /// Gets a specific version of an item. /// /// Id of the version to retrieve /// An item IMedia GetVersion(int versionId); /// /// Gets a collection of an objects versions by Id /// /// /// An Enumerable list of objects IEnumerable GetVersions(int id); /// /// Checks whether an item has any children /// /// Id of the /// True if the media has any children otherwise False bool HasChildren(int id); /// /// Permanently deletes versions from an object prior to a specific date. /// /// Id of the object to delete versions from /// Latest version date /// Optional Id of the User deleting versions of a Content object void DeleteVersions(int id, DateTime versionDate, int userId = 0); /// /// Permanently deletes specific version(s) from an object. /// /// Id of the object to delete a version from /// Id of the version to delete /// Boolean indicating whether to delete versions prior to the versionId /// Optional Id of the User deleting versions of a Content object void DeleteVersion(int id, int versionId, bool deletePriorVersions, int userId = 0); /// /// Gets an object from the path stored in the 'umbracoFile' property. /// /// Path of the media item to retrieve (for example: /media/1024/koala_403x328.jpg) /// IMedia GetMediaByPath(string mediaPath); /// /// Gets a collection of objects, which are ancestors of the current media. /// /// Id of the to retrieve ancestors for /// An Enumerable list of objects IEnumerable GetAncestors(int id); /// /// Gets a collection of objects, which are ancestors of the current media. /// /// to retrieve ancestors for /// An Enumerable list of objects IEnumerable GetAncestors(IMedia media); /// /// Gets descendants of a object by its Id /// /// The Parent object to retrieve descendants from /// An Enumerable flat list of objects IEnumerable GetDescendants(IMedia media); /// /// Gets the parent of the current media as an item. /// /// Id of the to retrieve the parent from /// Parent object IMedia GetParent(int id); /// /// Gets the parent of the current media as an item. /// /// to retrieve the parent from /// Parent object IMedia GetParent(IMedia media); /// /// Sorts a collection of objects by updating the SortOrder according /// to the ordering of items in the passed in . /// /// /// /// /// True if sorting succeeded, otherwise False bool Sort(IEnumerable items, int userId = 0, bool raiseEvents = true); /// /// Creates an object using the alias of the /// that this Media should based on. /// /// /// This method returns an object that has been persisted to the database /// and therefor has an identity. /// /// Name of the Media object /// Parent for the new Media item /// Alias of the /// Optional id of the user creating the media item /// IMedia CreateMediaWithIdentity(string name, IMedia parent, string mediaTypeAlias, int userId = 0); /// /// Creates an object using the alias of the /// that this Media should based on. /// /// /// This method returns an object that has been persisted to the database /// and therefor has an identity. /// /// Name of the Media object /// Id of Parent for the new Media item /// Alias of the /// Optional id of the user creating the media item /// IMedia CreateMediaWithIdentity(string name, int parentId, string mediaTypeAlias, int userId = 0); /// /// Gets the content of a media as a stream. /// /// The filesystem path to the media. /// The content of the media. Stream GetMediaFileContentStream(string filepath); /// /// Sets the content of a media. /// /// The filesystem path to the media. /// The content of the media. void SetMediaFileContent(string filepath, Stream content); /// /// Deletes a media file. /// /// The filesystem path to the media. void DeleteMediaFile(string filepath); /// /// Gets the size of a media. /// /// The filesystem path to the media. /// The size of the media. long GetMediaFileSize(string filepath); } }