private static string GetElementValue(ICmisExtensionElement element, string propertyName) { // the actual values can either be found on the value property, // be stored in an attribute, or in a children collection if (!string.IsNullOrEmpty(element.Value)) { return(element.Value); } // the value must be taken from the attributes collection. The attribute name is // separated from the property name with the @sign, e.g. datei@id --> get the id attribute of the datei property if (propertyName.Contains("@")) { var propertyNameParts = propertyName.Split('@'); if (propertyNameParts.Length > 1 && element.Attributes.ContainsKey(propertyNameParts[1])) { return(element.Attributes[propertyNameParts[1]]); } // trying to get property that does not exist if (propertyNameParts.Length > 1 && !element.Attributes.ContainsKey(propertyNameParts[1])) { return(string.Empty); } } // if we didn't find anything yet, the value must be in the childrens collection. if (element.Children != null && element.Children.Any()) { return(JsonConvert.SerializeObject(element.Children)); } return(null); }
/// <summary> /// Gets the extension parentElement of type "e1:value" of a parentElement with a specific name that /// is found in the children collection of the passed parent. /// </summary> /// <param name="parentElement">The parent element that is to be searched.</param> /// <param name="propertyName">Name of the property to find.</param> /// <returns>ICmisExtensionElement.</returns> private IList <ICmisExtensionElement> GetExtendedPropertyValueElements(ICmisExtensionElement parentElement, string propertyName) { IList <ICmisExtensionElement> retVal = new List <ICmisExtensionElement>(); try { foreach (var extensionElement in parentElement.Children) { switch (extensionElement.Name.ToLowerInvariant()) { case "e1:item": // Spezialfall. Ein Element kann mehrere e1.item Kinderelemente enthalten. // Der Name des Attributs ist im Kind-Element e1:name enthalten, // der Wert des Attributs im Kind-Element e1:value, wobei das e1:value // Element den Wert entweder direkt im Value property hat, oder es ist ein // komplexes Element mit eigenen Kinder-Einträgen if (extensionElement.Children.Any(c => c.Value != null && c.Value.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase))) { var valueElements = extensionElement.Children .Where(f => f.Name.Equals("e1:value", StringComparison.InvariantCultureIgnoreCase)).ToList(); if (valueElements.Any()) { retVal = valueElements; } } break; default: if (extensionElement.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)) // Wir haben ein normales Property gefunden. Wir können das Element der Collection hinzufügen. { retVal.Add(extensionElement); } break; } } } catch (Exception ex) { Log.Error(ex, "Unknown error while getting extended property elements. Error message is: {Message}", ex.Message); } return(retVal); }