public DiskLockedFileInformationLoader(FileInformationLoader fileInformationLoader, IFileSystem fileSystem, IOptions <InfrastructureOptions> options)
 {
     _fileInformationLoader = fileInformationLoader;
     _driveLocks            = new ConcurrentDictionary <string, Lazy <SemaphoreSlim> >();
     _fileSystem            = fileSystem;
     _options = options.Value;
 }
Exemple #2
0
 public FileInformationLoader(IFileHasher fileHasher, ILogger <FileInformationLoader> logger, IOptions <InfrastructureOptions> options, IMemoryCache cache)
 {
     _fileHasher = fileHasher;
     _logger     = logger;
     _cache      = cache;
     _options    = options.Value;
 }
        public static InfrastructureOptions UseDefaults(this InfrastructureOptions options)
        {
            options.FileSystemType  = typeof(DefaultFileSystem);
            options.SystemClockType = typeof(DefaultSystemClock);

            return(options);
        }
        public static IServiceCollection AddInfrastructure(
            this IServiceCollection serviceCollection, IConfiguration configuration,
            Action <InfrastructureOptions> optionsHandler)
        {
            Checker.NotNullArgument(configuration, nameof(configuration));
            Checker.NotNullArgument(optionsHandler, nameof(optionsHandler));

            var options = new InfrastructureOptions();

            optionsHandler(options);

            return(AddInfrastructure(serviceCollection, configuration, options));
        }
        public static IServiceCollection AddInfrastructureWithoutAutoload(
            this IServiceCollection serviceCollection, IConfiguration configuration,
            Action <InfrastructureOptions> optionsHandler)
        {
            Checker.NotNullArgument(configuration, nameof(configuration));
            Checker.NotNullArgument(optionsHandler, nameof(optionsHandler));

            var options = new InfrastructureOptions
            {
                RegisterRulesAutomatically                   = false,
                RegisterTransformersAutomatically            = false,
                RegisterCrossCuttingAutomatically            = false,
                RegisterNotificationDispatchersAutomatically = false,
                RegisterLazyGroupsAutomatically              = false
            };

            optionsHandler(options);

            return(AddInfrastructure(serviceCollection, configuration, options));
        }
 public FileContentInfoComparer(IBitmapHashComparer bitmapHashComparer, IOptions <InfrastructureOptions> options)
 {
     _bitmapHashComparer = bitmapHashComparer;
     _options            = options.Value;
 }
 public SimilarityDictionaryFactory(IOptions <InfrastructureOptions> options, IBitmapHashComparer bitmapHashComparer)
 {
     _bitmapHashComparer = bitmapHashComparer;
     _options            = options.Value;
 }
        public static IServiceCollection AddInfrastructure(
            this IServiceCollection serviceCollection, IConfiguration configuration,
            InfrastructureOptions options)
        {
            Checker.NotNullArgument(configuration, nameof(configuration));
            Checker.NotNullArgument(options, nameof(options));
            Checker.NotNullArgument(options.CustomServiceAssemblies,
                                    () => options.CustomServiceAssemblies);

            // Forçamos o carregamento dos assemblies informados.
            //
            // NOTE: Isso é necessário porque o otimizador de compiladores como
            //       Roslyn "removem" referências de objetos não utilizados.
            //       O efeito colateral disto é que mesmo que você tenha um projeto
            //       referenciado mas não utilize explicitamente nenhum objeto dessa
            //       referência, o assembly não estará disponível no AppDomain.
            //       Com isso, não conseguiríamos encontrar objetos para registrar
            //       aqui. Por isso forçamos o carregamos dos assemblies informados aqui.
            options.CustomServiceAssemblies.ToList().ForEach(n => AppDomain.CurrentDomain.Load(n));

            if (options.FileSystemType != null)
            {
                serviceCollection.TryAddScoped(typeof(IFileSystem), options.FileSystemType);
            }

            if (options.SystemClockType != null)
            {
                serviceCollection.TryAddScoped(typeof(ISystemClock), options.SystemClockType);
            }

            serviceCollection.TryAddScoped(typeof(NotificationManager <>));

            if (options.RegisterNotificationDispatchersAutomatically)
            {
                AppDomain.CurrentDomain.AddAllNotificationDispatchers(serviceCollection);
            }

            serviceCollection.TryAddScoped(typeof(ITransformationManager),
                                           options.TransformationManagerType);

            if (options.RegisterTransformersAutomatically)
            {
                AppDomain.CurrentDomain.AddAllTransformers(serviceCollection);
            }

            serviceCollection.TryAddScoped(typeof(IRuleSet <>), typeof(RuleSet <>));

            if (options.RegisterCrossCuttingAutomatically)
            {
                AppDomain.CurrentDomain.AddCrossCuttingRegistrar(serviceCollection, configuration);
            }

            if (options.RegisterRulesAutomatically)
            {
                AppDomain.CurrentDomain.AddAllRules(serviceCollection);
            }

            serviceCollection.TryAddScoped(typeof(ILazy <>), options.LazyResolverType);

            if (options.RegisterLazyGroupsAutomatically)
            {
                AppDomain.CurrentDomain.AddAllLazyGroups(serviceCollection);
            }

            return(serviceCollection);
        }