SaveXml() private method

private SaveXml ( XmlElement parent ) : void
parent System.Xml.XmlElement
return void
コード例 #1
0
        void SaveXml()
        {
            if (!canWrite)
            {
                throw new InvalidOperationException("Can't write incomplete description.");
            }

            XmlElement elem;

            if (configDoc == null)
            {
                configDoc = new XmlDocument();
                configDoc.AppendChild(configDoc.CreateElement("Addin"));
            }

            elem = configDoc.DocumentElement;

            if (HasUserId)
            {
                elem.SetAttribute("id", id);
            }
            else
            {
                elem.RemoveAttribute("id");
            }

            elem.SetAttribute("version", version);
            elem.SetAttribute("namespace", ns);

            if (isroot)
            {
                elem.SetAttribute("isroot", "true");
            }
            else
            {
                elem.RemoveAttribute("isroot");
            }

            // Name will return the file name when HasUserId=false
            if (Name.Length > 0)
            {
                elem.SetAttribute("name", Name);
            }
            else
            {
                elem.RemoveAttribute("name");
            }

            if (compatVersion != null && compatVersion.Length > 0)
            {
                elem.SetAttribute("compatVersion", compatVersion);
            }
            else
            {
                elem.RemoveAttribute("compatVersion");
            }

            if (author != null && author.Length > 0)
            {
                elem.SetAttribute("author", author);
            }
            else
            {
                elem.RemoveAttribute("author");
            }

            if (url != null && url.Length > 0)
            {
                elem.SetAttribute("url", url);
            }
            else
            {
                elem.RemoveAttribute("url");
            }

            if (copyright != null && copyright.Length > 0)
            {
                elem.SetAttribute("copyright", copyright);
            }
            else
            {
                elem.RemoveAttribute("copyright");
            }

            if (description != null && description.Length > 0)
            {
                elem.SetAttribute("description", description);
            }
            else
            {
                elem.RemoveAttribute("description");
            }

            if (category != null && category.Length > 0)
            {
                elem.SetAttribute("category", category);
            }
            else
            {
                elem.RemoveAttribute("category");
            }

            if (mainModule != null)
            {
                mainModule.Element = elem;
                mainModule.SaveXml(elem);
            }

            if (optionalModules != null)
            {
                optionalModules.SaveXml(elem);
            }

            if (nodeSets != null)
            {
                nodeSets.SaveXml(elem);
            }

            if (extensionPoints != null)
            {
                extensionPoints.SaveXml(elem);
            }
        }
コード例 #2
0
        void SaveXml()
        {
            if (!canWrite)
            {
                throw new InvalidOperationException("Can't write incomplete description.");
            }

            XmlElement elem;

            if (configDoc == null)
            {
                configDoc = new XmlDocument();
                configDoc.AppendChild(configDoc.CreateElement("Addin"));
            }

            elem = configDoc.DocumentElement;

            SaveCoreProperty(elem, HasUserId ? id : null, "id", "Id");
            SaveCoreProperty(elem, version, "version", "Version");
            SaveCoreProperty(elem, ns, "namespace", "Namespace");
            SaveCoreProperty(elem, isroot ? "true" : null, "isroot", "IsRoot");

            // Name will return the file name when HasUserId=false
            if (!string.IsNullOrEmpty(name))
            {
                elem.SetAttribute("name", name);
            }
            else
            {
                elem.RemoveAttribute("name");
            }

            SaveCoreProperty(elem, compatVersion, "compatVersion", "CompatVersion");
            SaveCoreProperty(elem, defaultEnabled ? null : "false", "defaultEnabled", "DefaultEnabled");
            SaveCoreProperty(elem, flags != AddinFlags.None ? flags.ToString() : null, "flags", "Flags");

            if (author != null && author.Length > 0)
            {
                elem.SetAttribute("author", author);
            }
            else
            {
                elem.RemoveAttribute("author");
            }

            if (url != null && url.Length > 0)
            {
                elem.SetAttribute("url", url);
            }
            else
            {
                elem.RemoveAttribute("url");
            }

            if (copyright != null && copyright.Length > 0)
            {
                elem.SetAttribute("copyright", copyright);
            }
            else
            {
                elem.RemoveAttribute("copyright");
            }

            if (description != null && description.Length > 0)
            {
                elem.SetAttribute("description", description);
            }
            else
            {
                elem.RemoveAttribute("description");
            }

            if (category != null && category.Length > 0)
            {
                elem.SetAttribute("category", category);
            }
            else
            {
                elem.RemoveAttribute("category");
            }

            if (localizer == null || localizer.Element == null)
            {
                // Remove old element if it exists
                XmlElement oldLoc = (XmlElement)elem.SelectSingleNode("Localizer");
                if (oldLoc != null)
                {
                    elem.RemoveChild(oldLoc);
                }
            }
            if (localizer != null)
            {
                localizer.SaveXml(elem);
            }

            if (mainModule != null)
            {
                mainModule.Element = elem;
                mainModule.SaveXml(elem);
            }

            if (optionalModules != null)
            {
                optionalModules.SaveXml(elem);
            }

            if (nodeSets != null)
            {
                nodeSets.SaveXml(elem);
            }

            if (extensionPoints != null)
            {
                extensionPoints.SaveXml(elem);
            }

            XmlElement oldHeader = (XmlElement)elem.SelectSingleNode("Header");

            if (properties == null || properties.Count == 0)
            {
                if (oldHeader != null)
                {
                    elem.RemoveChild(oldHeader);
                }
            }
            else
            {
                if (oldHeader == null)
                {
                    oldHeader = elem.OwnerDocument.CreateElement("Header");
                    if (elem.FirstChild != null)
                    {
                        elem.InsertBefore(oldHeader, elem.FirstChild);
                    }
                    else
                    {
                        elem.AppendChild(oldHeader);
                    }
                }
                else
                {
                    oldHeader.RemoveAll();
                }
                foreach (var prop in properties)
                {
                    XmlElement propElem = elem.OwnerDocument.CreateElement(prop.Name);
                    if (!string.IsNullOrEmpty(prop.Locale))
                    {
                        propElem.SetAttribute("locale", prop.Locale);
                    }
                    propElem.InnerText = prop.Value ?? string.Empty;
                    oldHeader.AppendChild(propElem);
                }
            }
        }
