Пример #1
0
        public XmlDocument GetMetadataReportWCategoryName(string mdXml, MetadataElementType mdType)
        {
            XmlDocument RetVal = new XmlDocument();

            RetVal.XmlResolver = null;
            RetVal.LoadXml(mdXml);
            Dictionary <string, string> MDCatGIDandNameColl = null;

            try
            {
                XmlNamespaceManager nsManager = new XmlNamespaceManager(RetVal.NameTable);
                nsManager.AddNamespace("generic", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic");
                nsManager.AddNamespace("message", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message");

                //-- Get Metadata Name and CategoryID
                MDCatGIDandNameColl = this.GetMetadataCategoryNameGIDCollection(mdType);

                XmlNodeList NodeListObj = RetVal.SelectNodes(METADATASET_XPATH, nsManager);

                foreach (XmlNode Node in NodeListObj[0].ChildNodes)
                {
                    if (Node.Name == REPORT_ELEMENT)
                    {
                        this.AddNameAttribteInAttributeSet(RetVal, MDCatGIDandNameColl, Node);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RetVal);
        }
Пример #2
0
        private Dictionary <string, string> GetMetadataCategoryNameGIDCollection(MetadataElementType mdType)
        {
            Dictionary <string, string> RetVal = new Dictionary <string, string>();

            DataTable Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.None, string.Empty));

            if (mdType == MetadataElementType.Indicator)
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='I'";
            }
            else if (mdType == MetadataElementType.Area)
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='A'";
            }
            else
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='S'";
            }

            Table = Table.DefaultView.ToTable();

            foreach (DataRow Row in Table.Rows)
            {
                if (!RetVal.ContainsKey(Convert.ToString(Row[Metadata_Category.CategoryGId])))
                {
                    RetVal.Add(Convert.ToString(Row[Metadata_Category.CategoryGId]), Convert.ToString(Row[Metadata_Category.CategoryName]));
                }
            }

            return(RetVal);
        }
Пример #3
0
        /// <summary>
        /// Returns categories table from database for the given metadata type
        /// </summary>
        /// <param name="metadataType"></param>
        /// <returns></returns>
        private DataTable GetCategoryDataTableFrmDB(MetaDataType metadataType)
        {
            DataTable           RetVal        = null;
            MetadataElementType MDElementType = MetadataElementType.Indicator;
            string ColumnInfo = string.Empty;

            switch (metadataType)
            {
            case MetaDataType.Indicator:
                MDElementType = MetadataElementType.Indicator;
                break;

            case MetaDataType.Map:
                MDElementType = MetadataElementType.Area;
                break;

            case MetaDataType.Source:
                MDElementType = MetadataElementType.Source;
                break;

            default:
                break;
            }


            RetVal = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[MDElementType]));

            return(RetVal);
        }
Пример #4
0
        /// <summary>
        /// Updates ElementXslt table
        /// </summary>
        /// <param name="elementNid"></param>
        /// <param name="mdElementType"></param>
        /// <returns></returns>
        protected bool UpdateElementXsltTable(int elementNid, MetadataElementType mdElementType, string mdXslTtype)
        {
            bool RetVal         = false;
            int  XsltNid        = 0;
            int  ElementXsltNid = 0;

            try
            {
                // 1. get xslt nid from XSLT table
                XsltNid = this.GetXslNidFrmXSLTTable(mdXslTtype);

                if (XsltNid > 0)
                {
                    // 2. check record exists in Element_Xslt table or not
                    ElementXsltNid = this.GetElementXsltNidFrmDB(mdElementType, elementNid);

                    // 3. If not then insert record
                    if (ElementXsltNid <= 0)
                    {
                        this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Xslt.Insert.InsertElementXSLT(this.DBQueries.DataPrefix, elementNid, mdElementType, XsltNid));
                    }
                    else
                    {
                        // 4. if exists then update record
                        this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Xslt.Update.UpdateElementXSLT(this.DBQueries.DataPrefix, XsltNid, elementNid, mdElementType));
                    }
                    RetVal = true;
                }
            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }
            return(RetVal);
        }
Пример #5
0
        /// <summary>
        /// Import Metdata report
        /// </summary>
        /// <param name="xmlFileNameWPath"></param>
        /// <param name="mdType"></param>
        /// <param name="selectedNidInTrgDatabase"></param>
        /// <param name="selectedFiles"></param>
        /// <param name="XsltFolderPath"></param>
        public void ImportMetadataFromXML(string xmlString, MetadataElementType metadataElementType, int selectedNidInTrgDatabase, string XsltFolderPath)
        {
            XmlDocument XmlDoc = new XmlDocument();
            DI7MetadataCategoryBuilder MDBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries);

            XmlDoc.LoadXml(xmlString);
            try
            {
                //--  check that Value/Name attribute exists or not
                if (this.IsMetadataNameAttributeExists(XmlDoc))
                {
                    this.CheckNInsertMetadataReportXml(XmlDoc, selectedNidInTrgDatabase, true, DIQueries.MetadataElementTypeText[metadataElementType]);
                }
                else
                {
                    // if not then use ID for mapping .
                    // If category ID exists in trg database then only import metadata report
                    this.CheckNInsertMetadataReportXml(XmlDoc, selectedNidInTrgDatabase, false, DIQueries.MetadataElementTypeText[metadataElementType]);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        private DataTable GetCategoryDataTable(MetadataElementType elementType)
        {
            DataTable RetVal = null;

            RetVal = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategoriesForEditor(FilterFieldType.Type, DIQueries.MetadataElementTypeText[elementType]));

            return(RetVal);
        }
Пример #7
0
        /// <summary>
        /// Returns sql query to delete XsltNid from UT_Element_XSLT table
        /// </summary>
        /// <param name="elementNIds"></param>
        /// <param name="elementType"></param>
        /// <returns></returns>
        public string DeleteElementXSLT( string elementNIds, MetadataElementType elementType)
        {
            string RetVal = string.Empty;

            RetVal = "DELETE FROM " + this.TablesName.ElementXSLT + " WHERE  " +  DIColumns.EelementXSLT.ElementNId + " IN (" + elementNIds + " ) AND  " + DIColumns.EelementXSLT.ElementType + "=" + DIQueries.MetadataElementTypeText[elementType];

            return RetVal;
        }
Пример #8
0
        public static string DeleteMetadataReportByCategory(DITables tables, MetadataElementType categoryType)
        {
            string RetVal=string.Empty;

            RetVal = "DELETE MR.* FROM " + tables.MetadataCategory + "  MC INNER JOIN " + tables.MetadataReport + " MR ON MC." + DIColumns.Metadata_Category.CategoryNId + " = MR." + DIColumns.MetadataReport.CategoryNid + " where  MC." + DIColumns.Metadata_Category.CategoryType + "=" + DIQueries.MetadataElementTypeText[categoryType] +";";

            return RetVal;
        }
Пример #9
0
        /// <summary>
        /// Returns sql query to insert element's xslt relationship into UT_Element_XSLT table
        /// </summary>
        /// <param name="dataprefix"></param>
        /// <param name="elementNId"></param>
        /// <param name="elementType"></param>
        /// <param name="XsltNid"></param>
        /// <returns></returns>
        public static string InsertElementXSLT(string dataprefix, int elementNId, MetadataElementType elementType, int XsltNid)
        {
            string RetVal = string.Empty;

            RetVal = "insert into " + dataprefix + Insert.ElementTableName + "(" + DIColumns.EelementXSLT.ElementNId + "," + DIColumns.EelementXSLT.ElementType + "," + DIColumns.XSLT.XSLTNId + ") values(" + elementNId + "," + DIQueries.MetadataElementTypeText[elementType] + "," + XsltNid + ")";

             return RetVal;
        }
Пример #10
0
        private DataTable GetMetadataReportsTableFrmDB(int elementNid, MetadataElementType elementType)
        {
            DataTable RetVal = null;

            // get indicator metadata from metadatareport table
            RetVal = this.DBConnection.ExecuteDataTable(this.DBQueries.MetadataReport.GetMetadataReportsByTargetNid(elementNid.ToString(), elementType));

            return(RetVal);
        }
Пример #11
0
        /// <summary>
        /// Returns sql query to update XsltNid into UT_Element_XSLT table
        /// </summary>
        /// <param name="dataprefix"></param>
        /// <param name="XSLTNid"></param>
        /// <param name="elementNId"></param>
        /// <param name="elementType"></param>
        /// <returns></returns>
        public static string UpdateElementXSLT(string dataprefix, int XSLTNid, int elementNId,MetadataElementType elementType)
        {
            string RetVal = string.Empty;

            RetVal = "Update " + dataprefix+ Update.ElementTableName + " set "+ DIColumns.EelementXSLT.XSLTNId +" ="
                + XSLTNid + " WHERE "+ DIColumns.EelementXSLT.ElementNId+"=" + elementNId+ " AND "+DIColumns.EelementXSLT.ElementType +"="+ DIQueries.MetadataElementTypeText[elementType] ;

            return RetVal;
        }
Пример #12
0
 /// <summary>
 /// Deletes metadata information 
 /// </summary>
 /// <param name="elementNIds"></param>
 /// <param name="elementType"></param>
 public void DeleteMetadata(string elementNIds, MetadataElementType elementType)
 {
     try
     {
         this.DBConnection.ExecuteNonQuery(this.DBQueries.Delete.Xslt.DeleteElementXSLT(elementNIds, elementType));
     }
     catch (Exception ex)
     {
         ExceptionFacade.ThrowException(ex);
     }
 }
Пример #13
0
        protected int GetElementXsltNidFrmDB(MetadataElementType mdElementtype, int elementNid)
        {
            int RetVal = -1;


            foreach (DataRow Row in this.DBConnection.ExecuteDataTable(this.DBQueries.Xslt.GetElementXSLTTable(elementNid.ToString(), mdElementtype)).Rows)
            {
                RetVal = Convert.ToInt32(Row[EelementXSLT.ElementXSLTNId]);
                break;
            }

            return(RetVal);
        }
Пример #14
0
        /// <summary>
        /// Returns sql query to get ElementXSLT table for a given  elementNId and ElementType
        /// </summary>
        /// <param name="elementNId">elementNId </param>
        /// <param name="metadataElementType">Indicator / Area / Source</param>
        /// <returns></returns>
        public string GetElementXSLTTable(string elementNId, MetadataElementType metadataElementType)
        {
            string RetVal = string.Empty;
            StringBuilder sbQuery = new StringBuilder();

            sbQuery.Append("SELECT * ");
            sbQuery.Append(" FROM " + this.TablesName.ElementXSLT + " ");

            sbQuery.Append(" WHERE ");
            sbQuery.Append(DIColumns.EelementXSLT.ElementType + " = " + DIQueries.MetadataElementTypeText[metadataElementType]);
            sbQuery.Append(" AND " + DIColumns.EelementXSLT.ElementNId + " IN (" + elementNId + ")");

            RetVal = sbQuery.ToString();
            return RetVal;
        }
Пример #15
0
        /// <summary>
        /// Get StyleSheet details from XSLT table for a given  elementNId and ElementType
        /// </summary>
        /// <param name="elementNId">elementNId for which icon is to be extracted</param>
        /// <param name="metadataElementType">Indicator / Area / Source</param>
        /// <returns></returns>
        public string GetXSLT(string elementNId, MetadataElementType metadataElementType)
        {
            string RetVal = string.Empty;
            StringBuilder sbQuery = new StringBuilder();

            sbQuery.Append("SELECT X." + DIColumns.XSLT.XSLTNId + ",EX." + DIColumns.EelementXSLT.ElementNId + ",X." + DIColumns.XSLT.XSLTText + ",X." + DIColumns.XSLT.XSLTFile);
            sbQuery.Append(" FROM " + this.TablesName.XSLT + " AS X," + this.TablesName.ElementXSLT + " AS EX");

            sbQuery.Append(" WHERE X." + DIColumns.XSLT.XSLTNId + " = EX." + DIColumns.EelementXSLT.XSLTNId);
            sbQuery.Append(" AND EX." + DIColumns.EelementXSLT.ElementType + " = " + DIQueries.MetadataElementTypeText[metadataElementType]);

            if (elementNId.Trim().Length >= 0)
            {
                sbQuery.Append(" AND EX." + DIColumns.EelementXSLT.ElementNId + " IN (" + elementNId + ")");
            }

            RetVal = sbQuery.ToString();
            return RetVal;
        }
Пример #16
0
        void MetadataConverter_WrongMetdataFoundEvent(MetadataElementType elementType, string name, string GID)
        {
            // check n create list object
            if (this._WrongMetadataElementList == null)
            {
                this._WrongMetadataElementList = new SortedDictionary <MetadataElementType, List <string> >();
            }

            // check n create element type key into dictionary object
            if (!this._WrongMetadataElementList.ContainsKey(elementType))
            {
                this._WrongMetadataElementList.Add(elementType, new List <string>());
            }

            // add name into list if doesnt exist
            if (!this._WrongMetadataElementList[elementType].Contains(name))
            {
                this._WrongMetadataElementList[elementType].Add(name);
            }
        }
Пример #17
0
        private void UpdateMetadataInfo(DIQueries queries, string targetNid, MetadataElementType categoryType, String metadataCategoryInfo)
        {
            switch (categoryType)
            {
            case MetadataElementType.Indicator:
                this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.Indicator + " set " + Indicator.IndicatorInfo + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "'where " + Indicator.IndicatorNId + "=" + targetNid);
                break;

            case MetadataElementType.Area:
                this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.AreaMapMetadata + " set " + Area_Map_Metadata.MetadataText + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "' where " + Area_Map_Layer.LayerNId + "=" + targetNid);
                break;

            case MetadataElementType.Source:
                this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.IndicatorClassifications + " set " + IndicatorClassifications.ICInfo + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "'where " + IndicatorClassifications.ICNId + "=" + targetNid);
                break;

            default:
                break;
            }
        }
