internal static bool Generate_MetadataReport(string SummaryFileName, string CodelistMappingFileName, string MetadataMappingFileName, string IndicatorNIds, string TargetAreaId, DIConnection DIConnection, DIQueries DIQueries, string OutputFolder, out string ErrorMessage, out List<string> GeneratedMetadataFiles, string HeaderfilePath, string xmlMetaFilePath)
    {
        bool RetVal;
        SDMXApi_2_0.Message.StructureType Summary;
        SDMXApi_2_0.Message.GenericMetadataType GenericMetadata;
        string MetadataSetName, MetadataStructureRef, MetadataStructureAgencyRef, ReportRef, TargetRef;
        string IndicatorNId, IndicatorGId,AreaId;
        Dictionary<string, string> DictIndicatorMapping, DictMetadataMapping,DictAreaMapping;
        DataTable DtIndicator,DtArea;
        ReportedAttributeType ReportedAttribute;
        DateTime CurrentTime;
        ErrorMessage = string.Empty;
        RetVal = false;
        CurrentTime = DateTime.Now;
        GeneratedMetadataFiles = new List<string>();

        XmlDocument UploadedHeaderXml = new XmlDocument();
        string AppSettingFile = string.Empty;
        XmlDocument XmlDoc;
        SDMXApi_2_0.Message.StructureType UploadedDSDStructure = new SDMXApi_2_0.Message.StructureType();
        SDMXApi_2_0.Message.HeaderType Header = new SDMXApi_2_0.Message.HeaderType();
        DataSet ds = new DataSet();
        Callback objCallBack = new Callback();
        AppSettingFile = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, ConfigurationManager.AppSettings[Constants.WebConfigKey.AppSettingFile]);
        if (File.Exists(HeaderfilePath))
        {
            UploadedHeaderXml.Load(HeaderfilePath);
            UploadedDSDStructure = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(SDMXApi_2_0.Message.StructureType), UploadedHeaderXml);
            Header = UploadedDSDStructure.Header;
        }
        if (File.Exists(xmlMetaFilePath))
        {
            ds.ReadXml(xmlMetaFilePath);

        }
        try
        {
            Summary = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.StructureType), SummaryFileName);
            MetadataSetName = "CountryData Metadata";

            if (Summary.MetadataStructureDefinitions.Count > 0)
            {
                MetadataStructureRef = Summary.MetadataStructureDefinitions[0].id;
                MetadataStructureAgencyRef = Summary.MetadataStructureDefinitions[0].agencyID;
                ReportRef = Summary.MetadataStructureDefinitions[0].ReportStructure[0].id;
                TargetRef = Summary.MetadataStructureDefinitions[0].ReportStructure[0].target;

                DtIndicator = DIConnection.ExecuteDataTable(DIQueries.Indicators.GetIndicator(FilterFieldType.NId, IndicatorNIds, FieldSelection.Light));
                DtIndicator = DtIndicator.DefaultView.ToTable(true, DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Indicator.IndicatorNId,
                              DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Indicator.IndicatorGId);

                DtArea = DIConnection.ExecuteDataTable(DIQueries.Area.GetAreaByAreaLevel(Global.registryAreaLevel));
                DtArea = DtArea.DefaultView.ToTable(true, DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaID,
                            DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaGId);

                DictIndicatorMapping = RegTwoZeroFunctionality.Get_Indicator_Mapping_Dict(CodelistMappingFileName, string.Empty);
                DictAreaMapping = RegTwoZeroFunctionality.Get_Area_Mapping_Dict(CodelistMappingFileName);
                foreach (DataRow DrArea in DtArea.Rows)
                {
                    AreaId = DrArea[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaID].ToString();
                    if (DictAreaMapping.ContainsKey(AreaId))
                    {
                        if (DictAreaMapping.Count == 1)
                        {
                            TargetAreaId = DictAreaMapping[AreaId].ToString();//DrArea[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Area.AreaID].ToString();
                        }
                    }
                }

                if (TargetAreaId != Global.registryMSDAreaId)
                {
                    XmlDoc = new XmlDocument();
                    XmlDoc.Load(AppSettingFile);
                    objCallBack.SaveAppSettingValue(XmlDoc, Constants.AppSettingKeys.registryMSDAreaId, TargetAreaId);
                    XmlDoc.Save(AppSettingFile);
                }

                if (File.Exists(MetadataMappingFileName))
                {
                    DictMetadataMapping = Get_Metadata_Mapping_Dict(MetadataMappingFileName);
                    foreach (DataRow DrIndicator in DtIndicator.Rows)
                    {
                        IndicatorNId = DrIndicator[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Indicator.IndicatorNId].ToString();
                        IndicatorGId = DrIndicator[DevInfo.Lib.DI_LibDAL.Queries.DIColumns.Indicator.IndicatorGId].ToString();

                        if (DictIndicatorMapping.ContainsKey(IndicatorGId))
                        {
                            if (File.Exists(xmlMetaFilePath))
                            {
                                foreach (DataRow DSRow in ds.Tables["Data"].Select("Ind=" + IndicatorNId))
                                {

                                    IndicatorNId = DSRow["Ind"].ToString();

                                }
                            }
                            GenericMetadata = new SDMXApi_2_0.Message.GenericMetadataType();
                            // GenericMetadata.Header = RegTwoZeroFunctionality.Get_Appropriate_Header();
                            if (!File.Exists(HeaderfilePath))
                            {
                                GenericMetadata.Header = RegTwoZeroFunctionality.Get_Appropriate_Header();
                            }
                            else
                            {
                                GenericMetadata.Header = Header;
                            }

                            GenericMetadata.MetadataSet = new SDMXApi_2_0.GenericMetadata.MetadataSetType();
                            GenericMetadata.MetadataSet.Annotations = null;

                            GenericMetadata.MetadataSet.Name = new List<SDMXApi_2_0.Common.TextType>();
                            GenericMetadata.MetadataSet.Name.Add(new SDMXApi_2_0.Common.TextType());
                            GenericMetadata.MetadataSet.Name[0].Value = MetadataSetName;

                            GenericMetadata.MetadataSet.MetadataStructureRef = MetadataStructureRef;
                            GenericMetadata.MetadataSet.MetadataStructureAgencyRef = MetadataStructureAgencyRef;
                            GenericMetadata.MetadataSet.ReportRef = ReportRef;

                            GenericMetadata.MetadataSet.AttributeValueSet = new List<SDMXApi_2_0.GenericMetadata.AttributeValueSetType>();
                            GenericMetadata.MetadataSet.AttributeValueSet.Add(new SDMXApi_2_0.GenericMetadata.AttributeValueSetType());
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetRef = TargetRef;

                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues = new List<SDMXApi_2_0.GenericMetadata.ComponentValueType>();

                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues.Add(new SDMXApi_2_0.GenericMetadata.ComponentValueType());
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].@object = SDMXApi_2_0.GenericMetadata.ObjectIDType.Dimension;
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].component = "SERIES";
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].Value = DictIndicatorMapping[IndicatorGId].ToString();

                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues.Add(new SDMXApi_2_0.GenericMetadata.ComponentValueType());
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].@object = SDMXApi_2_0.GenericMetadata.ObjectIDType.Dimension;
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].component = "REF_AREA";
                            GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].Value = TargetAreaId;

                            if (Summary.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute != null &&
                                Summary.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute.Count > 0)
                            {
                                GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute = new List<ReportedAttributeType>();

                                foreach (MetadataAttributeType MetadataAttribute in Summary.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute)
                                {
                                    ReportedAttribute = new ReportedAttributeType();
                                    ReportedAttribute.Annotations = null;
                                    ReportedAttribute.conceptID = MetadataAttribute.conceptRef;
                                    Fill_Reported_Attribute_Value(ReportedAttribute, IndicatorNId, DictMetadataMapping, DIConnection, DIQueries);
                                    Fill_Reported_Attribute_ChildAttributes(ReportedAttribute, MetadataAttribute, IndicatorNId, DictMetadataMapping, DIConnection, DIQueries);
                                    GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute.Add(ReportedAttribute);
                                }
                            }

                            //SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.Message.GenericMetadataType), GenericMetadata, Path.Combine(OutputFolder, DictIndicatorMapping[IndicatorGId].ToString() + "_" + CurrentTime.ToString("yyyy-MM-dd HHmmss") + DevInfo.Lib.DI_LibSDMX.Constants.XmlExtension));
                            //GeneratedMetadataFiles.Add(Convert.ToString(DictIndicatorMapping[IndicatorGId].ToString() + "_" + CurrentTime.ToString("yyyy-MM-dd HHmmss")));

                            SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.Message.GenericMetadataType), GenericMetadata, Path.Combine(OutputFolder, DictIndicatorMapping[IndicatorGId].ToString() + "_DIMD_" + IndicatorGId + DevInfo.Lib.DI_LibSDMX.Constants.XmlExtension));
                            GeneratedMetadataFiles.Add(Convert.ToString(DictIndicatorMapping[IndicatorGId].ToString() + "_DIMD_" + IndicatorGId));
                            RetVal = true;
                        }
                    }
                }
                else
                {
                    RetVal = false;
                    ErrorMessage = "MNF";
                    return RetVal;

                }

            }
            else
            {
                RetVal = false;
                ErrorMessage = "ANF";
                return RetVal;
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);

            throw ex;
        }
        finally
        {
        }

        return RetVal;
    }
    private bool UpdateNonMAForUploadedDSDWithHeader(string DbNId, string UserNId, string DataBaseNId)
    {
        bool RetVal;
        SDMXObjectModel.Message.RegistryInterfaceType Registrations;
        SDMXApi_2_0.Message.GenericMetadataType MetadataFiles;
        //SDMXObjectModel.Message.GenericDataType DataFiles;

        SDMXApi_2_0.Message.CompactDataType DataFiles;
        SDMXObjectModel.Message.RegistryInterfaceType Subscriptions;
        RetVal = true;
        string UploadedHeaderFileWPath = string.Empty;
        string UploadedHeaderFolderPath = Server.MapPath("../../stock/data");
        string UploadedDSDHeaderFilePath = string.Empty;
        string UploadedHeaderName = string.Empty;
        string SubscriptionsFolderPath = string.Empty;
        string MetadataFolderPath = string.Empty;
        string RegistrationsFolderPath = string.Empty;
        string SDMXMLFolderPath = string.Empty;
        string MappingFolderPath = string.Empty;
        XmlDocument UploadedHeaderXml = new XmlDocument();
        XmlDocument UploadedHeaderXmlFor2_0 = new XmlDocument();
        FileInfo[] Files = null;

        DirectoryInfo dirRegs = null;
        DirectoryInfo dirMetadata = null;
        DirectoryInfo dirSubscriptions = null;
        DirectoryInfo dirSDMXML = null;

        try
        {
            UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + DataBaseNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            UploadedDSDHeaderFilePath = UploadedHeaderFolderPath + "/" + DbNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            dirRegs = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations");
            dirMetadata = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata");
            dirSDMXML = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML");
            dirSubscriptions = new DirectoryInfo(UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions");
            MappingFolderPath = UploadedHeaderFolderPath + "/" + DbNId + "/" + "sdmx" + "/" + "Mappings";
            UploadedHeaderXml.Load(UploadedHeaderFileWPath);
            UploadedHeaderXmlFor2_0.Load(UploadedDSDHeaderFilePath);
            SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType();
            SDMXObjectModel.Message.StructureHeaderType Header = new SDMXObjectModel.Message.StructureHeaderType();

            SDMXApi_2_0.Message.StructureType UploadedDSDStruct20 = new SDMXApi_2_0.Message.StructureType();
            SDMXApi_2_0.Message.HeaderType DSDHeader = new SDMXApi_2_0.Message.HeaderType();

            UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml);
            Header = UploadedDSDStructure.Header;
            UploadedDSDStruct20 = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(SDMXApi_2_0.Message.StructureType), UploadedHeaderXmlFor2_0);
            DSDHeader = UploadedDSDStruct20.Header;

            foreach (DirectoryInfo dirReg in dirRegs.GetDirectories())
            {
                Files = dirReg.GetFiles();
                foreach (FileInfo regfile in Files)
                {
                    Registrations = new SDMXObjectModel.Message.RegistryInterfaceType();

                    Registrations = (SDMXObjectModel.Message.RegistryInterfaceType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations" + "\\" + dirReg.Name + "\\" + regfile.ToString());

                    Registrations.Header.ID = Header.ID.ToString();
                    Registrations.Header.Prepared = Header.Prepared.ToString();
                    foreach (PartyType receiver in Header.Receiver)
                    {
                        Registrations.Header.Receiver.Contact = receiver.Contact;
                        Registrations.Header.Receiver.id = receiver.id;
                        Registrations.Header.Receiver.Name = receiver.Name;
                    }
                    Registrations.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    Registrations.Header.Test = Header.Test;

                    Registrations.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Registrations, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Registrations" + "\\" + dirReg.Name + "\\" + regfile.ToString());
                }
            }

            foreach (DirectoryInfo dirMeta in dirMetadata.GetDirectories())
            {
                Files = null;
                Files = dirMeta.GetFiles();
                foreach (FileInfo metafile in Files)
                {
                    MetadataFiles = new SDMXApi_2_0.Message.GenericMetadataType();

                    MetadataFiles = (SDMXApi_2_0.Message.GenericMetadataType)Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.GenericMetadataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata" + "\\" + dirMeta.Name + "\\" + metafile.ToString());

                    MetadataFiles.Header.ID = DSDHeader.ID.ToString();
                    MetadataFiles.Header.Prepared = DSDHeader.Prepared.ToString();
                    MetadataFiles.Header.Receiver = DSDHeader.Receiver;
                    MetadataFiles.Header.Sender = DSDHeader.Sender;
                    MetadataFiles.Header.Test = DSDHeader.Test;

                    SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.Message.GenericMetadataType), MetadataFiles, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Metadata" + "\\" + dirMeta.Name + "\\" + metafile.ToString());
                }
            }

            foreach (DirectoryInfo dirSDMX in dirSDMXML.GetDirectories())
            {
                Files = null;
                Files = dirSDMX.GetFiles();
                foreach (FileInfo sdmxMlFile in Files)
                {
                    DataFiles = new SDMXApi_2_0.Message.CompactDataType();

                    DataFiles = (SDMXApi_2_0.Message.CompactDataType)Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.CompactDataType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML" + "\\" + dirSDMX.Name + "\\" + sdmxMlFile.ToString());

                    DataFiles.Header.ID = DSDHeader.ID.ToString();
                    DataFiles.Header.Prepared = Header.Prepared.ToString();
                    DataFiles.Header.Receiver = DSDHeader.Receiver;
                    DataFiles.Header.Sender = DSDHeader.Sender;
                    DataFiles.Header.Test = DSDHeader.Test;

                    SDMXApi_2_0.Serializer.SerializeToFile(typeof(SDMXApi_2_0.Message.CompactDataType), DataFiles, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "SDMX-ML" + "\\" + dirSDMX.Name + "\\" + sdmxMlFile.ToString());
                }
            }

            foreach (DirectoryInfo dirSubs in dirSubscriptions.GetDirectories())
            {
                Files = null;
                Files = dirSubs.GetFiles();
                foreach (FileInfo subsFile in Files)
                {
                    Subscriptions = new SDMXObjectModel.Message.RegistryInterfaceType();

                    Subscriptions = (SDMXObjectModel.Message.RegistryInterfaceType)Deserializer.LoadFromFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions" + "\\" + dirSubs.Name + "\\" + subsFile.ToString());

                    Subscriptions.Header.ID = Header.ID.ToString();
                    Subscriptions.Header.Prepared = Header.Prepared.ToString();
                    foreach (PartyType receiver in Header.Receiver)
                    {
                        Subscriptions.Header.Receiver.Contact = receiver.Contact;
                        Subscriptions.Header.Receiver.id = receiver.id;
                        Subscriptions.Header.Receiver.Name = receiver.Name;
                    }
                    Subscriptions.Header.Sender = (SDMXObjectModel.Message.SenderType)Header.Sender;
                    Subscriptions.Header.Test = Header.Test;

                    Subscriptions.Footer = null;
                    SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Subscriptions, UploadedHeaderFolderPath + "\\" + DbNId + "\\" + "sdmx" + "\\" + "Subscriptions" + "\\" + dirSubs.Name + "\\" + subsFile.ToString());
                }
            }

        }
        catch (Exception ex)
        {
            RetVal = false;
            Global.CreateExceptionString(ex, null);
            //Global.WriteErrorsInLog("Creating CategoryScheme For Uploaded DSD From Admin");
            //Global.WriteErrorsInLog(ex.StackTrace);
            //Global.WriteErrorsInLog(ex.Message);
        }
        finally
        {

        }

        return RetVal;
    }
    private static Dictionary<string, string> Validate_MSD_Compliance(GenericMetadataType Metadata, string completeFileNameWPath, string TargetAreaId)
    {
        Dictionary<string, string> RetVal;
        SDMXApi_2_0.Message.StructureType Complete;
        RetVal = new Dictionary<string, string>();

        try
        {
            Complete = (SDMXApi_2_0.Message.StructureType)(Deserializer.LoadFromFile(typeof(SDMXApi_2_0.Message.StructureType), completeFileNameWPath));

            RetVal = Referred_MSD_Validation(Metadata, Complete);

            if (RetVal.Keys.Count == 0)
            {
                RetVal = Referred_ReportRef_Validation(Metadata, Complete);

                if (RetVal.Keys.Count == 0)
                {
                    RetVal = Referred_Target_Validation(Metadata, Complete, TargetAreaId);

                    if (RetVal.Keys.Count == 0)
                    {
                        RetVal = Report_Structure_Validation(Metadata, Complete);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            throw ex;
        }
        return RetVal;
    }
    private static Dictionary<string, string> Validate_And_Load_Metadatafile(string metadataFileNameWPath, out GenericMetadataType Metadata)
    {
        Dictionary<string, string> RetVal;
        XmlDocument Document;

        RetVal = new Dictionary<string, string>();
        Metadata = null;
        Document = null;

        try
        {
            RetVal = Validate_XML(metadataFileNameWPath, out Document);

            if (RetVal.Keys.Count == 0)
            {
                RetVal = Validate_SDMX(Document.InnerXml);
            }

            if (RetVal.Keys.Count == 0)
            {
                Metadata = (GenericMetadataType)(Deserializer.LoadFromText(typeof(GenericMetadataType), Document.InnerXml));
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            if (ex is System.InvalidOperationException)
            {
                RetVal.Add(MetadataValidationStatus.SDMX_Invalid.ToString(), ex.InnerException.Message.ToString());
            }
            else
            {
                throw ex;
            }
        }

        return RetVal;
    }
    private static Dictionary<string, string> Report_Structure_Validation(GenericMetadataType GenericMetadata, StructureType Complete)
    {
        Dictionary<string, string> RetVal;
        RetVal = new Dictionary<string, string>();

        try
        {
            if (Complete.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute.Count == GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute.Count)
            {
                for (int i = 0; i < Complete.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute.Count; i++)
                {
                    if (RetVal.Keys.Count == 0)
                    {
                        if (Complete.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute[i].conceptRef != GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute[i].conceptID)
                        {
                            RetVal.Add(MetadataValidationStatus.Metadata_Report_Structure_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Metadata_Reported_Attribute + GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute[i].conceptID);
                        }
                        else
                        {
                            RetVal = ReportedAttribute_Validation(Complete.MetadataStructureDefinitions[0].ReportStructure[0].MetadataAttribute[i], GenericMetadata.MetadataSet.AttributeValueSet[0].ReportedAttribute[i]);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                RetVal.Add(MetadataValidationStatus.Metadata_Report_Structure_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Report_Structure);
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            throw ex;
        }

        return RetVal;
    }
    private static Dictionary<string, string> Referred_Target_Validation(GenericMetadataType GenericMetadata, StructureType Complete, string TargetAreaId)
    {
        Dictionary<string, string> RetVal;
        List<string> IndicatorIDs;
        RetVal = new Dictionary<string, string>();

        try
        {
            IndicatorIDs = Get_Indicator_GIds(Complete);

            if (GenericMetadata.MetadataSet.AttributeValueSet != null && GenericMetadata.MetadataSet.AttributeValueSet.Count > 0)
            {
                if (Complete.MetadataStructureDefinitions[0].ReportStructure[0].target != GenericMetadata.MetadataSet.AttributeValueSet[0].TargetRef)
                {
                    RetVal.Add(MetadataValidationStatus.Metadata_Target_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Metadata_Target + GenericMetadata.MetadataSet.AttributeValueSet[0].TargetRef);
                }

                if (GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues != null && GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues.Count > 1)
                {
                    if (GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].@object != SDMXApi_2_0.GenericMetadata.ObjectIDType.Dimension ||
                    GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].component != "SERIES" ||
                    !IndicatorIDs.Contains(GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[0].Value) ||
                    GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].@object != SDMXApi_2_0.GenericMetadata.ObjectIDType.Dimension ||
                    GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].component != "REF_AREA" ||
                    GenericMetadata.MetadataSet.AttributeValueSet[0].TargetValues[1].Value != TargetAreaId)
                    {
                        RetVal.Add(MetadataValidationStatus.Metadata_Target_Object_Reference_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Metadata_Target_Object_Reference);
                    }
                }
                else
                {
                    RetVal.Add(MetadataValidationStatus.Metadata_Target_Object_Reference_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Metadata_Target_Object_Reference);
                }
            }
            else
            {
                RetVal.Add(MetadataValidationStatus.Metadata_Report_Structure_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Report_Structure);
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            throw ex;
        }

        return RetVal;
    }
    private static Dictionary<string, string> Referred_ReportRef_Validation(GenericMetadataType GenericMetadata, StructureType Complete)
    {
        Dictionary<string, string> RetVal;
        RetVal = new Dictionary<string, string>();

        try
        {
            if (Complete.MetadataStructureDefinitions[0].ReportStructure[0].id != GenericMetadata.MetadataSet.ReportRef)
            {
                RetVal.Add(MetadataValidationStatus.Metadata_Report_Invalid.ToString(), DevInfo.Lib.DI_LibSDMX.Constants.ValidationMessages.Invalid_Metadata_Report + GenericMetadata.MetadataSet.ReportRef);
            }
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            throw ex;
        }

        return RetVal;
    }