コード例 #3
0
        void SaveXml()
        {
            if (!canWrite)
            {
                throw new InvalidOperationException("Can't write incomplete description.");
            }

            XmlElement elem;

            if (configDoc == null)
            {
                configDoc = new XmlDocument();
                configDoc.AppendChild(configDoc.CreateElement("Addin"));
            }

            elem = configDoc.DocumentElement;

            if (HasUserId)
            {
                elem.SetAttribute("id", id);
            }
            else
            {
                elem.RemoveAttribute("id");
            }

            elem.SetAttribute("version", version);
            elem.SetAttribute("namespace", ns);

            if (isroot)
            {
                elem.SetAttribute("isroot", "true");
            }
            else
            {
                elem.RemoveAttribute("isroot");
            }

            // Name will return the file name when HasUserId=false
            if (Name.Length > 0)
            {
                elem.SetAttribute("name", Name);
            }
            else
            {
                elem.RemoveAttribute("name");
            }

            if (compatVersion != null && compatVersion.Length > 0)
            {
                elem.SetAttribute("compatVersion", compatVersion);
            }
            else
            {
                elem.RemoveAttribute("compatVersion");
            }

            if (defaultEnabled)
            {
                elem.RemoveAttribute("defaultEnabled");
            }
            else
            {
                elem.SetAttribute("defaultEnabled", "false");
            }

            if (flags != AddinFlags.None)
            {
                elem.RemoveAttribute("flags");
            }
            else
            {
                elem.SetAttribute("flags", flags.ToString());
            }

            if (author != null && author.Length > 0)
            {
                elem.SetAttribute("author", author);
            }
            else
            {
                elem.RemoveAttribute("author");
            }

            if (url != null && url.Length > 0)
            {
                elem.SetAttribute("url", url);
            }
            else
            {
                elem.RemoveAttribute("url");
            }

            if (copyright != null && copyright.Length > 0)
            {
                elem.SetAttribute("copyright", copyright);
            }
            else
            {
                elem.RemoveAttribute("copyright");
            }

            if (description != null && description.Length > 0)
            {
                elem.SetAttribute("description", description);
            }
            else
            {
                elem.RemoveAttribute("description");
            }

            if (category != null && category.Length > 0)
            {
                elem.SetAttribute("category", category);
            }
            else
            {
                elem.RemoveAttribute("category");
            }

            if (localizer == null || localizer.Element == null)
            {
                // Remove old element if it exists
                XmlElement oldLoc = (XmlElement)elem.SelectSingleNode("Localizer");
                if (oldLoc != null)
                {
                    elem.RemoveChild(oldLoc);
                }
            }
            if (localizer != null)
            {
                localizer.SaveXml(elem);
            }

            if (mainModule != null)
            {
                mainModule.Element = elem;
                mainModule.SaveXml(elem);
            }

            if (optionalModules != null)
            {
                optionalModules.SaveXml(elem);
            }

            if (nodeSets != null)
            {
                nodeSets.SaveXml(elem);
            }

            if (extensionPoints != null)
            {
                extensionPoints.SaveXml(elem);
            }
        }