private XmlDocument ProcessRetrieveDocumentSetResponse(XmlDocument xmlDocRequest, out StringDictionary atnaParametersValue)
        {
            XmlDocument                xmlDocResponse         = null;
            RetrieveDocumentSet        objDocumentMetadata    = null;
            RepositoryLogic            repositoryLogic        = null;
            List <RetrieveDocumentSet> lstRetrieveDocumentSet = null;
            RetrieveDocumentSet        objRetrieveDocumentSet = null;
            XmlElement  eltRoot = null;
            XmlNodeList nodeListDocumentRequest = null;
            XmlNode     node = null;

            string documentEntryUUIDs   = string.Empty;
            string eventOutomeIndicator = "0";

            atnaParametersValue = new StringDictionary();

            try
            {
                repositoryLogic        = new RepositoryLogic();
                lstRetrieveDocumentSet = new List <RetrieveDocumentSet>();

                //Root Element
                eltRoot = xmlDocRequest.DocumentElement;

                nodeListDocumentRequest = eltRoot.SelectNodes(".//*[local-name()='DocumentRequest']");

                foreach (XmlNode nodeDocumentRequest in nodeListDocumentRequest)
                {
                    objRetrieveDocumentSet = new RetrieveDocumentSet();

                    if (nodeDocumentRequest.HasChildNodes)
                    {
                        node = nodeDocumentRequest.SelectSingleNode(".//*[local-name()='HomeCommunityId']");
                        if (node != null)
                        {
                            objRetrieveDocumentSet.HomeCommunityID = node.InnerText;
                        }

                        node = nodeDocumentRequest.SelectSingleNode(".//*[local-name()='RepositoryUniqueId']");
                        if (node != null)
                        {
                            objRetrieveDocumentSet.RepositoryUniqueID = node.InnerText;
                        }

                        node = nodeDocumentRequest.SelectSingleNode(".//*[local-name()='DocumentUniqueId']");
                        if (node != null)
                        {
                            objRetrieveDocumentSet.DocumentID = node.InnerText;
                        }

                        //Used for ATNA Logging
                        if (string.IsNullOrEmpty(documentEntryUUIDs))
                        {
                            documentEntryUUIDs = objRetrieveDocumentSet.DocumentID;
                        }
                        else
                        {
                            documentEntryUUIDs += ", " + objRetrieveDocumentSet.DocumentID;
                        }


                        //CP - No Validation required for RepositoryUniqueID
                        //objRetrieveDocumentSet.IsRepositoryUniqueIDExsists = IsRepositoryIDExists(objRetrieveDocumentSet.RepositoryUniqueID);

                        objDocumentMetadata = GetDocumentRepositoryMetaData(objRetrieveDocumentSet.DocumentID);

                        objRetrieveDocumentSet.ContentID = objDocumentMetadata.ContentID;
                        objRetrieveDocumentSet.MimeType  = objDocumentMetadata.MimeType;

                        if (objRetrieveDocumentSet.ContentID > 0)
                        {
                            objRetrieveDocumentSet.Content = SQLServerStorageService.RetreiveDocument(objRetrieveDocumentSet.ContentID.ToString());
                        }

                        lstRetrieveDocumentSet.Add(objRetrieveDocumentSet);
                    }
                }

                //ATNA
                atnaParametersValue.Add("$DocumentEntry.UUID$", documentEntryUUIDs);

                xmlDocResponse = GenerateTotalRetrieveDocument();

                int contentCount = 0;

                for (int i = 0; i < lstRetrieveDocumentSet.Count; i++)
                {
                    if (lstRetrieveDocumentSet[i].ContentID > 0)
                    {
                        contentCount++;
                    }
                }

                if (contentCount == 0)
                {
                    XmlElement docReosponseRootElement = xmlDocResponse.DocumentElement;
                    XmlElement xEleRegErrList          = xmlDocResponse.CreateElement("tns:RegistryResponse", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                    XmlAttribute xAttStatus = xmlDocResponse.CreateAttribute("status");
                    xAttStatus.Value = GlobalValues.CONST_RESPONSE_STATUS_TYPE_FAILURE;
                    xEleRegErrList.Attributes.Append(xAttStatus);

                    XmlAttribute xAttXmlNSrs = xmlDocResponse.CreateAttribute("xmlns:tns");
                    xAttXmlNSrs.Value = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0";
                    xEleRegErrList.Attributes.Append(xAttXmlNSrs);


                    XmlAttribute xAttXmlNS = xmlDocResponse.CreateAttribute("xmlns:rim");
                    xAttXmlNS.Value = GlobalValues.CONST_XML_NAMESPACE_x;
                    xEleRegErrList.Attributes.Append(xAttXmlNS);

                    XmlElement xEleRegErrList1 = xmlDocResponse.CreateElement("tns:RegistryErrorList", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                    XmlAttribute attribhighestSeverity = xmlDocResponse.CreateAttribute("highestSeverity");
                    attribhighestSeverity.Value = "Highest SeverityURI";
                    xEleRegErrList1.Attributes.Append(attribhighestSeverity);

                    for (int loop = 0; loop < lstRetrieveDocumentSet.Count; loop++)
                    {
                        XmlElement xEleRegErr = xmlDocResponse.CreateElement("tns:RegistryError", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                        XmlAttribute xAttcodeContext = xmlDocResponse.CreateAttribute("codeContext");
                        xAttcodeContext.Value = GlobalValues.CONST_ERROR_CODE_XDSUnknownRepositoryUniqueID;
                        xEleRegErr.Attributes.Append(xAttcodeContext);

                        XmlAttribute xAttErrorCode = xmlDocResponse.CreateAttribute("errorCode");
                        xAttErrorCode.Value = string.Format("XDSDocumentEntry {0} exists in metadata with no corresponding attached document", lstRetrieveDocumentSet[loop].DocumentID);
                        xEleRegErr.Attributes.Append(xAttErrorCode);

                        XmlAttribute xAttSeverity = xmlDocResponse.CreateAttribute("severity");
                        xAttSeverity.Value = "Error";
                        xEleRegErr.Attributes.Append(xAttSeverity);

                        XmlAttribute xAttLocation = xmlDocResponse.CreateAttribute("location");
                        xAttLocation.Value = lstRetrieveDocumentSet[loop].DocumentID;
                        xEleRegErr.Attributes.Append(xAttLocation);

                        xEleRegErrList1.AppendChild(xEleRegErr);
                    }

                    xEleRegErrList.AppendChild(xEleRegErrList1);

                    docReosponseRootElement.AppendChild(xEleRegErrList);

                    //ATNA Event Outcome Indicator
                    eventOutomeIndicator = "8"; //Failure
                }
                if (contentCount < lstRetrieveDocumentSet.Count && contentCount > 0)
                {
                    //Partial Error
                    XmlElement rootElement    = xmlDocResponse.DocumentElement;
                    XmlElement xEleRegErrList = xmlDocResponse.CreateElement("tns:RegistryResponse", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                    XmlAttribute xAttStatus = xmlDocResponse.CreateAttribute("status");
                    xAttStatus.Value = GlobalValues.CONST_RESPONSE_STATUS_TYPE_PARTIALSUCCESS;
                    xEleRegErrList.Attributes.Append(xAttStatus);

                    XmlAttribute xAttXmlNSrs = xmlDocResponse.CreateAttribute("xmlns:tns");
                    xAttXmlNSrs.Value = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0";
                    xEleRegErrList.Attributes.Append(xAttXmlNSrs);


                    XmlAttribute xAttXmlNS = xmlDocResponse.CreateAttribute("xmlns:rim");
                    xAttXmlNS.Value = GlobalValues.CONST_XML_NAMESPACE_x;
                    xEleRegErrList.Attributes.Append(xAttXmlNS);

                    XmlElement xEleRegErrList1 = xmlDocResponse.CreateElement("tns:RegistryErrorList", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");


                    XmlAttribute attribhighestSeverity = xmlDocResponse.CreateAttribute("highestSeverity");
                    attribhighestSeverity.Value = "Highest SeverityURI";
                    xEleRegErrList1.Attributes.Append(attribhighestSeverity);

                    for (int loop = 0; loop < lstRetrieveDocumentSet.Count; loop++)
                    {
                        //Rep False || ContentID < 1
                        //if(Rep == false)
                        //
                        //else
                        //
                        ////CP - No Validation required for RepositoryUniqueId
                        #region "CP - No Validation required for RepositoryUniqueId"
                        //if (lstRetrieveDocumentSet[loop].IsRepositoryUniqueIDExsists == false)
                        //{
                        //    //RepositoryUniqueID not available

                        //    XmlElement xEleRegErr = xmlDocTotalRetrieveDocumentSet.CreateElement("tns:RegistryError", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                        //    XmlAttribute xAttcodeContext = xmlDocTotalRetrieveDocumentSet.CreateAttribute("codeContext");
                        //    xAttcodeContext.Value = CONST_ERROR_CODE_XDSUnknownRepositoryUniqueID;
                        //    xEleRegErr.Attributes.Append(xAttcodeContext);

                        //    XmlAttribute xAttErrorCode = xmlDocTotalRetrieveDocumentSet.CreateAttribute("errorCode");
                        //    xAttErrorCode.Value = "The repositoryUniqueId value could not be resolved to a valid document repository or the value does not match the repositoryUniqueId of the Document Repository";
                        //    xEleRegErr.Attributes.Append(xAttErrorCode);

                        //    XmlAttribute xAttSeverity = xmlDocTotalRetrieveDocumentSet.CreateAttribute("severity");
                        //    xAttSeverity.Value = "PartialSuccess";
                        //    xEleRegErr.Attributes.Append(xAttSeverity);

                        //    XmlAttribute xAttLocation = xmlDocTotalRetrieveDocumentSet.CreateAttribute("location");
                        //    xAttLocation.Value = lstRetrieveDocumentSet[loop].DocumentID;
                        //    xEleRegErr.Attributes.Append(xAttLocation);

                        //    xEleRegErrList1.AppendChild(xEleRegErr);
                        //    xEleRegErrList.AppendChild(xEleRegErrList1);
                        //}
                        #endregion

                        if (lstRetrieveDocumentSet[loop].ContentID < 1)
                        {
                            //RepositoryUniqueID is available.....Content ID not available

                            XmlElement xEleRegErr = xmlDocResponse.CreateElement("tns:RegistryError", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                            XmlAttribute xAttcodeContext = xmlDocResponse.CreateAttribute("codeContext");
                            xAttcodeContext.Value = GlobalValues.CONST_ERROR_CODE_XDSRepositoryError;
                            xEleRegErr.Attributes.Append(xAttcodeContext);

                            XmlAttribute xAttErrorCode = xmlDocResponse.CreateAttribute("errorCode");
                            xAttErrorCode.Value = string.Format("XDSDocumentEntry {0} does not exists.", lstRetrieveDocumentSet[loop].DocumentID);
                            xEleRegErr.Attributes.Append(xAttErrorCode);

                            XmlAttribute xAttSeverity = xmlDocResponse.CreateAttribute("severity");
                            xAttSeverity.Value = "Error";
                            xEleRegErr.Attributes.Append(xAttSeverity);

                            XmlAttribute xAttLocation = xmlDocResponse.CreateAttribute("location");
                            xAttLocation.Value = lstRetrieveDocumentSet[loop].DocumentID;
                            xEleRegErr.Attributes.Append(xAttLocation);

                            xEleRegErrList1.AppendChild(xEleRegErr);
                            xEleRegErrList.AppendChild(xEleRegErrList1);
                        }
                        else
                        {
                            //Success
                            xmlDocResponse = repositoryLogic.GenerateContentDocument(xmlDocResponse, lstRetrieveDocumentSet[loop]);
                        }
                    }


                    rootElement.AppendChild(xEleRegErrList);

                    //ATNA Event Outcome Indicator
                    eventOutomeIndicator = "4"; //Partial Success
                }
                else if (contentCount == lstRetrieveDocumentSet.Count)
                {
                    //Success
                    XmlElement rootElement             = xmlDocResponse.DocumentElement;
                    XmlElement registryResponseElement = xmlDocResponse.CreateElement("tns:RegistryResponse", @"urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0");

                    //status
                    registryResponseElement.Attributes.Append(xmlDocResponse.CreateAttribute("status"));
                    registryResponseElement.Attributes["status"].Value = GlobalValues.CONST_RESPONSE_STATUS_TYPE_SUCCESS;

                    //xmlns:tns
                    registryResponseElement.Attributes.Append(xmlDocResponse.CreateAttribute("xmlns:tns"));
                    registryResponseElement.Attributes["xmlns:tns"].Value = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0";

                    //xmlns:rim
                    registryResponseElement.Attributes.Append(xmlDocResponse.CreateAttribute("xmlns:rim"));
                    registryResponseElement.Attributes["xmlns:rim"].Value = GlobalValues.CONST_XML_NAMESPACE_x;

                    //Appending Registry Response Element
                    rootElement.AppendChild(registryResponseElement);
                    for (int i = 0; i < lstRetrieveDocumentSet.Count; i++)
                    {
                        xmlDocResponse = repositoryLogic.GenerateContentDocument(xmlDocResponse, lstRetrieveDocumentSet[i]);
                    }

                    //ATNA Event Outcome Indicator
                    eventOutomeIndicator = "0"; //Success
                }
                //xmlDocTotalRetrieveDocumentSet = GenerateContentDocument(xmlDocTotalRetrieveDocumentSet, lstDocEntries);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //msgRetrieveDocumentSetResponse = Message.CreateMessage(input.Headers.MessageVersion, CONST_ACTION_RETRIEVEDOCSETRESPONSE, new XmlNodeReader(xmlDocTotalRetrieveDocumentSet));

            //ATNA
            atnaParametersValue.Add("$EventIdentification.EventOutcomeIndicator$", eventOutomeIndicator);

            //return msgRetrieveDocumentSetResponse;

            return(xmlDocResponse);
        }
        private XmlDocument ProcessProvideAndRegisterDocumentSet(XmlDocument xmlDocRequest, MessageVersion msgVersion, out StringDictionary atnaParameterValues)
        {
            XmlDocument          xmlDocRegistryRequest    = null;
            XmlDocument          xmlDocResponse           = null;
            Message              registryMessage          = null;
            XmlDocument          xmlDocRegistryResponse   = null;
            RepositoryLogic      repositoryLogic          = null;
            XmlElement           eltProvideAndRegDocSet   = null;
            XmlNode              nodeSubmitObjectsRequest = null;
            XmlNodeList          nodeListExtrinsicObject  = null;
            XmlNodeList          nodeListDocument         = null;
            XmlNode              nodeSubmissionSet        = null;
            XmlNode              nodeExternalIdentifier   = null;
            List <DocumentEntry> lstDocumentEntry         = null;
            StringBuilder        sbMetaData        = null;
            string xpathExternalIdentifierDocument = @".//*[local-name()='ExtrinsicObject'][@id='$id$']/*[local-name()='ExternalIdentifier'][@identificationScheme='$identificationScheme$']";
            string xpath                 = null;
            string entryUUID             = null;
            string uniqueID              = null;
            string eventOutcomeIndicator = "0";

            atnaParameterValues = new StringDictionary();

            try
            {
                repositoryLogic = new RepositoryLogic();
                xpathExternalIdentifierDocument = xpathExternalIdentifierDocument.Replace("$identificationScheme$", GlobalValues.XDSDocumentEntry_uniqueIdUUID);

                eltProvideAndRegDocSet = xmlDocRequest.DocumentElement;

                nodeListExtrinsicObject = eltProvideAndRegDocSet.SelectNodes(".//*[local-name()='ExtrinsicObject']");

                nodeListDocument = eltProvideAndRegDocSet.SelectNodes(".//*[local-name()='Document']");

                nodeSubmissionSet = eltProvideAndRegDocSet.SelectSingleNode("//*[local-name()='SubmitObjectsRequest']/*[local-name()=\"RegistryObjectList\"]/*[local-name()='RegistryPackage']/*[local-name()='ExternalIdentifier'][@identificationScheme='urn:uuid:96fdda7c-d067-4183-912e-bf5ee74998a8']/@value");

                if (nodeSubmissionSet != null)
                {
                    atnaParameterValues.Add("$SubmissionSet.UniqueID$", nodeSubmissionSet.Value);
                }

                //Proceed further only if any ExtrinsicObject Exists(with attachments)
                if (nodeListExtrinsicObject == null)
                {
                    throw new Exception();
                }

                //if (repositoryLogic.IsMissingDocumentAttachment(nodeListDocument, eltProvideAndRegDocSet))
                if (repositoryLogic.IsMissingDocumentAttachment(eltProvideAndRegDocSet))
                {
                    throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSMissingDocumentAttachment);
                }

                //if (repositoryLogic.IsMissingDocumentMetadata(nodeListExtrinsicObject, eltProvideAndRegDocSet))
                if (repositoryLogic.IsMissingDocumentMetadata(eltProvideAndRegDocSet))
                {
                    throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSMissingDocumentMetadata);
                }

#if debug
                if (!repositoryLogic.IsSchemaValid(xmlDocMsgBody))
                {
                    throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSInvalidRequest);
                }
#endif

                if (repositoryLogic.IsDuplicateUniqueID(eltProvideAndRegDocSet))
                {
                    throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSRepositoryDuplicateUniqueIdInMessage);
                }

                if (nodeListExtrinsicObject.Count > 0 && eltProvideAndRegDocSet.SelectNodes(@"//*[local-name()='Document']").Count > 0)
                {
                    //No document OR Metadata is Missing

                    lstDocumentEntry = new List <DocumentEntry>();
                    sbMetaData       = new StringBuilder();

                    foreach (XmlNode node in nodeListExtrinsicObject)
                    {
                        DocumentEntry objDocumentEntry = new DocumentEntry();

                        if (node.Attributes["mimeType"].Value == string.Empty)
                        {
                            throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSRepositoryMetadataError);
                        }

                        objDocumentEntry.MimeType = node.Attributes["mimeType"].Value;

                        entryUUID = node.Attributes["id"].Value;
                        xpath     = xpathExternalIdentifierDocument.Replace("$id$", node.Attributes["id"].Value);
                        nodeExternalIdentifier = eltProvideAndRegDocSet.SelectSingleNode(xpath);
                        uniqueID = nodeExternalIdentifier.Attributes["value"].Value;

                        if (string.IsNullOrEmpty(uniqueID))
                        {
                            throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSRepositoryMetadataError);
                        }

                        if (!repositoryLogic.IsValidUniqueID(uniqueID))
                        {
                            throw new Exception(GlobalValues.CONST_ERROR_CODE_XDSInvalidRequest);
                        }

                        objDocumentEntry.EntryUUID = entryUUID;
                        objDocumentEntry.UniqueID  = uniqueID;
                        objDocumentEntry.Hash      = repositoryLogic.GetHashCode(xmlDocRequest, entryUUID);
                        objDocumentEntry.Content   = repositoryLogic.GetDocumentContentStream(xmlDocRequest, entryUUID);
                        objDocumentEntry.Size      = (int)objDocumentEntry.Content.Length;

                        lstDocumentEntry.Add(objDocumentEntry);

                        sbMetaData.Append(node.OuterXml);
                    }

                    //Logging the Repository Data
                    objDocumentRepositoryLog.RequestMetadata = sbMetaData.ToString();

                    using (TransactionScope provideAndRegSetBScope = new TransactionScope())
                    {
                        //Information Logged in the Document Repository Log
                        objDocumentRepositoryLog.EndTime = DateTime.Now;
                        objDocumentRepositoryLog.Result  = "OK";
                        int noOfRows = repositoryLogic.LogRepositoryData(objDocumentRepositoryLog);
                        for (int docElement = 0; docElement < lstDocumentEntry.Count; docElement++)
                        {
                            string sStorageUniqueIdentifier = string.Empty;

                            DocumentEntry objDocEntry = lstDocumentEntry[docElement];

                            sStorageUniqueIdentifier = SQLServerStorageService.SaveDocument(objDocEntry.Content, objDocEntry.UniqueID);

                            //Save Metadata
                            repositoryLogic.SaveMetaData(objDocEntry);

                            //Insert into Document Entry Log
                            repositoryLogic.LogDocumentEntry();
                        }
                        //Create SLots for Repository ID,,Hash and Size and send those to
                        //Register document Set B
                        //this Array list already contains all ID's
                        if (lstDocumentEntry.Count > 0)
                        {
                            string repositoryUniqueId = repositoryLogic.GetRepositoryUniqueID("repositoryUniqueID");
                            string repositoryURI      = string.Empty;

                            for (int docID = 0; docID < lstDocumentEntry.Count; docID++)
                            {
                                DocumentEntry objDocumentEntry = lstDocumentEntry[docID];

                                //Creates Slots to add Medatada repositoryUniqueId
                                xmlDocRequest = repositoryLogic.CreateRepositorySlotElement(xmlDocRequest, "repositoryUniqueId", repositoryUniqueId, objDocumentEntry.EntryUUID);

                                //Creates Slots to add Medatada hash
                                xmlDocRequest = repositoryLogic.CreateRepositorySlotElement(xmlDocRequest, "hash", objDocumentEntry.Hash, objDocumentEntry.EntryUUID);

                                //Creates Slots to add Medatada size
                                xmlDocRequest = repositoryLogic.CreateRepositorySlotElement(xmlDocRequest, "size", objDocumentEntry.Content.Length.ToString(), objDocumentEntry.EntryUUID);

                                //Creates Slots to add Medatada URI
                                xmlDocRequest = repositoryLogic.CreateRepositorySlotElement(xmlDocRequest, "URI", repositoryURI, objDocumentEntry.EntryUUID);
                            }
                        }
                        //Message to be sent to Registry
                        try
                        {
                            //Sample RegistryResponse  - <RegistryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0" />;
                            //Call the XDSRegistry Service
                            Message provideAndResgiterSetInput = null;
                            string  xdsRegistryEndpointName    = CommonUtility.GetXDSRegistryEndpointName();
                            xmlDocRegistryRequest    = new XmlDocument();
                            nodeSubmitObjectsRequest = xmlDocRequest.SelectSingleNode(@"//*[local-name()='SubmitObjectsRequest']");
                            xmlDocRegistryRequest.LoadXml(nodeSubmitObjectsRequest.OuterXml);
                            XDSRegistry.XDSRegistryClient objRegsitryClient = new Microsoft.IHE.XDS.DocumentRepository.XDSRegistry.XDSRegistryClient(xdsRegistryEndpointName);
                            provideAndResgiterSetInput = Message.CreateMessage(msgVersion, GlobalValues.CONST_ACTION_REGISTERDOCUMENTSETB, new XmlNodeReader(xmlDocRegistryRequest));
                            registryMessage            = objRegsitryClient.RegisterDocumentSet(provideAndResgiterSetInput);
                        }
                        catch
                        {
                            throw new Exception("XDSRegistryNotAvailable");
                        }


                        xmlDocRegistryResponse = new XmlDocument();
                        xmlDocRegistryResponse.Load(registryMessage.GetReaderAtBodyContents());

                        XmlNode errorList = xmlDocRegistryResponse.SelectSingleNode(@"//*[local-name()='RegistryError']");
                        string  errorCode = null;

                        if (errorList != null)
                        {
                            errorCode = errorList.Attributes["errorCode"].Value;
                        }

                        //Move this outside TransactionScope...the log entry is rolled back
                        //Code block within TransactionScope should be
                        //if (errorCode == null)
                        //{
                        //    provideAndRegSetBScope.Complete();
                        //}
                        //Code block outside TransactionScope should be
                        //if (errorCode != null)
                        //{
                        //    repositoryLogic.LogRolledBackData(objDocumentRepositoryLog, errorCode);

                        //    //ATNA Failure Code
                        //    eventOutcomeIndicator = "8";
                        //}


                        if (errorCode != null)
                        {
                            repositoryLogic.LogRolledBackData(objDocumentRepositoryLog, errorCode);

                            //ATNA Failure Code
                            eventOutcomeIndicator = "8";
                        }
                        else
                        {
                            provideAndRegSetBScope.Complete();
                        }

                        //Assign Registry Response to Repository Response
                        xmlDocResponse = xmlDocRegistryResponse;

                        //Transaction is completed
                    }
                }
                else
                {
                    //Get Message from Registry
                    try
                    {
                        //Sample RegistryResponse - <RegistryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0" />;
                        //Call the XDSRegistry Service
                        Message msgProvideAndResgiterSetInput = null;
                        string  xdsRegistryEndpointName       = CommonUtility.GetXDSRegistryEndpointName();
                        xmlDocRegistryRequest    = new XmlDocument();
                        nodeSubmitObjectsRequest = xmlDocRequest.SelectSingleNode(@"//*[local-name()='SubmitObjectsRequest']");
                        xmlDocRegistryRequest.LoadXml(nodeSubmitObjectsRequest.OuterXml);
                        XDSRegistry.XDSRegistryClient objRegsitryClient = new Microsoft.IHE.XDS.DocumentRepository.XDSRegistry.XDSRegistryClient(xdsRegistryEndpointName);
                        msgProvideAndResgiterSetInput = Message.CreateMessage(msgVersion, GlobalValues.CONST_ACTION_REGISTERDOCUMENTSETB, new XmlNodeReader(xmlDocRegistryRequest));
                        registryMessage = objRegsitryClient.RegisterDocumentSet(msgProvideAndResgiterSetInput);
                    }
                    catch
                    {
                        throw new Exception("XDSRegistryNotAvailable");
                    }

                    xmlDocRegistryResponse = new XmlDocument();
                    xmlDocRegistryResponse.Load(registryMessage.GetReaderAtBodyContents());

                    XmlNode errorList = xmlDocRegistryResponse.SelectSingleNode(@"//*[local-name()='RegistryError']");
                    string  errorCode = null;

                    if (errorList != null)
                    {
                        errorCode = errorList.Attributes["errorCode"].Value;
                    }


                    if (errorCode != null)
                    {
                        repositoryLogic.LogRolledBackData(objDocumentRepositoryLog, errorCode);

                        //ATNA Failure Code
                        eventOutcomeIndicator = "8";
                    }

                    //Assign Registry Response to Repository Response
                    xmlDocResponse = xmlDocRegistryResponse;
                }
            }
            catch
            {
                throw;
            }

            atnaParameterValues.Add("$EventIdentification.EventOutcomeIndicator$", eventOutcomeIndicator);

            return(xmlDocResponse);
        }