/// <summary>
        /// Initializes topics in the supplied <paramref name="configuration"/> based on the
        /// properties of the specified <paramref name="configSection"/>
        /// </summary>
        /// <param name="configuration">The configuration to initialize</param>
        /// <param name="configSection">The configuration section containing the topic
        /// properties</param>
        protected virtual void InitializeTopics(LoopbackConfiguration configuration, LoopbackConfigurationSection configSection)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }
            IEnumerable <TopicElement> topics = configSection.Topics;

            foreach (var topic in topics)
            {
                configuration.AddTopic(topic.Name);
            }
        }
        /// <summary>
        /// Initializes subscriptions in the supplied <paramref name="configuration"/> based on the
        /// properties of the specified <paramref name="configSection"/>
        /// </summary>
        /// <param name="configuration">The configuration to initialize</param>
        /// <param name="configSection">The configuration section containing the subscription
        /// properties</param>
        protected virtual async Task InitializeDiagnostics(LoopbackConfiguration configuration,
                                                           LoopbackConfigurationSection configSection)
        {
            var diagnosticsConfig = configSection.Diagnostics;

            if (diagnosticsConfig == null)
            {
                return;
            }

            var factory = new DiagnosticEventSinkFactory(configuration.DiagnosticService);
            IEnumerable <DiagnosticEventSinkElement> sinkConfigs = diagnosticsConfig.Sinks;

            foreach (var sinkConfig in sinkConfigs)
            {
                var sink = await factory.InitDiagnosticEventSink(sinkConfig);

                configuration.DiagnosticService.AddSink(sink);
            }
        }
        /// <summary>
        /// Initializes the specified <paramref name="platibusConfiguration"/> object according to the
        /// values in the supplied loopback <paramref name="configSection"/>
        /// </summary>
        /// <param name="platibusConfiguration">The configuration object to initialize</param>
        /// <param name="configSection">The <see cref="LoopbackConfigurationSection"/>
        /// containing the values used to initialize the Platibus configuration</param>
        public async Task Initialize(LoopbackConfiguration platibusConfiguration, LoopbackConfigurationSection configSection)
        {
            if (platibusConfiguration == null)
            {
                throw new ArgumentNullException(nameof(platibusConfiguration));
            }
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }

            await InitializeDiagnostics(platibusConfiguration, configSection);

            platibusConfiguration.ReplyTimeout         = configSection.ReplyTimeout;
            platibusConfiguration.SerializationService = new DefaultSerializationService();
            platibusConfiguration.MessageNamingService = new DefaultMessageNamingService();
            platibusConfiguration.DefaultContentType   = configSection.DefaultContentType;

            if (configSection.DefaultSendOptions != null)
            {
                platibusConfiguration.DefaultSendOptions = new SendOptions
                {
                    ContentType = configSection.DefaultSendOptions.ContentType,
                    TTL         = configSection.DefaultSendOptions.TTL,
                    Synchronous = configSection.DefaultSendOptions.Synchronous
                };
            }

            InitializeTopics(platibusConfiguration, configSection);

            var messageJournalFactory = new MessageJournalFactory(platibusConfiguration.DiagnosticService);

            platibusConfiguration.MessageJournal = await messageJournalFactory.InitMessageJournal(configSection.Journaling);

            var mqsFactory = new MessageQueueingServiceFactory(platibusConfiguration.DiagnosticService);

            platibusConfiguration.MessageQueueingService = await mqsFactory.InitMessageQueueingService(configSection.Queueing);
        }