Beispiel #1
0
        public async Task Handle(TimerEvent @event)
        {
            try
            {
                var newFileStatus = await _fileStatusService.GetByNameAsync("NewFile");

                var inProcessingStatus = await _fileStatusService.GetByNameAsync("InProcessing");

                var processingFailStatus = await _fileStatusService.GetByNameAsync("ProcessingFail");

                var metadata = await _fileMetadataService.GetByStatusIdAsync(newFileStatus.Id, _filesReadingLimit);

                await SetStatuses(metadata, inProcessingStatus.Id);

                foreach (var item in metadata)
                {
                    try
                    {
                        var models = await _filesService.ReadFromFileAsync(item.Path);

                        await _mongoService.AddRangeAsync(models);

                        await DeleteFile(item);

                        LoggerExtensions.LogInfo($"File <{item.Path}> was successfully moved to MongoDB");
                    }
                    catch (Exception ex)
                    {
                        LoggerExtensions.LogError($"Exception: {ex.GetType().Name} | Message: {ex.Message} | File: {item.Path} | StackTrace: {ex.StackTrace}");
                        item.StatusId = processingFailStatus.Id;
                        await _fileMetadataService.UpdateAsync(item);
                    }
                }
            }
            catch (InvalidDataException ex)
            {
                LoggerExtensions.LogError($"Exception: {ex.GetType().Name} | Message: {ex.Message} | StackTrace: {ex.StackTrace}");
            }
            catch (Exception ex)
            {
                LoggerExtensions.LogError($"Exception: {ex.GetType().Name} | Message: {ex.Message} | StackTrace: {ex.StackTrace}");
            }
        }
        public async void GetByNameAsync_ExistingName_RightStatus()
        {
            var result = await _fileStatusesService.GetByNameAsync(_statuses[0].Status);

            Assert.Equal(1, result.Id);
        }