コード例 #1
0
        /// <summary>
        ///     Process and dispatch a message to registered functions for this message type.
        /// </summary>
        /// <param name="streamMessage"></param>
        /// <returns></returns>
        public async Task Visit(IStreamMessage streamMessage)
        {
            CombinedMessage combinedMessage = streamMessage as CombinedMessage;;

            if (combinedMessage != null)
            {
                foreach (var message in combinedMessage.Messages)
                {
                    await Visit(message);
                }

                return;
            }

            List <dynamic> funcList;

            _callbacks.TryGetValue(streamMessage.GetType(), out funcList);

            if (funcList != null)
            {
                foreach (var func in funcList)
                {
                    if (_logger != null && _logger.IsInfo)
                    {
                        _logger.Info("Dispatching message of type {0}", streamMessage.GetType().FullName);
                    }
                    await func(streamMessage as dynamic);

                    if (PostProcessedMessageFunc != null)
                    {
                        await PostProcessedMessageFunc();
                    }
                }
            }
        }