Exemplo n.º 1
0
        public TransactMessageResponse SendMessage(TransactMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            SendMessagePreCommunicationVerification(message);

            var encodedMessage = _encoder.Encode(message);

            string response;

            using (var silverpop = _silverpopFactory())
            {
                response = silverpop.HttpUpload(encodedMessage);
            }

            var decodedResponse = _decoder.Decode(response);

            if (decodedResponse.Status == TransactMessageResponseStatus.EncounteredErrorsNoMessagesSent)
            {
                throw new TransactClientException(
                          decodedResponse.Error.Value, encodedMessage, decodedResponse.RawResponse);
            }

            return(decodedResponse);
        }
Exemplo n.º 2
0
        public virtual TransactMessageResponse SendMessage(TransactMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            SendMessagePreCommunicationVerification(message);

            var encodedMessage = _encoder.Encode(message);

            string response;

            using (var silverpop = _silverpopFactory())
            {
                response = silverpop.HttpUpload(encodedMessage);
            }

            var decodedResponse = _decoder.Decode(response);

            if (decodedResponse.Status == TransactMessageResponseStatus.EncounteredErrorsNoMessagesSent)
            {
                var errorMessage = decodedResponse.Error.Value;

                if (string.IsNullOrWhiteSpace(errorMessage) && decodedResponse.RecipientDetails.Any())
                {
                    errorMessage = string.Join(
                        "; ",
                        decodedResponse.RecipientDetails
                        .Where(x => x.SendStatus == TransactMessageResponseRecipientSendStatus.ErrorEncounteredWillNotRetry)
                        .Select(x => $"{x.Email}: {(string.IsNullOrWhiteSpace(x.Error.Value) ? "Unknown error" : x.Error.Value)}"));
                }

                throw new TransactClientException(
                          errorMessage, encodedMessage, decodedResponse.RawResponse);
            }

            return(decodedResponse);
        }