Beispiel #1
0
        public async Task AddBatchDataFileMessages(
            Guid importId,
            ICollector <ImportObservationsMessage> collector)
        {
            var import = await _dataImportService.GetImport(importId);

            var batchFilesForDataFile = await _batchService.GetBatchFilesForDataFile(import.File);

            // If no batching was necessary, simply add a message to process the lone data file
            if (!batchFilesForDataFile.Any())
            {
                collector.Add(new ImportObservationsMessage
                {
                    Id      = import.Id,
                    BatchNo = 1,
                    ObservationsFilePath = import.File.Path()
                });
                return;
            }

            // Otherwise create a message per batch file to process
            var importBatchFileMessages = batchFilesForDataFile.Select(blobInfo =>
            {
                var batchFileName = blobInfo.FileName;
                var batchFilePath = blobInfo.Path;
                var batchNo       = GetBatchNumberFromBatchFileName(batchFileName);

                return(new ImportObservationsMessage
                {
                    Id = import.Id,
                    BatchNo = batchNo,
                    ObservationsFilePath = batchFilePath
                });
            });

            foreach (var importMessage in importBatchFileMessages)
            {
                collector.Add(importMessage);
            }
        }