/// <summary>
        /// Unsubscribe communications in MS-Individual Using Tool Service
        /// </summary>
        /// <param name="email">email address</param>
        /// <param name="communicationId">CommunicationId to Unsubscribe</param>
        /// <param name="deliveryFormatId">0 = Html , 1 = Text</param>
        /// <returns>Returns the EmailInterchangeResult alogn with the EI ID</returns>
        public AzureTBNService.EmailInterchangeResponseToken UnsubscribeV2(string email, int communicationId, int deliveryFormatId)
        {
            AzureTBNService.EmailInterchangeResponseToken emailInterchangeResponseToken = new AzureTBNService.EmailInterchangeResponseToken();
            try
            {
                AzureTBNService.TriggerRequestNotificationClient client = new AzureTBNService.TriggerRequestNotificationClient(PrimaryEndpoint);

                // Input Validations
                if (string.IsNullOrWhiteSpace(email))
                {
                    throw new ArgumentNullException("Email");
                }
                else if (!Regex.IsMatch(email, EmailRegExPattern))
                {
                    throw new ArgumentException("Invalid Email");
                }

                if (communicationId < 0)
                {
                    throw new ArgumentException("Invalid CommunicationId");
                }

                emailInterchangeResponseToken = client.UnsubscribeV2(email, communicationId, deliveryFormatId);
            }
            catch (Exception ex)
            {
                throw new Exception(MSIExceptionMessagePredicate + ex.Message.ToString());
            }

            return(emailInterchangeResponseToken);
        }
        /// <summary>
        /// Send Method to be called by Tenant.
        /// </summary>
        /// <param name="request">Request that is passed by Tenant.</param>
        /// <returns>Return the Request Acceptance Message alogn with the EI IDto Tenant.</returns>
        public AzureTBNService.EmailInterchangeResponseToken SendV2(AzureTBNService.RequestBase request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(ErrorExceptionMessagePredicate + RequestNullException);
            }

            AzureTBNService.EmailInterchangeResponseToken emailInterchangeResponseToken = new AzureTBNService.EmailInterchangeResponseToken();
            try
            {
                emailInterchangeResponseToken = CallSend(request, PrimaryEndpoint);
            }
            catch (Exception)
            {
                emailInterchangeResponseToken = CallSend(request, SecondaryEndpoint);
            }
            return(emailInterchangeResponseToken);
        }
        /// <summary>
        /// Method for Calling the Azure(Primary/Secondary) Endpoint.
        /// </summary>
        /// <param name="request">Request that is passed by Tenant.</param>
        /// <param name="endpointName">Azure endpoint to be used((Primary/Secondary).</param>
        /// <returns>Returns the Request Acceptance Message along with the EI ID to Calling method.</returns>
        internal AzureTBNService.EmailInterchangeResponseToken CallSend(AzureTBNService.RequestBase request, string endpointName)
        {
            int exceptionCount = 0;

            AzureTBNService.EmailInterchangeResponseToken emailInterchangeResponseToken = new AzureTBNService.EmailInterchangeResponseToken();
            emailInterchangeResponseToken.Result = AzureTBNService.EmailInterchangeResult.UnknownFailure;

            AzureTBNService.TriggerRequestNotificationClient client = null;
            for (int retryCount = 0; retryCount < retryAttempts; retryCount++)
            {
                try
                {
                    using (client = new AzureTBNService.TriggerRequestNotificationClient(endpointName))
                    {
                        emailInterchangeResponseToken = client.SendV2(request);
                    }

                    if (emailInterchangeResponseToken.Result != AzureTBNService.EmailInterchangeResult.UnknownFailure)
                    {
                        return(emailInterchangeResponseToken);
                    }
                }

                catch (Exception ex)
                {
                    if (client == null)
                    {
                        throw;
                    }

                    exceptionCount++;

                    // Throw exception if maxm retry attempts are exhausted
                    if (exceptionCount == retryAttempts)
                    {
                        throw new Exception(GenericExceptionMessagePredicate + ex.Message.ToString());
                    }
                }
            }
            return(emailInterchangeResponseToken);
        }
 /// <summary>
 /// Send Method to be called by Tenant.
 /// </summary>
 /// <param name="request">Request that is passed by Tenant.</param>
 /// <returns>Return the Request Acceptance Message to Tenant.</returns>
 public AzureTBNService.EmailInterchangeResult Send(AzureTBNService.RequestBase request)
 {
     AzureTBNService.EmailInterchangeResponseToken emailInterchangeResponseToken = new AzureTBNService.EmailInterchangeResponseToken();
     emailInterchangeResponseToken = this.SendV2(request);
     return(emailInterchangeResponseToken.Result);
 }
 /// <summary>
 /// Unsubscribe communications in MS-Individual Using Tool Service
 /// </summary>
 /// <param name="email">email address</param>
 /// <param name="communicationId">CommunicationId to Unsubscribe</param>
 /// <param name="deliveryFormatId">0 = Html , 1 = Text</param>
 /// <returns>Returns the EmailInterchangeResult type</returns>
 public AzureTBNService.EmailInterchangeResult Unsubscribe(string email, int communicationId, int deliveryFormatId)
 {
     AzureTBNService.EmailInterchangeResponseToken returnValue = new AzureTBNService.EmailInterchangeResponseToken();
     returnValue = this.UnsubscribeV2(email, communicationId, deliveryFormatId);
     return(returnValue.Result);
 }