Ejemplo n.º 1
0
        /// <summary>
        /// Initializes endpoints 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 endpoint
        /// properties</param>
        protected virtual void InitializeEndpoints(TConfiguration configuration, PlatibusConfigurationSection configSection)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }

            IEnumerable <EndpointElement> endpoints = configSection.Endpoints;

            foreach (var endpointConfig in endpoints)
            {
                IEndpointCredentials credentials = null;
                switch (endpointConfig.CredentialType)
                {
                case ClientCredentialType.Basic:
                    var un = endpointConfig.Username;
                    var pw = endpointConfig.Password;
                    credentials = new BasicAuthCredentials(un, pw);
                    break;

                case ClientCredentialType.Windows:
                case ClientCredentialType.NTLM:
                    credentials = new DefaultCredentials();
                    break;
                }

                var endpoint = new Endpoint(endpointConfig.Address, credentials);
                configuration.AddEndpoint(endpointConfig.Name, endpoint);
            }
        }
Ejemplo n.º 2
0
        private static void InitializeDefaultSendOptions(TConfiguration configuration,
                                                         PlatibusConfigurationSection configSection)
        {
            if (configSection.DefaultSendOptions == null)
            {
                return;
            }

            configuration.DefaultSendOptions = new SendOptions
            {
                ContentType = configSection.DefaultSendOptions.ContentType,
                TTL         = configSection.DefaultSendOptions.TTL,
                Synchronous = configSection.DefaultSendOptions.Synchronous
            };

            switch (configSection.DefaultSendOptions.CredentialType)
            {
            case ClientCredentialType.Basic:
                var un = configSection.DefaultSendOptions.Username;
                var pw = configSection.DefaultSendOptions.Password;
                configuration.DefaultSendOptions.Credentials = new BasicAuthCredentials(un, pw);
                break;

            case ClientCredentialType.Windows:
            case ClientCredentialType.NTLM:
                configuration.DefaultSendOptions.Credentials = new DefaultCredentials();
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the specified <paramref name="configuration"/> object according to the
        /// values in the supplied <paramref name="configSection"/>
        /// </summary>
        /// <param name="configuration">The configuration object to initialize</param>
        /// <param name="configSection">The <see cref="PlatibusConfigurationSection"/>
        /// containing the values used to initialize the Platibus configuration</param>
        public virtual async Task Initialize(TConfiguration configuration, PlatibusConfigurationSection configSection)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configSection == null)
            {
                throw new ArgumentNullException(nameof(configSection));
            }

            await InitializeDiagnostics(configuration, configSection);

            var diagnosticService = configuration.DiagnosticService;

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

            InitializeDefaultSendOptions(configuration, configSection);

            InitializeEndpoints(configuration, configSection);
            InitializeTopics(configuration, configSection);
            InitializeSendRules(configuration, configSection);
            InitializeSubscriptions(configuration, configSection);

            var messageJournalFactory = new MessageJournalFactory(diagnosticService);

            configuration.MessageJournal = await messageJournalFactory.InitMessageJournal(configSection.Journaling);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes send rules 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 send rule
        /// properties</param>
        protected virtual void InitializeSendRules(TConfiguration configuration, PlatibusConfigurationSection configSection)
        {
            IEnumerable <SendRuleElement> sendRules = configSection.SendRules;

            foreach (var sendRule in sendRules)
            {
                var messageSpec  = new MessageNamePatternSpecification(sendRule.NamePattern);
                var endpointName = (EndpointName)sendRule.Endpoint;
                configuration.AddSendRule(new SendRule(messageSpec, endpointName));
            }
        }
Ejemplo n.º 5
0
        /// <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 void InitializeSubscriptions(TConfiguration configuration,
                                                       PlatibusConfigurationSection configSection)
        {
            IEnumerable <SubscriptionElement> subscriptions = configSection.Subscriptions;

            foreach (var subscription in subscriptions)
            {
                var endpointName = subscription.Endpoint;
                var topicName    = subscription.Topic;
                var ttl          = subscription.TTL;
                configuration.AddSubscription(new Subscription(endpointName, topicName, ttl));
            }
        }
        public static async Task <TConfig> LoadConfiguration <TConfig>(PlatibusConfigurationSection configSection,
                                                                       bool processConfigurationHooks = true) where TConfig : PlatibusConfiguration, new()
        {
            var configurationManager = new NetFrameworkConfigurationManager <TConfig>();
            var configuration        = new TConfig();
            await configurationManager.Initialize(configuration, configSection);

            if (processConfigurationHooks)
            {
                await configurationManager.FindAndProcessConfigurationHooks(configuration);
            }
            return(configuration);
        }
Ejemplo n.º 7
0
        /// <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(TConfiguration configuration, PlatibusConfigurationSection 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);
            }
        }
Ejemplo n.º 8
0
        /// <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(TConfiguration configuration,
                                                           PlatibusConfigurationSection 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);
            }
        }