Пример #1
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        public Task SendAsync(SenderMessage message, CancellationToken cancellationToken)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (message.OriginatingSystem is null)
            {
                message.OriginatingSystem = "NamedPipe";
            }

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

            foreach (var header in message.Headers)
            {
                namedPipeMessage.Headers.Add(header.Key, header.Value.ToString() !);
            }

            var messageString = NamedPipeMessageSerializer.SerializeToString(namedPipeMessage);

            _workItems.Add(messageString, cancellationToken);

            return(Task.CompletedTask);
        }
Пример #2
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        public Task SendAsync(SenderMessage message, CancellationToken cancellationToken)
        {
            if (message.OriginatingSystem == null)
            {
                message.OriginatingSystem = "NamedPipe";
            }

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

            foreach (var header in message.Headers)
            {
                namedPipeMessage.Headers.Add(header.Key, header.Value.ToString());
            }

            var messageString = _serializer.SerializeToString(namedPipeMessage);
            var completion    = new TaskCompletionSource <bool>();

            _workItems.Add(new WorkItem {
                Message = messageString, Completion = completion, CancellationToken = cancellationToken
            });

            return(completion.Task);
        }
 /// <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)
     : base(() => namedPipeMessage.StringValue)
 {
     _namedPipeMessage = namedPipeMessage;
 }