private void PopulateMappings(RebusConfigurationElement configuration)
        {
            // ensure that all assembly mappings are processed first,
            // so that explicit type mappings will take precendence
            var mappingElements = configuration.MappingsCollection
                .OrderBy(c => !c.IsAssemblyName);

            foreach (var element in mappingElements)
            {
                if (element.IsAssemblyName)
                {
                    var assemblyName = element.Messages;

                    log.Info("Mapping assembly: {0}", assemblyName);

                    var assembly = LoadAssembly(assemblyName);

                    foreach (var type in assembly.GetTypes().Where(DefaultMessageTypeFilter))
                    {
                        this.Map(type, element.Endpoint);
                    }
                }
                else
                {
                    var typeName = element.Messages;

                    log.Info("Mapping type: {0}", typeName);

                    var messageType = Type.GetType(typeName);

                    if (messageType == null || DefaultMessageTypeFilter(messageType))
                    {
                        throw new ConfigurationException(
                            @"Could not find the message type {0}. If you choose to map a specific message type,
please ensure that the type is available for Rebus to load. This requires that the
assembly can be found in Rebus' current runtime directory, that the type is available,
and that any (of the optional) version and key requirements are matched",
                            typeName);
                    }

                    this.Map(messageType, element.Endpoint);
                }
            }
        }
        public BusInstallationModule(
            RebusConfigurationElement configuration, 
            Action<LoggingConfigurer> configureLogging, 
            Type eventMessageInterfaceMarkerType = null)
        {
            this.configuration = configuration;
            this.configureLogging = configureLogging;
            this.eventMessageInterfaceMarkerType = eventMessageInterfaceMarkerType;

            // TODO: Move functionality to configuration 
            this.configuration.Name = configuration.Name.IsNullOrWhiteSpace()
                ? configuration.InputQueue
                : configuration.Name;
            this.configuration.InputQueue = configuration.InputQueue.IsNullOrWhiteSpace()
                ? configuration.Name
                : configuration.InputQueue;
            this.configuration.ErrorQueue = configuration.ErrorQueue.IsNullOrWhiteSpace()
                ? configuration.InputQueue + ".error"
                : configuration.ErrorQueue;
            this.configuration.AuditQueue = configuration.AuditQueue.IsNullOrWhiteSpace()
                ? configuration.InputQueue + ".audit"
                : configuration.AuditQueue;
        }
 public DetermineMessageOwnershipFromRebusConfigurationElement(RebusConfigurationElement configuration)
 {
     this.PopulateMappings(configuration);
 }
 public static void FromRebusConfigurationElement(this RebusRoutingConfigurer configurer, RebusConfigurationElement configuration)
 {
     configurer.Use(new DetermineMessageOwnershipFromRebusConfigurationElement(configuration));
 }
        public RebusConfigurationElement SetBusConfigurationDefaults(RebusConfigurationElement configuration)
        {
            if(configuration.MaxRetries == null && this.MaxRetries != null)
                configuration.MaxRetries = this.MaxRetries;

            if(configuration.Workers == null && this.Workers != null)
                configuration.Workers = this.Workers;

            if(configuration.SetCurrentPrincipal == null && this.SetCurrentPrincipal != null)
                configuration.SetCurrentPrincipal = this.SetCurrentPrincipal;

            if(configuration.LatencyBackoffMilliseconds == null && this.LatencyBackoffMilliseconds != null)
                configuration.LatencyBackoffMilliseconds = this.LatencyBackoffMilliseconds;

            if(configuration.CompressMessages == null && this.CompressMessages != null)
                configuration.CompressMessages = this.CompressMessages;

            if(configuration.CompressionThreshold == null && this.CompressionThreshold != null)
                configuration.CompressionThreshold = this.CompressionThreshold;

            if(configuration.EncryptMessages == null && this.EncryptMessages != null)
                configuration.EncryptMessages = this.EncryptMessages;

            if(configuration.EncryptMessages == null && this.EncryptMessages != null)
                configuration.EncryptionKey = this.EncryptionKey;

            //if (configuration.SqlServerSubscriptionsStorageConfiguration == null && this.SqlServerSubscriptionsStorageConfiguration != null)
            configuration.SqlServerSubscriptionsStorageConfiguration = this.SqlServerSubscriptionsStorageConfiguration;

            //if (configuration.SqlServerSagaStorageConfiguration == null && this.SqlServerSagaStorageConfiguration != null)
            configuration.SqlServerSagaStorageConfiguration = this.SqlServerSagaStorageConfiguration;

            //if (configuration.SqlServerTimeoutsManagerConfiguration == null && this.SqlServerTimeoutsManagerConfiguration != null)
            configuration.SqlServerTimeoutsManagerConfiguration = this.SqlServerTimeoutsManagerConfiguration;

            return configuration;
        }