Ejemplo n.º 1
0
        internal void ApplyMappings(ReadOnlySettings settings, Configuration configuration)
        {
            var tableNamingConvention = settings.GetOrDefault <Func <Type, string> >("NHibernate.Sagas.TableNamingConvention");

            var scannedAssemblies = settings.GetAvailableTypes().Select(t => t.Assembly).Distinct();

            foreach (var assembly in scannedAssemblies)
            {
                configuration.AddAssembly(assembly);
            }

            var             types = settings.GetAvailableTypes().Except(configuration.ClassMappings.Select(x => x.MappedClass));
            SagaModelMapper modelMapper;

            if (tableNamingConvention == null)
            {
                modelMapper = new SagaModelMapper(types);
            }
            else
            {
                modelMapper = new SagaModelMapper(types, tableNamingConvention);
            }

            configuration.AddMapping(modelMapper.Compile());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the requested config section using the current configuration source.
        /// </summary>
        public static T GetConfigSection <T>(this ReadOnlySettings settings) where T : class, new()
        {
            Guard.AgainstNull(nameof(settings), settings);
            var typesToScan         = settings.GetAvailableTypes();
            var configurationSource = settings.Get <IConfigurationSource>();

            // ReSharper disable HeapView.SlowDelegateCreation
            var sectionOverrideType = typesToScan.Where(t => !t.IsAbstract)
                                      .FirstOrDefault(t => typeof(IProvideConfiguration <T>).IsAssignableFrom(t));

            // ReSharper restore HeapView.SlowDelegateCreation

            if (sectionOverrideType == null)
            {
                return(configurationSource.GetConfiguration <T>());
            }

            IProvideConfiguration <T> sectionOverride;

            if (HasConstructorThatAcceptsSettings(sectionOverrideType))
            {
                sectionOverride = (IProvideConfiguration <T>)Activator.CreateInstance(sectionOverrideType, settings);
            }
            else
            {
                sectionOverride = (IProvideConfiguration <T>)Activator.CreateInstance(sectionOverrideType);
            }

            return(sectionOverride.GetConfiguration());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the requested config section using the current configuration source.
        /// </summary>
        public static T GetConfigSection <T>(this ReadOnlySettings settings) where T : class, new()
        {
            Guard.AgainstNull(nameof(settings), settings);
            var typesToScan         = settings.GetAvailableTypes();
            var configurationSource = settings.Get <IConfigurationSource>();

            var sectionOverrideTypes = typesToScan.Where(t => !t.IsAbstract && typeof(IProvideConfiguration <T>).IsAssignableFrom(t)).ToArray();

            if (sectionOverrideTypes.Length > 1)
            {
                throw new Exception($"Multiple configuration providers implementing IProvideConfiguration<{typeof(T).Name}> were found: {string.Join(", ", sectionOverrideTypes.Select(s => s.FullName))}. Ensure that only one configuration provider per configuration section is found to resolve this error.");
            }

            if (sectionOverrideTypes.Length == 0)
            {
                return(configurationSource.GetConfiguration <T>());
            }

            var sectionOverrideType = sectionOverrideTypes[0];

            IProvideConfiguration <T> sectionOverride;

            if (HasConstructorThatAcceptsSettings(sectionOverrideType))
            {
                sectionOverride = (IProvideConfiguration <T>)Activator.CreateInstance(sectionOverrideType, settings);
            }
            else
            {
                sectionOverride = (IProvideConfiguration <T>)Activator.CreateInstance(sectionOverrideType);
            }

            return(sectionOverride.GetConfiguration());
        }
Ejemplo n.º 4
0
        internal void ApplyMappings(ReadOnlySettings settings, Configuration configuration)
        {
            var tableNamingConvention = settings.GetOrDefault <Func <Type, string> >("NHibernate.Sagas.TableNamingConvention");

            var scannedAssemblies = settings.GetAvailableTypes().Select(t => t.Assembly).Distinct();

            foreach (var assembly in scannedAssemblies)
            {
                configuration.AddAssembly(assembly);
            }

            var allSagaMetadata = settings.Get <SagaMetadataCollection>();
            var types           = settings.GetAvailableTypes().Except(configuration.ClassMappings.Select(x => x.MappedClass));

            SagaModelMapper.AddMappings(configuration, allSagaMetadata, types, tableNamingConvention);
        }
        void ApplyConventions(ReadOnlySettings settings)
        {
            if (DocumentIdConventionsExtensions.NeedToApplyDocumentIdConventionsToDocumentStore(settings))
            {
                var sagasEnabled    = settings.IsFeatureActive(typeof(Sagas));
                var timeoutsEnabled = settings.IsFeatureActive(typeof(TimeoutManager));
                var idConventions   = new DocumentIdConventions(docStore, settings.GetAvailableTypes(), settings.EndpointName(), sagasEnabled, timeoutsEnabled);
                docStore.Conventions.FindTypeTagName = idConventions.FindTypeTagName;
            }

            var store = docStore as DocumentStore;

            if (store == null)
            {
                return;
            }

            var isSendOnly = settings.GetOrDefault <bool>("Endpoint.SendOnly");

            if (!isSendOnly)
            {
                var usingDtc = settings.GetRequiredTransactionModeForReceives() == TransportTransactionMode.TransactionScope;
                if (usingDtc)
                {
                    throw new Exception("RavenDB Persistence does not support Distributed Transaction Coordinator (DTC) transactions. You must change the TransportTransactionMode in order to continue. See the RavenDB Persistence documentation for more details.");
                }
            }
#if NET452
            store.EnlistInDistributedTransactions = false;
#endif
        }
 public SerializationMapper(IMessageMapper mapper,Conventions conventions, ReadOnlySettings settings)
 {
     jsonSerializer = new JsonMessageSerializer(mapper);
     xmlSerializer = new XmlMessageSerializer(mapper, conventions);
     List<Type> messageTypes = settings.GetAvailableTypes().Where(conventions.IsMessageType).ToList();
     xmlSerializer.Initialize(messageTypes);
 }
Ejemplo n.º 7
0
        static IEnumerable<Type> ISpecifyMessageHandlerOrdering(ReadOnlySettings settings)
        {
            var types = new List<Type>();

            settings.GetAvailableTypes().Where(TypeSpecifiesMessageHandlerOrdering)
                .ToList().ForEach(t =>
                {
                    Logger.DebugFormat("Going to ask for message handler ordering from '{0}'.", t);

                    var order = new Order();
                    ((ISpecifyMessageHandlerOrdering) Activator.CreateInstance(t)).SpecifyOrder(order);

                    order.Types.ToList().ForEach(ht =>
                    {
                        if (types.Contains(ht))
                        {
                            throw new ConfigurationErrorsException(string.Format("The order in which the type '{0}' should be invoked was already specified by a previous implementor of ISpecifyMessageHandlerOrdering. Check the debug logs to see which other specifiers have been invoked.", ht));
                        }
                    });

                    types.AddRange(order.Types);
                });

            return types;
        }
Ejemplo n.º 8
0
        static IEnumerable <Type> ISpecifyMessageHandlerOrdering(ReadOnlySettings settings)
        {
            var types = new List <Type>();

            settings.GetAvailableTypes().Where(TypeSpecifiesMessageHandlerOrdering)
            .ToList().ForEach(t =>
            {
                Logger.DebugFormat("Going to ask for message handler ordering from '{0}'.", t);

                var order = new Order();
                ((ISpecifyMessageHandlerOrdering)Activator.CreateInstance(t)).SpecifyOrder(order);

                order.Types.ToList().ForEach(ht =>
                {
                    if (types.Contains(ht))
                    {
                        throw new ConfigurationErrorsException(string.Format("The order in which the type '{0}' should be invoked was already specified by a previous implementor of ISpecifyMessageHandlerOrdering. Check the debug logs to see which other specifiers have been invoked.", ht));
                    }
                });

                types.AddRange(order.Types);
            });

            return(types);
        }
 private static List<Type> GetSagaTypes(ReadOnlySettings settings)
 {
     var sagaDataTypes =
         settings.GetAvailableTypes()
             .Where(t => typeof (IContainSagaData).IsAssignableFrom(t) && !t.IsInterface)
             .ToList();
     return sagaDataTypes;
 }
    public SerializationMapper(IMessageMapper mapper, Conventions conventions, ReadOnlySettings settings)
    {
        jsonSerializer = new JsonMessageSerializer(mapper);
        xmlSerializer  = new XmlMessageSerializer(mapper, conventions);
        List <Type> messageTypes = settings.GetAvailableTypes().Where(conventions.IsMessageType).ToList();

        xmlSerializer.Initialize(messageTypes);
    }
        public MessageStreamerConnection(ISendMessages sender, ReadOnlySettings settings, Conventions conventions)
        {
            this.sender = sender;

            messageTypes = settings.GetAvailableTypes()
                           .Where(conventions.IsMessageType)
                           .ToList();
            localAddress = settings.LocalAddress();
        }
        public SubscriptionPersister(IDocumentStore store, ReadOnlySettings settings)
        {
            this.store   = store;
            localAddress = settings.LocalAddress();

            locallyHandledEventTypes = settings.GetAvailableTypes().Implementing <IEvent>().Select(e => new MessageType(e)).ToArray();


            SetSubscriptions(new Subscriptions());
        }
        public MessageStreamerConnection(IDispatchMessages sender, ReadOnlySettings settings)
        {
            var conventions = settings.Get <Conventions>();

            this.sender = sender;

            messageTypes = settings.GetAvailableTypes()
                           .Where(conventions.IsMessageType)
                           .GroupBy(x => x.Name)
                           .ToDictionary(x => x.Key, x => x.FirstOrDefault().AssemblyQualifiedName);
            localAddress = settings.LocalAddress();
        }
        void ApplyConventions(ReadOnlySettings settings)
        {
            if (DocumentIdConventionsExtensions.NeedToApplyDocumentIdConventionsToDocumentStore(settings))
            {
                var sagasEnabled = settings.IsFeatureActive(typeof(Sagas));
                var timeoutsEnabled = settings.IsFeatureActive(typeof(TimeoutManager));
                var idConventions = new DocumentIdConventions(docStore, settings.GetAvailableTypes(), settings.EndpointName(), sagasEnabled, timeoutsEnabled);
                docStore.Conventions.FindTypeTagName = idConventions.FindTypeTagName;
            }

            var store = docStore as DocumentStore;
            if (store == null)
            {
                return;
            }

            bool suppressDistributedTransactions;
            if (settings.TryGet("Transactions.SuppressDistributedTransactions", out suppressDistributedTransactions) && suppressDistributedTransactions)
            {
                store.EnlistInDistributedTransactions = false;
            }
            else 
            {
                if (store.JsonRequestFactory == null) // If the DocStore has not been initialized yet
                {
                    if (store.ResourceManagerId == Guid.Empty || store.ResourceManagerId == ravenDefaultResourceManagerId)
                    {
                        var resourceManagerId = settings.LocalAddress();
                        store.ResourceManagerId = DeterministicGuidBuilder(resourceManagerId);
                    }

                    // If using the default (Volatile - null should be impossible) then switch to IsolatedStorage
                    // Leave alone if LocalDirectoryTransactionRecoveryStorage!
                    if (store.TransactionRecoveryStorage == null || store.TransactionRecoveryStorage is VolatileOnlyTransactionRecoveryStorage)
                    {
                        store.TransactionRecoveryStorage = new IsolatedStorageTransactionRecoveryStorage();
                    }
                }

                var dtcSettingsNotIdeal = store.ResourceManagerId == Guid.Empty ||
                                          store.ResourceManagerId == ravenDefaultResourceManagerId ||
                                          !(store.TransactionRecoveryStorage is LocalDirectoryTransactionRecoveryStorage);

                if (dtcSettingsNotIdeal)
                {
                    Logger.Warn("NServiceBus has detected that a RavenDB DocumentStore is being used with Distributed Transaction Coordinator transactions, but without the recommended production-safe settings for ResourceManagerId or TransactionStorageRecovery. Refer to \"Setting RavenDB DTC settings manually\" in the NServiceBus documentation for more information.");
                }
            }
        }
        internal void ApplyMappings(ReadOnlySettings settings, Configuration configuration)
        {
            var tableNamingConvention = settings.GetOrDefault<Func<Type, string>>("NHibernate.Sagas.TableNamingConvention");

            var scannedAssemblies = settings.GetAvailableTypes().Select(t => t.Assembly).Distinct();

            foreach (var assembly in scannedAssemblies)
            {
                configuration.AddAssembly(assembly);
            }

            var types = settings.GetAvailableTypes().Except(configuration.ClassMappings.Select(x => x.MappedClass));
            SagaModelMapper modelMapper;
            if (tableNamingConvention == null)
            {
                modelMapper = new SagaModelMapper(types);
            }
            else
            {
                modelMapper = new SagaModelMapper(types, tableNamingConvention);
            }

            configuration.AddMapping(modelMapper.Compile());
        }
 public SubscriptionPersister(IDocumentStore store, ReadOnlySettings settings) :
     this(store, settings, settings.EndpointName(), settings.LocalAddress(), settings.GetAvailableTypes().Implementing <IEvent>().Select(e => new MessageType(e)).ToArray())
 {
 }