This commit is contained in:
@@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using ChoETL;
|
||||
using System;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -99,36 +100,43 @@ namespace AyaNova.Api.Controllers
|
||||
string outputZipFullpath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, baseFileName + ".zip");
|
||||
|
||||
log.LogDebug($"Calling render export data to file {outputZipFullpath}");
|
||||
switch (format)
|
||||
try
|
||||
{
|
||||
case "csv":
|
||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest);
|
||||
w.Write(ToDynamicList(dat));
|
||||
}
|
||||
break;
|
||||
case "json":
|
||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest);
|
||||
dat.WriteTo(writer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (format)
|
||||
{
|
||||
case "csv":
|
||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest, DateTime.UtcNow.AddMinutes(ServerBootConfig.AYANOVA_REPORT_RENDERING_TIMEOUT));
|
||||
w.Write(ToDynamicList(dat));
|
||||
}
|
||||
break;
|
||||
case "json":
|
||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest, DateTime.UtcNow.AddMinutes(ServerBootConfig.AYANOVA_REPORT_RENDERING_TIMEOUT));
|
||||
dat.WriteTo(writer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//zip it
|
||||
using (FileStream fs = new FileStream(outputZipFullpath, FileMode.Create))
|
||||
using (ZipArchive arch = new ZipArchive(fs, ZipArchiveMode.Create))
|
||||
//zip it
|
||||
using (FileStream fs = new FileStream(outputZipFullpath, FileMode.Create))
|
||||
using (ZipArchive arch = new ZipArchive(fs, ZipArchiveMode.Create))
|
||||
{
|
||||
arch.CreateEntryFromFile(outputSourceFullPath, outputSourceFileName);
|
||||
}
|
||||
|
||||
log.LogDebug($"Completed, returning results");
|
||||
return Ok(ApiOkResponse.Response(baseFileName + ".zip"));
|
||||
}
|
||||
catch (ReportRenderTimeOutException)
|
||||
{
|
||||
arch.CreateEntryFromFile(outputSourceFullPath, outputSourceFileName);
|
||||
log.LogInformation($"RenderExport timeout data list key: {selectedRequest.DataListKey}, record count:{selectedRequest.SelectedRowIds.LongLength}, user:{UserNameFromContext.Name(HttpContext.Items)} ");
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "timeout - select fewer records"));
|
||||
}
|
||||
|
||||
log.LogDebug($"Completed, returning results");
|
||||
return Ok(ApiOkResponse.Response(baseFileName + ".zip"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static IList<dynamic> ToDynamicList(JArray data)
|
||||
|
||||
Reference in New Issue
Block a user