/// <summary>
 /// The build error response.
 /// </summary>
 /// <param name="exception">
 /// The exception.
 /// </param>
 /// <returns>
 /// The <see cref="RegistryInterface"/>.
 /// </returns>
 public RegistryInterface BuildErrorResponse(Exception exception)
 {
     var responseType = new RegistryInterface();
     RegistryInterfaceType regInterface = responseType.Content;
     var returnType = new SubmitProvisioningResponseType();
     regInterface.SubmitProvisioningResponse = returnType;
     V2Helper.Header = regInterface;
     var statusType = new ProvisioningStatusType();
     returnType.ProvisioningStatus.Add(statusType);
     var statusMessage = new StatusMessageType();
     statusType.StatusMessage = statusMessage;
     this.AddStatus(statusMessage, exception);
     return responseType;
 }
        /// <summary>
        /// The build response.
        /// </summary>
        /// <param name="response">
        /// The response.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildResponse(ICollection<IProvisionAgreementObject> response)
        {
            var responseType = new RegistryInterface();
            RegistryInterfaceType regInterface = responseType.Content;
            var returnType = new SubmitProvisioningResponseType();
            regInterface.SubmitProvisioningResponse = returnType;
            V2Helper.Header = regInterface;

            /* foreach */
            foreach (IProvisionAgreementObject provisionAgreement in response)
            {
                this.ProcessResponse(returnType, provisionAgreement);
            }

            return responseType;
        }
        /// <summary>
        /// The process response.
        /// </summary>
        /// <param name="returnType">
        /// The return type.
        /// </param>
        /// <param name="provisionAgreement">
        /// The provision agreement.
        /// </param>
        private void ProcessResponse(
            SubmitProvisioningResponseType returnType, IProvisionAgreementObject provisionAgreement)
        {
            var statusType = new ProvisioningStatusType();
            returnType.ProvisioningStatus.Add(statusType);
            var statusMessage = new StatusMessageType();
            statusType.StatusMessage = statusMessage;
            this.AddStatus(statusMessage, null);

            var provRefType = new ProvisionAgreementRefType();
            statusType.ProvisionAgreementRef = provRefType;

            if (ObjectUtil.ValidString(provisionAgreement.Urn))
            {
                provRefType.URN = provisionAgreement.Urn;
            }

            if (provisionAgreement.DataproviderRef != null)
            {
                ICrossReference crossRef = provisionAgreement.DataproviderRef;
                IMaintainableRefObject maintRef = crossRef.MaintainableReference;
                string value = maintRef.AgencyId;
                if (!string.IsNullOrWhiteSpace(value))
                {
                    provRefType.OrganisationSchemeAgencyID = maintRef.AgencyId;
                }

                string value1 = maintRef.MaintainableId;
                if (!string.IsNullOrWhiteSpace(value1))
                {
                    provRefType.OrganisationSchemeID = maintRef.MaintainableId;
                }

                string value2 = crossRef.ChildReference.Id;
                if (crossRef.ChildReference != null && !string.IsNullOrWhiteSpace(value2))
                {
                    provRefType.DataProviderID = crossRef.ChildReference.Id;
                }

                string value3 = maintRef.Version;
                if (!string.IsNullOrWhiteSpace(value3))
                {
                    provRefType.DataProviderVersion = maintRef.Version;
                }
            }

            if (provisionAgreement.StructureUseage != null)
            {
                ICrossReference structUseageCrossRef = provisionAgreement.StructureUseage;
                IMaintainableRefObject maintRef0 = structUseageCrossRef.MaintainableReference;
                if (structUseageCrossRef.TargetReference.EnumType == SdmxStructureEnumType.Dataflow)
                {
                    string value = maintRef0.AgencyId;
                    if (!string.IsNullOrWhiteSpace(value))
                    {
                        provRefType.DataflowAgencyID = maintRef0.AgencyId;
                    }

                    string value1 = maintRef0.MaintainableId;
                    if (!string.IsNullOrWhiteSpace(value1))
                    {
                        provRefType.DataflowID = maintRef0.MaintainableId;
                    }

                    string value2 = maintRef0.Version;
                    if (!string.IsNullOrWhiteSpace(value2))
                    {
                        provRefType.DataflowVersion = maintRef0.Version;
                    }
                }
            }
        }