Files
Umbraco-CMS/src/Umbraco.Core/Models/Media.cs

85 lines
3.6 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System;
using System.Runtime.Serialization;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Media object
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class Media : ContentBase, IMedia
{
/// <summary>
/// Constructor for creating a Media object
/// </summary>
2019-01-22 18:03:39 -05:00
/// <param name="name">name of the Media object</param>
2018-06-29 19:52:40 +02:00
/// <param name="parent">Parent <see cref="IMedia"/> object</param>
/// <param name="contentType">MediaType for the current Media object</param>
public Media(string name, IMedia parent, IMediaType contentType)
: this(name, parent, contentType, new PropertyCollection())
2018-10-23 15:04:41 +02:00
{ }
2018-06-29 19:52:40 +02:00
/// <summary>
/// Constructor for creating a Media object
/// </summary>
2019-01-22 18:03:39 -05:00
/// <param name="name">name of the Media object</param>
2018-06-29 19:52:40 +02:00
/// <param name="parent">Parent <see cref="IMedia"/> object</param>
/// <param name="contentType">MediaType for the current Media object</param>
/// <param name="properties">Collection of properties</param>
2019-11-19 14:12:11 +01:00
public Media(string name, IMedia parent, IMediaType contentType, IPropertyCollection properties)
2018-06-29 19:52:40 +02:00
: base(name, parent, contentType, properties)
2019-02-05 14:06:48 +01:00
{ }
2018-06-29 19:52:40 +02:00
/// <summary>
/// Constructor for creating a Media object
/// </summary>
2019-01-22 18:03:39 -05:00
/// <param name="name">name of the Media object</param>
2018-06-29 19:52:40 +02:00
/// <param name="parentId">Id of the Parent IMedia</param>
/// <param name="contentType">MediaType for the current Media object</param>
public Media(string name, int parentId, IMediaType contentType)
: this(name, parentId, contentType, new PropertyCollection())
2018-10-23 15:04:41 +02:00
{ }
2018-06-29 19:52:40 +02:00
/// <summary>
/// Constructor for creating a Media object
/// </summary>
/// <param name="name">Name of the Media object</param>
/// <param name="parentId">Id of the Parent IMedia</param>
/// <param name="contentType">MediaType for the current Media object</param>
/// <param name="properties">Collection of properties</param>
2019-11-19 14:12:11 +01:00
public Media(string name, int parentId, IMediaType contentType, IPropertyCollection properties)
2018-06-29 19:52:40 +02:00
: base(name, parentId, contentType, properties)
2019-02-05 14:06:48 +01:00
{ }
2018-06-29 19:52:40 +02:00
/// <summary>
/// Changes the <see cref="IMediaType"/> for the current Media object
/// </summary>
/// <param name="contentType">New MediaType for this Media</param>
/// <remarks>Leaves PropertyTypes intact after change</remarks>
internal void ChangeContentType(IMediaType contentType)
2018-06-29 19:52:40 +02:00
{
2019-02-05 14:06:48 +01:00
ChangeContentType(contentType, false);
2018-06-29 19:52:40 +02:00
}
/// <summary>
/// Changes the <see cref="IMediaType"/> for the current Media object and removes PropertyTypes,
/// which are not part of the new MediaType.
/// </summary>
/// <param name="contentType">New MediaType for this Media</param>
/// <param name="clearProperties">Boolean indicating whether to clear PropertyTypes upon change</param>
internal void ChangeContentType(IMediaType contentType, bool clearProperties)
2018-06-29 19:52:40 +02:00
{
2019-02-05 14:06:48 +01:00
ChangeContentType(new SimpleContentType(contentType));
2019-02-05 14:06:48 +01:00
if (clearProperties)
Properties.EnsureCleanPropertyTypes(contentType.CompositionPropertyTypes);
else
Properties.EnsurePropertyTypes(contentType.CompositionPropertyTypes);
2018-06-29 19:52:40 +02:00
2019-02-05 14:06:48 +01:00
Properties.CollectionChanged -= PropertiesChanged; // be sure not to double add
Properties.CollectionChanged += PropertiesChanged;
2018-06-29 19:52:40 +02:00
}
}
}