Exemple #1
0
    private static List<string> Get_Registrations_OverlapList(RegistrationType Registration, bool IsMetadata, bool IsAdminUploadedDSD)
    {
        List<string> RetVal;
        string FileURL, WSURL, Content, ElementName, AttributeName, PAIdPrefixRemoved, MFDId;
        WebRequest Request;
        WebResponse Response;
        StreamReader DataReader;
        Stream DataStream;
        XmlElement QueryElement;
        Registry.RegistryService Service;
        XmlDocument FileXML;

        RetVal = new List<string>();
        FileURL = string.Empty;
        WSURL = string.Empty;
        Content = string.Empty;
        ElementName = string.Empty;
        AttributeName = string.Empty;
        PAIdPrefixRemoved = string.Empty;
        MFDId = string.Empty;
        Request = null;
        Response = null;
        DataReader = null;
        DataStream = null;
        QueryElement = null;
        Service = new Registry.RegistryService();
        FileXML = new XmlDocument();

        if (IsMetadata == false)
        {
            if (Registration.Datasource[0] is SDMXObjectModel.Registry.QueryableDataSourceType)
            {
                WSURL = ((SDMXObjectModel.Registry.QueryableDataSourceType)Registration.Datasource[0]).DataURL;

                if (Registration.Datasource.Count == 2)
                {
                    FileURL = Registration.Datasource[1].ToString();
                }
            }
            else
            {
                FileURL = Registration.Datasource[0].ToString();

                if (Registration.Datasource.Count == 2)
                {
                    WSURL = ((SDMXObjectModel.Registry.QueryableDataSourceType)Registration.Datasource[1]).DataURL;
                }
            }

            if (IsAdminUploadedDSD == false)
            {
                if (!string.IsNullOrEmpty(FileURL))
                {
                    Request = WebRequest.Create(FileURL);
                    Response = Request.GetResponse();

                    DataStream = Response.GetResponseStream();
                    DataReader = new StreamReader(DataStream);
                    Content = DataReader.ReadToEnd();
                }
                else if (!string.IsNullOrEmpty(WSURL))
                {
                    QueryElement = SDMXUtility.Get_Query(SDMXSchemaType.Two_One, null, QueryFormats.StructureSpecificTS, DataReturnDetailTypes.SeriesKeyOnly, DevInfo.Lib.DI_LibSDMX.Constants.AgencyId, null, null).DocumentElement;
                    Service.Url = WSURL.ToString();
                    Service.GetStructureSpecificTimeSeriesData(ref QueryElement);
                    Content = QueryElement.OuterXml;
                }

                ElementName = "Series";
                AttributeName = DevInfo.Lib.DI_LibSDMX.Constants.Concept.INDICATOR.Id;
            }
            else
            {
                if (!string.IsNullOrEmpty(FileURL))
                {
                    Request = WebRequest.Create(FileURL);
                    Response = Request.GetResponse();

                    DataStream = Response.GetResponseStream();
                    DataReader = new StreamReader(DataStream);
                    Content = DataReader.ReadToEnd();
                }

                ElementName = SDMXApi_2_0.Constants.Namespaces.Prefixes.DevInfo + ":" + "Series";
                AttributeName = Constants.UNSD.Concept.Indicator.Id;
            }

            FileXML.LoadXml(Content);

            foreach (XmlNode Series in FileXML.GetElementsByTagName(ElementName))
            {
                if (!RetVal.Contains(Series.Attributes[AttributeName].Value))
                {
                    RetVal.Add(Series.Attributes[AttributeName].Value);
                }
            }
        }
        else
        {
            if (Registration.ProvisionAgreement != null && Registration.ProvisionAgreement.Items != null && Registration.ProvisionAgreement.Items.Count > 0)
            {
                PAIdPrefixRemoved = ((ProvisionAgreementRefType)Registration.ProvisionAgreement.Items[0]).id.Replace(DevInfo.Lib.DI_LibSDMX.Constants.PA.Prefix, string.Empty);
                MFDId = PAIdPrefixRemoved.Substring(PAIdPrefixRemoved.IndexOf('_') + 1);
                RetVal.Add(MFDId);
            }
        }

        return RetVal;
    }
    public string GetDataForGenerateApiCall(string requestParam)
    {
        string RetVal;
        string[] Params;
        int DBNId;
        string SelectedFunction;
        string Id;
        string AgencyId;
        string Version;
        string UserIdAndType;
        string UploadedHeaderFileWPath, UploadedHeaderFolderPath;
        Registry.RegistryService Service;
        SDMXObjectModel.Message.StructureHeaderType Header;
        SDMXApi_2_0.Message.HeaderType Header_2_0;
        XmlDocument Query;
        XmlElement Element;
        XmlDocument Response;
        XmlDocument UploadedHeaderXml;

        string agencyId;
        List<bool> isSOAPMailIds;
        List<string> notificationMailIds;
        List<bool> isSOAPHTTPs;
        List<string> notificationHTTPs;
        DateTime startDate;
        DateTime endDate;
        string eventSelector;
        Dictionary<string, string> dictCategories;
        string mfdId;
        string CategoriesGIDAndSchemeIds;
        string CategoryGID;
        string CategorySchemeId;
        string DFDOrMFDId;
        string WebServiceURL;
        bool IsREST;
        string WADLURL;
        bool IsSOAP;
        string WSDLURL;
        string FileURL;
        string RequestURL;
        string ResponseURL;
        string preferredLangNid;
        string[] DBDetails;
        string checkIfSDMXDB;
        RetVal = string.Empty;
        Params = null;
        DBNId = -1;
        SelectedFunction = string.Empty;
        Id = string.Empty;
        AgencyId = string.Empty;
        Version = string.Empty;
        UserIdAndType = string.Empty;
        Service = new Registry.RegistryService();

        Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
        Query = new XmlDocument();
        Response = new XmlDocument();
        Element = null;

        agencyId = string.Empty;
        isSOAPMailIds = new List<bool>();
        notificationMailIds = new List<string>();
        isSOAPHTTPs = new List<bool>();
        notificationHTTPs = new List<string>();
        startDate = new DateTime();
        endDate = new DateTime();
        eventSelector = string.Empty;
        dictCategories = new Dictionary<string, string>();
        mfdId = string.Empty;
        CategoriesGIDAndSchemeIds = string.Empty;
        CategoryGID = string.Empty;
        CategorySchemeId = string.Empty;

        DFDOrMFDId = string.Empty;
        WebServiceURL = string.Empty;
        IsREST = false;
        WADLURL = string.Empty;
        IsSOAP = false;
        WSDLURL = string.Empty;
        FileURL = string.Empty;
        RequestURL = string.Empty;
        ResponseURL = string.Empty;
        preferredLangNid = string.Empty;
        DBDetails = null;
        checkIfSDMXDB = string.Empty;
        Header = new SDMXObjectModel.Message.StructureHeaderType();
        Header_2_0 = new SDMXApi_2_0.Message.HeaderType();
        UploadedHeaderXml = new XmlDocument();
        UploadedHeaderFolderPath = Server.MapPath("../../stock/data");
        try
        {
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
            DBNId = Convert.ToInt32(Params[0].ToString().Trim());
            SelectedFunction = Params[1].ToString().Trim();

            DBDetails = Global.GetDbConnectionDetails(Convert.ToString(DBNId));
           checkIfSDMXDB = DBDetails[4].ToString();

            UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + DBNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            if (File.Exists(UploadedHeaderFileWPath))
            {
                UploadedHeaderXml.Load(UploadedHeaderFileWPath);
                if (checkIfSDMXDB == "true")
                {
                    SDMXApi_2_0.Message.StructureType UploadedDSDStructure = new SDMXApi_2_0.Message.StructureType();
                    UploadedDSDStructure = (SDMXApi_2_0.Message.StructureType)SDMXApi_2_0.Deserializer.LoadFromXmlDocument(typeof(SDMXApi_2_0.Message.StructureType), UploadedHeaderXml);
                    Header_2_0 = UploadedDSDStructure.Header;
                }
                else
                {
                    SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType();
                    UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml);
                    Header = UploadedDSDStructure.Header;
                }

            }

            if ((SelectedFunction == "QuerySubscription") || (SelectedFunction == "QueryRegistration"))
            {
                UserIdAndType = Params[2].ToString().Trim();
            }
            else if (SelectedFunction == "SubmitSubscription")
            {
                UserIdAndType = Params[2].ToString().Trim();

                if (Params[3].ToString().Trim() == "0")
                {
                    isSOAPMailIds = new List<bool>();
                    isSOAPMailIds.Add(false);
                    isSOAPHTTPs = new List<bool>();
                    isSOAPHTTPs.Add(false);
                }
                else
                {
                    isSOAPMailIds = new List<bool>();
                    isSOAPMailIds.Add(true);
                    isSOAPHTTPs = new List<bool>();
                    isSOAPHTTPs.Add(true);
                }
                notificationMailIds = new List<string>();
                notificationMailIds.Add(Params[4].ToString().Trim());
                notificationHTTPs = new List<string>();
                notificationHTTPs.Add(Params[5].ToString().Trim());
                startDate = DateTime.ParseExact(Params[6].ToString().Trim(), "dd-MM-yyyy", null);
                endDate = DateTime.ParseExact(Params[7].ToString().Trim(), "dd-MM-yyyy", null);
                eventSelector = Params[8].ToString().Trim();
                CategoriesGIDAndSchemeIds = Params[9].ToString().Trim();
                dictCategories = new Dictionary<string, string>();
                if (eventSelector == "Data Registration")
                {
                    foreach (string CategoryGIDAndSchemeId in Global.SplitString(CategoriesGIDAndSchemeIds, ","))
                    {
                        CategoryGID = CategoryGIDAndSchemeId.Split('|')[0];
                        CategorySchemeId = CategoryGIDAndSchemeId.Split('|')[1];
                        dictCategories.Add(CategoryGID, CategorySchemeId);
                    }
                }
                agencyId = Global.Get_AgencyId_From_DFD(DBNId.ToString());
                mfdId = Params[10].ToString().Trim();
                preferredLangNid = Params[11].ToString().Trim();
            }
            else if (SelectedFunction == "SubmitRegistration")
            {
                UserIdAndType = Params[2].ToString().Trim();
                agencyId = Global.Get_AgencyId_From_DFD(DBNId.ToString());
                DFDOrMFDId = Params[3].ToString().Trim();
                FileURL = Params[4].ToString().Trim();
            }
            else
            {
                Id = Params[2].ToString().Trim();
                AgencyId = Params[3].ToString().Trim();
                Version = Params[4].ToString().Trim();
            }

            Service.Url += "?p=" + DBNId.ToString();
            RetVal = Service.Url;
            RetVal += Constants.Delimiters.ParamDelimiter + SelectedFunction;
            switch (SelectedFunction)
            {
                case "GetDataflow":
                    Query = GetQueryXmlDocumentOnTypeBasis(0, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetDataflow(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetMetadataflow":
                    Query = GetQueryXmlDocumentOnTypeBasis(1, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetMetadataflow(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetDataStructure":
                    Query = GetQueryXmlDocumentOnTypeBasis(2, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetDataStructure(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetMetadataStructure":
                    Query = GetQueryXmlDocumentOnTypeBasis(3, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetMetadataStructure(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetCategoryScheme":
                    Query = GetQueryXmlDocumentOnTypeBasis(4, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetCategoryScheme(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetCategorisation":
                    Query = GetQueryXmlDocumentOnTypeBasis(5, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetCategorisation(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetConceptScheme":
                    Query = GetQueryXmlDocumentOnTypeBasis(6, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetConceptScheme(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetCodelist":
                    Query = GetQueryXmlDocumentOnTypeBasis(7, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetCodelist(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetOrganisationScheme":
                    Query = GetQueryXmlDocumentOnTypeBasis(8, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetOrganisationScheme(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetProvisionAgreement":
                    Query = GetQueryXmlDocumentOnTypeBasis(9, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetProvisionAgreement(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetConstraint":
                    Query = GetQueryXmlDocumentOnTypeBasis(10, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetConstraint(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetStructures":
                    Query = GetQueryXmlDocumentOnTypeBasis(11, Id, AgencyId, Version, string.Empty);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.GetStructures(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "QuerySubscription":
                    Query = GetQueryXmlDocumentOnTypeBasis(12, Id, AgencyId, Version, UserIdAndType);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.QuerySubscription(ref Element);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "QueryRegistration":
                    Query = GetQueryXmlDocumentOnTypeBasis(13, Id, AgencyId, Version, UserIdAndType);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.QueryRegistration(ref Element,preferredLangNid);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "SubmitSubscription":
                    Query = GetQueryXmlDocumentForSubmitSubscription(ActionType.Append, UserIdAndType, agencyId, isSOAPMailIds, notificationMailIds, isSOAPHTTPs, notificationHTTPs, startDate, endDate, eventSelector, dictCategories, mfdId, string.Empty,Header);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.SubmitSubscription(ref Element, preferredLangNid);//language code
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "SubmitRegistration":
                    Query = GetQueryXmlDocumentForSubmitRegistration(UserIdAndType, agencyId, DFDOrMFDId, WebServiceURL, IsREST, WADLURL, IsSOAP, WSDLURL, FileURL);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Query);
                    Element = Query.DocumentElement;
                    Service.SubmitRegistration(ref Element, string.Empty, preferredLangNid);
                    Response.LoadXml(Element.OuterXml);
                    RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
                    RequestURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Query));
                    ResponseURL = SaveContentTemporarilyandDeleteOtherFiles(this.Get_Formatted_XML(Response));
                    RetVal += Constants.Delimiters.ParamDelimiter + RequestURL;
                    RetVal += Constants.Delimiters.ParamDelimiter + ResponseURL;
                    break;
                case "GetGenericData":

                    break;
                case "GetGenericTimeSeriesData":

                    break;
                case "GetStructureSpecificData":

                    break;
                case "GetStructureSpecificTimeSeriesData":

                    break;
                case "GetGenericMetadata":

                    break;
                case "GetStructureSpecificMetadata":

                    break;
                case "SubmitStructure":

                    break;
                case "GetReportingTaxonomy":

                    break;
                case "GetStructureSet":

                    break;
                case "GetProcess":

                    break;
                case "GetHierarchicalCodelist":

                    break;
                case "GetDataSchema":

                    break;
                case "GetMetadataSchema":

                    break;
                default:
                    break;
            }
        }
        catch (SoapException SOAPex)
        {
            Response.LoadXml(SOAPex.Detail.InnerText);
            RetVal += Constants.Delimiters.ParamDelimiter + this.Get_Formatted_XML(Response);
            Global.CreateExceptionString(SOAPex, null);
        }
        catch (Exception ex)
        {
            RetVal += "false" + Constants.Delimiters.ParamDelimiter + ex.Message;
            Global.CreateExceptionString(ex, null);
        }
        finally
        {
        }

        return RetVal;
    }
    public string UpdateRegistration(string requestParam)
    {
        string RetVal;
        string[] Params;
        string[] DBDetails;
        string DbNId, UserNId, DFDOrMFDId, RegistrationId, WebServiceURL, WADLURL, WSDLURL, FileURL, Language, UploadedHeaderFileWPath, UploadedHeaderFolderPath, OriginalDBNId, SDMXFileName;
        bool IsREST, IsSOAP, IsMetadata;
        RegistryInterfaceType RegistryInterfaceRequest, RegistryInterfaceResponse;
        Registry.RegistryService Service;
        XmlDocument Request;
        XmlElement Element;
        XmlDocument UploadedHeaderXml;
        SDMXObjectModel.Message.StructureHeaderType Header;
        RetVal = string.Empty;
        RegistryInterfaceRequest = null;
        RegistryInterfaceResponse = null;
        Service = null;
        Request = new XmlDocument();
        Element = null;
        Header = new SDMXObjectModel.Message.StructureHeaderType();
        UploadedHeaderXml = new XmlDocument();
        UploadedHeaderFolderPath = Server.MapPath("../../stock/data");
        DBDetails = null;
        OriginalDBNId = string.Empty;
        SDMXFileName = string.Empty;
        try
        {
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
            DbNId = Params[0].ToString().Trim();
            UserNId = Params[1].ToString().Trim();
            IsMetadata = bool.Parse(Params[2].ToString().Trim());
            DFDOrMFDId = Params[3].ToString().Trim();
            RegistrationId = Params[4].ToString().Trim();
            WebServiceURL = Params[5].ToString().Trim();
            IsREST = bool.Parse(Params[6].ToString().Trim());
            WADLURL = Params[7].ToString().Trim();
            IsSOAP = bool.Parse(Params[8].ToString().Trim());
            WSDLURL = Params[9].ToString().Trim();
            if (Params.Length > 10)
            {
                FileURL = Params[10].ToString().Trim();
            }
            else
            {
                FileURL = string.Empty;
            }
            if (Params.Length > 11)
            {
                Language = Params[11].ToString().Trim();
            }
            else
            {
                Language = Global.GetDefaultLanguageCode();
            }
            if (Params.Length > 12)
            {
                SDMXFileName = Params[12].ToString().Trim();
            }
            else
            {
                SDMXFileName = string.Empty;
            }
            RegistryInterfaceRequest = new RegistryInterfaceType();
            //RegistryInterfaceRequest.Header = Global.Get_Appropriate_Header();
            DBDetails = Global.GetDbConnectionDetails(DbNId);
            if (DBDetails[4] == "true")
            {
                OriginalDBNId = Convert.ToString(this.Get_AssociatedDB_NId(DbNId));
            }
            else
            {
                OriginalDBNId = DbNId;
            }
            UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + OriginalDBNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType();

            if (File.Exists(UploadedHeaderFileWPath))
            {
                UploadedHeaderXml.Load(UploadedHeaderFileWPath);
                UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml);
                Header = UploadedDSDStructure.Header;
            }

            RegistryInterfaceRequest = new RegistryInterfaceType();
            if (Header == null)
            {
                RegistryInterfaceRequest.Header = Global.Get_Appropriate_Header();
            }
            else
            {

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

            }
            RegistryInterfaceRequest.Footer = null;

            RegistryInterfaceRequest.Item = new SDMXObjectModel.Registry.SubmitRegistrationsRequestType();
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest = new List<RegistrationRequestType>();
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest.Add(new RegistrationRequestType(null, ActionType.Replace));
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration = new RegistrationType(RegistrationId);
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.ProvisionAgreement = new ProvisionAgreementReferenceType();
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.ProvisionAgreement.Items = new List<object>();
            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.ProvisionAgreement.Items.Add(new ProvisionAgreementRefType(DevInfo.Lib.DI_LibSDMX.Constants.PA.Prefix + UserNId + "_" + DFDOrMFDId, Global.Get_AgencyId_From_DFD(DbNId), DevInfo.Lib.DI_LibSDMX.Constants.PA.Version));

            ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.Datasource = new List<object>();
            if (!string.IsNullOrEmpty(WebServiceURL))
            {
                ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.Datasource.Add(new SDMXObjectModel.Registry.QueryableDataSourceType(WebServiceURL, IsREST, WADLURL, IsSOAP, WSDLURL));
            }

            if (!string.IsNullOrEmpty(FileURL))
            {
                ((SDMXObjectModel.Registry.SubmitRegistrationsRequestType)RegistryInterfaceRequest.Item).RegistrationRequest[0].Registration.Datasource.Add(FileURL);
            }

            Service = new Registry.RegistryService();
            Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
            Service.Url += "?p=" + DbNId.ToString();

            Request = Serializer.SerializeToXmlDocument(typeof(RegistryInterfaceType), RegistryInterfaceRequest);
            Element = Request.DocumentElement;
            string languageNid = Global.GetLangNidFromlangCode(Language);
            Service.SubmitRegistration(ref Element, SDMXFileName, languageNid);
            RegistryInterfaceResponse = (RegistryInterfaceType)Deserializer.LoadFromText(typeof(RegistryInterfaceType), Element.OuterXml);

            if (((SDMXObjectModel.Registry.SubmitRegistrationsResponseType)RegistryInterfaceResponse.Item).RegistrationStatus[0].StatusMessage.status == StatusType.Success)
            {
                this.Frame_Message_And_Send_Registration_Mail(UserNId, RegistrationId, Language);
                RetVal = "true" + Constants.Delimiters.ParamDelimiter + ((SDMXObjectModel.Registry.SubmitRegistrationsResponseType)RegistryInterfaceResponse.Item).RegistrationStatus[0].Registration.id;
            }
            else
            {
                RetVal = "false" + Constants.Delimiters.ParamDelimiter + ((SDMXObjectModel.Registry.SubmitRegistrationsResponseType)RegistryInterfaceResponse.Item).RegistrationStatus[0].StatusMessage.MessageText[0].Text;
            }
        }
        catch (Exception ex)
        {
            RetVal = "false" + Constants.Delimiters.ParamDelimiter + ex.Message;
            Global.CreateExceptionString(ex, null);
        }
        finally
        {
        }

        return RetVal;
    }
    public string GetDataQueryResponseSDMXML(string requestParam)
    {
        string RetVal;
        string[] Params;
        int DBNId, SDMXFormat, RequestType;
        string Request;
        XmlDocument Query, SDMXML;
        XmlElement Element;
        DIConnection DIConnection;
        DIQueries DIQueries;
        Registry.RegistryService Service;
        string SOAPMethodName;
        WebRequest WebRequest;
        StreamReader ResponseReader;

        RetVal = string.Empty;
        Params = null;
        DBNId = -1;
        Request = string.Empty;
        Query = new XmlDocument();
        SDMXML = new XmlDocument();
        Element = null;
        DIConnection = null;
        DIQueries = null;
        Service = new Registry.RegistryService();
        SOAPMethodName = string.Empty;
        WebRequest = null;
        ResponseReader = null;

        try
        {
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
            DBNId = Convert.ToInt32(Params[0].ToString().Trim());
            RequestType = Convert.ToInt32(Params[1].ToString().Trim());
            Request = this.Server.HtmlDecode(Params[2].ToString().Trim());
            SDMXFormat = Convert.ToInt32(Params[3].ToString().Trim());

            DIConnection = Global.GetDbConnection(DBNId);
            DIQueries = new DIQueries(DIConnection.DIDataSetDefault(), DIConnection.DILanguageCodeDefault(DIConnection.DIDataSetDefault()));

            switch (RequestType)
            {
                case 0://SOAP
                    Query.LoadXml(Request);
                    Element = Query.DocumentElement;
                     //HttpContext.Current.RewritePath("~/libraries/ws/RegistryService.asmx");
                     //Service.Url = HttpContext.Current.Request.Url.ToString();
                    Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
                    Service.Url += "?p=" + DBNId.ToString();

                    switch ((DataFormats)SDMXFormat)
                    {
                        case DataFormats.Generic:
                            SOAPMethodName = "GetGenericData";

                            try
                            {
                                Service.GetGenericData(ref Element);
                                SDMXML.LoadXml(Element.OuterXml);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                            }
                            catch (SoapException SOAPex)
                            {
                                SDMXML.LoadXml(SOAPex.Detail.InnerText);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                                Global.CreateExceptionString(SOAPex, null);
                            }
                            break;
                        case DataFormats.GenericTS:
                            SOAPMethodName = "GetGenericTimeSeriesData";

                            try
                            {
                                Service.GetGenericTimeSeriesData(ref Element);
                                SDMXML.LoadXml(Element.OuterXml);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                            }
                            catch (SoapException SOAPex)
                            {
                                SDMXML.LoadXml(SOAPex.Detail.InnerText);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                                Global.CreateExceptionString(SOAPex, null);
                            }
                            break;
                        case DataFormats.StructureSpecific:
                            SOAPMethodName = "GetStructureSpecificData";

                            try
                            {
                                Service.GetStructureSpecificData(ref Element);
                                SDMXML.LoadXml(Element.OuterXml);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                            }
                            catch (SoapException SOAPex)
                            {
                                SDMXML.LoadXml(SOAPex.Detail.InnerText);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                                Global.CreateExceptionString(SOAPex, null);
                            }
                            break;
                        case DataFormats.StructureSpecificTS:
                            SOAPMethodName = "GetStructureSpecificTimeSeriesData";

                            try
                            {
                                Service.GetStructureSpecificTimeSeriesData(ref Element);
                                SDMXML.LoadXml(Element.OuterXml);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                            }
                            catch (SoapException SOAPex)
                            {
                                SDMXML.LoadXml(SOAPex.Detail.InnerText);
                                RetVal = this.Get_Formatted_XML(SDMXML);
                                Global.CreateExceptionString(SOAPex, null);
                            }
                            break;
                    }

                    RetVal += Constants.Delimiters.ParamDelimiter + Service.Url;
                    RetVal += Constants.Delimiters.ParamDelimiter + SOAPMethodName;
                    break;
                case 1://REST
                    WebRequest = WebRequest.Create(Request);

                    switch ((DataFormats)SDMXFormat)
                    {
                        case DataFormats.Generic:
                            WebRequest.ContentType = Constants.WSQueryStrings.SDMXContentTypes.Generic;
                            break;
                        case DataFormats.GenericTS:
                            WebRequest.ContentType = Constants.WSQueryStrings.SDMXContentTypes.GenericTS;
                            break;
                        case DataFormats.StructureSpecific:
                            WebRequest.ContentType = Constants.WSQueryStrings.SDMXContentTypes.StructureSpecific;
                            break;
                        case DataFormats.StructureSpecificTS:
                            WebRequest.ContentType = Constants.WSQueryStrings.SDMXContentTypes.StructureSpecificTS;
                            break;
                    }

                    ResponseReader = new StreamReader(WebRequest.GetResponse().GetResponseStream());

                    SDMXML.LoadXml(ResponseReader.ReadToEnd());
                    RetVal = this.Get_Formatted_XML(SDMXML);
                    break;
                case 2://HTTP
                    WebRequest = WebRequest.Create(Request);
                    ResponseReader = new StreamReader(WebRequest.GetResponse().GetResponseStream());

                    SDMXML.LoadXml(ResponseReader.ReadToEnd());
                    RetVal = this.Get_Formatted_XML(SDMXML);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            RetVal = "false" + Constants.Delimiters.ParamDelimiter + ex.Message;
            Global.CreateExceptionString(ex, null);
        }
        finally
        {
        }

        return RetVal;
    }
    public string GetRegistrationDetails(string requestParam)
    {
        string RetVal;
        string[] Params;
        string DbNId, UserNId, RegistrationId, DFDOrMFDId, LanguageCode;
        bool IsMetadata;
        RegistryInterfaceType RegistryInterfaceRequest, RegistryInterfaceResponse;
        RegistrationType Registration;
        Registry.RegistryService Service;
        XmlDocument Request;
        XmlElement Element;
        SDMXObjectModel.Registry.QueryableDataSourceType QueryableDataSource = null;
        string SimpleDataSource = string.Empty;
        string DataUrl = string.Empty;
        string WADLUrl = string.Empty;
        string WSDLUrl = string.Empty;
        string SimpleDataFileUrl = string.Empty;
        bool IsRest = false;
        bool IsSoap = false;

        RetVal = string.Empty;
        DbNId = string.Empty;
        UserNId = string.Empty;
        RegistrationId = string.Empty;
        DFDOrMFDId = string.Empty;
        LanguageCode = string.Empty;
        IsMetadata = false;

        RegistryInterfaceRequest = null;
        RegistryInterfaceResponse = null;
        Registration = null;
        Service = null;
        Request = new XmlDocument();
        Element = null;

        try
        {
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
            DbNId = Params[0].ToString().Trim();
            UserNId = Params[1].ToString().Trim();
            RegistrationId = Params[2].ToString().Trim();
            LanguageCode = Params[3].ToString().Trim();
            RegistryInterfaceRequest = new RegistryInterfaceType();
            RegistryInterfaceRequest.Header = Global.Get_Appropriate_Header();
            RegistryInterfaceRequest.Footer = null;

            RegistryInterfaceRequest.Item = new SDMXObjectModel.Registry.QueryRegistrationRequestType();
            ((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item = new DataProviderReferenceType();
            ((DataProviderReferenceType)((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item).Items = new List<object>();
            ((DataProviderReferenceType)((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item).Items.Add(new DataProviderRefType
            (DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Prefix + UserNId, DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.AgencyId,
             DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Id, DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Version));

            Service = new Registry.RegistryService();
            Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
            Service.Url += "?p=" + DbNId.ToString();

            Request = Serializer.SerializeToXmlDocument(typeof(RegistryInterfaceType), RegistryInterfaceRequest);
            Element = Request.DocumentElement;
            string languageNid = Global.GetLangNidFromlangCode(LanguageCode);
            Service.QueryRegistration(ref Element, languageNid);
            RegistryInterfaceResponse = (RegistryInterfaceType)Deserializer.LoadFromText(typeof(RegistryInterfaceType), Element.OuterXml);

            foreach (QueryResultType QueryResult in ((SDMXObjectModel.Registry.QueryRegistrationResponseType)RegistryInterfaceResponse.Item).QueryResult)
            {
                if (QueryResult.Item.Registration.id == RegistrationId)
                {
                    Registration = QueryResult.Item.Registration;
                    break;
                }
            }

            DFDOrMFDId = ((ProvisionAgreementRefType)(Registration.ProvisionAgreement.Items[0])).id.Replace(DevInfo.Lib.DI_LibSDMX.Constants.PA.Prefix + UserNId + "_", "");

            if (Registration.Datasource != null && Registration.Datasource.Count > 0 && Registration.Datasource.Count < 3)
            {
                if (Registration.Datasource.Count == 1)
                {
                    if (Registration.Datasource[0] is SDMXObjectModel.Registry.QueryableDataSourceType)
                    {
                        QueryableDataSource = (SDMXObjectModel.Registry.QueryableDataSourceType)Registration.Datasource[0];
                    }
                    else if (Registration.Datasource[0] is string)
                    {
                        SimpleDataSource = (string)Registration.Datasource[0];
                    }
                }
                else if (Registration.Datasource.Count == 2)
                {
                    if (Registration.Datasource[0] is SDMXObjectModel.Registry.QueryableDataSourceType)
                    {
                        QueryableDataSource = (SDMXObjectModel.Registry.QueryableDataSourceType)Registration.Datasource[0];

                        if (Registration.Datasource[1] is string)
                        {
                            SimpleDataSource = (string)Registration.Datasource[1];
                        }
                    }
                    else if (Registration.Datasource[0] is string)
                    {
                        SimpleDataSource = (string)Registration.Datasource[0];

                        if (Registration.Datasource[1] is SDMXObjectModel.Registry.QueryableDataSourceType)
                        {
                            QueryableDataSource = (SDMXObjectModel.Registry.QueryableDataSourceType)Registration.Datasource[1];
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(SimpleDataSource))
            {
                SimpleDataFileUrl = SimpleDataSource;
            }

            if (QueryableDataSource != null)
            {
                DataUrl = QueryableDataSource.DataURL;
                WADLUrl = QueryableDataSource.WADLURL;
                WSDLUrl = QueryableDataSource.WSDLURL;
                IsRest = QueryableDataSource.isRESTDatasource;
                IsSoap = QueryableDataSource.isWebServiceDatasource;
            }

            RetVal = Registration.id + Constants.Delimiters.ParamDelimiter + DataUrl + Constants.Delimiters.ParamDelimiter + IsRest.ToString() +
                     Constants.Delimiters.ParamDelimiter + WADLUrl + Constants.Delimiters.ParamDelimiter + IsSoap.ToString() + Constants.Delimiters.ParamDelimiter +
                     WSDLUrl + Constants.Delimiters.ParamDelimiter + SimpleDataFileUrl;

            if (DFDOrMFDId == DevInfo.Lib.DI_LibSDMX.Constants.DFD.Id)
            {
                IsMetadata = false;
            }
            else
            {
                IsMetadata = true;
            }

            RetVal += Constants.Delimiters.ParamDelimiter + IsMetadata;
            RetVal += Constants.Delimiters.ParamDelimiter + DFDOrMFDId;
        }
        catch (Exception ex)
        {
            RetVal = ex.Message;
            Global.CreateExceptionString(ex, null);
        }
        finally
        {
        }

        return RetVal;
    }
    private string GetRegistrationsSummaryHTML(string DbNId, string UserNId, string LanguageCode, int StartIndex, int NumberPagingRows)
    {
        string RetVal;
        int TotalRows, Counter, TotalRowCount = 0, TempRowCount = 0;
        RegistryInterfaceType RegistryInterfaceRequest, RegistryInterfaceResponse;
        Registry.RegistryService Service;
        XmlDocument Request;
        XmlElement Element;

        RetVal = string.Empty;
        TotalRows = 0;
        Counter = 0;
        RegistryInterfaceRequest = null;
        RegistryInterfaceResponse = null;
        Service = null;
        Request = new XmlDocument();
        Element = null;

        try
        {

            RegistryInterfaceRequest = new RegistryInterfaceType();
            RegistryInterfaceRequest.Header = Global.Get_Appropriate_Header();
            RegistryInterfaceRequest.Footer = null;

            RegistryInterfaceRequest.Item = new SDMXObjectModel.Registry.QueryRegistrationRequestType();
            ((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item = new DataProviderReferenceType();
            ((DataProviderReferenceType)((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item).Items = new List<object>();
            ((DataProviderReferenceType)((SDMXObjectModel.Registry.QueryRegistrationRequestType)RegistryInterfaceRequest.Item).Item).Items.Add(new DataProviderRefType(DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Prefix + UserNId, DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.AgencyId, DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Id, DevInfo.Lib.DI_LibSDMX.Constants.DataProviderScheme.Version));

            Service = new Registry.RegistryService();
            Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
            Service.Url += "?p=" + DbNId.ToString();

            Request = Serializer.SerializeToXmlDocument(typeof(RegistryInterfaceType), RegistryInterfaceRequest);
            Element = Request.DocumentElement;
            string languageNid = Global.GetLangNidFromlangCode(LanguageCode);
            Service.QueryRegistration(ref Element, languageNid);
            RegistryInterfaceResponse = (RegistryInterfaceType)Deserializer.LoadFromText(typeof(RegistryInterfaceType), Element.OuterXml);
            TotalRows = ((SDMXObjectModel.Registry.QueryRegistrationResponseType)RegistryInterfaceResponse.Item).QueryResult.Count;

            foreach (QueryResultType QueryResult in ((SDMXObjectModel.Registry.QueryRegistrationResponseType)RegistryInterfaceResponse.Item).QueryResult)
            {
                if (StartIndex + NumberPagingRows <= TotalRows)
                {
                    if ((Counter >= StartIndex) && (Counter < StartIndex + NumberPagingRows))
                    {
                        TempRowCount = TotalRowCount;
                        RetVal += this.Get_InnerHtml_For_Single_Registration(DbNId, UserNId, LanguageCode, QueryResult.Item.Registration, TempRowCount, out TotalRowCount);
                        RetVal += Constants.Delimiters.PivotRowDelimiter;
                    }
                }
                else
                {
                    if ((Counter >= StartIndex) && (Counter < TotalRows))
                    {
                        TempRowCount = TotalRowCount;
                        RetVal += this.Get_InnerHtml_For_Single_Registration(DbNId, UserNId, LanguageCode, QueryResult.Item.Registration, TempRowCount, out TotalRowCount);
                        RetVal += Constants.Delimiters.PivotRowDelimiter;
                    }
                }
                if (RetVal.Contains("#"))
                {

                    RetVal = RetVal.Replace("##########", "#").Replace("#########", "#").Replace("########", "#").Replace("#######", "#").Replace("######", "#").Replace("#####", "#").Replace("####", "#").Replace("###", "#").Replace("##", "#");
                    if (RetVal.StartsWith("#"))
                    {
                        RetVal = RetVal.Substring(1);
                    }
                }
                Counter++;
            }

            RetVal = RetVal.Remove(RetVal.Length - 1, 1);
            // TotalRows =TotalRowCount;

            RetVal += Constants.Delimiters.ParamDelimiter + StartIndex.ToString() + Constants.Delimiters.ParamDelimiter + NumberPagingRows.ToString() + Constants.Delimiters.ParamDelimiter + TotalRows.ToString();
        }
        catch (Exception ex)
        {
            Global.CreateExceptionString(ex, null);
            throw ex;
        }
        finally
        {
        }

        return RetVal;
    }
    public string DeleteSubscription(string requestParam)
    {
        string RetVal;
        string[] Params;
        string Action;
        string NotificationMail;
        string NotificationHTTP;
        int IsSOAP;
        string SubscriberAssignedID;
        string StartDate;
        string EndDate;
        string EventSelector;
        string CategoriesGIDAndSchemeIds;
        string MFDId;
        string DbNId;
        string CodelistId;
        string SubscriberIdAndType;
        string SubscriptionId;
        string CategoryGID;
        string CategorySchemeId;
        string UploadedHeaderFileWPath, UploadedHeaderFolderPath;
        string OriginalDBNId;
        string[] DBDetails;
        Registry.RegistryService Service;
        XmlDocument Query;
        XmlElement Element;
        XmlDocument Response;
        XmlDocument UploadedHeaderXml;
        SDMXObjectModel.Message.RegistryInterfaceType SubRegistryInterface;
        SDMXObjectModel.Message.StructureHeaderType Header;
        List<bool> isSOAPMailIds;
        List<string> notificationMailIds;
        List<bool> isSOAPHTTPs;
        List<string> notificationHTTPs;
        DateTime startDate;
        DateTime endDate;
        Dictionary<string, string> dictCategories;
        string AgencyId;

        RetVal = "true";
        Service = new Registry.RegistryService();
        Query = new XmlDocument();
        Response = new XmlDocument();
        Element = null;
        SubRegistryInterface = new SDMXObjectModel.Message.RegistryInterfaceType();
        Action = string.Empty;
        NotificationMail = string.Empty;
        NotificationHTTP = string.Empty;
        IsSOAP = 0;
        SubscriberAssignedID = string.Empty;
        StartDate = string.Empty;
        EndDate = string.Empty;
        EventSelector = string.Empty;
        CategoriesGIDAndSchemeIds = string.Empty;
        MFDId = string.Empty;
        DbNId = string.Empty;
        CodelistId = string.Empty;
        SubscriberIdAndType = string.Empty;
        CategoryGID = string.Empty;
        CategorySchemeId = string.Empty;
        isSOAPMailIds = new List<bool>();
        notificationMailIds = new List<string>();
        isSOAPHTTPs = new List<bool>();
        notificationHTTPs = new List<string>();
        dictCategories = new Dictionary<string, string>();
        AgencyId = string.Empty;
        Header = new SDMXObjectModel.Message.StructureHeaderType();
        UploadedHeaderXml = new XmlDocument();
        UploadedHeaderFolderPath = Server.MapPath("../../stock/data");
        OriginalDBNId = string.Empty;
        DBDetails = null;
        UploadedHeaderFileWPath = string.Empty;
        try
        {
            Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);

            Action = Params[0];
            NotificationMail = Params[1];
            NotificationHTTP = Params[2];
            IsSOAP = Convert.ToInt16(Params[3]);
            StartDate = Params[4];
            EndDate = Params[5];
            EventSelector = Params[6];
            CategoriesGIDAndSchemeIds = Params[7];
            MFDId = Params[8];
            DbNId = Params[9];
            SubscriberIdAndType = Params[10];
            SubscriptionId = Params[11];
            OriginalDBNId = Params[12];
            AgencyId = Global.Get_AgencyId_From_DFD(DbNId.ToString());

            DBDetails = Global.GetDbConnectionDetails(DbNId);

            if (DbNId != OriginalDBNId && DBDetails[4] == "true")
            {
                UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + OriginalDBNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;

            }
            else
            {
                UploadedHeaderFileWPath = UploadedHeaderFolderPath + "/" + DbNId + "/" + "sdmx" + "/" + DevInfo.Lib.DI_LibSDMX.Constants.Header.FileName;
            }
            SDMXObjectModel.Message.StructureType UploadedDSDStructure = new SDMXObjectModel.Message.StructureType();

            if (File.Exists(UploadedHeaderFileWPath))
            {
                UploadedHeaderXml.Load(UploadedHeaderFileWPath);
                UploadedDSDStructure = (SDMXObjectModel.Message.StructureType)SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureType), UploadedHeaderXml);
                Header = UploadedDSDStructure.Header;
            }

            if (IsSOAP == 0)
            {
                isSOAPMailIds = new List<bool>();
                isSOAPMailIds.Add(false);
                isSOAPHTTPs = new List<bool>();
                isSOAPHTTPs.Add(false);
            }
            else
            {
                isSOAPMailIds = new List<bool>();
                isSOAPMailIds.Add(true);
                isSOAPHTTPs = new List<bool>();
                isSOAPHTTPs.Add(true);
            }
            notificationMailIds = new List<string>();
            notificationMailIds.Add(NotificationMail);
            notificationHTTPs = new List<string>();
            notificationHTTPs.Add(NotificationHTTP);

            startDate = DateTime.ParseExact(StartDate.ToString().Trim(), "dd-MM-yyyy", null);
            endDate = DateTime.ParseExact(EndDate.ToString().Trim(), "dd-MM-yyyy", null);
            dictCategories = new Dictionary<string, string>();
            if (EventSelector == "Data Registration")
            {
                foreach (string CategoryGIDAndSchemeId in Global.SplitString(CategoriesGIDAndSchemeIds, ","))
                {
                    CategoryGID = CategoryGIDAndSchemeId.Split('|')[0];
                    CategorySchemeId = CategoryGIDAndSchemeId.Split('|')[1];
                    dictCategories.Add(CategoryGID, CategorySchemeId);
                }
            }
            Query = GetQueryXmlDocumentForSubmitSubscription(ActionType.Delete, SubscriberIdAndType, AgencyId, isSOAPMailIds, notificationMailIds, isSOAPHTTPs, notificationHTTPs, startDate, endDate, EventSelector, dictCategories, MFDId, SubscriptionId,Header);
            Element = Query.DocumentElement;

            Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
            Service.Url += "?p=" + DbNId.ToString();

            Service.SubmitSubscription(ref Element, string.Empty);
            Response.LoadXml(Element.OuterXml);
            SubRegistryInterface = (SDMXObjectModel.Message.RegistryInterfaceType)(SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Response));
            if (((SDMXObjectModel.Registry.SubmitSubscriptionsResponseType)(SubRegistryInterface.Item)).SubscriptionStatus[0].StatusMessage.status == SDMXObjectModel.Registry.StatusType.Success)
            {
                RetVal = "true";
            }
            else
            {
                RetVal = "false";
            }
        }
        catch (Exception ex)
        {
            RetVal = "false" + Constants.Delimiters.ParamDelimiter + ex.Message;
            Global.CreateExceptionString(ex, null);
        }
        finally
        {
        }

        return RetVal;
    }
    public string GetSubscriptionDetails(string requestParam)
    {
        string RetVal = string.Empty;
        string[] Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
        string DbNId, UserIdAndType, SubscriptionId;
        XmlDocument SubscriptionDetailsXml = new XmlDocument();
        string CategoriesGIDAndSchemeIds = string.Empty;
        string CategoriesGIDAndSchemeId = string.Empty;
        string CategoryGId = string.Empty;
        string CategorySchemeId = string.Empty;
        string Email = string.Empty;
        string WebServiceAddress = string.Empty;
        bool IsSOAP = false;
        string StartDate = string.Empty;
        string EndDate = string.Empty;
        string EventType = string.Empty;
        string hlngcode = string.Empty;
        Registry.RegistryService Service;
        XmlDocument Query;
        XmlElement Element;
        XmlDocument Response;
        SDMXObjectModel.Message.RegistryInterfaceType SubRegistryInterface;
        int i;

        Service = new Registry.RegistryService();
        Query = new XmlDocument();
        Response = new XmlDocument();
        Element = null;
        SubRegistryInterface = new SDMXObjectModel.Message.RegistryInterfaceType();

        try
        {
            SubscriptionId = Params[0];
            DbNId = Params[1].ToString().Trim();
            UserIdAndType = Params[2].ToString();
            hlngcode = Params[3].ToString().Trim();
            Query = GetQueryXmlDocumentOnTypeBasis(12, string.Empty, string.Empty, string.Empty, UserIdAndType);
            Element = Query.DocumentElement;
            Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
            Service.Url += "?p=" + DbNId.ToString();
            Service.QuerySubscription(ref Element);
            Response.LoadXml(Element.OuterXml);
            SubRegistryInterface = (SDMXObjectModel.Message.RegistryInterfaceType)(SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Response));
            foreach (SDMXObjectModel.Registry.SubscriptionType Subscription in ((SDMXObjectModel.Registry.QuerySubscriptionResponseType)(SubRegistryInterface.Item)).Subscription)
            {
                if (SubscriptionId == Subscription.RegistryURN)
                {
                    Email = Subscription.NotificationMailTo[0].Value.ToString();
                    WebServiceAddress = Subscription.NotificationHTTP[0].Value.ToString();
                    IsSOAP = Subscription.NotificationHTTP[0].isSOAP;
                    StartDate = Subscription.ValidityPeriod.StartDate.ToString("dd-MM-yyyy");
                    EndDate = Subscription.ValidityPeriod.EndDate.ToString("dd-MM-yyyy");

                    RetVal = Email;
                    RetVal += Constants.Delimiters.ValuesDelimiter + WebServiceAddress;
                    RetVal += Constants.Delimiters.ValuesDelimiter + IsSOAP;
                    RetVal += Constants.Delimiters.ValuesDelimiter + StartDate;
                    RetVal += Constants.Delimiters.ValuesDelimiter + EndDate;

                    if (Subscription.EventSelector[0] is DataRegistrationEventsType)
                    {
                        EventType = GetlanguageBasedValueOfKey("lang_Data_Registration", hlngcode, "RegSubscription.xml");
                        for (i = 0; i < ((DataRegistrationEventsType)(Subscription.EventSelector[0])).Items.Length; i++)
                        {
                            CategoryGId = ((SDMXObjectModel.Common.CategoryRefType)(((CategoryReferenceType)(((DataRegistrationEventsType)(Subscription.EventSelector[0])).Items[i])).Items[0])).id;
                            CategorySchemeId = ((SDMXObjectModel.Common.CategoryRefType)(((CategoryReferenceType)(((DataRegistrationEventsType)(Subscription.EventSelector[0])).Items[i])).Items[0])).maintainableParentID;
                            CategoriesGIDAndSchemeIds = CategoriesGIDAndSchemeIds + CategoryGId + Constants.Delimiters.PivotColumnDelimiter + CategorySchemeId + ",";
                        }
                        CategoriesGIDAndSchemeIds = CategoriesGIDAndSchemeIds.Remove(CategoriesGIDAndSchemeIds.Length - 1, 1);
                        RetVal += Constants.Delimiters.ValuesDelimiter + EventType;
                        RetVal += Constants.Delimiters.ValuesDelimiter + CategoriesGIDAndSchemeIds;
                    }
                    else if (Subscription.EventSelector[0] is MetadataRegistrationEventsType)
                    {
                        EventType = GetlanguageBasedValueOfKey("lang_Metadata_Registration", hlngcode, "RegSubscription.xml");
                        RetVal += Constants.Delimiters.ValuesDelimiter + EventType;
                        RetVal += Constants.Delimiters.ValuesDelimiter + ((MaintainableQueryType)((MaintainableEventType)(((MetadataRegistrationEventsType)(Subscription.EventSelector[0])).Items[0])).Item).id;
                    }
                    else if (Subscription.EventSelector[0] is StructuralRepositoryEventsType)
                    {
                        EventType = GetlanguageBasedValueOfKey("lang_Structural_Metadata_Registration", hlngcode,
        "RegSubscription.xml");
                        RetVal += Constants.Delimiters.ValuesDelimiter + EventType;
                    }

                    // get preferred language

                    RetVal += Constants.Delimiters.ValuesDelimiter + Global.GetPreferredLanguageFromSubscriptionId(SubscriptionId);
                    break;
                }

            }

        }
        catch (Exception ex)
        {
            RetVal = string.Empty;
            Global.CreateExceptionString(ex, null);
        }

        return RetVal;
    }
    public string GetLoggedInUserSubscriptions(string requestParam)
    {
        string RetVal;
        string[] Params;
        string DBNId;
        string UserIdAndType;
        string hlngcode;
        StringBuilder sb;
        Registry.RegistryService Service;
        XmlDocument Query;
        XmlElement Element;
        XmlDocument Response;
        SDMXObjectModel.Message.RegistryInterfaceType SubRegistryInterface;
        string RegistryURN;
        string Email;
        string WebServiceAddress;
        string StartDate;
        string EndDate;
        string EventType;
        string Action;
        string prefLang;

        RetVal = string.Empty;
        Params = Global.SplitString(requestParam, Constants.Delimiters.ParamDelimiter);
        DBNId = Params[0];
        UserIdAndType = Params[1];
        hlngcode = Params[2];

        sb = new StringBuilder();
        Service = new Registry.RegistryService();
        Query = new XmlDocument();
        Response = new XmlDocument();
        Element = null;
        SubRegistryInterface = new SDMXObjectModel.Message.RegistryInterfaceType();
        RegistryURN = string.Empty;
        Email = string.Empty;
        WebServiceAddress = string.Empty;
        StartDate = string.Empty;
        EndDate = string.Empty;
        EventType = string.Empty;
        Action = string.Empty;
        prefLang = string.Empty;

        Query = GetQueryXmlDocumentOnTypeBasis(12, string.Empty, string.Empty, string.Empty, UserIdAndType);
        Element = Query.DocumentElement;

        Service.Url = HttpContext.Current.Request.Url.OriginalString.Substring(0, HttpContext.Current.Request.Url.OriginalString.IndexOf("libraries")) + Constants.FolderName.SDMX.RegistryServicePath;
        Service.Url += "?p=" + DBNId.ToString();
        Service.QuerySubscription(ref Element);
        Response.LoadXml(Element.OuterXml);
        SubRegistryInterface = (SDMXObjectModel.Message.RegistryInterfaceType)(SDMXObjectModel.Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.RegistryInterfaceType), Response));
        foreach (SDMXObjectModel.Registry.SubscriptionType Subscription in ((SDMXObjectModel.Registry.QuerySubscriptionResponseType)(SubRegistryInterface.Item)).Subscription)
        {
            RegistryURN = Subscription.RegistryURN;
            Email = Subscription.NotificationMailTo[0].Value.ToString();
            WebServiceAddress = Subscription.NotificationHTTP[0].Value.ToString();
            StartDate = Subscription.ValidityPeriod.StartDate.ToString("dd-MM-yyyy");
            EndDate = Subscription.ValidityPeriod.EndDate.ToString("dd-MM-yyyy");
            if (Subscription.EventSelector[0] is DataRegistrationEventsType)
            {
                EventType = GetlanguageBasedValueOfKey("lang_Data_Registration", hlngcode, "RegSubscription.xml");
            }
            else if (Subscription.EventSelector[0] is MetadataRegistrationEventsType)
            {
                EventType = GetlanguageBasedValueOfKey("lang_Metadata_Registration", hlngcode, "RegSubscription.xml");
            }
            else if (Subscription.EventSelector[0] is StructuralRepositoryEventsType)
            {
                EventType = GetlanguageBasedValueOfKey("lang_Structural_Metadata_Registration", hlngcode, "RegSubscription.xml");
            }

            // Get preferred language
            prefLang = Global.GetLanguageNameFromNid(Global.GetPreferredLanguageFromSubscriptionId(RegistryURN));

            sb.Append(RegistryURN);
            sb.Append("~");
            sb.Append(Email);
            sb.Append("~");
            sb.Append(WebServiceAddress);
            sb.Append("~");
            sb.Append(StartDate);
            sb.Append("~");
            sb.Append(EndDate);
            sb.Append("~");
            sb.Append(EventType);
            sb.Append("~");
            // Append preferred language
            sb.Append(prefLang);
            sb.Append("~");
            sb.Append("<a style=\"cursor:pointer;\" href=\"javascript:void(0);\" onclick=\"OpenSubscriptionDetailsPopup('V','" + Subscription.RegistryURN + "' );\" name=\"lang_View\"></a> | ");
            sb.Append("<a style=\"cursor:pointer;\" href=\"javascript:void(0);\" onclick=\"OpenSubscriptionDetailsPopup('U','" + Subscription.RegistryURN + "');\" name=\"lang_Edit\"></a> | ");
            sb.Append("<a style=\"cursor:pointer;\" href=\"javascript:void(0);\" onclick=\"OpenSubscriptionDetailsPopup('D','" + Subscription.RegistryURN + "');\" name=\"lang_Delete\"></a>");
            sb.Append(Constants.Delimiters.PivotRowDelimiter);
        }

        sb.Remove(sb.Length - 1, 1);
        RetVal = sb.ToString();
        return RetVal;
    }