Exemplo n.º 1
0
        /// <summary>
        ///     Please see <seealso cref="IEncodeMessageService{T}.Encode" /> for documentation.
        /// </summary>
        /// <param name="sendMessageParameters">-</param>
        /// <returns>-</returns>
        public EncodedMessage Encode(SendChunkedMessageParameters sendMessageParameters)
        {
            var messageHeaderParameters = new MessageHeaderParameters
            {
                ApplicationMessageId = sendMessageParameters.ApplicationMessageId,
                TeamSetContextId     = sendMessageParameters.TeamsetContextId ?? "",
                TechnicalMessageType = sendMessageParameters.TechnicalMessageType,
                Mode       = Mode,
                Recipients = sendMessageParameters.Recipients,
                ChunkInfo  = sendMessageParameters.ChunkInfo
            };

            var messagePayloadParameters = new MessagePayloadParameters
            {
                TypeUrl = sendMessageParameters.TypeUrl ?? TechnicalMessageTypes.Empty,
                Value   = ByteString.FromBase64(sendMessageParameters.Base64MessageContent)
            };

            var encodedMessage = new EncodedMessage
            {
                Id      = Guid.NewGuid().ToString(),
                Content = EncodeMessageService.Encode(messageHeaderParameters, messagePayloadParameters)
            };

            return(encodedMessage);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Please see base class declaration for documentation.
        /// </summary>
        /// <param name="sendMessageParameters">-</param>
        /// <returns>-</returns>
        public MessagingResult Send(SendMessageParameters sendMessageParameters)
        {
            var encodedMessages = new List <string>();

            if (string.IsNullOrWhiteSpace(sendMessageParameters.Base64MessageContent))
            {
                throw new CouldNotSendEmptyMessageException("Sending empty messages does not make any sense.");
            }

            if (MessageCanBeChunked(sendMessageParameters.TechnicalMessageType))
            {
                if (MessageHasToBeChunked(sendMessageParameters.Base64MessageContent))
                {
                    var chunkContextId = Guid.NewGuid().ToString();
                    var totalSize      = Encoding.Unicode.GetByteCount(sendMessageParameters.Base64MessageContent);

                    var chunkedMessages = ChunkMessageContent(sendMessageParameters.Base64MessageContent,
                                                              sendMessageParameters.ChunkSize > 0
                            ? sendMessageParameters.ChunkSize
                            : ChunkSizeDefinition.MaximumSupported);

                    var current = 0;
                    foreach (var chunkedMessage in chunkedMessages)
                    {
                        var sendMessageParametersDuplicate = new SendChunkedMessageParameters
                        {
                            Recipients           = sendMessageParameters.Recipients,
                            TypeUrl              = sendMessageParameters.TypeUrl,
                            TechnicalMessageType = sendMessageParameters.TechnicalMessageType,
                            ApplicationMessageId = MessageIdService.ApplicationMessageId()
                        };
                        var chunkComponent = new ChunkComponent
                        {
                            Current   = current++,
                            Total     = chunkedMessage.Length,
                            ContextId = chunkContextId,
                            TotalSize = totalSize
                        };
                        sendMessageParametersDuplicate.ChunkInfo            = chunkComponent;
                        sendMessageParametersDuplicate.Base64MessageContent = chunkedMessage;
                        encodedMessages.Add(Encode(sendMessageParametersDuplicate).Content);
                    }
                }
                else
                {
                    encodedMessages = new List <string> {
                        Encode(sendMessageParameters).Content
                    };
                }
            }
            else
            {
                encodedMessages = new List <string> {
                    Encode(sendMessageParameters).Content
                };
            }

            var messagingParameters = sendMessageParameters.BuildMessagingParameter(encodedMessages);

            return(_messagingService.Send(messagingParameters));
        }