Пример #18
0
        private void UpdateMetadataInfoByCategoryType(MetadataElementType categoryType, MetadataCategoryBuilder metadataCategoryBuilder, DIQueries queries)
        {
            List <string> TargetNids;
            DataTable     SrcCategoryTable       = null;
            StringBuilder Metadata_Category_Info = new StringBuilder();

            SrcCategoryTable = this._DBConnection.ExecuteDataTable(queries.MetadataReport.GetAllMetadataReportsByCategoryType(categoryType));
            TargetNids       = DICommon.GetCommaSeperatedListOfGivenColumn(SrcCategoryTable, MetadataReport.TargetNid, false, string.Empty);

            //for every target like for indicator one there is many metadata category may be definition, Classification, Method of Computation
            foreach (string targetNid in TargetNids)
            {
                Metadata_Category_Info.Remove(0, Metadata_Category_Info.Length);

                //Step 1 Create metadata Info in xml format
                this.CreateMetadataXML(SrcCategoryTable.Select(MetadataReport.TargetNid + "='" + targetNid + "'"), ref Metadata_Category_Info, metadataCategoryBuilder, DIQueries.MetadataElementTypeText[categoryType].Trim("'".ToCharArray()));

                //Step 2 Update metadata Info in xml format
                this.UpdateMetadataInfo(queries, targetNid, categoryType, Metadata_Category_Info.ToString());
            }
        }
