示例#1
0
        /// <summary>
        /// Stores the list of component manifests as an XML element
        /// </summary>
        /// <param name="manifests"></param>
        /// <returns></returns>
        public static XElement SerializeComponents(IEnumerable <ComponentManifest> manifests)
        {
            if (manifests == null)
            {
                throw new ArgumentNullException(nameof(manifests));
            }

            List <XElement> list          = new List <XElement>();
            XmlSerializer   xmlSerializer = new XmlSerializer(typeof(ComponentManifest), XmlNames.ProjectManifestNamespace);

            foreach (ComponentManifest manifest in manifests)
            {
                XElement item = SerializeComponent(xmlSerializer, manifest);
                list.Add(item);
            }

            XElement components = new XElement(XmlNames.GetComponentXName(XmlNames.Components));

            foreach (XElement xElement in list)
            {
                components.Add(xElement);
            }

            return(components);
        }
示例#2
0
        private static void SaveTags(List <string> tags, XElement componentElement)
        {
            string   tagsString  = string.Join(";", tags);
            XElement tagsElement = new XElement(XmlNames.GetComponentXName(XmlNames.Tags));

            tagsElement.Add(new XAttribute(XmlNames.Value, tagsString));
            componentElement.Add(tagsElement);
        }
        /// <summary>
        /// Serializes ProjectInfo as XML
        /// </summary>
        /// <param name="infoElement"></param>
        /// <returns></returns>
        public static ProjectInfo DeserializeProjectInfo(XElement infoElement)
        {
            if (infoElement == null)
            {
                throw new ArgumentNullException(nameof(infoElement));
            }

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ProjectInfo), XmlNames.ProjectManifestNamespace);

            ProjectInfo info = (ProjectInfo)xmlSerializer.Deserialize(infoElement.CreateReader());

            LoadTags(infoElement, info.Tags);
            LoadProperties(infoElement, info.Properties);

            XElement componentsElement          = infoElement.Element(XmlNames.GetComponentXName(XmlNames.Components));
            List <ComponentManifest> components = DeserializeComponents(componentsElement);

            info.Components.AddRange(components);
            return(info);
        }
示例#4
0
        private static void SaveProperties(PropertiesCollection properties, XElement element)
        {
            XElement props = new XElement(XmlNames.GetComponentXName(XmlNames.Properties));

            if (properties != null)
            {
                foreach (var manifestProperty in properties)
                {
                    XElement propertyElement = new XElement(XmlNames.GetComponentXName(XmlNames.Property));
                    propertyElement.Add(new XAttribute(XmlNames.Key, manifestProperty.Key));
                    if (manifestProperty.ValueList != null && manifestProperty.ValueList.Any())
                    {
                        propertyElement.Value = Json.Serialize(manifestProperty.ValueList);
                    }
                    else
                    {
                        propertyElement.Value = Json.Serialize(manifestProperty.Value);
                    }
                    props.Add(propertyElement);
                }
            }

            element.Add(props);
        }