예제 #1
0
        /// <summary>
        /// Asynchronously publishes the specified message.
        /// </summary>
        /// <typeparam name="TMessage">The message type.</typeparam>
        /// <param name="message">The message.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task PublishAsync <TMessage>(TMessage message) where TMessage : IMessage
        {
            this.log.DebugFormat(
                "Simulating publishing message of type '{0}' (not connected to service) with contents:\r\n{1}.",
                typeof(TMessage).FullName,
                message.Dump());

            MessageDumper.DumpMessage(message, "Simulating publishing message (not connected to service)");

            await Task.FromResult(0);
        }
예제 #2
0
        /// <summary>
        /// Handles the subscription of the specified command message.
        /// </summary>
        /// <param name="message">The command message.</param>
        public void HandleSubscribe(IMessage message)
        {
            try
            {
                if (message == null)
                {
                    return;
                }

                if (message.OriginationHash == this.originationHash /*&& message.GetType() != typeof(UserSignUp)*/)
                {
                    this.log.DebugFormat(
                        "Received self-published message of type '{0}'. Message will be ignored.",
                        message.GetType().FullName);

                    MessageDumper.DumpMessage(message, "Received self-published message");

                    return;
                }

                this.log.DebugFormat(
                    "Received published message of type '{0}' and contents:\r\n{1}.",
                    message.GetType().FullName,
                    message.Dump());

                MessageDumper.DumpMessage(message, "Received message");

                this.MessageReceived?.Invoke(
                    this,
                    new PublishedEventArgs
                {
                    Message = message
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// Asynchronously publishes the specified message.
        /// </summary>
        /// <typeparam name="TMessage">The message type.</typeparam>
        /// <param name="message">The message.</param>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task PublishAsync <TMessage>(TMessage message) where TMessage : IMessage
        {
            message.OriginationHash = this.originationHash;

            this.log.DebugFormat(
                "Publishing message of type '{0}' with contents:\r\n{1}.",
                typeof(TMessage).FullName,
                message.Dump());

            MessageDumper.DumpMessage(message, "Publishing message to service");

            await Task.Run(async() =>
            {
                try
                {
                    await Task.Run(() => this.commandChannel.Publish(message));
                }
                catch (Exception e)
                {
                    ;
                }
            });
        }