Пример #19
0
        public void DeleteMetadataReports(MetadataElementType categoryType)
        {
            DITables TableNames;


            try
            {
                // Step1: Delete records from metadata Report table
                foreach (DataRow Row in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows)
                {
                    // Get table name
                    TableNames = new DITables(this.DBQueries.DataPrefix, Row[Language.LanguageCode].ToString());

                    // delete records
                    this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.MetadataReport.Delete.DeleteMetadataReportByCategory(TableNames, categoryType));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
        private string GetCategoryTypeText(MetadataElementType categoryMaskType)
        {
            string RetVal = string.Empty;

            switch (categoryMaskType)
            {
            case MetadataElementType.Indicator:
                RetVal = "I";
                break;

            case MetadataElementType.Area:
                RetVal = "A";
                break;

            case MetadataElementType.Source:
                RetVal = "S";
                break;
            }


            return(RetVal);
        }
Пример #21
0
        public void DeleteMetadataReports(MetadataElementType categoryType)
        {
            DITables TableNames;

            try
            {
                // Step1: Delete records from metadata Report table
                foreach (DataRow Row in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows)
                {
                    // Get table name
                    TableNames = new DITables(this.DBQueries.DataPrefix, Row[Language.LanguageCode].ToString());

                    // delete records
                    this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.MetadataReport.Delete.DeleteMetadataReportByCategory(TableNames, categoryType));

                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Пример #22
0
        /// <summary>
        /// Export metadata to excel file
        /// </summary>
        /// <param name="ExcelFilePath">Excel File Path to be written as export data</param>
        public void ExportMetaDataToExcel(string ExcelFilePath, MetadataElementType elementType, string elementName, string elementGId, int targetElementNID)
        {
            try
            {
                // --Open excel and get first worksheet
                this.DiExcel  = new DIExcel(ExcelFilePath);
                MetadataSheet = DiExcel.GetWorksheet(0);

                // --Set Matadata Type in Cell 0,0
                switch (elementType)
                {
                case MetadataElementType.Indicator:
                    SetMetadataCommonCellValues(DILanguage.GetLanguageString("INDICATOR") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                    break;

                case MetadataElementType.Area:
                    SetMetadataCommonCellValues(DILanguage.GetLanguageString("AREA") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                    break;

                case MetadataElementType.Source:
                    SetMetadataCommonCellValues(DILanguage.GetLanguageString("SOURCE") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                    break;

                default:
                    break;
                }

                // --Load data from xml to excel file
                this.LoadData(elementType, targetElementNID);

                //-- Save excel
                this.DiExcel.Save();
            }
            catch (Exception ex)
            {
            }
        }
Пример #23
0
        /// <summary>
        /// Imports metadata from the source database into current database
        /// </summary>
        /// <param name="srcConnection"></param>
        /// <param name="srcQueries"></param>
        /// <param name="srcElementNid"></param>
        /// <param name="trgElementNid"></param>
        /// <param name="categoryType"></param>
        /// <param name="metadataType"></param>
        /// <param name="iconType"></param>
        public void ImportMetadata(DIConnection srcConnection, DIQueries srcQueries, int srcElementNid, int trgElementNid, MetadataElementType categoryType, MetaDataType metadataType, IconElementType iconType)
        {
            string    SrcCategoryGID   = string.Empty;
            string    MetadataText     = string.Empty;
            int       TrgCategoryNid   = 0;
            DataTable TrgCategoryTable = null;
            Dictionary <String, String> OldIconNIdnNewIconNId = new Dictionary <string, string>();

            try
            {
                // Get target Category table
                TrgCategoryTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType]));

                // update metadata icon in DICon table
                OldIconNIdnNewIconNId = DIIcons.ImportElement(srcElementNid, trgElementNid, iconType, srcQueries, srcConnection, this.DBQueries, this.DBConnection);



                //get source metadata reports
                foreach (DataRow SrcRow in srcConnection.ExecuteDataTable(srcQueries.MetadataReport.GetMetadataReportsByTargetNid(srcElementNid.ToString(), categoryType)).Rows)
                {
                    SrcCategoryGID = Convert.ToString(SrcRow[Metadata_Category.CategoryGId]);

                    // check source category GID exists in current database
                    // Import metadta report only if category exists in current database
                    foreach (DataRow TrgCategoryRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryGID) + "' "))
                    {
                        MetadataText = Convert.ToString(SrcRow[MetadataReport.Metadata]);

                        // Update IconNids in metadata if exists
                        foreach (string OldIconName in OldIconNIdnNewIconNId.Keys)
                        {
                            MetadataText = MetadataText.Replace(OldIconName, OldIconNIdnNewIconNId[OldIconName].ToString());
                        }

                        TrgCategoryNid = Convert.ToInt32(TrgCategoryRow[Metadata_Category.CategoryNId]);
                        this.InsertORUpdateMetadataInfo(metadataType, TrgCategoryNid.ToString(), trgElementNid, MetadataText);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
            }
        }
Пример #24
0
 private void UpdateMetadataInfo(DIQueries queries, string targetNid, MetadataElementType categoryType, String metadataCategoryInfo)
 {
     switch (categoryType)
     {
         case MetadataElementType.Indicator:
             this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.Indicator + " set " + Indicator.IndicatorInfo + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "'where " + Indicator.IndicatorNId + "=" + targetNid);
             break;
         case MetadataElementType.Area:
             this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.AreaMapMetadata + " set " + Area_Map_Metadata.MetadataText + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "' where " + Area_Map_Layer.LayerNId + "=" + targetNid);
             break;
         case MetadataElementType.Source:
             this._DBConnection.ExecuteNonQuery("update " + queries.TablesName.IndicatorClassifications + " set " + IndicatorClassifications.ICInfo + "='" + DIQueries.RemoveQuotesForSqlQuery(metadataCategoryInfo) + "'where " + IndicatorClassifications.ICNId + "=" + targetNid);
             break;
         default:
             break;
     }
 }
Пример #25
0
        /// <summary>
        /// Load Data into excel report file
        /// </summary>
        private void LoadData(MetadataElementType elementType,int elementNID)
        {
            string ParaNodeText = string.Empty;
            string ConcatenatedParaNodeText = string.Empty;
            DataTable CategoryTable = null;
            DataTable MetadataReportTable = null;
            string CategoryName = string.Empty;
            string CategoryNid = string.Empty;
            string MetadataText = string.Empty;
            string ReplaceableSymbol = "{{~}}";
            string CategoryGID = string.Empty;

                try
                {

                    // 1. Get category table from database where ispresentational is false
                    CategoryTable = this.GetCategoryDataTable(elementType);

                    // rearrange categories
                    CategoryTable = DI7MetadataCategoryBuilder.RearrangeCategoryTableByCategoryOrder(CategoryTable);

                    // 2. get metadata reports
                    MetadataReportTable = this.GetMetadataReportsTableFrmDB(elementNID,elementType);

                    // 3. Add Title
                    // writes metadata values in excel report.
                    this.WriteMetadataField(CategoryIndex, DILanguage.GetLanguageString("CATEGORY"), DILanguage.GetLanguageString("CATEGORY_GID"));
                    //Write values to excel
                    this.WriteMetadataValueToExcel(CategoryIndex, DILanguage.GetLanguageString("METADATA"));

                    this.MetadataSheet.Cells[this._MetadataStartRowIndexInExl + CategoryIndex, 0, this._MetadataStartRowIndexInExl + CategoryIndex, 2].Font.Bold = true;
                    this.MetadataSheet.Cells[this._MetadataStartRowIndexInExl + CategoryIndex, 0, this._MetadataStartRowIndexInExl + CategoryIndex, 2].Interior.Color = SpreadsheetGear.Drawing.Color.FromArgb(System.Drawing.Color.LightGray.ToArgb());
                    CategoryIndex++;

                    //Iterate through category node
                    foreach (DataRow CategoryRow in CategoryTable.Rows)
                    {
                        // 4.2 get category label form table
                        CategoryName = Convert.ToString(CategoryRow[Metadata_Category.CategoryName]);
                        CategoryNid = Convert.ToString(CategoryRow[Metadata_Category.CategoryNId]);
                        CategoryGID = Convert.ToString(CategoryRow[Metadata_Category.CategoryGId]);

                        // writes metadata values in excel report.
                        this.WriteMetadataField(CategoryIndex, CategoryName,CategoryGID);

                        // Get metadata report from metadata report table for the  current category
                        foreach (DataRow Row in MetadataReportTable.Select(MetadataReport.CategoryNid + "=" + CategoryNid))
                        {
                            MetadataText = Convert.ToString(Row[MetadataReport.Metadata]).Replace(ReplaceableSymbol, Microsoft.VisualBasic.ControlChars.NewLine);

                            //Write values to excel
                            WriteMetadataValueToExcel(CategoryIndex, MetadataText);
                        }

                        CategoryIndex = CategoryIndex + 1;
                    }

                }
                catch (Exception ex)
                { ExceptionHandler.ExceptionFacade.ThrowException(ex); }
        }
Пример #26
0
        private DataTable GetCategoryDataTable( MetadataElementType elementType)
        {
            DataTable RetVal = null;

            RetVal = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategoriesForEditor(FilterFieldType.Type, DIQueries.MetadataElementTypeText[elementType]));

            return RetVal;
        }
Пример #27
0
        public XmlDocument GetMetadataReportWCategoryName(string mdXml, MetadataElementType mdType)
        {
            XmlDocument RetVal = new XmlDocument();
            RetVal.XmlResolver = null;
            RetVal.LoadXml(mdXml);
            Dictionary<string, string> MDCatGIDandNameColl = null;

            try
            {
                XmlNamespaceManager nsManager = new XmlNamespaceManager(RetVal.NameTable);
                nsManager.AddNamespace("generic", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic");
                nsManager.AddNamespace("message", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message");

                //-- Get Metadata Name and CategoryID
                MDCatGIDandNameColl = this.GetMetadataCategoryNameGIDCollection(mdType);

                XmlNodeList NodeListObj = RetVal.SelectNodes(METADATASET_XPATH, nsManager);

                foreach (XmlNode Node in NodeListObj[0].ChildNodes)
                {
                    if (Node.Name == REPORT_ELEMENT)
                    {
                        this.AddNameAttribteInAttributeSet(RetVal, MDCatGIDandNameColl, Node);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return RetVal;
        }
Пример #28
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);
        }
Пример #29
0
        /// <summary>
        /// Import Metdata report
        /// </summary>
        /// <param name="xmlFileNameWPath"></param>
        /// <param name="mdType"></param>
        /// <param name="selectedNidInTrgDatabase"></param>
        /// <param name="selectedFiles"></param>
        /// <param name="XsltFolderPath"></param>
        public void ImportMetadataFromXML(string xmlString, MetadataElementType metadataElementType, int selectedNidInTrgDatabase, string XsltFolderPath)
        {
            XmlDocument XmlDoc = new XmlDocument();
            DI7MetadataCategoryBuilder MDBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries);

            XmlDoc.LoadXml(xmlString);
            try
            {
                //--  check that Value/Name attribute exists or not
                if (this.IsMetadataNameAttributeExists(XmlDoc))
                {

                    this.CheckNInsertMetadataReportXml(XmlDoc, selectedNidInTrgDatabase, true, DIQueries.MetadataElementTypeText[metadataElementType]);
                }
                else
                {
                    // if not then use ID for mapping .
                    // If category ID exists in trg database then only import metadata report
                    this.CheckNInsertMetadataReportXml(XmlDoc, selectedNidInTrgDatabase, false, DIQueries.MetadataElementTypeText[metadataElementType]);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #30
0
        private Dictionary<string, string> GetMetadataCategoryNameGIDCollection(MetadataElementType mdType)
        {
            Dictionary<string, string> RetVal = new Dictionary<string, string>();

            DataTable Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.None, string.Empty));
            if (mdType == MetadataElementType.Indicator)
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='I'";
            }
            else if (mdType == MetadataElementType.Area)
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='A'";
            }
            else
            {
                Table.DefaultView.RowFilter = Metadata_Category.CategoryType + "='S'";
            }

            Table = Table.DefaultView.ToTable();

            foreach (DataRow Row in Table.Rows)
            {
                if (!RetVal.ContainsKey(Convert.ToString(Row[Metadata_Category.CategoryGId])))
                {
                    RetVal.Add(Convert.ToString(Row[Metadata_Category.CategoryGId]), Convert.ToString(Row[Metadata_Category.CategoryName]));
                }
            }

            return RetVal;
        }
Пример #31
0
        private void UpdateMetadataInfoByCategoryType(MetadataElementType categoryType, MetadataCategoryBuilder metadataCategoryBuilder, DIQueries queries)
        {
            List<string> TargetNids;
            DataTable SrcCategoryTable = null;
            StringBuilder Metadata_Category_Info = new StringBuilder();

            SrcCategoryTable = this._DBConnection.ExecuteDataTable(queries.MetadataReport.GetAllMetadataReportsByCategoryType(categoryType));
            TargetNids = DICommon.GetCommaSeperatedListOfGivenColumn(SrcCategoryTable, MetadataReport.TargetNid, false, string.Empty);

            //for every target like for indicator one there is many metadata category may be definition, Classification, Method of Computation
            foreach (string targetNid in TargetNids)
            {
                Metadata_Category_Info.Remove(0, Metadata_Category_Info.Length);

                //Step 1 Create metadata Info in xml format
                this.CreateMetadataXML(SrcCategoryTable.Select(MetadataReport.TargetNid + "='" + targetNid + "'"), ref Metadata_Category_Info, metadataCategoryBuilder, DIQueries.MetadataElementTypeText[categoryType].Trim("'".ToCharArray()));

                //Step 2 Update metadata Info in xml format
                this.UpdateMetadataInfo(queries, targetNid, categoryType, Metadata_Category_Info.ToString());
            }
        }
Пример #32
0
        /// <summary>
        /// Load Data into excel report file
        /// </summary>
        private void LoadData(MetadataElementType elementType, int elementNID)
        {
            string    ParaNodeText             = string.Empty;
            string    ConcatenatedParaNodeText = string.Empty;
            DataTable CategoryTable            = null;
            DataTable MetadataReportTable      = null;
            string    CategoryName             = string.Empty;
            string    CategoryNid       = string.Empty;
            string    MetadataText      = string.Empty;
            string    ReplaceableSymbol = "{{~}}";
            string    CategoryGID       = string.Empty;

            try
            {
                // 1. Get category table from database where ispresentational is false
                CategoryTable = this.GetCategoryDataTable(elementType);

                // rearrange categories
                CategoryTable = DI7MetadataCategoryBuilder.RearrangeCategoryTableByCategoryOrder(CategoryTable);

                // 2. get metadata reports
                MetadataReportTable = this.GetMetadataReportsTableFrmDB(elementNID, elementType);


                // 3. Add Title
                // writes metadata values in excel report.
                this.WriteMetadataField(CategoryIndex, DILanguage.GetLanguageString("CATEGORY"), DILanguage.GetLanguageString("CATEGORY_GID"));
                //Write values to excel
                this.WriteMetadataValueToExcel(CategoryIndex, DILanguage.GetLanguageString("METADATA"));

                this.MetadataSheet.Cells[this._MetadataStartRowIndexInExl + CategoryIndex, 0, this._MetadataStartRowIndexInExl + CategoryIndex, 2].Font.Bold      = true;
                this.MetadataSheet.Cells[this._MetadataStartRowIndexInExl + CategoryIndex, 0, this._MetadataStartRowIndexInExl + CategoryIndex, 2].Interior.Color = SpreadsheetGear.Drawing.Color.FromArgb(System.Drawing.Color.LightGray.ToArgb());
                CategoryIndex++;



                //Iterate through category node
                foreach (DataRow CategoryRow in CategoryTable.Rows)
                {
                    // 4.2 get category label form table
                    CategoryName = Convert.ToString(CategoryRow[Metadata_Category.CategoryName]);
                    CategoryNid  = Convert.ToString(CategoryRow[Metadata_Category.CategoryNId]);
                    CategoryGID  = Convert.ToString(CategoryRow[Metadata_Category.CategoryGId]);

                    // writes metadata values in excel report.
                    this.WriteMetadataField(CategoryIndex, CategoryName, CategoryGID);

                    // Get metadata report from metadata report table for the  current category
                    foreach (DataRow Row in MetadataReportTable.Select(MetadataReport.CategoryNid + "=" + CategoryNid))
                    {
                        MetadataText = Convert.ToString(Row[MetadataReport.Metadata]).Replace(ReplaceableSymbol, Microsoft.VisualBasic.ControlChars.NewLine);

                        //Write values to excel
                        WriteMetadataValueToExcel(CategoryIndex, MetadataText);
                    }


                    CategoryIndex = CategoryIndex + 1;
                }
            }
            catch (Exception ex)
            { ExceptionHandler.ExceptionFacade.ThrowException(ex); }
        }
Пример #33
0
        private void AddWrongMetadataElement(SortedDictionary<MetadataElementType, List<string>> wrongMetadataElementList, MetadataElementType metadataType)
        {
            DataTable Table = new DataTable();
            DataRow Row;

            Table.Columns.Add(metadataType.ToString() + " Name");

            // add indicators
            if (wrongMetadataElementList.ContainsKey(metadataType))
            {
                foreach (string ElementName in wrongMetadataElementList[metadataType])
                {
                    Row = Table.NewRow();
                    Row[0] = ElementName;
                    Table.Rows.Add(Row);
                }

                this.LogFile.AddDataTable(Table, metadataType.ToString() + "s where metadata exist in a wrong format:");
            }
        }
Пример #34
0
        /// <summary>
        ///  Main Method for Displaying Metadata
        /// </summary>
        /// <param name="elementType"> Element Type.<example>ElementType.All, ElementType.Indicator </example> <seealso cref="DI_MetaInfo.ElementType"/></param>
        /// <param name="elementNid">ID of selected Data.IND - IndicatorNId, Area - AreaNId, Source - ICNId</param>
        /// <param name="DI_QueryBase"> This contain Connection Details</param>
        /// <param name="outPutPath">This contains the path where  output files were created</param>
        /// <param name="outputFileName">
        /// this will be  the name of outputFile without extention
        /// which will be created at the output path to display metadata
        /// <remarks> extension like ".xml" ".xsl" and ".html" are added to this outputFile name
        /// while creating files </remarks>
        /// </param>
        /// <returns>
        /// </returns>
        public static bool ExtractXmlMetadata(MetadataElementType metadataElementType, int elementNId, DIConnection DIConnection, DIQueries DIQueries, string outputFolder, string outputFileName, ref string infoTitle)
        {
            bool RetVal = false;

            infoTitle = string.Empty;   //Will return the Element name against  ElementNId
            IconElementType IconElementType = IconElementType.MetadataIndicator;
            XmlDocument     XMLDoc          = new XmlDocument();

            DataTable DTMetaDataInfo = null;
            string    MetadataInfo   = string.Empty;
            String    sSql           = "";
            int       LayerNId       = -1;
            string    TargetObjectID = string.Empty;

            Lib.DI_LibSDMX.MetadataTypes SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator;

            switch (metadataElementType)
            {
            case MetadataElementType.Area:
                IconElementType  = IconElementType.MetadataArea;
                SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Area;

                //-- Get LayerNId associated with AreaNId
                if (_LayerNId == -1)
                {
                    LayerNId = GetLayerNId(elementNId.ToString(), DIConnection, DIQueries);
                }
                else
                {
                    LayerNId = _LayerNId;
                }
                //if (LayerNId != -1)
                //{
                //    //-- Get Layer Metadata Info
                //    sSql = DIQueries.Area.GetAreaMapMetadata(LayerNId.ToString());
                //    DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                //    if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                //    {
                //        MetadataInfo = DTMetaDataInfo.Rows[0][Area_Map_Metadata.MetadataText].ToString();
                //    }
                //}
                // Set Meta Info title.
                sSql           = DIQueries.Area.GetArea(FilterFieldType.NId, elementNId.ToString());
                DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                {
                    infoTitle      = DTMetaDataInfo.Rows[0][Area.AreaName].ToString() + " (" + DTMetaDataInfo.Rows[0][Area.AreaID].ToString() + ")";
                    TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Area.AreaID]);
                }
                break;

            case MetadataElementType.Indicator:
                IconElementType  = IconElementType.MetadataIndicator;
                SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator;

                sSql           = DIQueries.Indicators.GetIndicator(FilterFieldType.NId, elementNId.ToString(), FieldSelection.Heavy);
                DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                {
                    infoTitle      = DTMetaDataInfo.Rows[0][Indicator.IndicatorName].ToString();
                    TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Indicator.IndicatorGId]);
                }
                break;

            case MetadataElementType.Source:
                IconElementType  = IconElementType.MetadataSource;
                SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Source;

                sSql           = DIQueries.IndicatorClassification.GetIC(FilterFieldType.NId, elementNId.ToString(), ICType.Source, FieldSelection.Heavy);
                DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                {
                    infoTitle      = DTMetaDataInfo.Rows[0][IndicatorClassifications.ICName].ToString();
                    TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][IndicatorClassifications.ICGId]);
                }
                break;
            }


            try
            {
                // Get metadata xml file using SDMX library

                MetadataInfo = Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DevInfo.Lib.DI_LibSDMX.SDMXSchemaType.Two_One, TargetObjectID, SDMXMetadataType, "MDAgency", DIQueries.LanguageCode.Replace("_", ""), DIConnection, DIQueries).InnerXml;

                DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder MetadataBuilder = new DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder(DIConnection, DIQueries);

                // Get metadata xml file with category name..
                XMLDoc = MetadataBuilder.GetMetadataReportWCategoryName(MetadataInfo, metadataElementType);

                MetadataInfo = XMLDoc.InnerXml;

                //Write Metadata text to physical file
                // --Change on 18-03-08 .blank xml with root element will be written in case of no metadata info found in database
                // If no metadata info create a blank xml file. with root element.
                if (string.IsNullOrEmpty(MetadataInfo) || MetadataInfo.Trim().Length == 0)
                {
                    WriteToFile("<?xml version='1.0'?><root ></root >", System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
                }
                else
                {
                    WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
                }
                // Commented on 18-march -2008. shifted in if else part above.
                ////WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
            }
            catch (Exception ex)
            {
                RetVal = false;
            }

            if (MetadataInfo.Trim().Length > 0)
            {
                RetVal = true;

                //Write XLS and HTMLFile
                try
                {
                    switch (metadataElementType)
                    {
                    case MetadataElementType.Area:
                        //In Case Area Get Xslt associated with LayerNId (not with AreaNId)
                        sSql = DIQueries.Xslt.GetXSLT(LayerNId.ToString(), metadataElementType);
                        break;

                    case MetadataElementType.Indicator:
                    case MetadataElementType.Source:
                        sSql = DIQueries.Xslt.GetXSLT(elementNId.ToString(), metadataElementType);
                        break;

                    default:
                        break;
                    }
                    DataTable XSLTInfo = (DIConnection.ExecuteDataTable(sSql));

                    // If  XSLT info was Found Write write Xsl and Html file
                    if (XSLTInfo != null & XSLTInfo.Rows.Count > 0)
                    {
                        // Creating Xsl File
                        String xslString = XSLTInfo.Rows[0]["XSLT_Text"].ToString();
                        WriteToFile(xslString, System.IO.Path.Combine(outputFolder, outputFileName + ".xsl"));

                        //Write HTml file
                        WriteHtmlFile(outputFolder, outputFileName);
                    }
                }
                catch (Exception)
                {
                }

                //Extract Images associated with metadata
                try
                {
                    if (metadataElementType == MetadataElementType.Area)
                    {
                        ExtractImage(LayerNId, IconElementType, DIConnection, DIQueries, outputFolder);
                    }
                    else
                    {
                        ExtractImage(elementNId, IconElementType, DIConnection, DIQueries, outputFolder);
                    }
                }
                catch (Exception)
                {
                    //Old database may not have Icon table
                }
            }

            infoTitle = infoTitle.Replace("&", "&&"); //label control do not display & character
            return(RetVal);
        }
