private DocumentsJoinerWorker CreateWorker(DocumentsJoinerConfigurationSection configuration)
        {
            Trace.Listeners.Add(new TextWriterTraceListener("log.txt"));
            var detector = new ZXingBarcodeDetector();
            Func <DocumentsController, SortedDictionary <int, IDocumentHandler> > handlersChainFactory = ctrl =>
            {
                var sorted = new SortedDictionary <int, IDocumentHandler>
                {
                    { 1, new DocumentValidator(configuration.BrokenFilesDirectory) },
                    { 2, new BarCodeHandler(detector, ctrl) },
                    { 3, new ImageHandler(ctrl) },
                };

                return(sorted);
            };
            var fileReader        = new WaitForFile(configuration.AttemptsToOpenFile, configuration.OpeningFilePeriodMs);
            var exceptionsHandler = new ErrorHandler(configuration.BrokenFilesDirectory);
            Func <DocumentsController> controllersFactory
                = () => new DocumentsController(
                      handlersChainFactory,
                      exceptionsHandler,
                      fileReader);
            Func <CancellationToken, IDocumentsJoiner> joinerFactory
                = token => new PdfSharpDocumentsJoiner(token, fileReader);
            var queue = new ChunkedQueue();

            return(new DocumentsJoinerWorker(configuration, controllersFactory, joinerFactory, queue));
        }
 private void SetupDirectories(DocumentsJoinerConfigurationSection config)
 {
     Directory.CreateDirectory(config.BrokenFilesDirectory);
     Directory.CreateDirectory(config.BatchesFolder);
     foreach (var element in config.Watchers.Cast <FolderWatcherConfigurationElement>())
     {
         Directory.CreateDirectory(element.Path);
     }
 }
 private void CleanDirectories(DocumentsJoinerConfigurationSection config)
 {
     Directory.Delete(config.BrokenFilesDirectory, recursive: true);
     Directory.Delete(config.BatchesFolder, recursive: true);
     foreach (var element in config.Watchers.Cast <FolderWatcherConfigurationElement>())
     {
         Directory.Delete(element.Path, recursive: true);
     }
 }
 public DocumentsJoinerWorker(
     DocumentsJoinerConfigurationSection configuration,
     Func <DocumentsController> documentsControllerFactory,
     Func <CancellationToken, IDocumentsJoiner> documentsJoinerFactory)
 {
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     this.documentsControllerFactory
         = documentsControllerFactory ?? throw new ArgumentNullException(nameof(documentsControllerFactory));
     this.documentsJoinerFactory = documentsJoinerFactory ?? throw new ArgumentNullException(nameof(documentsJoinerFactory));
     Initialize();
 }
Example #5
0
        private void UpdateConfiguration(object state)
        {
            var prevCfg = DocumentsJoinerConfiguration;

            ConfigurationManager.RefreshSection(DOCUMENTS_JOINER_CONFIGURATION);
            var cfg = (DocumentsJoinerConfigurationSection)ConfigurationManager
                      .GetSection(DOCUMENTS_JOINER_CONFIGURATION);

            if (prevCfg.Timeout != cfg.Timeout ||
                prevCfg.AttemptsToOpenFile != cfg.AttemptsToOpenFile ||
                prevCfg.BarcodeSeparatorValue != cfg.BarcodeSeparatorValue ||
                prevCfg.BatchesFolder != cfg.BatchesFolder ||
                prevCfg.BrokenFilesDirectory != cfg.BrokenFilesDirectory ||
                prevCfg.OpeningFilePeriodMs != cfg.OpeningFilePeriodMs ||
                !prevCfg.Watchers.Equals(cfg.Watchers))
            {
                DocumentsJoinerConfiguration = cfg;
                OnPropertyChanged(nameof(DocumentsJoinerConfiguration));
            }
        }