示例#1
0
        private async Task ProcessFile(string fileItem)
        {
            //Move the file from Src folder to Processing folder
            var file = _jobStorage.MoveFileToProcessing(fileItem);

            try
            {
                //Parse and serialize csv file
                var products   = _productsCsvParser.Parse(file);
                var jsonString = JsonSerializer.Serialize(products, new JsonSerializerOptions
                {
                    WriteIndented = true
                });

                //get path to destination folder
                string destination = _jobStorage.GetPathToProcessedFolder();
                string filename    = $"{destination}\\{Guid.NewGuid()}.json";

                //store file as json in the destination folder
                await _jsonFileStorageService.StoreAsJson(filename, jsonString);

                _jobStorage.RemoveFileFromProcessing(file.Substring(file.LastIndexOf("\\") + 1));
            }
            catch (Exception)
            {
                string filename = file.Substring(file.LastIndexOf("\\") + 1);
                _jobStorage.MoveFileToFailed(filename);
            }
        }
示例#2
0
        public async Task Handle(FileUploadedEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("JsonTransformer strated.");
            //Move the file from Src folder to Processing folder
            var file = _jobStorage.MoveFileToProcessing(notification.FileName);

            _logger.LogInformation($"Processing {file}");
            try
            {
                //Parse and serialize csv file
                var products   = _productsCsvParser.Parse(file);
                var jsonString = JsonSerializer.Serialize(products, new JsonSerializerOptions {
                    WriteIndented = true
                });

                //get path to destination folder
                string destination = _jobStorage.GetPathToProcessedFolder();
                string filename    = $"{destination}\\{Guid.NewGuid()}.json";

                //store file as json in the destination folder
                await _jsonFileStorageService.StoreAsJson(filename, jsonString);

                _jobStorage.RemoveFileFromProcessing(file.Substring(file.LastIndexOf("\\") + 1));
            }
            catch (Exception e)
            {
                _logger.LogError($"Failed processing {file} , moving file to failed folder", e);

                string filename = file.Substring(file.LastIndexOf("\\") + 1);
                _jobStorage.MoveFileToFailed(filename);
            }
        }