Пример #35
0
        /// <summary>
        /// Set metadata master tables for Indicator / Area / Source
        /// </summary>
        /// <param name="metadataElementType">Indicator / Area / Source</param>
        /// <param name="userPreference"></param>
        /// <param name="dIConnection"></param>
        /// <param name="dIQueries"></param>
        /// <returns></returns>
        private bool SetMetedataTables(MetadataElementType metadataElementType, UserPreference.UserPreference userPreference, DI_LibDAL.Connection.DIConnection dIConnection, DI_LibDAL.Queries.DIQueries dIQueries)
        {
            bool RetVal = false;
            string MaskFilePath = string.Empty;
            XmlDocument MaskFileDocument = new XmlDocument();
            XmlNodeList MaskNodeList;

            string MaskPathText = string.Empty;
            string MaskPositionText = string.Empty;
            string[] MaskPositionArray;

            XmlDocument MetadataDocument = new XmlDocument();
            string MetadataXml = string.Empty;
            XmlNodeList MetadataFld_ValNodeList;

            string[] arrSelectedMetadataFields = null;
            string JoinColumnName = string.Empty;
            string MetadataColumnName = string.Empty;

            string _Query = string.Empty;
            DataTable DistinctElementTable;
            string[] DistinctNIds = null;

            DataView dvMetadataInfo = null;

            DataTable ElementMetadataTable = null;

            string CategoryType = string.Empty; // I / A / S
            string MetadataPrefix = string.Empty; //MD_IND_, MD_SRC_

            switch (metadataElementType)
            {
                case MetadataElementType.Indicator:
                    // Set Category Type
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Indicator];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataIndicator;
                    // Get Metadata fields from  userPreference
                    arrSelectedMetadataFields = userPreference.DataView.MetadataIndicatorField.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);

                    // Set Mask file path
                    MaskFilePath = Path.Combine(this.msMaskFolder, MASK_FILE_INDICATOR);

                    //Set Join column and Metadata Column name
                    JoinColumnName = Indicator.IndicatorNId;
                    MetadataColumnName = Indicator.IndicatorInfo;

                    // Get distinct indicator nids
                    DistinctElementTable = this._IUSIndicator.DefaultView.ToTable(true, JoinColumnName);
                    DistinctNIds = new string[DistinctElementTable.Rows.Count];
                    for (int i = 0; i < DistinctElementTable.Rows.Count; i++)
                    {
                        DistinctNIds[i] = DistinctElementTable.Rows[i][JoinColumnName].ToString();
                    }

                    // Get Metadata Info for all Indicators
                    _Query = this.mdIQueries.Indicators.GetIndicator(FilterFieldType.NId, string.Join(",", DistinctNIds), FieldSelection.Heavy);
                    dvMetadataInfo = this.ExecuteInvariantDataTable(_Query).DefaultView;

                    ElementMetadataTable = this._MetadataIndicator;

                    break;
                case MetadataElementType.Area:
                    // Set Category Type
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Area];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataArea;
                    // Get Metadata fields from  userPreference
                    arrSelectedMetadataFields = userPreference.DataView.MetadataAreaField.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);

                    // Set Mask file path
                    MaskFilePath = Path.Combine(this.msMaskFolder, MASK_FILE_AREA);

                    //Get LayerNids for these areas
                    _Query = this.mdIQueries.Area.GetAreaMapByAreaNIds(this._AreaNIds, false);
                    DataTable dtAreaMap = this.ExecuteInvariantDataTable(_Query);

                    //Get Distinct LayerNIds
                    string[] ColumnArray = new string[1];
                    ColumnArray[0] = Area_Map.LayerNId;
                    DistinctElementTable = dtAreaMap.DefaultView.ToTable(true, ColumnArray);
                    DistinctNIds = new string[DistinctElementTable.Rows.Count];
                    for (int i = 0; i < DistinctElementTable.Rows.Count; i++)
                    {
                        DistinctNIds[i] = DistinctElementTable.Rows[i][ColumnArray[0]].ToString();
                    }

                    //Get Metadata for LayerNIds along with associated AreaNIds
                    DataTable dtMetadata = GetInvariantDataTable();
                    if (DistinctNIds.Length > 0)
                    {
                        //Join to Associate AreaNId and LayerNId
                        DataSet dsParentChild = GetInvariantDataSet();

                        // Add AreaMap Table
                        dtMetadata = dtAreaMap.Copy();  // Since it might be part if a relationship, therefore adding the COPY
                        dtMetadata.TableName = "Parent";
                        dtMetadata.Columns.Add(Area_Map_Metadata.MetadataText, typeof(string));
                        dsParentChild.Tables.Add(dtMetadata);

                        // Add AreaMapMetadata Table
                        _Query = this.mdIQueries.Area.GetAreaMapMetadata(string.Join(",", DistinctNIds));
                        DataTable dtAreaMapMetadata = this.ExecuteInvariantDataTable(_Query);
                        dtAreaMapMetadata.TableName = "Child";

                        // Set Primaty Key in the AreaMapMetadata
                        DataColumn[] PK = new DataColumn[1];
                        PK[0] = dtAreaMapMetadata.Columns[Area_Map_Metadata.LayerNId];
                        dtAreaMapMetadata.PrimaryKey = PK;

                        dsParentChild.Tables.Add(dtAreaMapMetadata);

                        // Define relationship
                        dsParentChild.Relations.Add("RelAreaMap", dsParentChild.Tables[1].Columns[Area_Map.LayerNId], dsParentChild.Tables[0].Columns[Area_Map_Metadata.LayerNId], false);
                        dsParentChild.Tables[0].Columns[Area_Map_Metadata.MetadataText].Expression = "Parent(RelAreaMap)." + Area_Map_Metadata.MetadataText;
                        dsParentChild.AcceptChanges();
                    }
                    dvMetadataInfo = dtMetadata.DefaultView; //(AreaNId-LayerNId-MetadataText)

                    //Set Join column and Metadata Column name
                    JoinColumnName = Area.AreaNId;
                    MetadataColumnName = Area_Map_Metadata.MetadataText;

                    // Get distinct area nids
                    DistinctNIds = this._AreaNIds.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);

                    // Set metadata table
                    ElementMetadataTable = this._MetadataArea;

                    break;
                case MetadataElementType.Source:
                    // Set Category Type
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Source];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataSource;

                    // Get Metadata fields from  userPreference
                    arrSelectedMetadataFields = userPreference.DataView.MetadataSourceField.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);

                    // Set Mask file path
                    MaskFilePath = Path.Combine(this.msMaskFolder, MASK_FILE_SOURCE);

                    //Set Join column and Metadata Column name
                    JoinColumnName = IndicatorClassifications.ICNId;
                    MetadataColumnName = IndicatorClassifications.ICInfo;

                    // Get distinct source nids
                    DistinctNIds = new string[this._Sources.Rows.Count];
                    for (int i = 0; i < this._Sources.Rows.Count; i++)
                    {
                        DistinctNIds[i] = this._Sources.Rows[i][JoinColumnName].ToString();
                    }

                    // Get Metadata Info for all sources
                    _Query = this.mdIQueries.IndicatorClassification.GetIC(FilterFieldType.NId, string.Join(",", DistinctNIds), ICType.Source, FieldSelection.Heavy);
                    dvMetadataInfo = this.ExecuteInvariantDataTable(_Query).DefaultView;

                    // Set metadata table
                    ElementMetadataTable = this._MetadataSource;

                    break;
            }

            // Check for existence of indicator mask file
            if (File.Exists(MaskFilePath))
            {
                // Try loading indicator mask file
                try
                {
                    MaskFileDocument.Load(MaskFilePath);
                }
                catch (Exception)
                {
                    //TODO do not proceed further
                }
            }

            // Add Join columns to Metadata table
            ElementMetadataTable.Columns.Clear();
            ElementMetadataTable.Columns.Add(JoinColumnName, typeof(int));

            if (this._CensusInfoFeature)
            {
                _Query = this.mdIQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, CategoryType);
                DataView dvMetadataCategory = this.ExecuteInvariantDataTable(_Query).DefaultView;

                for (int j = 0; j < arrSelectedMetadataFields.Length; j++)
                {
                    // Add Metadata columns to Metadata table

                    ElementMetadataTable.Columns.Add(arrSelectedMetadataFields[j], typeof(string));
                    ElementMetadataTable.Columns[arrSelectedMetadataFields[j]].DefaultValue = string.Empty;

                    // For each distinct Element
                    for (int i = 0; i < DistinctNIds.Length; i++)
                    {
                        DataRow drMetadata;
                        if (j == 0)
                        {
                            // Create data row for each Element (Indicator / Area / Source) only once
                            drMetadata = ElementMetadataTable.NewRow();
                            drMetadata[JoinColumnName] = DistinctNIds[i];
                        }
                        else
                        {
                            // If data row alreday exists simply update the desired field
                            drMetadata = ElementMetadataTable.Select(JoinColumnName + " = " + DistinctNIds[i])[0];
                        }

                        if (dvMetadataInfo != null && dvMetadataInfo.Table.Columns.Contains(JoinColumnName))
                        {
                            dvMetadataInfo.RowFilter = JoinColumnName + " = " + DistinctNIds[i];
                            // Check for valid xml content
                            if (dvMetadataInfo.Count > 0)
                            {
                                MetadataXml = dvMetadataInfo[0][MetadataColumnName].ToString();
                                if (MetadataXml != null && MetadataXml.Trim().Length > 0)
                                {
                                    try   // Try loading metadata xml
                                    {
                                        //Get all FLD_VAL contents into a Nodelist
                                        XmlDocument xmlDoc = new XmlDocument();
                                        xmlDoc.LoadXml(dvMetadataInfo[0][MetadataColumnName].ToString());

                                        dvMetadataCategory.RowFilter = Metadata_Category.CategoryNId + " = " + arrSelectedMetadataFields[j].Replace(MetadataPrefix, "");
                                        if (dvMetadataCategory != null && dvMetadataCategory.Count > 0)
                                        {

                                            XmlNode CategoryXmlNode = xmlDoc.SelectSingleNode("//Category[@name='" + dvMetadataCategory[0][Metadata_Category.CategoryName].ToString() + "']");

                                            string ParaNodeText = string.Empty;
                                            if (!String.IsNullOrEmpty(CategoryXmlNode.InnerText))
                                            {
                                                // Replace Para defining delimiter by new line character
                                                ParaNodeText = CategoryXmlNode.InnerText.Replace(DevInfo.Lib.DI_LibBAL.DA.DML.MetadataManagerConstants.ReplaceableSymbol, Environment.NewLine);
                                            }

                                            // get category value from xml (from <para> tags)
                                            //foreach (XmlNode ParaNode in CategoryXmlNode.ChildNodes)
                                            //{
                                            //    // get para node text
                                            //    // add para node into concatenated category value
                                            //    if (!string.IsNullOrEmpty(ParaNodeText))
                                            //    {
                                            //        ParaNodeText += Microsoft.VisualBasic.ControlChars.NewLine ;
                                            //    }
                                            //     ParaNodeText +=  ParaNode.InnerText.Trim();

                                            //}

                                            // Based on position information (index) get Metadata content
                                            drMetadata[arrSelectedMetadataFields[j]] = ParaNodeText;
                                        }

                                    }
                                    catch (Exception)
                                    {
                                        //If unable to load metadata text then fields shall remain empty
                                    }
                                }

                            }
                            dvMetadataInfo.RowFilter = string.Empty;
                        }
                        // Add element row only while looping for first field
                        if (j == 0)
                        {
                            ElementMetadataTable.Rows.Add(drMetadata);
                        }
                    }

                }
            }
            else
            {
                // For each selected field for indicator / area (map) / source metadata
                for (int j = 0; j < arrSelectedMetadataFields.Length; j++)
                {

                    // Add Metadata columns to Metadata table
                    ElementMetadataTable.Columns.Add(arrSelectedMetadataFields[j], typeof(string));
                    ElementMetadataTable.Columns[arrSelectedMetadataFields[j]].DefaultValue = string.Empty;

                    // Get position information from mask file
                    MaskNodeList = MaskFileDocument.SelectNodes("*/*[ID='" + arrSelectedMetadataFields[j] + "']"); //root/Input1/ID

                    if (MaskNodeList.Count > 0)
                    {
                        if (MaskNodeList[0].SelectNodes("Position")[0] != null)     //TODO Remove Hardcoding "Position"
                        {
                            MaskPositionText = MaskNodeList[0].SelectNodes("Position")[0].InnerText;    //TODO Remove Hardcoding "Position"
                            MaskPositionArray = MaskPositionText.Split("/".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                            if (MaskPositionArray.Length == 5) // 1/1/1/n/1   1/2/1/n/1
                            {
                                // For each distinct Element
                                for (int i = 0; i < DistinctNIds.Length; i++)
                                {
                                    DataRow drMetadata;
                                    if (j == 0)
                                    {
                                        // Create data row for each Element (Indicator / Area / Source) only once
                                        drMetadata = ElementMetadataTable.NewRow();
                                        drMetadata[JoinColumnName] = DistinctNIds[i];
                                    }
                                    else
                                    {
                                        // If data row alreday exists simply update the desired field
                                        drMetadata = ElementMetadataTable.Select(JoinColumnName + " = " + DistinctNIds[i])[0];
                                    }

                                    if (dvMetadataInfo != null && dvMetadataInfo.Table.Columns.Contains(JoinColumnName))
                                    {
                                        dvMetadataInfo.RowFilter = JoinColumnName + " = " + DistinctNIds[i];
                                        // Check for valid xml content
                                        if (dvMetadataInfo.Count > 0)
                                        {
                                            MetadataXml = dvMetadataInfo[0][MetadataColumnName].ToString();
                                            if (MetadataXml.Trim().Length > 0)
                                            {
                                                try   // Try loading metadata xml
                                                {
                                                    MetadataDocument.LoadXml(MetadataXml);

                                                    //Get all FLD_VAL contents into a Nodelist
                                                    MetadataFld_ValNodeList = MetadataDocument.SelectNodes("Indicator_Info/Row1/FLD_VAL"); //TODO Remove Hardcoding

                                                    // Based on position information (index) get Metadata content
                                                    //drMetadata[arrSelectedMetadataFields[j]] = "abc";
                                                    if (MetadataFld_ValNodeList.Count >= int.Parse(MaskPositionArray[1]))
                                                    {
                                                        drMetadata[arrSelectedMetadataFields[j]] = MetadataFld_ValNodeList[(int.Parse(MaskPositionArray[1]) - 1)].InnerText.Trim();
                                                    }
                                                }
                                                catch (Exception)
                                                {
                                                    //If unable to load metadata text then fields shall remain empty
                                                }
                                            }

                                        }
                                    }
                                    // Add element row only while looping for first field
                                    if (j == 0)
                                    {
                                        ElementMetadataTable.Rows.Add(drMetadata);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return RetVal;
        }
Пример #36
0
        private void CreateIndicatorTransformInfo(string XSLTText, string XsltFilename, string elementNId, MetadataElementType elementType)
        {
            // -- this function insert the values into RT_XSLT table
            string SqlString = string.Empty;
            try
            {
                int XsltNid = 0;

                // -- step1 : check xslt info already exists or not
                SqlString = this.DBQueries.Xslt.GetXSLT(FilterFieldType.Name, XsltFilename);

                if (this.DBConnection.ExecuteDataTable(SqlString).Rows.Count == 0)
                {
                    //-- step 2: insert into xslt table
                    SqlString = DALQueries.Xslt.Insert.InsertXSLT(this.DBQueries.DataPrefix, DICommon.RemoveQuotes(XSLTText), DICommon.RemoveQuotes(XsltFilename));

                    this.DBConnection.ExecuteNonQuery(SqlString);
                }
                else
                {
                    //-- step 2: Update xslt table
                    SqlString = DALQueries.Xslt.Update.UpdateXSLT(this.DBQueries.DataPrefix, DICommon.RemoveQuotes(XSLTText), XsltFilename);
                    this.DBConnection.ExecuteNonQuery(SqlString);
                }
                //-- step 3: find the xslt_nid against xslFilename
                SqlString = this.DBQueries.Xslt.GetXSLT(FilterFieldType.Name, XsltFilename);

                // -- step 4: insert into Element_xslt table
                XsltNid = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(SqlString));

                SqlString = DALQueries.Xslt.Insert.InsertElementXSLT(this.DBQueries.DataPrefix, Convert.ToInt32(elementNId), elementType, Convert.ToInt32(XsltNid));

                this.DBConnection.ExecuteNonQuery(SqlString);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Пример #37
0
        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;
        }
Пример #38
0
        ///// <summary>
        ///// Save metadata into database
        ///// </summary>
        ///// <param name="mdType"></param>
        ///// <param name="elementNid"></param>
        ///// <param name="metadataString"></param>
        //private void SaveMetadataIntoDatabase(MetaDataType mdType, int elementNid, string metadataString)
        //{

        //}

        #endregion

        #region "-- Public --"

        #region "-- Properties --"


        ///// <summary>
        ///// stores updated categories
        ///// </summary>
        //private Dictionary<int, string> _UpdatedCategories = new Dictionary<int, string>();
        //public Dictionary<int, string> UpdatedCategories
        //{
        //    get { return this._UpdatedCategories; }
        //    set { this._UpdatedCategories = value; }
        //}
        //private DataTable CategoryTable;


        //private DIConnection _DBConnection;
        ///// <summary>
        ///// Gets or sets instance of DIConnection
        ///// </summary>
        //public DIConnection DBConnection
        //{
        //    get { return this._DBConnection; }
        //    set { this._DBConnection = value; }

        //}

        //private DIQueries _DBQueries;
        ///// <summary>
        ///// Gets or sets instance of DIQueries
        ///// </summary>
        //public DIQueries DBQueries
        //{
        //    get { return this._DBQueries; }
        //    set { this._DBQueries = value; }
        //}

        #endregion

        #region "-- Methods --"

        ///// <summary>
        ///// Removes categories from collection.
        ///// </summary>
        //public void RemoveCategoriesFromCollection()
        //{
        //    this.UpdatedCategories.Clear();
        //}

        /// <summary>
        /// Update category in metadata in database.
        /// </summary>
        /// <param name="oldCategories"></param>
        public void UpdateCategoryInMetadataIntoDB(Dictionary <int, string> oldCategories, MetaDataType mdType)
        {
            DataTable           Table = null;
            MetadataInfo        MetadataInfoObject = null;
            MetadataElementType MDElementType      = MetadataElementType.Indicator;
            string    MetadataColumnName           = string.Empty;
            string    MetadataString       = string.Empty;
            string    ElementNidColumnName = string.Empty;
            int       ElementNid           = 0;
            string    MetadataText         = string.Empty;
            DataTable CategoryTable;

            MetaDataBuilder MDBuilder = new MetaDataBuilder(this.DBConnection, this.DBQueries);

            // 1. get category table order by category_order
            CategoryTable = this.GetCategoryDataTableFrmDB(mdType);

            // 2. Get indicators/Area/Source from database where metadata text is not null or empty
            switch (mdType)
            {
            case MetaDataType.Indicator:
                MDElementType        = MetadataElementType.Indicator;
                MetadataColumnName   = DIColumns.Indicator.IndicatorInfo;
                ElementNidColumnName = DIColumns.Indicator.IndicatorNId;

                Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Indicators.GetIndicator(FilterFieldType.None, String.Empty, FieldSelection.Heavy));
                break;

            case MetaDataType.Map:
                MDElementType        = MetadataElementType.Area;
                MetadataColumnName   = DIColumns.Area_Map_Metadata.MetadataText;
                ElementNidColumnName = DIColumns.Area_Map_Metadata.MetadataNId;

                Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaMapMetadata(string.Empty));
                break;

            case MetaDataType.Source:
                MDElementType        = MetadataElementType.Source;
                MetadataColumnName   = DIColumns.IndicatorClassifications.ICInfo;
                ElementNidColumnName = DIColumns.IndicatorClassifications.ICNId;

                Table = this.DBConnection.ExecuteDataTable(this.DBQueries.IndicatorClassification.GetIC(FilterFieldType.None, string.Empty, ICType.Source, FieldSelection.Heavy));
                break;

            default:
                break;
            }


            // update metedata into database
            foreach (DataRow IndicatorRow in Table.Rows)
            {
                // get metadata from row
                MetadataString = Convert.ToString(IndicatorRow[MetadataColumnName]);
                if (string.IsNullOrEmpty(MetadataString))
                {
                    XmlDocument XmlDoc = new XmlDocument();
                    DevInfo.Lib.DI_LibBAL.Metadata.MetadataConverter.InsertRootNode(XmlDoc);
                    MetadataString = XmlDoc.InnerXml;
                }
                //--check metadata string.
                if (!string.IsNullOrEmpty(MetadataString))
                {
                    // get metadataInfo object from metadata text
                    MetadataInfoObject = this.GetMetadataInfoFrmMetadataText(MetadataString, MDElementType);

                    if (MetadataInfoObject != null)
                    {
                        //-- update metadata categories into indicator metadataInfo object
                        MetadataInfoObject = this.UpdateCategryInMetadataInfo(MetadataInfoObject, oldCategories, CategoryTable);

                        ElementNid = Convert.ToInt32(IndicatorRow[ElementNidColumnName]);

                        // get new metadata text and update it into database
                        MetadataText = this.GetNewMetadataText(MetadataInfoObject);

                        MDBuilder.UpdateMetadataInfo(mdType, string.Empty, ElementNid, MetadataText);

                        #region "-- to be deleted --"
                        //switch (mdType)
                        //{
                        //    //-if Indicator
                        //    case MetaDataType.Indicator:
                        //        MetadataInfoObject = this.UpdateCategryInMetadataInfo(MetadataInfoObject, oldCategories, DIQueries.MetadataElementTypeText[MetadataElementType.Indicator]);
                        //        ElementNid = Convert.ToInt32(IndicatorRow[DIColumns.Indicator.IndicatorNId]);
                        //        MetadataText = this.GetNewMetadataText(MetadataInfoObject);
                        //        this.SaveMetadataIntoDatabase(MetaDataType.Indicator, ElementNid, MetadataText);
                        //        break;

                        //    //-If map
                        //    case MetaDataType.Map:
                        //        MetadataInfoObject = this.UpdateCategryInMetadataInfo(MetadataInfoObject, oldCategories, DIQueries.MetadataElementTypeText[MetadataElementType.Area]);
                        //        ElementNid = Convert.ToInt32(IndicatorRow[DIColumns.Area_Map_Metadata .MetadataNId ]);
                        //        MetadataText = this.GetNewMetadataText(MetadataInfoObject);
                        //        this.SaveMetadataIntoDatabase(MetaDataType.Map, ElementNid, MetadataText);
                        //        break;

                        //    //-If source.
                        //    case MetaDataType.Source:
                        //        MetadataInfoObject = this.UpdateCategryInMetadataInfo(MetadataInfoObject, oldCategories, DIQueries.MetadataElementTypeText[MetadataElementType.Source]);
                        //        ElementNid = Convert.ToInt32(IndicatorRow[DIColumns.IndicatorClassifications.ICNId]);
                        //        MetadataText = this.GetNewMetadataText(MetadataInfoObject);
                        //        this.SaveMetadataIntoDatabase(MetaDataType.Source, ElementNid, MetadataText);
                        //        break;
                        //    default:
                        //        break;
                        //}
                        #endregion
                    }

                    //else

                    ////--save metadata into database.
                    //{
                    //    switch (mdType)
                    //    {
                    //        case MetaDataType.Indicator:
                    //            ElementNid = Convert.ToInt32(IndicatorRow[DIColumns.Indicator.IndicatorNId]);
                    //            MetadataText = "";
                    //            this.SaveMetadataIntoDatabase(MetaDataType.Indicator, ElementNid, MetadataText);
                    //            break;
                    //        case MetaDataType.Map:
                    //            ElementNid = Convert.ToInt32(IndicatorRow[DIColumns .Area_Map_Metadata.MetadataNId]);
                    //            MetadataText = "";
                    //            this.SaveMetadataIntoDatabase(MetaDataType.Map, ElementNid, MetadataText);
                    //            break;
                    //        case MetaDataType.Source:
                    //            ElementNid = Convert.ToInt32(IndicatorRow[DIColumns .IndicatorClassifications .ICNId ]);
                    //            MetadataText = "";
                    //            this.SaveMetadataIntoDatabase(MetaDataType.Source, ElementNid, MetadataText);
                    //            break;
                    //        default:
                    //            break;
                    //    }
                    //}
                }
            }
        }
        /// <summary>
        /// Imports all metadata categories from given source database to current database
        /// </summary>
        /// <param name="srcDBConnection"></param>
        /// <param name="srcDBQueries"></param>
        /// <param name="categoryType"></param>
        public void ImportAllMetadataCategories(DIConnection srcDBConnection, DIQueries srcDBQueries, MetadataElementType categoryType)
        {
            // import by GID. If GID exists then update existing category otherwise insert it into current database            // update process will update in current langauge but insert process will insert in all langauges

            DataTable SrcCategoryTable = null;
            DI7MetadataCategoryInfo SrcCategoryInfo = null;
            DataTable TrgCategoryTable     = null;
            int       TrgCategoryNid       = 0;
            int       TrgCategoryParentNid = -1;

            try
            {
                // get source category table
                SrcCategoryTable = srcDBConnection.ExecuteDataTable(srcDBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType]));

                // get target(current database) category table
                TrgCategoryTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType]));

                // import categories & sub categories from source database into current database
                foreach (DataRow SrcRow in SrcCategoryTable.Select(Metadata_Category.ParentCategoryNId + "=-1"))
                {
                    // get category from source database
                    SrcCategoryInfo = DI7MetadataCategoryBuilder.GetMetadataCategoryInfo(SrcRow, srcDBConnection, srcDBQueries);
                    // check src category gid exists in current(target) database of not
                    TrgCategoryNid       = 0;
                    TrgCategoryParentNid = -1;

                    foreach (DataRow TrgRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryInfo.CategoryGID) + "' OR " + Metadata_Category.CategoryName + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryInfo.CategoryName) + "'"))
                    {
                        // if exists then get nid and parent nid
                        TrgCategoryNid       = Convert.ToInt32(TrgRow[Metadata_Category.CategoryNId]);
                        TrgCategoryParentNid = Convert.ToInt32(TrgRow[Metadata_Category.ParentCategoryNId]);
                    }
                    // update nid & parent nid in  src category info
                    SrcCategoryInfo.CategoryNId = TrgCategoryNid;
                    SrcCategoryInfo.ParentNid   = TrgCategoryParentNid;

                    if (TrgCategoryNid > 0)
                    {
                        // update category info
                        this.UpdateMetadataCategory(SrcCategoryInfo);
                    }
                    else
                    {
                        // insert category into current database
                        TrgCategoryNid = this.InsertIntoDatabase(SrcCategoryInfo);
                    }

                    #region -- insert/update sub categories into current database --

                    // insert/update only if target category parent nid is equal to -1 (means at level1)
                    if (TrgCategoryParentNid == -1)
                    {
                        foreach (DI7MetadataCategoryInfo SrcSubCategory in SrcCategoryInfo.SubCategories.Values)
                        {
                            SrcSubCategory.CategoryNId = 0;
                            SrcSubCategory.ParentNid   = TrgCategoryNid;

                            // check sub category exists ( where gid=<src gid> and parent nid=<trg nid>
                            foreach (DataRow TrgSubCategoryRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcSubCategory.CategoryGID) + "' AND " + Metadata_Category.ParentCategoryNId + "=" + TrgCategoryNid))
                            {
                                // if exists then get nid
                                SrcSubCategory.CategoryNId = Convert.ToInt32(TrgSubCategoryRow[Metadata_Category.CategoryNId]);
                            }

                            if (SrcSubCategory.CategoryNId > 0)
                            {
                                // update sub category into current database
                                this.UpdateMetadataCategory(SrcSubCategory);
                            }
                            else
                            {
                                // insert sub category into current database
                                this.InsertIntoDatabase(SrcSubCategory);
                            }
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
            }
        }
