Esempio n. 1
0
        public LibraryCataloguer(BookParserConfig configuration, ConcurrentQueue <Exception> exceptions,
                                 IBookParserTrace tracer, Action <int> progress)
        {
            Progress = progress ?? throw new ArgumentNullException(nameof(progress));

            Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            GetMetadataFromFileDictionaryDelegate = new Dictionary <String, Delegate>()
            {
                { ".pdf", new Func <string, BookAtHome>(new PdfTextReaderFileInfoExtractor().GetPocoBook) },
                { ".txt", new Func <string, BookAtHome>(new FileInfoExtractor().GetPocoBook) },
                { ".rtf", new Func <string, BookAtHome>(new RtfFileInfoExtractor().GetPocoBook) },
                { ".epub", new Func <string, BookAtHome>(new EpubFileInfoExtractor().GetPocoBook) },
                { ".lit", new Func <string, BookAtHome>(new LitFileInfoExtractor().GetPocoBook) },
                { ".doc", new Func <string, BookAtHome>(new FileInfoExtractor().GetPocoBook) }
            };


            _mongoServerManager = new MongodbServerManager(Configuration.libraryContext.hostname);

            BooksInLibrary = new BooksCollectedDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            BookToReview = new BookToBeReviewedDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            LibStatistics = new LibraryStatisticsDataMapper(Configuration.libraryContext.hostname, Configuration.libraryContext.databasename);

            _tracer = tracer;

            _exceptions = exceptions;

            Init();
        }
Esempio n. 2
0
        public MongodbConnection(BookParserConfig configuration)
        {
            var mongoUrl = MongoUrl.Create(configuration.libraryContext.connectionstring);

            Client = new MongoClient(mongoUrl);

            Database = Client.GetDatabase(configuration.libraryContext.databasename);
        }
Esempio n. 3
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var configFile = GetConfigFileFromCommandLine(args);

            var configuration = BookParserConfig.FromJson(File.ReadAllText(configFile));

            IBookParserTrace trace = new FileBookParserTrace(configuration.tracefile, configuration.tracelevel);

            using var progress = new ProgressBar();

            var exceptions = new ConcurrentQueue <Exception>();

            LibraryCataloguer cataloger = new LibraryCataloguer(configuration, exceptions, trace, progress);

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                await cataloger.CatalogBooksAsync().ConfigureAwait(false);

                sw.Stop();

                cataloger.CreateStatistics(sw.Elapsed);
            }
            catch (AggregateException ae)
            {
                foreach (var ex in ae.Flatten().InnerExceptions)
                {
                    if (ex is ArgumentException)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Esempio n. 4
0
 public static string ToJson(this BookParserConfig self) => JsonConvert.SerializeObject(self, BooksParser.Converter.Settings);