コード例 #1
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        public Task SendAsync(ISenderMessage message)
        {
            var shouldCompress = message.ShouldCompress(_compressed);

            var stringValue = shouldCompress
                ? MessageCompression.Compress(message.StringValue)
                : message.StringValue;

            var namedPipeMessage = new NamedPipeMessage
            {
                StringValue   = stringValue,
                MessageFormat = message.MessageFormat,
                Priority      = message.Priority,
                Headers       = new Dictionary <string, string>()
            };

            var originatingSystemAlreadyExists = false;

            foreach (var header in message.Headers)
            {
                if (header.Key == HeaderName.OriginatingSystem)
                {
                    originatingSystemAlreadyExists = true;
                }

                namedPipeMessage.Headers.Add(header.Key, header.Value);
            }

            namedPipeMessage.Headers[HeaderName.MessageFormat] = message.MessageFormat.ToString();

            if (!originatingSystemAlreadyExists)
            {
                namedPipeMessage.Headers[HeaderName.OriginatingSystem] = "NamedPipe";
            }

            if (shouldCompress)
            {
                namedPipeMessage.Headers[HeaderName.CompressedPayload] = "true";
            }

            var messageString = _serializer.SerializeToString(namedPipeMessage);

            _messages.Add(messageString);
            return(_completedTask);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeReceiverMessage"/> class.
 /// </summary>
 /// <param name="namedPipeMessage">The message that was sent.</param>
 internal NamedPipeReceiverMessage(NamedPipeMessage namedPipeMessage)
 {
     _namedPipeMessage = namedPipeMessage;
 }