Пример #1
0
        /// <summary>
        /// Updates metadata object using latest category table and old categories collection
        /// </summary>
        /// <param name="metadataObject"></param>
        /// <param name="oldCategories">oldCategories collection (key = nid and value = name)</param>        
        /// <param name="categoryTable">latest category table</param>
        /// <returns></returns>
        private MetadataInfo UpdateCategryInMetadataInfo(MetadataInfo metadataObject, Dictionary<int, string> oldCategories, DataTable categoryTable)
        {
            MetadataInfo RetVal = new MetadataInfo();
            CategoryInfo CategoryObject;

            foreach (DataRow categoryRow in categoryTable.Rows)
            {

                // create new category object for each category
                CategoryObject = new CategoryInfo();
                CategoryObject.CategoryName = Convert.ToString(categoryRow[Metadata_Category.CategoryName]);
                CategoryObject.CategoryNId = Convert.ToInt32(categoryRow[Metadata_Category.CategoryNId]);
                CategoryObject.MetadataText = string.Empty;

                // check for key existance
                if (oldCategories.ContainsKey(CategoryObject.CategoryNId))
                {
                    // check old category name exists in metadata object as metadata object (or metadata text) build on Old categories name
                    if (metadataObject.Categories.ContainsKey(oldCategories[CategoryObject.CategoryNId]))
                    {
                        //-- if category exists in metadata text then update metadata text into category object
                        CategoryObject.MetadataText = metadataObject.Categories[oldCategories[CategoryObject.CategoryNId]].MetadataText;
                    }
                }

                //-- add category into Metadata info object
                if (!RetVal.Categories.ContainsKey(CategoryObject.CategoryName))
                {
                    RetVal.Categories.Add(CategoryObject.CategoryName, CategoryObject);
                }

            }
            return RetVal;
        }
Пример #2
0
        /// <summary>
        /// Returns MetadaataInfo object from the given metadata text
        /// </summary>
        /// <param name="mdElementType"></param>
        /// <returns></returns>
        private MetadataInfo GetMetadataInfoFrmMetadataText(string metadataText, MetadataElementType mdElementType)
        {
            MetadataInfo RetVal = new MetadataInfo();
            CategoryInfo Category;
            XmlDocument XmlDoc;

            //string ConcatinatedParaNodeText = string.Empty;
            //XmlElement CategoryNode = default(XmlElement);
            //XmlNode CategoryXmlNode = null;
            //DataTable CategoryTable;
            //XmlElement RootNode = default(XmlElement);

            //XmlDocument XmldocumentNew = new XmlDocument();
            //XmlDeclaration xmlDeclaration = default(XmlDeclaration);
            //string XmlString = string.Empty;
            //String ConcatenatedParaNodeText = string.Empty;
            //string CategoryParaXml;

            try
            {
                //xmlDeclaration = XmldocumentNew.CreateXmlDeclaration("1.0", "utf-8", null);
                //RootNode = XmldocumentNew.CreateElement(MetadataManagerConstants.Metadata);
                //XmldocumentNew.InsertBefore(xmlDeclaration, XmldocumentNew.DocumentElement);
                //XmldocumentNew.AppendChild(RootNode);

                //--Load xml from database.
                XmlDoc = new XmlDocument();
                XmlDoc.LoadXml(metadataText);

                //--get categories
                foreach (XmlNode Node in XmlDoc.SelectNodes("metadata/Category"))
                {

                    Category = new CategoryInfo();
                    Category.CategoryName = Convert.ToString(Node.Attributes["name"].Value);
                    Category.CategoryType = DIQueries.MetadataElementTypeText[mdElementType];

                    // get metadata text from xml's Para node
                    if (Node.ChildNodes.Count > 0)
                    {
                        Category.MetadataText = Convert.ToString(Node.ChildNodes[0].InnerXml);
                    }

                    // add category into metadataInfo object
                    if (!RetVal.Categories.ContainsKey(Category.CategoryName))
                    {
                        RetVal.Categories.Add(Category.CategoryName, Category);
                    }
                }

                //foreach (DataRow CategoryNameRow in CategoryTable.Rows)
                //{
                //    Category = new CategoryInfo();
                //    Category.CategoryName = Convert.ToString(CategoryNameRow[DIColumns.Metadata_Category.CategoryName]);
                //    Category.CategoryType = metadataType.ToString();

                //    //--Create new xmlelement as Category
                //    CategoryNode = XmldocumentNew.CreateElement(MetadataManagerConstants.Category);

                //    //--Set attribute values of category element.
                //    CategoryNode.SetAttribute(MetadataManagerConstants.NameAttribute, Category.CategoryName);

                //    //--Select Category node with appropriate attribute name(category name)
                //    CategoryXmlNode = XmlDoc.SelectSingleNode(MetadataManagerConstants.CategoryName + Category.CategoryName + MetadataManagerConstants.ClosingSymbol);

                //    //--Add in category collection
                //    if (CategoryXmlNode != null)
                //    {
                //        CategoryParaXml = CategoryXmlNode.InnerXml;
                //        Category.MetadataText = CategoryXmlNode.InnerXml;

                //        //--check for category in collection
                //        if (!RetVal.Categories.ContainsKey(Category.CategoryName))
                //        {
                //            RetVal.Categories.Add(Category.CategoryName, Category);
                //        }
                //    }
                //}
                //return RetVal;
            }
            catch
            {
                RetVal = null;
            }

            return RetVal;
        }