public void CreateExportDirectory_StateUnderTest_ExpectedBehavior() { string directory = Path.GetTempPath(); string subDirName = "996"; var result = ExportManager.CreateExportDirectory(directory, subDirName); Assert.IsNotNull(result); Assert.AreEqual(Path.Join(directory, "export", subDirName), result); }
private async Task <ExportResult> ToCSVResult <TResult>(IEnumerable <TResult> data, CancellationToken cancellationToken) { var tempId = Guid.NewGuid().ToString(); string exportDirectory = ExportManager.CreateExportDirectory(_directory, tempId); var distPath = Path.Join(exportDirectory, $"{_fileNamePrefix}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.csv"); await using var writer = new StreamWriter(distPath); await using var csv = new CsvWriter(writer, CultureInfo.InvariantCulture); await csv.WriteRecordsAsync(data, cancellationToken); return(new() { ExportFormat = ExportFormat.SingleCSVFile, FilePath = distPath }); }
private async Task <ExportResult> ToZippedJsonResult <TE>(IEnumerable <TE> list) { var tempId = Guid.NewGuid().ToString(); string exportDirectory = ExportManager.CreateExportDirectory(_directory, tempId); foreach (var item in list) { var json = JsonConvert.SerializeObject(item, Formatting.Indented); // JsonSerializer.Serialize(item); await SaveJsonToDirectory(json, Path.Join(exportDirectory, tempId), $"{Guid.NewGuid()}.json"); } var distPath = Path.Join(exportDirectory, $"{_fileNamePrefix}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.zip"); ZipFile.CreateFromDirectory(Path.Join(exportDirectory, tempId), distPath); return(new() { ExportFormat = ExportFormat.ZippedJsonFiles, FilePath = distPath }); }
private async Task <ExportResult> ToZippedJsonResult <TE>(IEnumerable <TE> list, CancellationToken cancellationToken) { var tempId = Guid.NewGuid().ToString(); string exportDirectory = ExportManager.CreateExportDirectory(_directory, tempId); foreach (var item in list) { var json = JsonSerializer.Serialize(item, MoongladeJsonSerializerOptions.Default); await SaveJsonToDirectory(json, exportDirectory, $"{Guid.NewGuid()}.json", cancellationToken); } var distPath = Path.Join(_directory, "export", $"{_fileNamePrefix}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.zip"); ZipFile.CreateFromDirectory(exportDirectory, distPath); return(new() { ExportFormat = ExportFormat.ZippedJsonFiles, FilePath = distPath }); }