Пример #40
0
        /// <summary>
        /// Imports metadata from the source database into current database
        /// </summary>
        /// <param name="srcConnection"></param>
        /// <param name="srcQueries"></param>
        /// <param name="srcElementNid"></param>
        /// <param name="trgElementNid"></param>
        /// <param name="categoryType"></param>
        /// <param name="metadataType"></param>
        /// <param name="iconType"></param>
        public void ImportMetadata(DIConnection srcConnection, DIQueries srcQueries, int srcElementNid, int trgElementNid, MetadataElementType categoryType, MetaDataType metadataType, IconElementType iconType)
        {
            string SrcCategoryGID = string.Empty;
            string MetadataText = string.Empty;
            int TrgCategoryNid = 0;
            DataTable TrgCategoryTable = null;
            Dictionary<String, String> OldIconNIdnNewIconNId = new Dictionary<string, string>();

            try
            {
                // Get target Category table
                TrgCategoryTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, DIQueries.MetadataElementTypeText[categoryType]));

                // update metadata icon in DICon table
                OldIconNIdnNewIconNId = DIIcons.ImportElement(srcElementNid, trgElementNid, iconType, srcQueries, srcConnection, this.DBQueries, this.DBConnection);

                //get source metadata reports
                foreach (DataRow SrcRow in srcConnection.ExecuteDataTable(srcQueries.MetadataReport.GetMetadataReportsByTargetNid(srcElementNid.ToString(), categoryType)).Rows)
                {
                    SrcCategoryGID = Convert.ToString(SrcRow[Metadata_Category.CategoryGId]);

                    // check source category GID exists in current database
                    // Import metadta report only if category exists in current database
                    foreach (DataRow TrgCategoryRow in TrgCategoryTable.Select(Metadata_Category.CategoryGId + "='" + DIQueries.RemoveQuotesForSqlQuery(SrcCategoryGID) + "' "))
                    {
                        MetadataText = Convert.ToString(SrcRow[MetadataReport.Metadata]);

                        // Update IconNids in metadata if exists
                        foreach (string OldIconName in OldIconNIdnNewIconNId.Keys)
                        {
                            MetadataText = MetadataText.Replace(OldIconName, OldIconNIdnNewIconNId[OldIconName].ToString());
                        }

                        TrgCategoryNid = Convert.ToInt32(TrgCategoryRow[Metadata_Category.CategoryNId]);
                        this.InsertORUpdateMetadataInfo(metadataType, TrgCategoryNid.ToString(), trgElementNid, MetadataText);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
            }
        }
