Class MediaService
Represents the Media Service, which is an easy access to operations involving
Namespace: Umbraco.Cms.Core.Services.Implement
Assembly: cs.temp.dll.dll
Syntax
public class MediaService : RepositoryService
Constructors
MediaService(IScopeProvider, MediaFileManager, ILoggerFactory, IEventMessagesFactory, IMediaRepository, IAuditRepository, IMediaTypeRepository, IEntityRepository, IShortStringHelper)
Declaration
public MediaService(IScopeProvider provider, MediaFileManager mediaFileManager, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMediaRepository mediaRepository, IAuditRepository auditRepository, IMediaTypeRepository mediaTypeRepository, IEntityRepository entityRepository, IShortStringHelper shortStringHelper)
Parameters
Type | Name | Description |
---|---|---|
IScope |
provider | |
Media |
mediaFileManager | |
ILogger |
loggerFactory | |
IEvent |
eventMessagesFactory | |
IMedia |
mediaRepository | |
IAudit |
auditRepository | |
IMedia |
mediaTypeRepository | |
IEntity |
entityRepository | |
IShort |
shortStringHelper |
Methods
CheckDataIntegrity(ContentDataIntegrityReportOptions)
Declaration
public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options)
Parameters
Type | Name | Description |
---|---|---|
Content |
options |
Returns
Type | Description |
---|---|
Content |
Count(String)
Declaration
public int Count(string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
mediaTypeAlias |
Returns
Type | Description |
---|---|
System. |
CountChildren(Int32, String)
Declaration
public int CountChildren(int parentId, string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
parentId | |
System. |
mediaTypeAlias |
Returns
Type | Description |
---|---|
System. |
CountDescendants(Int32, String)
Declaration
public int CountDescendants(int parentId, string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
parentId | |
System. |
mediaTypeAlias |
Returns
Type | Description |
---|---|
System. |
CountNotTrashed(String)
Declaration
public int CountNotTrashed(string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
mediaTypeAlias |
Returns
Type | Description |
---|---|
System. |
CreateMedia(String, IMedia, String, Int32)
Creates an
Declaration
public IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the media object. |
IMedia | parent | The parent media object. |
System. |
mediaTypeAlias | The alias of the media type. |
System. |
userId | The optional id of the user creating the media. |
Returns
Type | Description |
---|---|
IMedia | The media object. |
Remarks
This method simply returns a new, non-persisted, IMedia without any identity. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMedia(String, Guid, String, Int32)
Creates an
Declaration
public IMedia CreateMedia(string name, Guid parentId, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | Name of the Media object |
System. |
parentId | Id of Parent for the new Media item |
System. |
mediaTypeAlias | Alias of the |
System. |
userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia |
Remarks
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.
CreateMedia(String, Int32, String, Int32)
Creates an
Declaration
public IMedia CreateMedia(string name, int parentId, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the media object. |
System. |
parentId | The identifier of the parent, or -1. |
System. |
mediaTypeAlias | The alias of the media type. |
System. |
userId | The optional id of the user creating the media. |
Returns
Type | Description |
---|---|
IMedia | The media object. |
Remarks
This method simply returns a new, non-persisted, IMedia without any identity. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMedia(String, String, Int32)
Creates an
Declaration
public IMedia CreateMedia(string name, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the media object. |
System. |
mediaTypeAlias | The alias of the media type. |
System. |
userId | The optional id of the user creating the media. |
Returns
Type | Description |
---|---|
IMedia | The media object. |
Remarks
This method simply returns a new, non-persisted, IMedia without any identity. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMediaWithIdentity(String, IMedia, String, Int32)
Creates an
Declaration
public IMedia CreateMediaWithIdentity(string name, IMedia parent, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the media object. |
IMedia | parent | The parent media object. |
System. |
mediaTypeAlias | The alias of the media type. |
System. |
userId | The optional id of the user creating the media. |
Returns
Type | Description |
---|---|
IMedia | The media object. |
Remarks
This method returns a new, persisted, IMedia with an identity.
CreateMediaWithIdentity(String, Int32, String, Int32)
Creates an
Declaration
public IMedia CreateMediaWithIdentity(string name, int parentId, string mediaTypeAlias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the media object. |
System. |
parentId | The identifier of the parent, or -1. |
System. |
mediaTypeAlias | The alias of the media type. |
System. |
userId | The optional id of the user creating the media. |
Returns
Type | Description |
---|---|
IMedia | The media object. |
Remarks
This method returns a new, persisted, IMedia with an identity.
Delete(IMedia, Int32)
Permanently deletes an
Declaration
public Attempt<OperationResult> Delete(IMedia media, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The |
System. |
userId | Id of the User deleting the Media |
Returns
Type | Description |
---|---|
Attempt<Operation |
DeleteMediaFile(String)
Declaration
public void DeleteMediaFile(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System. |
filepath |
DeleteMediaOfType(Int32, Int32)
Deletes all media of specified type. All children of deleted media is moved to Recycle Bin.
Declaration
public void DeleteMediaOfType(int mediaTypeId, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
mediaTypeId | Id of the |
System. |
userId | Optional id of the user deleting the media |
Remarks
This needs extra care and attention as its potentially a dangerous and extensive operation
DeleteMediaOfTypes(IEnumerable<Int32>, Int32)
Deletes all media of specified type. All children of deleted media is moved to Recycle Bin.
Declaration
public void DeleteMediaOfTypes(IEnumerable<int> mediaTypeIds, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
mediaTypeIds | Id of the |
System. |
userId | Optional id of the user deleting the media |
Remarks
This needs extra care and attention as its potentially a dangerous and extensive operation.
Deletes media items of the specified type, and only that type. Does not handle content types inheritance and compositions, which need to be managed outside of this method.
DeleteVersion(Int32, Int32, Boolean, Int32)
Permanently deletes specific version(s) from an
Declaration
public void DeleteVersion(int id, int versionId, bool deletePriorVersions, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the |
System. |
versionId | Id of the version to delete |
System. |
deletePriorVersions | Boolean indicating whether to delete versions prior to the versionId |
System. |
userId | Optional Id of the User deleting versions of a Media object |
DeleteVersions(Int32, DateTime, Int32)
Permanently deletes versions from an
Declaration
public void DeleteVersions(int id, DateTime versionDate, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the |
System. |
versionDate | Latest version date |
System. |
userId | Optional Id of the User deleting versions of a Media object |
EmptyRecycleBin(Int32)
Empties the Recycle Bin by deleting all
Declaration
public OperationResult EmptyRecycleBin(int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
userId | Optional Id of the User emptying the Recycle Bin |
Returns
Type | Description |
---|---|
Operation |
GetAncestors(IMedia)
Gets a collection of
Declaration
public IEnumerable<IMedia> GetAncestors(IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media |
Returns
Type | Description |
---|---|
System. |
An Enumerable list of |
GetAncestors(Int32)
Gets a collection of
Declaration
public IEnumerable<IMedia> GetAncestors(int id)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the |
Returns
Type | Description |
---|---|
System. |
An Enumerable list of |
GetById(Guid)
Gets an
Declaration
public IMedia GetById(Guid key)
Parameters
Type | Name | Description |
---|---|---|
System. |
key | Guid key of the Media to retrieve |
Returns
Type | Description |
---|---|
IMedia |
GetById(Int32)
Gets an
Declaration
public IMedia GetById(int id)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the Media to retrieve |
Returns
Type | Description |
---|---|
IMedia |
GetByIds(IEnumerable<Guid>)
Gets an
Declaration
public IEnumerable<IMedia> GetByIds(IEnumerable<Guid> ids)
Parameters
Type | Name | Description |
---|---|---|
System. |
ids | Ids of the Media to retrieve |
Returns
Type | Description |
---|---|
System. |
GetByIds(IEnumerable<Int32>)
Gets an
Declaration
public IEnumerable<IMedia> GetByIds(IEnumerable<int> ids)
Parameters
Type | Name | Description |
---|---|---|
System. |
ids | Ids of the Media to retrieve |
Returns
Type | Description |
---|---|
System. |
GetByLevel(Int32)
Gets a collection of
Declaration
public IEnumerable<IMedia> GetByLevel(int level)
Parameters
Type | Name | Description |
---|---|---|
System. |
level | The level to retrieve Media from |
Returns
Type | Description |
---|---|
System. |
An Enumerable list of |
Remarks
Contrary to most methods, this method filters out trashed media items.
GetMediaByPath(String)
Gets an
Declaration
public IMedia GetMediaByPath(string mediaPath)
Parameters
Type | Name | Description |
---|---|---|
System. |
mediaPath | Path of the media item to retrieve (for example: /media/1024/koala_403x328.jpg) |
Returns
Type | Description |
---|---|
IMedia |
GetMediaFileContentStream(String)
Declaration
public Stream GetMediaFileContentStream(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System. |
filepath |
Returns
Type | Description |
---|---|
Stream |
GetMediaFileSize(String)
Declaration
public long GetMediaFileSize(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System. |
filepath |
Returns
Type | Description |
---|---|
System. |
GetPagedChildren(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Declaration
public IEnumerable<IMedia> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | |
System. |
pageIndex | |
System. |
pageSize | |
System. |
totalChildren | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System. |
GetPagedDescendants(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Declaration
public IEnumerable<IMedia> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | |
System. |
pageIndex | |
System. |
pageSize | |
System. |
totalChildren | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System. |
GetPagedMediaInRecycleBin(Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Declaration
public IEnumerable<IMedia> GetPagedMediaInRecycleBin(long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
pageIndex | |
System. |
pageSize | |
System. |
totalRecords | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System. |
GetPagedOfType(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Declaration
public IEnumerable<IMedia> GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
contentTypeId | |
System. |
pageIndex | |
System. |
pageSize | |
System. |
totalRecords | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System. |
GetPagedOfTypes(Int32[], Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Declaration
public IEnumerable<IMedia> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
contentTypeIds | |
System. |
pageIndex | |
System. |
pageSize | |
System. |
totalRecords | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System. |
GetParent(IMedia)
Gets the parent of the current media as an
Declaration
public IMedia GetParent(IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media |
Returns
Type | Description |
---|---|
IMedia | Parent |
GetParent(Int32)
Gets the parent of the current media as an
Declaration
public IMedia GetParent(int id)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the |
Returns
Type | Description |
---|---|
IMedia | Parent |
GetRootMedia()
Gets a collection of
Declaration
public IEnumerable<IMedia> GetRootMedia()
Returns
Type | Description |
---|---|
System. |
An Enumerable list of |
GetVersion(Int32)
Gets a specific version of an
Declaration
public IMedia GetVersion(int versionId)
Parameters
Type | Name | Description |
---|---|---|
System. |
versionId | Id of the version to retrieve |
Returns
Type | Description |
---|---|
IMedia | An |
GetVersions(Int32)
Gets a collection of an
Declaration
public IEnumerable<IMedia> GetVersions(int id)
Parameters
Type | Name | Description |
---|---|---|
System. |
id |
Returns
Type | Description |
---|---|
System. |
An Enumerable list of |
HasChildren(Int32)
Checks whether an
Declaration
public bool HasChildren(int id)
Parameters
Type | Name | Description |
---|---|---|
System. |
id | Id of the |
Returns
Type | Description |
---|---|
System. |
True if the media has any children otherwise False |
Move(IMedia, Int32, Int32)
Moves an
Declaration
public Attempt<OperationResult> Move(IMedia media, int parentId, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The |
System. |
parentId | Id of the Media's new Parent |
System. |
userId | Id of the User moving the Media |
Returns
Type | Description |
---|---|
Attempt<Operation |
MoveToRecycleBin(IMedia, Int32)
Deletes an
Declaration
public Attempt<OperationResult> MoveToRecycleBin(IMedia media, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The |
System. |
userId | Id of the User deleting the Media |
Returns
Type | Description |
---|---|
Attempt<Operation |
RecycleBinSmells()
Declaration
public bool RecycleBinSmells()
Returns
Type | Description |
---|---|
System. |
Save(IMedia, Int32)
Saves a single
Declaration
public Attempt<OperationResult> Save(IMedia media, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The |
System. |
userId | Id of the User saving the Media |
Returns
Type | Description |
---|---|
Attempt<Operation |
Save(IEnumerable<IMedia>, Int32)
Saves a collection of
Declaration
public Attempt<OperationResult> Save(IEnumerable<IMedia> medias, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
medias | Collection of |
System. |
userId | Id of the User saving the Media |
Returns
Type | Description |
---|---|
Attempt<Operation |
SetMediaFileContent(String, Stream)
Declaration
public void SetMediaFileContent(string filepath, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System. |
filepath | |
Stream | stream |
Sort(IEnumerable<IMedia>, Int32)
Sorts a collection of
Declaration
public bool Sort(IEnumerable<IMedia> items, int userId = default(int))
Parameters
Type | Name | Description |
---|---|---|
System. |
items | |
System. |
userId |
Returns
Type | Description |
---|---|
System. |
True if sorting succeeded, otherwise False |