예제 #1
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;
        }
예제 #2
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);
        }