initial refactor of device export so it can be reused for future exporting

This commit is contained in:
Gary Sharp
2023-11-11 17:52:24 +11:00
parent 46222f2a78
commit a4f18d1d49
24 changed files with 401 additions and 324 deletions
@@ -0,0 +1,27 @@
using System;
namespace Disco.Models.Exporting
{
public class ExportFieldMetadata<T> where T : IExportRecord
{
public string Name { get; set; }
public string ColumnName { get; set; }
public Type ValueType { get; set; }
public Func<T, object> Accessor { get; set; }
public Func<object, string> CsvEncoder { get; set; }
public ExportFieldMetadata(string name, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
{
Name = name;
ValueType = valueType;
Accessor = accessor;
CsvEncoder = csvEncoder;
}
public ExportFieldMetadata(string name, string columnName, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
: this(name, valueType, accessor, csvEncoder)
{
ColumnName = columnName;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace Disco.Models.Exporting
{
public enum ExportFormat
{
Csv,
Xlsx,
}
}
+12
View File
@@ -0,0 +1,12 @@
using System.IO;
namespace Disco.Models.Services.Exporting
{
public class ExportResult
{
public MemoryStream Result { get; set; }
public string Filename { get; set; }
public string MimeType { get; set; }
public int RecordCount { get; set; }
}
}
+12
View File
@@ -0,0 +1,12 @@
using Disco.Models.Exporting;
namespace Disco.Models.Services.Exporting
{
public interface IExportOptions
{
ExportFormat Format { get; }
string FilenamePrefix { get; }
string ExcelWorksheetName { get; }
string ExcelTableName { get; }
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace Disco.Models.Exporting
{
public interface IExportRecord
{
}
}