Пример #41
0
        void MetadataConverter_WrongMetdataFoundEvent(MetadataElementType elementType, string name, string GID)
        {
            // check n create list object
            if (this._WrongMetadataElementList == null)
            {
                this._WrongMetadataElementList = new SortedDictionary<MetadataElementType, List<string>>();
            }

            // check n create element type key into dictionary object
            if (!this._WrongMetadataElementList.ContainsKey(elementType))
            {
                this._WrongMetadataElementList.Add(elementType, new List<string>());
            }

            // add name into list if doesnt exist
            if (!this._WrongMetadataElementList[elementType].Contains(name))
            {
                this._WrongMetadataElementList[elementType].Add(name);
            }
        }
Пример #42
0
        /// <summary>
        /// Export metadata to excel file
        /// </summary>
        /// <param name="ExcelFilePath">Excel File Path to be written as export data</param>
        public void ExportMetaDataToExcel(string ExcelFilePath, MetadataElementType elementType, string elementName, string elementGId,int targetElementNID)
        {
            try
            {
                // --Open excel and get first worksheet
                this.DiExcel = new DIExcel(ExcelFilePath);
                MetadataSheet = DiExcel.GetWorksheet(0);

                // --Set Matadata Type in Cell 0,0
                switch (elementType)
                {
                    case MetadataElementType.Indicator:
                        SetMetadataCommonCellValues(DILanguage.GetLanguageString("INDICATOR") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                        break;
                    case MetadataElementType.Area:
                        SetMetadataCommonCellValues(DILanguage.GetLanguageString("AREA") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                        break;
                    case MetadataElementType.Source:
                        SetMetadataCommonCellValues(DILanguage.GetLanguageString("SOURCE") + "-" + DILanguage.GetLanguageString("METADATA"), elementName, elementGId);
                        break;
                    default:
                        break;
                }

                // --Load data from xml to excel file
                this.LoadData(elementType,targetElementNID);

                //-- Save excel
                this.DiExcel.Save();
            }
            catch (Exception ex)
            {
            }
        }
Пример #43
0
        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);
        }
