public async Task SaveAsync(DataFeed dataFeed) { var text = mapper.Map(dataFeed); string fileName = $"{FilePrefix}{dataFeed.GetDataFeedDateTime():yyyyMMddHHmmss}"; var tmpFilePath = Path.Combine(configuration.StorageFolderPath, $"{fileName}{TempFileExtension}"); if (!Directory.Exists(configuration.StorageFolderPath)) { Directory.CreateDirectory(configuration.StorageFolderPath); } var filePath = Path.Combine(configuration.StorageFolderPath, $"{fileName}{FileExtension}"); if (File.Exists(filePath)) { return; } using (var writer = new StreamWriter(tmpFilePath)) { await writer.WriteAsync(text); } File.Move(tmpFilePath, filePath); }