Пример #1
0
        /// <summary>
        /// Process the SqlXml Data from Database to prepare MetadataXml.
        /// </summary>
        private void PrepareMetadataXml(SqlXml dataXml, out Dictionary <id, MetadataAttributes> metadataXml)
        {
            metadataXml = new Dictionary <id, MetadataAttributes>();

            if (!dataXml.IsNull)
            {
                XmlDocument metadata = new XmlDocument();
                metadata.LoadXml(dataXml.Value);

                XmlNodeList dataList = metadata.SelectNodes("//data");
                if (dataList.Count > 0)
                {
                    MetadataAttributes attributes = new MetadataAttributes();

                    foreach (XmlNode node in dataList)
                    {
                        string key   = node.ChildNodes[0].InnerText;
                        string value = node.ChildNodes[1].InnerText;

                        attributes.Add(new MetadataAttribute(key, value));
                    }

                    if (attributes.Count > 0)
                    {
                        metadataXml.Add("data", attributes);
                    }
                }
                else
                {
                    MetadataAttributes attributes = new MetadataAttributes();
                    XmlNodeList        targetNode = metadata.SelectNodes("//" + RootNode);
                    foreach (XmlNode node in targetNode)
                    {
                        if (node.HasChildNodes)
                        {
                            ProcessingNodes(node, ref metadataXml, attributes);
                        }
                        else
                        {
                            XmlAttributeCollection attrList = node.Attributes;
                            foreach (XmlAttribute attr in attrList)
                            {
                                attributes.Add(new MetadataAttribute(attr.Name, attr.Value));
                            }

                            if (attributes.Count > 0)
                            {
                                metadataXml.Add("data", attributes);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Set Metadata with id = key
        /// </summary>
        /// <param name="key"></param>
        /// <param name="data"></param>
        public void SetMetadata(string key, MetadataAttribute data)
        {
            MetadataAttributes attributes = this.GetMetadataList(key);

            if (!attributes.Contains(data))
            {
                attributes.Add(data);
            }

            this.SetMetadata(key, attributes);
        }