private IEnumerable <XmpProperty> AggregateProperties(IEnumerable value) { if (value == null) { yield break; } if (value is IDictionary <string, object> ) { // unwrap generic container value = ((IDictionary <string, object>)value).Values; } // filter out any values which are not enumerable foreach (IEnumerable item in value.OfType <IEnumerable>()) { // each item is either a list of properties or a sequence holding a list of properties IEnumerable <XmpProperty> properties = (item is IEnumerable <XmpProperty>) ? (IEnumerable <XmpProperty>)item : this.AggregateProperties(item); // aggregate into single sequence foreach (XmpProperty property in properties) { yield return(XmpPropertyCollection.ProcessValue(property)); } } }
private IEnumerable <XmpProperty> ExtractSchemas(BitmapMetadata metadata, IEnumerable <Enum> schemas) { foreach (Enum schema in schemas) { string name = null; object value = null; foreach (string query in this.GetQueryForSchema(schema)) { if (String.IsNullOrEmpty(query)) { continue; } value = metadata.GetQuery(query); if (value == null) { continue; } name = query; break; } if (String.IsNullOrEmpty(name)) { continue; } name = name.Substring(name.LastIndexOf('/') + 1); #if DIAGNOSTICS Console.WriteLine("{0} => {1}: {2}", name, value != null ? value.GetType().Name : "null", Convert.ToString(value)); #endif if (value is BitmapMetadata) { value = this.ProcessMetadata((BitmapMetadata)value, '/' + name, 0); } else if (value is BitmapMetadataBlob) { value = ((BitmapMetadataBlob)value).GetBlobValue(); } if (value == null) { continue; } yield return(XmpPropertyCollection.ProcessValue(new XmpProperty { Schema = schema, Value = value })); } }
private XmpProperty GetProperty(XmpProperty property, XElement elem) { switch (property.Quantity) { case XmpQuantity.Alt: { elem = elem.Element(XName.Get(property.Quantity.ToString(), RdfNamespace)); if (elem != null) { if (elem.Elements().Count() == 0) { property.Value = elem.Value; } else { if (property.ValueType is XmpBasicType && ((XmpBasicType)property.ValueType) == XmpBasicType.LangAlt) { // convert to dictionary property.Value = elem.Elements().ToDictionary( n => n.Attribute(XNamespace.Xml + "lang").Value, n => (object)n.Value); } else { // TODO: find how best to process non-lang alts // convert to array property.Value = elem.Elements(XName.Get("li", RdfNamespace)).Select(n => n.Value).ToList(); } } } break; } case XmpQuantity.Bag: case XmpQuantity.Seq: { elem = elem.Element(XName.Get(property.Quantity.ToString(), RdfNamespace)); if (elem != null) { if (elem.Elements().Count() == 0) { property.Value = elem.Value; } else { // convert to array property.Value = elem.Elements(XName.Get("li", RdfNamespace)).Select(n => n.Value).ToList(); } } break; } default: { if (elem.Elements().Count() == 0) { property.Value = elem.Value; } else { // convert to dictionary property.Value = elem.Elements().ToDictionary( n => n.Name.LocalName, n => (object)n.Value); } break; } } return(XmpPropertyCollection.ProcessValue(property)); }