/// <summary> /// Convenience method to set a simple attribute in a dictionary of media item aspects. 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> /// <typeparam name="TE">Type parameter.</typeparam> /// <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 SetAttribute <TE>(IDictionary <Guid, MediaItemAspect> aspectData, MediaItemAspectMetadata.AttributeSpecification attributeSpecification, TE value) { MediaItemAspect aspect = GetOrCreateAspect(aspectData, attributeSpecification.ParentMIAM); aspect.SetAttribute(attributeSpecification, value); }
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()); 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}'", aspectTypeId)); } MediaItemAspect result = new MediaItemAspect(miaType); 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); }