public void BuildOutputData(FileContentDto fileContent)
        {
            try
            {
                _outputData = new OutputDataDto
                {
                    FileName         = fileContent.InputFile.FileName
                    , FileExtension  = fileContent.InputFile.FileExtension
                    , GenerationDate = DateTime.Now
                }
                .GetCustomersQuantity(fileContent)
                .GetSalesmenQuantity(fileContent)
                .GetIdFromMostExpensiveSale(fileContent
                                            , _context)
                .GetWorstSalesman(fileContent);

                _clientPublisher.Publish(_outputData
                                         , _configuration["RabbitMqHostName"]
                                         , _configuration["RabbitMqUsername"]
                                         , _configuration["RabbitMqPassword"]
                                         , int.Parse(_configuration["RabbitMqRetryCount"])
                                         , _configuration["RabbitMqPublishQueueName"]);
            }
            catch (Exception exception)
            {
                _logger.LogCritical("An unexpected exception occurred when building output data object");
                _logger.LogCritical("Exception: {message}", exception.Message);
                _logger.LogTrace(exception.Message);
            }
        }
        private void ProcessFileFailed(InputFile inputFile)
        {
            _logger.LogCritical("{FileName} couldn't be processed.", inputFile.FileName);

            _publisher.Publish(inputFile
                               , _configuration["RabbitMqHostnName"]
                               , _configuration["RabbitMqUsername"]
                               , _configuration["RabbitMqPassword"]
                               , int.Parse(_configuration["RabbitMqRetryCount"])
                               , _configuration["RabbitMqFailedQueueName"]);
        }
Esempio n. 3
0
        private void ScanFolder()
        {
            var extensions = GetExtensions();

            var files = _context.InputFiles.ToList();

            var filesInFolder = new DirectoryInfo(_folderPath).GetFiles();

            foreach (var fileInfo in filesInFolder)
            {
                if (!extensions.Any(e => e.Equals(fileInfo.Extension)))
                {
                    continue;
                }

                if (files.Any(f => f.FileName == fileInfo.Name &&
                              f.FileExtension == fileInfo.Extension &&
                              f.Processed))
                {
                    continue;
                }

                var file = CreateInputFileEntity(fileInfo);

                _context.InputFiles.Add(file);

                _publisher.Publish(file
                                   , _configuration["RabbitMqHostName"]
                                   , _configuration["RabbitMqUsername"]
                                   , _configuration["RabbitMqPassword"]
                                   , int.Parse(_configuration["RabbitMqRetryCount"])
                                   , _configuration["RabbitMqPublishQueueName"]);
            }

            var saved = _context.SaveAsync();
        }