コード例 #1
0
 public static void ExportToXml(IEnumerable <MAObjectHologram> maObjects, XmlWriter writer, ObjectModificationType modificationType)
 {
     foreach (MAObjectHologram maObject in maObjects)
     {
         ImportExportEngine.ExportToXml(maObject, writer, modificationType);
     }
 }
コード例 #2
0
 private static void XmlReadAnchorAttributesNode(XElement element, CSEntryChange csentry)
 {
     foreach (var child in element.Elements().Where(t => t.Name.LocalName == "anchor-attribute"))
     {
         ImportExportEngine.XmlReadAnchorAttributeNode(child, csentry);
     }
 }
コード例 #3
0
        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 = ImportExportEngine.GetValueChange(child, attributeType);
                if (change != null)
                {
                    valueChanges.Add(change);
                }
            }

            return(valueChanges);
        }
コード例 #4
0
        public static void ExportToXml(IEnumerable <MAObjectHologram> maObjects, string fileName, ObjectModificationType modificationType)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent       = true;
            settings.IndentChars  = "  ";
            settings.NewLineChars = Environment.NewLine;
            XmlWriter writer = XmlWriter.Create(fileName, settings);

            writer.WriteStartDocument();
            writer.WriteStartElement("acma-export");

            ImportExportEngine.ExportToXml(maObjects, writer, modificationType);

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();
        }
コード例 #5
0
        public static CSEntryChange ImportFromXml(XElement element)
        {
            CSEntryChange csentry = CSEntryChange.Create();

            return(ImportExportEngine.ImportFromXml(element, csentry));
        }
コード例 #6
0
        private static void XmlReadAttributeChangeNode(XElement element, CSEntryChange csentry)
        {
            string name = null;
            AttributeModificationType modificationType = AttributeModificationType.Unconfigured;
            AcmaSchemaAttribute       attribute        = null;
            List <ValueChange>        valueChanges     = null;
            AttributeChange           attributeChange  = null;

            foreach (var child in element.Elements())
            {
                if (child.Name.LocalName == "name")
                {
                    name      = (string)child;
                    attribute = ActiveConfig.DB.GetAttribute(name);
                }
                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 == "value-changes")
                {
                    if (attribute == null)
                    {
                        throw new ArgumentException("The attribute name must appear first in the list of <attribute-change> elements");
                    }

                    valueChanges = ImportExportEngine.GetValueChanges(child, attribute.Type);
                }
            }

            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);
        }