This commit is contained in:
@@ -14,6 +14,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using ChoETL;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -80,27 +81,31 @@ namespace AyaNova.Api.Controllers
|
||||
log.LogDebug($"Instantiating biz object handler for {dataListSelection.ObjectType}");
|
||||
var biz = BizObjectFactory.GetBizObject(dataListSelection.ObjectType, ct);
|
||||
log.LogDebug($"Fetching data for {dataListSelection.SelectedRowIds.Length} {dataListSelection.ObjectType} items");
|
||||
var TheData = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
// var TheData = await ((IExportAbleObject)biz).GetJSONExportData(dataListSelection.SelectedRowIds);
|
||||
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{dataListSelection.ObjectType.ToString().ToLowerInvariant()}-{FileUtil.GetSafeDateFileName()}");
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{dataListSelection.ObjectType.ToString().ToLowerInvariant()}-{format}-{FileUtil.GetSafeDateFileName()}");
|
||||
|
||||
// string outputRandomFileNameNoExtension = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "");
|
||||
string outputSourceFileName = baseFileName + "." + format;
|
||||
string outputSourceFullPath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, outputSourceFileName);
|
||||
string outputZipFullpath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, baseFileName + ".zip");
|
||||
// string outputFullPathSourceFile=outputFullPathNoExtension
|
||||
// string outputFullpathZipFile=outputFullPathNoExtension + ".zip";
|
||||
log.LogDebug($"Calling render export data to file");
|
||||
|
||||
log.LogDebug($"Calling render export data to file {outputZipFullpath}");
|
||||
switch (format)
|
||||
{
|
||||
case "csv":
|
||||
throw new System.NotImplementedException("CSV export not implemented yet");
|
||||
case "csv":
|
||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
w.Write(ToDynamicList(dat));
|
||||
}
|
||||
break;
|
||||
case "json":
|
||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||
{
|
||||
TheData.WriteTo(writer);
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
dat.WriteTo(writer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -118,6 +123,18 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
}
|
||||
|
||||
public static IList<dynamic> ToDynamicList(JArray data)
|
||||
{
|
||||
var dynamicData = new List<dynamic>();
|
||||
var expConverter = new Newtonsoft.Json.Converters.ExpandoObjectConverter();
|
||||
|
||||
foreach (var dataItem in data)
|
||||
{
|
||||
dynamic obj = JsonConvert.DeserializeObject<System.Dynamic.ExpandoObject>(dataItem.ToString(), expConverter);
|
||||
dynamicData.Add(obj);
|
||||
}
|
||||
return dynamicData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a rendered Export
|
||||
|
||||
Reference in New Issue
Block a user