Beispiel #1
0
 public UserRepository(IOptions <CatalogOptions> options)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     _options = options.Value;
 }
        public static ElasticsearchOptions GetElasticsearchOptions(
            this IConfiguration configuration)
        {
            var options = new CatalogOptions();

            configuration.GetSection(CatalogOptions.SectionName).Bind(options);
            return(options.Elasticsearch);
        }
Beispiel #3
0
 public CatalogDbContext(DbContextOptions <CatalogDbContext> options, IOptions <CatalogOptions> catalogOptions) : base(options)
 {
     if (catalogOptions == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     _catalogOptions = catalogOptions.Value;
 }
 public SaleRepository(IOptions <CatalogOptions> options, CatalogDbContext context)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     _options = options.Value;
     _context = context;
 }
Beispiel #5
0
        private static int RunOptionsAndReturnExitCode(CatalogOptions opts)
        {
            var pathToCheck = opts.InputPath;

            Console.WriteLine($"Checking path: '{opts.InputPath}' and saving catalog to '{opts.CatalogFilename}'.");
            Console.WriteLine("\nStarting catalog...");
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            int    filesProcessed = 0;
            string lastFile       = null;
            bool   running        = true;
            var    progressTask   = Task.Run(() =>
            {
                do
                {
                    if (!running)
                    {
                        break;
                    }
                    Console.Clear();
                    Console.WriteLine($"Files processed: {filesProcessed}");
                    Console.WriteLine($"Current file: {lastFile}");
                    System.Threading.Thread.Sleep(500);
                } while (running);
            });
            Action <FileInformation> trackProgress = (info) =>
            {
                System.Threading.Interlocked.Increment(ref filesProcessed);
                lastFile = info.AbsolutePath;
            };
            var co    = new CatalogOperation(opts.InputPath, trackProgress);
            var files = co.Run().ToList();

            running = false;
            var timeToIndex = sw.ElapsedMilliseconds;

            progressTask.GetAwaiter().GetResult();
            Console.WriteLine("Time to index: {0} files.  {1}ms", files.Count, timeToIndex);
            var duplicates = files.GroupBy(zz => zz.MD5Hash).Where(zz => zz.Count() > 1).ToList();

            Console.WriteLine($"{duplicates.Count()} sets of duplicates.");
            foreach (var f in duplicates)
            {
                var md5String = f.First().MD5Hash;
                Console.WriteLine($"{md5String} - {f.Count()} matching files.");
                Console.WriteLine("\t{0}", string.Join("\r\n\t", f.Select(zz => zz.AbsolutePath)));
            }
            FileInformation.SerializeToDisk(opts.CatalogFilename, files);
            return(0);
        }
Beispiel #6
0
 /// <summary>
 /// Registers FileBasedCatalogProvider to the services collection
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddFileBasedCatalogProvider(this IServiceCollection services, CatalogOptions options)
 {
     if (services == null)
     {
         throw new ArgumentNullException(nameof(services));
     }
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     services.Add(new ServiceDescriptor(typeof(IServiceCatalogProvider), FileBasedCatalogProvider.Create(options)));
     return(services);
 }