/// <summary> /// Returns the metadata text from database /// </summary> /// <param name="elementNid"></param> /// <returns></returns> public override string GetMetadataTextFrmDB(int elementNid) { string RetVal = string.Empty; string ElementGID = string.Empty; DataTable Table; DI7MetaDataBuilder MDBuilder = null; try { Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaByLayer(elementNid.ToString())); foreach (DataRow Row in Table.Rows) { ElementGID = Convert.ToString(Row[Area.AreaID]); // get xml file from SDMX library RetVal = DevInfo.Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DI_LibSDMX.SDMXSchemaType.Two_One, ElementGID, DevInfo.Lib.DI_LibSDMX.MetadataTypes.Area, "MDAgency", this.DBQueries.LanguageCode.Replace("_", ""), this.DBConnection, this.DBQueries).InnerXml; MDBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); RetVal = MDBuilder.GetMetadataReportWCategoryName(RetVal, MetadataElementType.Area).InnerXml; break; } } catch (Exception) { RetVal = string.Empty; } return RetVal; }
/// <summary> /// Returns the metadata text from database /// </summary> /// <param name="elementNid"></param> /// <returns></returns> public override string GetMetadataTextFrmDB(int elementNid) { string RetVal = string.Empty; string ElementGID = string.Empty; IndicatorBuilder Indicators; DI7MetaDataBuilder MDBuilder = null; try { Indicators = new IndicatorBuilder(this.DBConnection, this.DBQueries); ElementGID = Indicators.GetIndicatorInfo(FilterFieldType.NId, elementNid.ToString(), FieldSelection.Light).GID; // get xml file from SDMX library RetVal = DevInfo.Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DI_LibSDMX.SDMXSchemaType.Two_One, ElementGID, DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator, "MDAgency", this.DBQueries.LanguageCode.Replace("_", ""), this.DBConnection, this.DBQueries).InnerXml; MDBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); RetVal = MDBuilder.GetMetadataReportWCategoryName(RetVal, MetadataElementType.Indicator).InnerXml; } catch (Exception) { RetVal = string.Empty; } return RetVal; }
/// <summary> /// Imports records from source database to target database/template /// </summary> /// <param name="selectedNids"></param> /// <param name="allSelected">Set true to import all records</param> public override void ImportValues(List<string> SelectedNids, bool allSelected) { DI7MetaDataBuilder MetaData = new DI7MetaDataBuilder(this._TargetDBConnection, this._TargetDBQueries); MetaData.BeforeProcess += new ProcessInfoDelegate(MetaData_BeforeProcess); MetaData.ProcessInfo += new ProcessInfoDelegate(MetaData_ProcessInfo); if (this.InputFileType != DataSourceType.Database && this.InputFileType != DataSourceType.Template) { // Import data from xml file this.RaiseInitializeProgessBarEvent(1); if (System.IO.Path.GetExtension(this._SelectedFiles[0]).ToUpper() == DICommon.FileExtension.Excel.ToUpper()) { // import from excel MetaData.ImportMetataFromExcel(MetadataElementType.Area, MetaDataType.Map, this.SelectedNidInTrgDatabase, this._SelectedFiles[0].ToString(), this.XsltFolderPath); } else { ////MetaData.ImportMetadataFromXML(this.GetFileText(this._SelectedFiles[0]), MetaDataType.Map, this.SelectedNidInTrgDatabase, this.XsltFolderPath); MetaData.ImportMetadataFromXML(this.GetFileText(this._SelectedFiles[0]), MetadataElementType.Area, this.SelectedNidInTrgDatabase, this.XsltFolderPath); } this.RaiseIncrementProgessBarEvent(1); } else { int SelectedCount = SelectedNids.Count; if (allSelected) SelectedCount = -1; MetaData.ImportAreaMetadata(this._TargetDBQueries.DataPrefix, this.SourceDBConnection, this.SourceDBQueries, string.Join(",", SelectedNids.ToArray()), SelectedCount, MetaDataType.Map); } }
/// <summary> /// To import indicator into template or database /// </summary> /// <param name="indicatorInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportIndicator(IndicatorInfo sourceIndicatorInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection, bool importIndicatorInfoAlso) { int RetVal = -1; string metadataInfo = string.Empty; string SqlString = string.Empty; DataRow Row; DataTable TempTable; //Dictionary<String, String> OldIconNId_NewIconNId = new Dictionary<string, string>(); //MetaDataBuilder MetaDataBuilderObj; DI7MetaDataBuilder MetadataBuilderObj = null; IndicatorInfo TrgIndicatorInfo; try { //check Indicator already exists in database or not RetVal = this.GetIndicatorNid(sourceIndicatorInfo.GID, sourceIndicatorInfo.Name); if (RetVal > 0) { TrgIndicatorInfo = this.GetIndicatorInfo(FilterFieldType.NId, RetVal.ToString(), FieldSelection.Heavy); // dont import if trg indicator is global but source indicator is local if (TrgIndicatorInfo.Global & sourceIndicatorInfo.Global == false) { // dont import if trg indicator is global but source indicator is local } else { sourceIndicatorInfo.Info = DICommon.CheckNConvertMetadataXml(sourceIndicatorInfo.Info); //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Indicator.Update.UpdateByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, sourceIndicatorInfo.Name, sourceIndicatorInfo.GID, sourceIndicatorInfo.Global, sourceIndicatorInfo.Info, RetVal, sourceIndicatorInfo.HighIsGood)); } } else if (importIndicatorInfoAlso) { if (this.InsertIntoDatabase(sourceIndicatorInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } if (RetVal > 0) { //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.Indicator, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata MetadataBuilderObj = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); MetadataBuilderObj.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Indicator, MetaDataType.Indicator, IconElementType.MetadataIndicator); //////// -- insert records in xslt tables //////SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Indicator); //////TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //////if (TempTable.Rows.Count > 0) //////{ ////// Row = TempTable.Rows[0]; ////// MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); ////// MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Indicator); //////} } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }
/// <summary> /// To import indicator into template or database /// </summary> /// <param name="indicatorInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportIndicator(IndicatorInfo sourceIndicatorInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection, bool importIndicatorInfoAlso) { int RetVal = -1; string metadataInfo = string.Empty; string SqlString = string.Empty; DataRow Row; DataTable TempTable; //Dictionary<String, String> OldIconNId_NewIconNId = new Dictionary<string, string>(); //MetaDataBuilder MetaDataBuilderObj; DI7MetaDataBuilder MetadataBuilderObj = null; IndicatorInfo TrgIndicatorInfo; try { //check Indicator already exists in database or not RetVal = this.GetIndicatorNid(sourceIndicatorInfo.GID, sourceIndicatorInfo.Name); if (RetVal > 0) { TrgIndicatorInfo = this.GetIndicatorInfo(FilterFieldType.NId, RetVal.ToString(), FieldSelection.Heavy); // dont import if trg indicator is global but source indicator is local if (TrgIndicatorInfo.Global & sourceIndicatorInfo.Global == false) { // dont import if trg indicator is global but source indicator is local } else { sourceIndicatorInfo.Info = DICommon.CheckNConvertMetadataXml(sourceIndicatorInfo.Info); //update the gid,name and global on the basis of nid this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Indicator.Update.UpdateByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, sourceIndicatorInfo.Name, sourceIndicatorInfo.GID, sourceIndicatorInfo.Global, sourceIndicatorInfo.Info, RetVal, sourceIndicatorInfo.HighIsGood)); } } else if (importIndicatorInfoAlso) { if (this.InsertIntoDatabase(sourceIndicatorInfo)) { //get nid RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY")); } } if (RetVal > 0) { //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.Indicator, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata MetadataBuilderObj = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); MetadataBuilderObj.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Indicator, MetaDataType.Indicator, IconElementType.MetadataIndicator); //////// -- insert records in xslt tables //////SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Indicator); //////TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //////if (TempTable.Rows.Count > 0) //////{ ////// Row = TempTable.Rows[0]; ////// MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); ////// MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Indicator); //////} } } catch (Exception ex) { throw new ApplicationException(ex.Message); } return RetVal; }
/// <summary> /// To import source into template or database /// </summary> /// <param name="sourceInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSource(SourceInfo sourceInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; string MetadataInfo = string.Empty; string SqlString = string.Empty; string Publisher = string.Empty; int ParentNid = -1; DataRow Row; DataTable TempTable; Dictionary<String, String> OldIconNId_NewIconNId = new Dictionary<string, string>(); DI7MetaDataBuilder SourceMetadataBuilder = null; try { //check source already exists in database or not RetVal = this.GetSourceNid(sourceInfo.Name); if (RetVal > 0) { // if source indicator is global if (sourceInfo.Global) { // do nothing } } else { RetVal = this.CheckNCreateSource(sourceInfo.Name, sourceInfo.ISBN, sourceInfo.Nature); } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.IndicatorClassification, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata reports from source database into current database SourceMetadataBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); SourceMetadataBuilder.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource); //OldIconNId_NewIconNId = DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.MetadataSource, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); //// get metadata info. //MetadataInfo = sourceInfo.Info; //// Update IconNids in xml if exists //foreach (string OldIconName in OldIconNId_NewIconNId.Keys) //{ // MetadataInfo = MetadataInfo.Replace(OldIconName, OldIconNId_NewIconNId[OldIconName].ToString()); //} //MetadataInfo = DICommon.CheckNConvertMetadataXml(MetadataInfo); //// Update Metadata //this.DBConnection.ExecuteNonQuery(DALQueries.IndicatorClassification.Update.UpdateICInfo(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, DICommon.RemoveQuotes(MetadataInfo), ICType.Source, RetVal)); //// -- insert records in xslt tables //SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Source); //TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //if (TempTable.Rows.Count > 0) //{ // Row = TempTable.Rows[0]; // MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); // MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Source); //} } catch (Exception ex) { throw new ApplicationException(ex.Message); } return RetVal; }
public bool ImportMetataFromExcel(MetadataElementType categoryType, MetaDataType metadataType, int elementNId, string xlsFileNameWPath, string xsltFldrPath) { bool RetVal = true; string MetadataText = string.Empty; string FirstColumnValue = string.Empty; string SecondColumnValue = string.Empty; string ThirdColumnValue = string.Empty; string ElementName = string.Empty; string ElementGID = string.Empty; DataTable ExcelDataTable = null; DataRow Row; DI7MetaDataBuilder MDBuilder; DI7MetadataCategoryBuilder MDCategoryBuilder; DI7MetadataCategoryInfo MetadataCategory; DIExcel ExcelFile = null; try { // -- Get data table from excel file ExcelFile = new DIExcel(xlsFileNameWPath); ExcelDataTable = ExcelFile.GetDataTableFromSheet(ExcelFile.GetSheetName(0)); // -- create database builder objects MDCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries); MDBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); // -- import metadata reports with category for (int RowIndex = 1; RowIndex < ExcelDataTable.Rows.Count; RowIndex++) { Row = ExcelDataTable.Rows[RowIndex]; FirstColumnValue = Convert.ToString(Row[0]); SecondColumnValue = Convert.ToString(Row[1]); ThirdColumnValue = Convert.ToString(Row[2]); // get element name if (string.IsNullOrEmpty(ElementName)) { if (string.IsNullOrEmpty(FirstColumnValue)) { break; } else { ElementName = FirstColumnValue; continue; } } // get element gid/id if (string.IsNullOrEmpty(ElementGID)) { if (string.IsNullOrEmpty(FirstColumnValue)) { break; } else { ElementGID = FirstColumnValue; // get element nid by element gid if (metadataType == MetaDataType.Source) { elementNId = this.GetElementNidByGID(ElementName, metadataType); } else { elementNId = this.GetElementNidByGID(ElementGID, metadataType); } // Skip title row by incrementing row index RowIndex++; continue; } } // continue if row is blank if (string.IsNullOrEmpty(FirstColumnValue) && string.IsNullOrEmpty(SecondColumnValue) && string.IsNullOrEmpty(ThirdColumnValue)) { // reset element value elementNId = 0; ElementName = string.Empty; ElementGID = string.Empty; continue; } else if (elementNId > 0) { // import metadata report with metadata category // get metadata category and metedata report MetadataCategory = new DI7MetadataCategoryInfo(); MetadataCategory.CategoryName = SecondColumnValue; MetadataCategory.CategoryGID = FirstColumnValue; MetadataCategory.CategoryType = DIQueries.MetadataElementTypeText[categoryType]; // import metadata category MetadataCategory.CategoryNId = MDCategoryBuilder.CheckNInsertCategory(MetadataCategory); // import metadata report if (MetadataCategory.CategoryNId > 0) { MDBuilder.InsertORUpdateMetadataInfo(metadataType, MetadataCategory.CategoryNId.ToString(), elementNId, this.ReplaceNewLineInMetadataReport(ThirdColumnValue)); } } } } catch (Exception) { RetVal = false; } finally { if (ExcelFile != null) { ExcelFile.Close(); } } return(RetVal); }
public bool ImportMetataFromExcel(MetadataElementType categoryType, MetaDataType metadataType, int elementNId, string xlsFileNameWPath, string xsltFldrPath) { bool RetVal = true; string MetadataText = string.Empty; string FirstColumnValue = string.Empty; string SecondColumnValue = string.Empty; string ThirdColumnValue = string.Empty; string ElementName = string.Empty; string ElementGID = string.Empty; DataTable ExcelDataTable = null; DataRow Row; DI7MetaDataBuilder MDBuilder; DI7MetadataCategoryBuilder MDCategoryBuilder; DI7MetadataCategoryInfo MetadataCategory; DIExcel ExcelFile = null; try { // -- Get data table from excel file ExcelFile = new DIExcel(xlsFileNameWPath); ExcelDataTable = ExcelFile.GetDataTableFromSheet(ExcelFile.GetSheetName(0)); // -- create database builder objects MDCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries); MDBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); // -- import metadata reports with category for (int RowIndex = 1; RowIndex < ExcelDataTable.Rows.Count; RowIndex++) { Row = ExcelDataTable.Rows[RowIndex]; FirstColumnValue = Convert.ToString(Row[0]); SecondColumnValue = Convert.ToString(Row[1]); ThirdColumnValue = Convert.ToString(Row[2]); // get element name if (string.IsNullOrEmpty(ElementName)) { if (string.IsNullOrEmpty(FirstColumnValue)) { break; } else { ElementName = FirstColumnValue; continue; } } // get element gid/id if (string.IsNullOrEmpty(ElementGID)) { if (string.IsNullOrEmpty(FirstColumnValue)) { break; } else { ElementGID = FirstColumnValue; // get element nid by element gid if (metadataType == MetaDataType.Source) { elementNId = this.GetElementNidByGID(ElementName, metadataType); } else { elementNId = this.GetElementNidByGID(ElementGID, metadataType); } // Skip title row by incrementing row index RowIndex++; continue; } } // continue if row is blank if (string.IsNullOrEmpty(FirstColumnValue) && string.IsNullOrEmpty(SecondColumnValue) && string.IsNullOrEmpty(ThirdColumnValue)) { // reset element value elementNId = 0; ElementName = string.Empty; ElementGID = string.Empty; continue; } else if (elementNId > 0) { // import metadata report with metadata category // get metadata category and metedata report MetadataCategory = new DI7MetadataCategoryInfo(); MetadataCategory.CategoryName = SecondColumnValue; MetadataCategory.CategoryGID = FirstColumnValue; MetadataCategory.CategoryType = DIQueries.MetadataElementTypeText[categoryType]; // import metadata category MetadataCategory.CategoryNId = MDCategoryBuilder.CheckNInsertCategory(MetadataCategory); // import metadata report if (MetadataCategory.CategoryNId > 0) { MDBuilder.InsertORUpdateMetadataInfo(metadataType, MetadataCategory.CategoryNId.ToString(), elementNId, this.ReplaceNewLineInMetadataReport(ThirdColumnValue)); } } } } catch (Exception) { RetVal = false; } finally { if (ExcelFile != null) { ExcelFile.Close(); } } return RetVal; }
/// <summary> /// To import source into template or database /// </summary> /// <param name="sourceInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSource(SourceInfo sourceInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; string MetadataInfo = string.Empty; string SqlString = string.Empty; string Publisher = string.Empty; int ParentNid = -1; DataRow Row; DataTable TempTable; Dictionary <String, String> OldIconNId_NewIconNId = new Dictionary <string, string>(); DI7MetaDataBuilder SourceMetadataBuilder = null; try { //check source already exists in database or not RetVal = this.GetSourceNid(sourceInfo.Name); if (RetVal > 0) { // if source indicator is global if (sourceInfo.Global) { // do nothing } } else { RetVal = this.CheckNCreateSource(sourceInfo.Name, sourceInfo.ISBN, sourceInfo.Nature); } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.IndicatorClassification, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata reports from source database into current database SourceMetadataBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); SourceMetadataBuilder.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource); //OldIconNId_NewIconNId = DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.MetadataSource, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); //// get metadata info. //MetadataInfo = sourceInfo.Info; //// Update IconNids in xml if exists //foreach (string OldIconName in OldIconNId_NewIconNId.Keys) //{ // MetadataInfo = MetadataInfo.Replace(OldIconName, OldIconNId_NewIconNId[OldIconName].ToString()); //} //MetadataInfo = DICommon.CheckNConvertMetadataXml(MetadataInfo); //// Update Metadata //this.DBConnection.ExecuteNonQuery(DALQueries.IndicatorClassification.Update.UpdateICInfo(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, DICommon.RemoveQuotes(MetadataInfo), ICType.Source, RetVal)); //// -- insert records in xslt tables //SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Source); //TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //if (TempTable.Rows.Count > 0) //{ // Row = TempTable.Rows[0]; // MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); // MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Source); //} } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }