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 { /// /// 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 = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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 /// 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, IQuery filter = null, Ordering ordering = null); /// /// 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 /// /// /// An Enumerable list of objects IEnumerable GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null); /// /// Gets paged documents of a content /// /// The page number. /// The page number. /// The page size. /// Total number of documents. /// Search text filter. /// Ordering infos. IEnumerable GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null); /// /// Gets paged documents for specified content types /// /// The page number. /// The page number. /// The page size. /// Total number of documents. /// Search text filter. /// Ordering infos. IEnumerable GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null); /// /// 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 GetPagedMediaInRecycleBin(long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null); /// /// Moves an object to a new location /// /// The to move /// Id of the Media's new Parent /// Id of the User moving the Media /// True if moving succeeded, otherwise False Attempt Move(IMedia media, int parentId, int userId = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// Empties the Recycle Bin by deleting all that resides in the bin /// [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("Use EmptyRecycleBin with explicit indication of user ID instead")] OperationResult EmptyRecycleBin(); /// /// Empties the Recycle Bin by deleting all that resides in the bin /// /// Optional Id of the User emptying the Recycle Bin OperationResult EmptyRecycleBin(int userId = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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 issuing the delete operation void DeleteMediaOfTypes(IEnumerable mediaTypeIds, int userId = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId, 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 = Constants.Security.SuperUserId, 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 = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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 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 = Constants.Security.SuperUserId, 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 = Constants.Security.SuperUserId); /// /// 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 = Constants.Security.SuperUserId); /// /// 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); } }