Пример #44
0
        private DataTable GetMetadataReportsTableFrmDB(int elementNid, MetadataElementType elementType)
        {
            DataTable RetVal = null;

            // get indicator metadata from metadatareport table
            RetVal = this.DBConnection.ExecuteDataTable(this.DBQueries.MetadataReport.GetMetadataReportsByTargetNid(elementNid.ToString(), elementType));

            return RetVal;
        }
Пример #45
0
        protected int GetElementXsltNidFrmDB(MetadataElementType mdElementtype, int elementNid)
        {
            int RetVal = -1;

            foreach (DataRow Row in this.DBConnection.ExecuteDataTable(this.DBQueries.Xslt.GetElementXSLTTable(elementNid.ToString(),mdElementtype)).Rows)
            {
                RetVal = Convert.ToInt32(Row[EelementXSLT.ElementXSLTNId]);
                break;
            }

            return RetVal;
        }
Пример #46
0
        private void CreateIndicatorTransformInfo(string XSLTText, string XsltFilename, string elementNId, MetadataElementType elementType)
        {
            // -- this function insert the values into RT_XSLT table
            string SqlString = string.Empty;

            try
            {
                int XsltNid = 0;

                // -- step1 : check xslt info already exists or not
                SqlString = this.DBQueries.Xslt.GetXSLT(FilterFieldType.Name, XsltFilename);

                if (this.DBConnection.ExecuteDataTable(SqlString).Rows.Count == 0)
                {
                    //-- step 2: insert into xslt table
                    SqlString = DALQueries.Xslt.Insert.InsertXSLT(this.DBQueries.DataPrefix, DICommon.RemoveQuotes(XSLTText), DICommon.RemoveQuotes(XsltFilename));

                    this.DBConnection.ExecuteNonQuery(SqlString);
                }
                else
                {
                    //-- step 2: Update xslt table
                    SqlString = DALQueries.Xslt.Update.UpdateXSLT(this.DBQueries.DataPrefix, DICommon.RemoveQuotes(XSLTText), XsltFilename);
                    this.DBConnection.ExecuteNonQuery(SqlString);
                }
                //-- step 3: find the xslt_nid against xslFilename
                SqlString = this.DBQueries.Xslt.GetXSLT(FilterFieldType.Name, XsltFilename);

                // -- step 4: insert into Element_xslt table
                XsltNid = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(SqlString));

                SqlString = DALQueries.Xslt.Insert.InsertElementXSLT(this.DBQueries.DataPrefix, Convert.ToInt32(elementNId), elementType, Convert.ToInt32(XsltNid));

                this.DBConnection.ExecuteNonQuery(SqlString);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Пример #47
0
        /// <summary>
        /// Updates ElementXslt table
        /// </summary>
        /// <param name="elementNid"></param>
        /// <param name="mdElementType"></param>
        /// <returns></returns>
        protected bool UpdateElementXsltTable(int elementNid,MetadataElementType mdElementType,string mdXslTtype)
        {
            bool RetVal = false;
            int XsltNid = 0;
            int ElementXsltNid = 0;

            try
            {

                // 1. get xslt nid from XSLT table
                XsltNid = this.GetXslNidFrmXSLTTable(mdXslTtype);

                if (XsltNid > 0)
                {
                    // 2. check record exists in Element_Xslt table or not
                    ElementXsltNid = this.GetElementXsltNidFrmDB(mdElementType, elementNid);

                    // 3. If not then insert record
                    if (ElementXsltNid <= 0)
                    {
                        this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Xslt.Insert.InsertElementXSLT(this.DBQueries.DataPrefix, elementNid, mdElementType, XsltNid));
                    }
                    else
                    {
                        // 4. if exists then update record
                        this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Xslt.Update.UpdateElementXSLT(this.DBQueries.DataPrefix, XsltNid, elementNid, mdElementType));
                    }
                    RetVal = true;
                }
            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }
            return RetVal;
        }
Пример #48
0
        private void AddWrongMetadataElement(SortedDictionary <MetadataElementType, List <string> > wrongMetadataElementList, MetadataElementType metadataType)
        {
            DataTable Table = new DataTable();
            DataRow   Row;

            Table.Columns.Add(metadataType.ToString() + " Name");

            // add indicators
            if (wrongMetadataElementList.ContainsKey(metadataType))
            {
                foreach (string ElementName in wrongMetadataElementList[metadataType])
                {
                    Row    = Table.NewRow();
                    Row[0] = ElementName;
                    Table.Rows.Add(Row);
                }


                this.LogFile.AddDataTable(Table, metadataType.ToString() + "s where metadata exist in a wrong format:");
            }
        }
