private static void XmlReadAnchorAttributesNode(XElement element, CSEntryChange csentry) { foreach (var child in element.Elements().Where(t => t.Name.LocalName == "anchor-attribute")) { CSEntryChangeXmlImport.XmlReadAnchorAttributeNode(child, csentry); } }
private static void XmlReadAttributeChangesNode(XElement element, CSEntryChange csentry, bool throwOnMissingAttribute) { foreach (var child in element.Elements().Where(t => t.Name.LocalName == "attribute-change")) { CSEntryChangeXmlImport.XmlReadAttributeChangeNode(child, csentry, throwOnMissingAttribute); } }
public static AcmaCSEntryChange ImportFromXml(XElement element, bool throwOnMissingAttribute) { AcmaCSEntryChange csentry = new AcmaCSEntryChange(); CSEntryChangeXmlImport.ImportFromXml(element, csentry, throwOnMissingAttribute); return(csentry); }
public void ReadXml(XmlReader reader) { var doc = XDocument.Load(reader.ReadSubtree()); XElement element = doc.Root.Elements().FirstOrDefault(); if (element == null) { throw new ArgumentException("The XML stream did not contain the object-change element"); } CSEntryChangeXmlImport.ImportFromXml(element, this, false); }
private static List <ValueChange> GetValueChanges(XElement element, ExtendedAttributeType attributeType) { List <ValueChange> valueChanges = new List <ValueChange>(); foreach (var child in element.Elements().Where(t => t.Name.LocalName == "value-change")) { ValueChange change = CSEntryChangeXmlImport.GetValueChange(child, attributeType); if (change != null) { valueChanges.Add(change); } } return(valueChanges); }
private static void XmlReadAttributeChangeNode(XElement element, CSEntryChange csentry, bool throwOnMissingAttribute) { string name = null; AttributeModificationType modificationType = AttributeModificationType.Unconfigured; ExtendedAttributeType dataType = ExtendedAttributeType.Undefined; List <ValueChange> valueChanges = null; AttributeChange attributeChange = null; foreach (var child in element.Elements()) { if (child.Name.LocalName == "name") { name = (string)child; } else if (child.Name.LocalName == "modification-type") { string modificationTypeString = (string)child; if (!Enum.TryParse <AttributeModificationType>(modificationTypeString, out modificationType)) { throw new InvalidCastException(string.Format("Cannot convert '{0}' to type {1}", modificationTypeString, typeof(AttributeModificationType).Name)); } } else if (child.Name.LocalName == "data-type") { string dataTypeString = (string)child; if (!Enum.TryParse <ExtendedAttributeType>(dataTypeString, out dataType)) { throw new InvalidCastException(string.Format("Cannot convert '{0}' to type '{1}'", dataTypeString, typeof(ExtendedAttributeType).Name)); } } else if (child.Name.LocalName == "value-changes") { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The attribute name must appear first in the list of <attribute-change> elements"); } if (dataType == ExtendedAttributeType.Undefined) { if (ActiveConfig.DB == null) { throw new NotConnectedException("The CSEntryChange did not specify a data type in the attribute change, and there was no active connection to the database to resolve it internally"); } else { AcmaSchemaAttribute attribute = null; try { attribute = ActiveConfig.DB.GetAttribute(name); dataType = attribute.Type; } catch (NoSuchAttributeException) { if (throwOnMissingAttribute) { throw; } else { continue; } } } } valueChanges = CSEntryChangeXmlImport.GetValueChanges(child, dataType); } } switch (modificationType) { case AttributeModificationType.Add: if (valueChanges.Count == 0) { // discard attribute change with no values return; } attributeChange = AttributeChange.CreateAttributeAdd(name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()); break; case AttributeModificationType.Replace: if (valueChanges.Count == 0) { // discard attribute change with no values return; //throw new ArgumentException("The attribute replace in the CSEntry provided no values"); } attributeChange = AttributeChange.CreateAttributeReplace(name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList()); break; case AttributeModificationType.Delete: attributeChange = AttributeChange.CreateAttributeDelete(name); break; case AttributeModificationType.Update: if (valueChanges.Count == 0) { // discard attribute change with no values return; //throw new ArgumentException("The attribute update in the CSEntry provided no values"); } attributeChange = AttributeChange.CreateAttributeUpdate(name, valueChanges); break; case AttributeModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(modificationType); } csentry.AttributeChanges.Add(attributeChange); }