private void CreateMetadataXML(DataRow[] metadataCategoryRows, ref StringBuilder xmlInfo, MetadataCategoryBuilder metadataCategoryBuilder, string categoryType) { string MetadataCategoryName = string.Empty; try { xmlInfo = new StringBuilder(); xmlInfo.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xmlInfo.Append("<metadata>"); foreach (DataRow metadataCategoryRow in metadataCategoryRows) { MetadataCategoryName = Convert.ToString(metadataCategoryRow[Metadata_Category.CategoryName]); //Step 1 Check and create metadata category if (!metadataCategoryBuilder.IsAlreadyExists(MetadataCategoryName, categoryType, -1)) { MetadataCategoryInfo metadataCategoryInfo = new MetadataCategoryInfo(); metadataCategoryInfo.CategoryName = MetadataCategoryName; metadataCategoryInfo.CategoryType = categoryType; metadataCategoryBuilder.CheckNCreateMetadataCategory(metadataCategoryInfo); } //Step 2 Add category into metadata xml xmlInfo.Append("<Category name=\"" + MetadataCategoryName + "\">"); xmlInfo.Append("<para>" + Convert.ToString(metadataCategoryRow[MetadataReport.Metadata]) + "</para></Category>"); } xmlInfo.Append("</metadata>"); } catch (Exception ex) { } }
private string GetElementMetadata(MetaDataType elementType, string elementGId, int elementNId, DIExcel diExcel, int startRowIndex) { string RetVal = string.Empty; MetadataCategoryBuilder MDCatBuilder; MetadataCategoryInfo MDCatInfo; XmlDocument MetadataXmlDoc = new XmlDocument(); XmlElement CategoryNode; XmlElement ParaNode; XmlText CategoryText; string Category = string.Empty; string CategoryValue = string.Empty; string ElementMetadataXml = string.Empty; int CategoryNId = 0; //-- Get Metadata Info for Element ElementMetadataXml = this.GetElementInfo(elementType, elementGId); if (string.IsNullOrEmpty(ElementMetadataXml)) { MetadataConverter.InsertRootNode(MetadataXmlDoc); } else { MetadataXmlDoc.LoadXml(ElementMetadataXml); } MDCatBuilder = new MetadataCategoryBuilder(this.DBConnection, this.DBQueries); //foreach (IRange Row in DiExcel.GetUsedRange(0).Rows ) for (int Index = startRowIndex; Index < diExcel.GetUsedRange(0).Rows.RowCount; Index++) { Category = Convert.ToString(diExcel.GetUsedRange(0).Rows[Index, 0].Value); CategoryValue = Convert.ToString(diExcel.GetUsedRange(0).Rows[Index, 1].Value); if (!string.IsNullOrEmpty(Category)) { //-- Get Metadata CategoryInfo MDCatInfo = MDCatBuilder.GetMetadataCategoryInfo(FilterFieldType.Name, "'" + DICommon.RemoveQuotes(Category) + "'"); //-- If Metadata not category exists if (MDCatInfo != null && string.IsNullOrEmpty(MDCatInfo.CategoryName)) { MDCatInfo.CategoryName = Category; MDCatInfo.CategoryType = this.GetCategoryTypeText(elementType); //Create new xmlelement as Category CategoryNode = MetadataXmlDoc.CreateElement(MetaDataConstants.CategoryTagName); //Set attribute values of category element. CategoryNode.SetAttribute(MetaDataConstants.NameAttribute, Category); // create para element ParaNode = MetadataXmlDoc.CreateElement(MetaDataConstants.ParaTagName); //Append as para node under category node CategoryNode.AppendChild(ParaNode); // create text node CategoryText = MetadataXmlDoc.CreateTextNode(this.ReplaceInvalidString(CategoryValue)); //Append category text in paraNode ParaNode.AppendChild(CategoryText); //Append it under metadata node MetadataXmlDoc.DocumentElement.AppendChild(CategoryNode); } //-- Get CategoryNId CategoryNId = MDCatBuilder.CheckNCreateMetadataCategory(MDCatInfo); this.UpdateMetadataCategory(MetadataXmlDoc, Category, CategoryValue); } else { //-- Exit for Next Metadata break; } } RetVal = MetadataXmlDoc.InnerXml; return RetVal; }
private bool ISMetadataXmlForCategory(string metadataXml, MetaDataType elementType) { bool RetVal = false; string CategoryName = string.Empty; string CategoryValue = string.Empty; XmlDocument XmlDoc = new XmlDocument(); MetadataCategoryBuilder MDCatBuilder; MetadataCategoryInfo MDCatInfo; XmlDoc.LoadXml(metadataXml); try { MDCatBuilder = new MetadataCategoryBuilder(this.DBConnection, this.DBQueries); XmlNodeList XmlList = XmlDoc.SelectNodes(METADATA_CATEGORYTAG); for (int i = 0; i < XmlList.Count; i++) { CategoryName = XmlList[i].Attributes["name"].Value; MDCatInfo = MDCatBuilder.GetMetadataCategoryInfo(FilterFieldType.Name, "'" + DICommon.RemoveQuotes(CategoryName) + "'"); if (MDCatInfo.CategoryType == this.GetCategoryTypeText(elementType)) { MDCatBuilder.CheckNCreateMetadataCategory(MDCatInfo); RetVal = true; } } } catch (Exception) { } return RetVal; }
private void CheckNUpdateMetadataCategory(string metadataXml) { string CategoryName = string.Empty; string CategoryValue = string.Empty; XmlDocument XmlDoc = new XmlDocument(); MetadataCategoryBuilder MDCatBuilder; MetadataCategoryInfo MDCatInfo; XmlDoc.LoadXml(metadataXml); try { MDCatBuilder = new MetadataCategoryBuilder(this.DBConnection, this.DBQueries); XmlNodeList XmlList = XmlDoc.SelectNodes(METADATA_CATEGORYTAG); for (int i = 0; i < XmlList.Count; i++) { CategoryName = XmlList[i].Attributes["name"].Value; MDCatInfo = MDCatBuilder.GetMetadataCategoryInfo(FilterFieldType.Name, "'" + DICommon.RemoveQuotes(CategoryName) + "'"); MDCatBuilder.CheckNCreateMetadataCategory(MDCatInfo); } } catch (Exception) { } }
private void ImportAreaMetadataCategories(DIConnection srcDBConn, DIQueries srcDBQueries) { MetadataCategoryInfo MDCatInfo = null; MetadataCategoryBuilder MDCatBuilder = new MetadataCategoryBuilder(this.DBConnection, this.DBQueries); MetadataCategoryBuilder SrcMDCatBuilder = new MetadataCategoryBuilder(srcDBConn, srcDBQueries); //-- Get Categories from Source Table DataTable Table = SrcMDCatBuilder.GetAllRecordsFromMetadataCategory(); DataRow[] Rows = Table.Select(Metadata_Category.CategoryType + "=" + "'A'"); foreach (DataRow Row in Rows) { MDCatInfo = new MetadataCategoryInfo(); MDCatInfo.CategoryName = Convert.ToString(Row[Metadata_Category.CategoryName]); MDCatInfo.CategoryType = Convert.ToString(Row[Metadata_Category.CategoryType]); // Add MetadataCategory Into all metdata category language tables MDCatBuilder.CheckNCreateMetadataCategory(MDCatInfo); } }