Пример #49
0
        /// <summary>
        ///  Main Method for Displaying Metadata
        /// </summary>       
        /// <param name="elementType"> Element Type.<example>ElementType.All, ElementType.Indicator </example> <seealso cref="DI_MetaInfo.ElementType"/></param>
        /// <param name="elementNid">ID of selected Data.IND - IndicatorNId, Area - AreaNId, Source - ICNId</param>
        /// <param name="DI_QueryBase"> This contain Connection Details</param>
        /// <param name="outPutPath">This contains the path where  output files were created</param>
        /// <param name="outputFileName"> 
        /// this will be  the name of outputFile without extention
        /// which will be created at the output path to display metadata
        /// <remarks> extension like ".xml" ".xsl" and ".html" are added to this outputFile name 
        /// while creating files </remarks>
        /// </param>
        /// <returns>
        /// </returns>
        public static bool ExtractXmlMetadata(MetadataElementType metadataElementType, int elementNId, DIConnection DIConnection, DIQueries DIQueries, string outputFolder, string outputFileName, ref string infoTitle)
        {
            bool RetVal = false;
            infoTitle = string.Empty;   //Will return the Element name against  ElementNId
            IconElementType IconElementType = IconElementType.MetadataIndicator;
            XmlDocument XMLDoc = new XmlDocument();

            DataTable DTMetaDataInfo = null;
            string MetadataInfo = string.Empty;
            String sSql = "";
            int LayerNId = -1;
            string TargetObjectID = string.Empty;
            Lib.DI_LibSDMX.MetadataTypes SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator;

            switch (metadataElementType)
            {
                case MetadataElementType.Area:
                    IconElementType = IconElementType.MetadataArea;
                    SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Area;

                    //-- Get LayerNId associated with AreaNId
                    if (_LayerNId == -1)
                    {
                        LayerNId = GetLayerNId(elementNId.ToString(), DIConnection, DIQueries);
                    }
                    else
                    {
                        LayerNId = _LayerNId;
                    }
                    //if (LayerNId != -1)
                    //{
                    //    //-- Get Layer Metadata Info
                    //    sSql = DIQueries.Area.GetAreaMapMetadata(LayerNId.ToString());
                    //    DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                    //    if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                    //    {
                    //        MetadataInfo = DTMetaDataInfo.Rows[0][Area_Map_Metadata.MetadataText].ToString();
                    //    }
                    //}
                    // Set Meta Info title.
                    sSql = DIQueries.Area.GetArea(FilterFieldType.NId, elementNId.ToString());
                    DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                    if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                    {
                        infoTitle = DTMetaDataInfo.Rows[0][Area.AreaName].ToString() + " (" + DTMetaDataInfo.Rows[0][Area.AreaID].ToString() + ")";
                        TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Area.AreaID]);
                    }
                    break;
                case MetadataElementType.Indicator:
                    IconElementType = IconElementType.MetadataIndicator;
                    SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator;

                    sSql = DIQueries.Indicators.GetIndicator(FilterFieldType.NId, elementNId.ToString(), FieldSelection.Heavy);
                    DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                    if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                    {
                        infoTitle = DTMetaDataInfo.Rows[0][Indicator.IndicatorName].ToString();
                        TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][Indicator.IndicatorGId]);
                    }
                    break;

                case MetadataElementType.Source:
                    IconElementType = IconElementType.MetadataSource;
                    SDMXMetadataType = DevInfo.Lib.DI_LibSDMX.MetadataTypes.Source;

                    sSql = DIQueries.IndicatorClassification.GetIC(FilterFieldType.NId, elementNId.ToString(), ICType.Source, FieldSelection.Heavy);
                    DTMetaDataInfo = DIConnection.ExecuteDataTable(sSql);
                    if (DTMetaDataInfo != null & DTMetaDataInfo.Rows.Count > 0)
                    {
                        infoTitle = DTMetaDataInfo.Rows[0][IndicatorClassifications.ICName].ToString();
                        TargetObjectID = Convert.ToString(DTMetaDataInfo.Rows[0][IndicatorClassifications.ICGId]);
                    }
                    break;
            }

            try
            {
                // Get metadata xml file using SDMX library

                MetadataInfo = Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DevInfo.Lib.DI_LibSDMX.SDMXSchemaType.Two_One, TargetObjectID, SDMXMetadataType, "MDAgency", DIQueries.LanguageCode.Replace("_", ""), DIConnection, DIQueries).InnerXml;

                DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder MetadataBuilder = new DevInfo.Lib.DI_LibBAL.DA.DML.DI7MetaDataBuilder(DIConnection,DIQueries);

                // Get metadata xml file with category name..
                XMLDoc = MetadataBuilder.GetMetadataReportWCategoryName(MetadataInfo,metadataElementType);

                MetadataInfo= XMLDoc.InnerXml;

                //Write Metadata text to physical file
                // --Change on 18-03-08 .blank xml with root element will be written in case of no metadata info found in database
                // If no metadata info create a blank xml file. with root element.
                if (string.IsNullOrEmpty(MetadataInfo) || MetadataInfo.Trim().Length == 0)
                {
                    WriteToFile("<?xml version='1.0'?><root ></root >", System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
                }
                else
                {
                    WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
                }
                // Commented on 18-march -2008. shifted in if else part above.
                ////WriteToFile(MetadataInfo, System.IO.Path.Combine(outputFolder, outputFileName + ".xml"));
            }
            catch (Exception ex)
            {
                RetVal = false;
            }

            if (MetadataInfo.Trim().Length > 0)
            {

                RetVal = true;

                //Write XLS and HTMLFile
                try
                {
                    switch (metadataElementType)
                    {
                        case MetadataElementType.Area:
                            //In Case Area Get Xslt associated with LayerNId (not with AreaNId)
                            sSql = DIQueries.Xslt.GetXSLT(LayerNId.ToString(), metadataElementType);
                            break;
                        case MetadataElementType.Indicator:
                        case MetadataElementType.Source:
                            sSql = DIQueries.Xslt.GetXSLT(elementNId.ToString(), metadataElementType);
                            break;
                        default:
                            break;
                    }
                    DataTable XSLTInfo = (DIConnection.ExecuteDataTable(sSql));

                    // If  XSLT info was Found Write write Xsl and Html file
                    if (XSLTInfo != null & XSLTInfo.Rows.Count > 0)
                    {
                        // Creating Xsl File
                        String xslString = XSLTInfo.Rows[0]["XSLT_Text"].ToString();
                        WriteToFile(xslString, System.IO.Path.Combine(outputFolder, outputFileName + ".xsl"));

                        //Write HTml file
                        WriteHtmlFile(outputFolder, outputFileName);
                    }

                }
                catch (Exception)
                {
                }

                //Extract Images associated with metadata
                try
                {
                    if (metadataElementType == MetadataElementType.Area)
                    {
                        ExtractImage(LayerNId, IconElementType, DIConnection, DIQueries, outputFolder);
                    }
                    else
                    {
                        ExtractImage(elementNId, IconElementType, DIConnection, DIQueries, outputFolder);
                    }

                }
                catch (Exception)
                {

                    //Old database may not have Icon table
                }

            }

            infoTitle = infoTitle.Replace("&", "&&"); //label control do not display & character
            return RetVal;
        }
Пример #50
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;
        }
Пример #51
0
        /// <summary>
        /// Set language based captions for metadata fields in main data table (mdtData)
        /// </summary>
        /// <param name="MetadataFields">Comma delimited metadata fields. MD_IND_1,MD_IND_3...</param>
        /// <param name="MaskFilePath">Mask file path with extension</param>
        /// <param name="languageCode">language code against which caption shall be picked from mask file. en / fr / ru ...</param>
        private void SetMetadataCaption(MetadataElementType metadataElementType, string MetadataFields, string MaskFilePath)
        {
            string[] arrSelectedMetadataFields = null;
            DataTable MetadataTable = null;
            string CategoryType = string.Empty; // I / A / S
            string MetadataPrefix = string.Empty; //MD_IND_, MD_SRC_

            switch (metadataElementType)
            {
                case MetadataElementType.Indicator:
                    MetadataTable = this._MetadataIndicator;
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Indicator];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataIndicator;
                    break;
                case MetadataElementType.Area:
                    MetadataTable = this._MetadataArea;
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Area];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataArea;
                    break;
                case MetadataElementType.Source:
                    MetadataTable = this._MetadataSource;
                    // Set Category Type
                    CategoryType = DIQueries.MetadataElementTypeText[MetadataElementType.Source];
                    MetadataPrefix = UserPreference.UserPreference.DataviewPreference.MetadataSource;
                    break;
            }

            // Get Metadata fields from  userPreference
            arrSelectedMetadataFields = MetadataFields.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);

            if (this._CensusInfoFeature)
            {

                try
                {
                    string _Query = this.mdIQueries.Metadata_Category.GetMetadataCategories(FilterFieldType.Type, CategoryType);
                    DataView dvMetadataCategory = this.ExecuteInvariantDataTable(_Query).DefaultView;

                    //Set Metadata captions
                    for (int i = 0; i < arrSelectedMetadataFields.Length; i++)
                    {
                        // Filter for Category
                        dvMetadataCategory.RowFilter = Metadata_Category.CategoryNId + " = " + arrSelectedMetadataFields[i].Replace(MetadataPrefix, "");

                        // Get Caption from Mask file based on current interface language
                        if (dvMetadataCategory != null && dvMetadataCategory.Count > 0)
                        {
                            // Set Column caption for both main table as well as metadata master tables
                            this._MainDataTable.Columns[arrSelectedMetadataFields[i]].Caption = dvMetadataCategory[0][Metadata_Category.CategoryName].ToString();
                            MetadataTable.Columns[arrSelectedMetadataFields[i]].Caption = dvMetadataCategory[0][Metadata_Category.CategoryName].ToString();
                        }

                    }
                }
                catch (Exception)
                {

                }

            }
            else
            {

                string languageCode = DILanguage.GetLanguageString("LANGUAGE_CODE");
                XmlDocument MaskFileDocument = new XmlDocument();
                XmlNodeList MaskNodeList;
                XmlNode MaskCaptionNode;
                // Check for existence of indicator mask file
                if (File.Exists(MaskFilePath))
                {
                    try
                    {
                        // Try loading indicator mask file
                        MaskFileDocument.Load(MaskFilePath);

                        //Set Metadata captions
                        for (int i = 0; i < arrSelectedMetadataFields.Length; i++)
                        {
                            // Get position information from mask file
                            MaskNodeList = MaskFileDocument.SelectNodes("*/*[ID='" + arrSelectedMetadataFields[i] + "']"); //root/Input1/ID

                            // Get Caption from Mask file based on current interface language
                            //TODO Remove Hardcoding "Caption"
                            if (MaskNodeList[0].SelectNodes("Caption[@lang='" + languageCode + "']") != null)
                            {
                                MaskCaptionNode = MaskNodeList[0].SelectNodes("Caption[@lang='" + languageCode + "']")[0];
                                if (MaskCaptionNode != null)
                                {
                                    // Set Column caption for both main table as well as metadata master tables
                                    this._MainDataTable.Columns[arrSelectedMetadataFields[i]].Caption = MaskCaptionNode.InnerText;
                                    MetadataTable.Columns[arrSelectedMetadataFields[i]].Caption = MaskCaptionNode.InnerText;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }