This commit is contained in:
@@ -15,6 +15,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using ChoETL;
|
using ChoETL;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace AyaNova.Api.Controllers
|
namespace AyaNova.Api.Controllers
|
||||||
{
|
{
|
||||||
@@ -99,36 +100,43 @@ namespace AyaNova.Api.Controllers
|
|||||||
string outputZipFullpath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, baseFileName + ".zip");
|
string outputZipFullpath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, baseFileName + ".zip");
|
||||||
|
|
||||||
log.LogDebug($"Calling render export data to file {outputZipFullpath}");
|
log.LogDebug($"Calling render export data to file {outputZipFullpath}");
|
||||||
switch (format)
|
try
|
||||||
{
|
{
|
||||||
case "csv":
|
switch (format)
|
||||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
{
|
||||||
{
|
case "csv":
|
||||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest);
|
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||||
w.Write(ToDynamicList(dat));
|
{
|
||||||
}
|
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest, DateTime.UtcNow.AddMinutes(ServerBootConfig.AYANOVA_REPORT_RENDERING_TIMEOUT));
|
||||||
break;
|
w.Write(ToDynamicList(dat));
|
||||||
case "json":
|
}
|
||||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
break;
|
||||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
case "json":
|
||||||
{
|
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||||
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest);
|
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||||
dat.WriteTo(writer);
|
{
|
||||||
}
|
var dat = await ((IExportAbleObject)biz).GetExportData(selectedRequest, DateTime.UtcNow.AddMinutes(ServerBootConfig.AYANOVA_REPORT_RENDERING_TIMEOUT));
|
||||||
break;
|
dat.WriteTo(writer);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//zip it
|
//zip it
|
||||||
using (FileStream fs = new FileStream(outputZipFullpath, FileMode.Create))
|
using (FileStream fs = new FileStream(outputZipFullpath, FileMode.Create))
|
||||||
using (ZipArchive arch = new ZipArchive(fs, ZipArchiveMode.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)
|
public static IList<dynamic> ToDynamicList(JArray data)
|
||||||
|
|||||||
Reference in New Issue
Block a user