Beispiel #1
0
        private bool MayRunConfigurator(CachedType cachedType)
        {
            if (cachedType.State >= ProcessingState.ConfiguratorRan)
            {
                return(false);
            }

            if (cachedType.State != ProcessingState.Configured)
            {
                throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" +
                                                    $" '{ProcessingState.Configured}' but is '{cachedType.State}'.");
            }

            return(cachedType.RegistratorConfigurator != null);
        }
Beispiel #2
0
        private bool MayConfigureType(CachedType cachedType)
        {
            if (cachedType.State >= ProcessingState.Configured)
            {
                return(false);
            }

            if (cachedType.State != ProcessingState.RegistratorRan)
            {
                throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" +
                                                    $" '{ProcessingState.Registered}' but is '{cachedType.State}'.");
            }

            // The conditions were already checked during registration.
            return(true);
        }
Beispiel #3
0
        private bool MayCacheExtensionType(CachedType cachedType)
        {
            if (cachedType.State >= ProcessingState.CachedExtension)
            {
                return(false);
            }

            if (cachedType.State != ProcessingState.None)
            {
                throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" +
                                                    $" '{ProcessingState.None}' but is '{cachedType.State}'.");
            }

            var type = cachedType.Type;

            return(type.IsClass && !type.IsAbstract && typeof(IExtensionForProcessableAttribute).IsAssignableFrom(type));
        }
Beispiel #4
0
        private void RunConfigurator(IConfigurationContext context, CachedType cachedType)
        {
            if (!MayRunConfigurator(cachedType) || SimulateOnlyUnprocessableTypes)
            {
                if (cachedType.State == ProcessingState.Configured)
                {
                    cachedType.State = ProcessingState.ConfiguratorRan;
                }

                return;
            }

            cachedType.RegistratorConfigurator !.Configure(context);

            cachedType.State = ProcessingState.ConfiguratorRan;

            Options.Logger?.Log($"Ran configurator '{cachedType.Type.Name}'");
        }
Beispiel #5
0
        private bool MayRunRegistrator(CachedType cachedType)
        {
            if (cachedType.State >= ProcessingState.RegistratorRan)
            {
                return(false);
            }

            if (cachedType.State != ProcessingState.Registered)
            {
                throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" +
                                                    $" '{ProcessingState.Registered}' but is '{cachedType.State}'.");
            }

            var type = cachedType.Type;

            return(type.IsClass && !type.IsAbstract && typeof(IRegistratorConfigurator).IsAssignableFrom(type) &&
                   type != typeof(IRegistratorConfigurator));
        }
Beispiel #6
0
        private bool MayRegisterType(CachedType cachedType)
        {
            if (cachedType.State >= ProcessingState.Registered)
            {
                return(false);
            }

            if (cachedType.State != ProcessingState.CachedExtension)
            {
                throw new InvalidOperationException($"The state of type '{cachedType.Type.Name}' must be" +
                                                    $" '{ProcessingState.CachedExtension}' but is '{cachedType.State}'.");
            }

            var type = cachedType.Type;

            return(type.IsClass && !type.IsAbstract &&
                   (!Options.ProcessOnlyClassesDerivedFromIProcessable || typeof(IProcessable).IsAssignableFrom(type)));
        }
Beispiel #7
0
        private void CacheTypes(CachedAssembly cachedAssembly)
        {
            if (cachedAssembly.TypesAndExtensionsAreCached)
            {
                return;
            }

            foreach (var type in cachedAssembly.Assembly.GetExportedTypes())
            {
                if (Options.ExcludedTypes.Contains(type))
                {
                    Options.Logger?.Log($"Type '{type.Name}' is excluded from processing.");
                }
                else
                {
                    var cachedType = new CachedType(type);
                    CachedTypes.Add(cachedType.Type, cachedType);

                    Statistics.CachedTypes++;
                }
            }
        }