public bool Convert(IDataDescriptor[] values, Type targetType, object parameter, out object result)
        {
            result = null;
            if (values.Length < 2)
            {
                return(false);
            }

            MediaItem mi = values[0].Value as MediaItem;

            if (mi == null)
            {
                return(true);
            }
            MediaItemAspectMetadata.MultipleAttributeSpecification mas = values[1].Value as MediaItemAspectMetadata.MultipleAttributeSpecification;
            if (mas == null)
            {
                return(true);
            }
            List <object> attributes;

            if (!MediaItemAspect.TryGetAttribute(mi.Aspects, mas, out attributes) || attributes.Count == 0)
            {
                return(true);
            }

            string separator = parameter as string;

            if (string.IsNullOrEmpty(separator))
            {
                separator = DEFAULT_SEPARATOR;
            }

            bool          first = true;
            StringBuilder sb    = new StringBuilder();

            foreach (object attribute in attributes)
            {
                if (attribute == null)
                {
                    continue;
                }
                string attributeString = attribute.ToString();
                if (!string.IsNullOrEmpty(attributeString))
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(separator);
                    }
                    sb.Append(attributeString);
                }
            }
            result = sb.ToString();
            return(true);
        }
Exemple #2
0
        public static MediaItemAspectMetadata.AttributeSpecification GetAttributeSpecification(MediaItem mediaItem, IEnumerable <MediaItemAspectMetadata.MultipleAttributeSpecification> attributes, out MediaItemAspect aspect)
        {
            IList <MultipleMediaItemAspect> multipleAspects = null;

            MediaItemAspectMetadata.MultipleAttributeSpecification attr = attributes.FirstOrDefault(a => MediaItemAspect.TryGetAspects(mediaItem.Aspects, a.ParentMIAM, out multipleAspects));
            aspect = attr != null ? multipleAspects[0] : null;
            return(attr);
        }
Exemple #3
0
        private void AssertMultipleMIAMSpec(ICollection <MediaItemAspectMetadata.AttributeSpecification> src, ICollection <MediaItemAspectMetadata.AttributeSpecification> dest, MediaItemAspectMetadata.MultipleAttributeSpecification attr)
        {
            MediaItemAspectMetadata.MultipleAttributeSpecification srcSpec = src.FirstOrDefault(x => x.AttributeName == attr.AttributeName) as MediaItemAspectMetadata.MultipleAttributeSpecification;
            Assert.IsNotNull(srcSpec, "Source spec");

            MediaItemAspectMetadata.MultipleAttributeSpecification destSpec = dest.FirstOrDefault(x => x.AttributeName == attr.AttributeName) as MediaItemAspectMetadata.MultipleAttributeSpecification;
            Assert.IsNotNull(destSpec, "Dest spec");

            Assert.AreEqual(srcSpec.AttributeName, destSpec.AttributeName, "Attribute name");
            Assert.AreEqual(srcSpec.AttributeType, destSpec.AttributeType, "Attribute type");
            Assert.AreEqual(srcSpec.Cardinality, destSpec.Cardinality, "Attribute cardinality");
            Assert.AreEqual(srcSpec.IsCollectionAttribute, destSpec.IsCollectionAttribute, "Attribute collection attribute");
            Assert.AreEqual(srcSpec.IsIndexed, destSpec.IsIndexed, "Attribute indexed");
            Assert.AreEqual(srcSpec.MaxNumChars, destSpec.MaxNumChars, "Attribute max characters");
        }
Exemple #4
0
        public static object GetAttributeValue(this MediaItem mediaItem, MediaItemAspectMetadata.MultipleAttributeSpecification attribute)
        {
            List <object> values = null;

            if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, attribute, out values))
            {
                return(null);
            }

            if (values.Count == 0)
            {
                return(null);
            }

            return(values[0]);
        }
 protected AbstractSortByFirstComparableAttribute(MediaItemAspectMetadata.MultipleAttributeSpecification attr)
 {
     _multiAttrs = new[] { attr };
 }
 protected AbstractSortByComparableValueAttribute(string displayName, string groupByDisplayName, MediaItemAspectMetadata.MultipleAttributeSpecification sortAttr)
     : this(displayName, groupByDisplayName, new[] { sortAttr })
 {
 }