Exemple #1
0
        /// <summary>
        /// Convenience method to set a collection attribute in a dictionary of media item aspectData. If the given <paramref name="aspectData"/>
        /// dictionary contains the media item aspect of the requested aspect type, that aspect instance is used to store the
        /// attribute corresponding to the given <paramref name="attributeSpecification"/>. If the corresponding aspect instance is not
        /// present in the dictionary yet, it is created and added to the dictionary before setting the value.
        /// </summary>
        /// <param name="aspectData">Dictionary of aspect data to be written to.</param>
        /// <param name="attributeSpecification">Type of the attribute to write.</param>
        /// <param name="value">Value to be set.</param>
        public static void SetCollectionAttribute <T>(IDictionary <Guid, IList <MediaItemAspect> > aspectData,
                                                      MediaItemAspectMetadata.SingleAttributeSpecification attributeSpecification, IEnumerable <T> value)
        {
            SingleMediaItemAspect aspect = GetOrCreateAspect(aspectData, attributeSpecification.ParentMIAM);

            aspect.SetCollectionAttribute(attributeSpecification, value);
        }
        public bool GetPlayData(out string mimeType, out string mediaItemTitle)
        {
            mimeType       = null;
            mediaItemTitle = null;
            SingleMediaItemAspect mediaAspect = null;

            if (!MediaItemAspect.TryGetAspect(this.Aspects, MediaAspect.Metadata, out mediaAspect))
            {
                return(false);
            }
            IList <MultipleMediaItemAspect> resourceAspects = null;

            if (!MediaItemAspect.TryGetAspects(this.Aspects, ProviderResourceAspect.Metadata, out resourceAspects))
            {
                return(false);
            }
            foreach (MultipleMediaItemAspect pra in resourceAspects)
            {
                if (pra.GetAttributeValue <bool?>(ProviderResourceAspect.ATTR_PRIMARY) == true)
                {
                    mimeType       = (string)pra[ProviderResourceAspect.ATTR_MIME_TYPE];
                    mediaItemTitle = (string)mediaAspect[MediaAspect.ATTR_TITLE];
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Convenience method to set the <see cref="MediaItemAspect"/> from the given <paramref name="aspects"/> dictionary
        /// </summary>
        /// <param name="aspects">Dictionary of MediaItemAspects.</param>
        /// <param name="mediaItemAspectMetadata">Definiton of metadata that is used for creation.</param>
        /// <param name="value">Metadata values used for creation.</param>
        public static void SetAspect(IDictionary <Guid, IList <MediaItemAspect> > aspects, SingleMediaItemAspect value)
        {
            Guid aspectId = value.Metadata.AspectId;

            if (!aspects.ContainsKey(aspectId))
            {
                aspects[aspectId] = new List <MediaItemAspect>();
                aspects[aspectId].Add(value);
            }
            else
            {
                aspects[aspectId][0] = value;
            }
        }
Exemple #4
0
        /// <summary>
        /// Convenience method to get a <see cref="MediaItemAspect"/> from the given <paramref name="aspects"/> dictionary or add a new instance to the
        /// dictionary and return it.
        /// </summary>
        /// <param name="aspects">Dictionary of MediaItemAspects.</param>
        /// <param name="mediaItemAspectMetadata">Definiton of metadata that is used for creation.</param>
        /// <returns>Existing or new <see cref="MediaItemAspect"/> instance.</returns>
        public static SingleMediaItemAspect GetOrCreateAspect(IDictionary <Guid, IList <MediaItemAspect> > aspects, SingleMediaItemAspectMetadata mediaItemAspectMetadata)
        {
            SingleMediaItemAspect mediaAspect;
            Guid aspectId = mediaItemAspectMetadata.AspectId;

            if (!TryGetAspect(aspects, mediaItemAspectMetadata, out mediaAspect))
            {
                if (!aspects.ContainsKey(aspectId))
                {
                    aspects[aspectId] = new List <MediaItemAspect>();
                }
                aspects[aspectId].Add(mediaAspect = new SingleMediaItemAspect(mediaItemAspectMetadata));
            }
            return(mediaAspect);
        }
Exemple #5
0
        public static IDictionary <Guid, IList <MediaItemAspect> > GetAspects(IEnumerable <MediaItemAspect> aspectData)
        {
            IDictionary <Guid, IList <MediaItemAspect> > aspects = new Dictionary <Guid, IList <MediaItemAspect> >();

            foreach (MediaItemAspect aspect in aspectData)
            {
                SingleMediaItemAspect singleAspect = aspect as SingleMediaItemAspect;
                if (singleAspect != null)
                {
                    SetAspect(aspects, singleAspect);
                }
                else
                {
                    MultipleMediaItemAspect multiAspect = aspect as MultipleMediaItemAspect;
                    if (multiAspect != null)
                    {
                        AddOrUpdateAspect(aspects, multiAspect);
                    }
                }
            }
            return(aspects);
        }
Exemple #6
0
        public static bool TryGetAspect(IDictionary <Guid, IList <MediaItemAspect> > aspectData,
                                        SingleMediaItemAspectMetadata mediaItemAspectMetadata, out SingleMediaItemAspect value)
        {
            value = null;
            IList <MediaItemAspect> mediaAspects;

            if (!aspectData.TryGetValue(mediaItemAspectMetadata.AspectId, out mediaAspects) || mediaAspects.Count == 0)
            {
                return(false);
            }

            value = (SingleMediaItemAspect)mediaAspects[0];
            return(true);
        }
Exemple #7
0
        public static MediaItemAspect Deserialize(XmlReader reader)
        {
            if (!reader.MoveToAttribute("Id"))
            {
                throw new ArgumentException("Media item aspect cannot be deserialized: 'Id' attribute missing");
            }
            Guid aspectTypeId = new Guid(reader.ReadContentAsString());
            bool deleted      = false;

            if (reader.MoveToAttribute("Deleted"))
            {
                deleted = reader.ReadContentAsBoolean();
            }
            reader.MoveToElement();
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();
            MediaItemAspectMetadata          miaType;

            if (!miatr.LocallyKnownMediaItemAspectTypes.TryGetValue(aspectTypeId, out miaType))
            {
                throw new ArgumentException(string.Format("Media item aspect cannot be deserialized: Unknown media item aspect type '{0}' in [{1} / {2}]", aspectTypeId, string.Join(",", miatr.LocallyKnownMediaItemAspectTypes.Keys), string.Join(",", miatr.LocallyKnownMediaItemAspectTypes.Values.ToList().Select(x => x.Name))));
            }
            MediaItemAspect result = null;

            if (miaType is SingleMediaItemAspectMetadata)
            {
                result = new SingleMediaItemAspect((SingleMediaItemAspectMetadata)miaType);
            }
            else if (miaType is MultipleMediaItemAspectMetadata)
            {
                result = new MultipleMediaItemAspect((MultipleMediaItemAspectMetadata)miaType);
            }
            result.Deleted = deleted;
            if (SoapHelper.ReadEmptyStartElement(reader, "Aspect"))
            {
                return(result);
            }
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (!reader.MoveToAttribute("Name"))
                {
                    throw new ArgumentException("Media item aspect attribute cannot be deserialized: 'Name' attribute missing");
                }
                String attributeName = reader.ReadContentAsString();
                reader.MoveToElement();
                if (SoapHelper.ReadEmptyStartElement(reader, "Attr"))
                {
                    continue;
                }
                MediaItemAspectMetadata.AttributeSpecification attributeSpec;
                if (!miaType.AttributeSpecifications.TryGetValue(attributeName, out attributeSpec))
                {
                    throw new ArgumentException(string.Format(
                                                    "Media item aspect attribute cannot be deserialized: Unknown attribute specification '{0}'", attributeName));
                }
                if (attributeSpec.IsCollectionAttribute)
                {
                    IList valuesCollection = attributeSpec.CreateValuesCollection();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        valuesCollection.Add(DeserializeValue(reader, attributeSpec.AttributeType));
                    }
                    result.SetCollectionAttribute(attributeSpec, valuesCollection);
                }
                else
                {
                    result.SetAttribute(attributeSpec, DeserializeValue(reader, attributeSpec.AttributeType));
                }
                reader.ReadEndElement(); // Attr
            }
            reader.ReadEndElement();     // Aspect
            return(result);
        }