using System;
using System.Runtime.Serialization;
namespace Umbraco.Cms.Core.Models
{
///
/// Represents a Media object
///
[Serializable]
[DataContract(IsReference = true)]
public class Media : ContentBase, IMedia
{
///
/// Constructor for creating a Media object
///
/// name of the Media object
/// Parent object
/// MediaType for the current Media object
public Media(string name, IMedia parent, IMediaType contentType)
: this(name, parent, contentType, new PropertyCollection())
{ }
///
/// Constructor for creating a Media object
///
/// name of the Media object
/// Parent object
/// MediaType for the current Media object
/// Collection of properties
public Media(string name, IMedia parent, IMediaType contentType, IPropertyCollection properties)
: base(name, parent, contentType, properties)
{ }
///
/// Constructor for creating a Media object
///
/// name of the Media object
/// Id of the Parent IMedia
/// MediaType for the current Media object
public Media(string name, int parentId, IMediaType contentType)
: this(name, parentId, contentType, new PropertyCollection())
{ }
///
/// Constructor for creating a Media object
///
/// Name of the Media object
/// Id of the Parent IMedia
/// MediaType for the current Media object
/// Collection of properties
public Media(string name, int parentId, IMediaType contentType, IPropertyCollection properties)
: base(name, parentId, contentType, properties)
{ }
///
/// Changes the for the current Media object
///
/// New MediaType for this Media
/// Leaves PropertyTypes intact after change
internal void ChangeContentType(IMediaType contentType)
{
ChangeContentType(contentType, false);
}
///
/// Changes the for the current Media object and removes PropertyTypes,
/// which are not part of the new MediaType.
///
/// New MediaType for this Media
/// Boolean indicating whether to clear PropertyTypes upon change
internal void ChangeContentType(IMediaType contentType, bool clearProperties)
{
ChangeContentType(new SimpleContentType(contentType));
if (clearProperties)
Properties.EnsureCleanPropertyTypes(contentType.CompositionPropertyTypes);
else
Properties.EnsurePropertyTypes(contentType.CompositionPropertyTypes);
Properties.ClearCollectionChangedEvents(); // be sure not to double add
Properties.CollectionChanged += PropertiesChanged;
}
}
}