示例#1
0
        static List <string> GetExcludedAssemblies(AssemblyScannerConfiguration configuration)
        {
            var property = typeof(AssemblyScannerConfiguration).GetProperty("ExcludedAssemblies",
                                                                            BindingFlags.Instance | BindingFlags.NonPublic);

            return((List <string>)property?.GetValue(configuration, null));
        }
        public void When_using_default_settings_all_messages_should_be_found()
        {
            var assemblyScannerConfig = new AssemblyScannerConfiguration();

            var conventions = new Conventions();

            conventions.Add(new DelegateMessageConvention()
            {
                IsCommandTypeConvention = t => t.Name.EndsWith("Command"),
                IsMessageTypeConvention = t => t.Name.EndsWith("Message")
            });

            var types = TypesScanner.ScanMessageTypes(assemblyScannerConfig, conventions).ToList();

            Assert.Contains(typeof(ACommand), types);
            Assert.Contains(typeof(AMessage), types);
            Assert.Contains(typeof(ThisIsAnExcludedCommand), types);
        }
示例#3
0
        public static IEnumerable <Type> ScanMessageTypes(AssemblyScannerConfiguration coreScannerConfiguration, Conventions conventions)
        {
            var excludedTypes      = GetExcludedTypes(coreScannerConfiguration).ToImmutableHashSet();
            var excludedAssemblies = GetExcludedAssemblies(coreScannerConfiguration).ToImmutableHashSet();

            var scanner = new InternalAssemblyScanner();

            scanner.AddAssemblyFilter(fullPath => excludedAssemblies.Contains(Path.GetFileName(fullPath))
                ? InternalAssemblyScanner.FilterResults.Exclude
                : InternalAssemblyScanner.FilterResults.Include);

            var assemblies   = scanner.Scan().ToList();
            var messageTypes = assemblies.SelectMany(a => a.GetTypes())
                               .Where(t => !excludedTypes.Contains(t) && (conventions.IsCommandType(t) || conventions.IsMessageType(t)))
                               .ToList();

            return(messageTypes);
        }
        public void When_excluding_types_types_from_assembly_should_not_be_found()
        {
            var assemblyScannerConfig = new AssemblyScannerConfiguration();

            assemblyScannerConfig.ExcludeTypes(typeof(ThisIsAnExcludedCommand));

            var conventions = new Conventions();

            conventions.Add(new DelegateMessageConvention()
            {
                IsCommandTypeConvention = t => t.Name.EndsWith("Command"),
                IsMessageTypeConvention = t => t.Name.EndsWith("Message")
            });

            var types = TypesScanner.ScanMessageTypes(assemblyScannerConfig, conventions).ToList();

            Assert.Contains(typeof(ACommand), types);
            Assert.Contains(typeof(AMessage), types);
            Assert.False(types.Contains(typeof(ThisIsAnExcludedCommand)));
        }
示例#5
0
        private void ExcludeMessageHandlers(AssemblyScannerConfiguration assemblyScanner)
        {
            var supportedMessageTypes = ConfigHelper.SupportedActionTypes;

            if (supportedMessageTypes == MessageActionType.All)
            {
                return;
            }
            foreach (MessageActionType value in Enum.GetValues(typeof(MessageActionType)))
            {
                if (value == MessageActionType.All)
                {
                    continue;
                }
                if ((supportedMessageTypes & value) != value)
                {
                    if (GetMessageActionToHandlerMapping().ContainsKey(value))
                    {
                        assemblyScanner.ExcludeTypes(GetMessageActionToHandlerMapping()[value]);
                    }
                }
            }
        }