public void Consume(IProcessingSuccessEvent command)
        {
            _store.Record(command.Client, command.Id, command.Keywords);
            var processEndEvent = new ProcessEndEvent
            {
                DocumentName = command.DocumentName,
                Client       = command.Client
            };

            _manager.SendProcessEndEvent(processEndEvent);
        }
Beispiel #2
0
        public async Task DoWork()
        {
            var directories = _fileShareQuery.GetDirectories(FILESHARE_LOCAL_ROOT);

            foreach (string companyDirectory in directories)
            {
                var fileNames = await _fileShareQuery.GetFileNamesForNetworkLocationAsync(companyDirectory);

                _logger.LogInformation($"Retrieved {fileNames.Count()} files from network path: {companyDirectory}");

                foreach (string fileNameWithPath in fileNames)
                {
                    var fileName = Path.GetFileName(fileNameWithPath);
                    if (fileName.IsValidFileName())
                    {
                        string documentId   = fileName.GetDocumentId();
                        string documentName = fileName.GetDocumentName();
                        var    keywords     = await _fileProcessingService.ProcessFile(fileNameWithPath);

                        if (keywords != null)
                        {
                            await _lookupStore.Record(documentId, documentName, keywords);

                            //future improvement - batch success files and delete after every file has been processed
                            await _fileDeletionService.DeleteFileAsync(fileNameWithPath);
                        }
                        else
                        {
                            _logger.LogWarning($"File processed unsuccesfully: {fileName}, result will not be stored");
                            //future improvement: add retry mechanism for unsuccessful files
                        }
                    }
                    else
                    {
                        _logger.LogWarning($"Invalid filename: {fileName}");
                    }
                }
            }
        }