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
+5 -2
View File
@@ -49,6 +49,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BI\Config\OrganisationAddress.cs" />
<Compile Include="Exporting\ExportFieldMetadata.cs" />
<Compile Include="Exporting\ExportFormat.cs" />
<Compile Include="Exporting\IExportRecord.cs" />
<Compile Include="Services\Expressions\Extensions\ImageExpressionFormat.cs" />
<Compile Include="ClientServices\EnrolmentInformation\BaseBoard.cs" />
<Compile Include="ClientServices\EnrolmentInformation\Battery.cs" />
@@ -66,13 +69,13 @@
<Compile Include="ClientServices\EnrolmentInformation\WirelessProfileStore.cs" />
<Compile Include="ClientServices\EnrolmentInformation\WirelessProfileTransformation.cs" />
<Compile Include="Repository\Device\DeviceBatchAttachment.cs" />
<Compile Include="Services\Devices\Exporting\DeviceExportFieldMetadata.cs" />
<Compile Include="Services\Devices\Importing\IDeviceImportColumn.cs" />
<Compile Include="Services\Devices\Importing\IDeviceImportDataReader.cs" />
<Compile Include="Services\Documents\DocumentField.cs" />
<Compile Include="Services\Documents\DocumentFieldType.cs" />
<Compile Include="Services\Documents\DocumentTemplatePackage.cs" />
<Compile Include="Services\Documents\OnImportUserFlagRule.cs" />
<Compile Include="Exporting\IExportOptions.cs" />
<Compile Include="Services\Jobs\LocationModes.cs" />
<Compile Include="ClientServices\EnrolmentInformation\Certificate.cs" />
<Compile Include="ClientServices\Register.cs" />
@@ -126,7 +129,7 @@
<Compile Include="Repository\User\UserDetail.cs" />
<Compile Include="Repository\User\AuthorizationRole.cs" />
<Compile Include="Services\Devices\Exporting\DeviceExportRecord.cs" />
<Compile Include="Services\Devices\Exporting\DeviceExportResult.cs" />
<Compile Include="Exporting\ExportResult.cs" />
<Compile Include="Services\Devices\Exporting\DeviceExportTypes.cs" />
<Compile Include="Services\Devices\Exporting\DeviceExportOptions.cs" />
<Compile Include="Services\Devices\Importing\DeviceImportFieldTypes.cs" />
@@ -1,16 +1,16 @@
using System;
namespace Disco.Models.Services.Devices.Exporting
namespace Disco.Models.Exporting
{
public class DeviceExportFieldMetadata
public class ExportFieldMetadata<T> where T : IExportRecord
{
public string Name { get; set; }
public string ColumnName { get; set; }
public Type ValueType { get; set; }
public Func<DeviceExportRecord, object> Accessor { get; set; }
public Func<T, object> Accessor { get; set; }
public Func<object, string> CsvEncoder { get; set; }
public DeviceExportFieldMetadata(string name, Type valueType, Func<DeviceExportRecord, object> accessor, Func<object, string> csvEncoder)
public ExportFieldMetadata(string name, Type valueType, Func<T, object> accessor, Func<object, string> csvEncoder)
{
Name = name;
ValueType = valueType;
@@ -18,7 +18,7 @@ namespace Disco.Models.Services.Devices.Exporting
CsvEncoder = csvEncoder;
}
public DeviceExportFieldMetadata(string name, string columnName, Type valueType, Func<DeviceExportRecord, object> accessor, Func<object, string> 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
{
}
}
@@ -1,13 +1,18 @@
using System.ComponentModel.DataAnnotations;
using Disco.Models.Exporting;
using Disco.Models.Services.Exporting;
using System.ComponentModel.DataAnnotations;
namespace Disco.Models.Services.Devices.Exporting
{
public class DeviceExportOptions
public class DeviceExportOptions : IExportOptions
{
public DeviceExportTypes ExportType { get; set; }
public int? ExportTypeTargetId { get; set; }
public bool ExcelFormat { get; set; }
public ExportFormat Format { get; set; }
public string FilenamePrefix { get; } = "DiscoDeviceExport";
public string ExcelWorksheetName { get; } = "DeviceExport";
public string ExcelTableName { get; } = "Devices";
// Device
[Display(ShortName = "Device", Name = "Serial Number", Description = "The device serial number")]
@@ -136,7 +141,7 @@ namespace Disco.Models.Services.Devices.Exporting
return new DeviceExportOptions()
{
ExportType = DeviceExportTypes.All,
ExcelFormat = true,
Format = ExportFormat.Xlsx,
DeviceSerialNumber = true,
ModelId = true,
ProfileId = true,
@@ -1,11 +1,12 @@
using Disco.Models.ClientServices.EnrolmentInformation;
using Disco.Models.Exporting;
using Disco.Models.Repository;
using System;
using System.Collections.Generic;
namespace Disco.Models.Services.Devices.Exporting
{
public class DeviceExportRecord
public class DeviceExportRecord : IExportRecord
{
public Device Device { get; set; }
@@ -1,10 +0,0 @@
using System.IO;
namespace Disco.Models.Services.Devices.Exporting
{
public class DeviceExportResult
{
public MemoryStream Result { get; set; }
public int RecordCount { get; set; }
}
}
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Disco.Models.Services.Devices.Exporting
namespace Disco.Models.Services.Devices.Exporting
{
public enum DeviceExportTypes
{
+2 -1
View File
@@ -1,4 +1,5 @@
using Disco.Models.Services.Devices.Exporting;
using Disco.Models.Services.Exporting;
using System.Collections.Generic;
namespace Disco.Models.UI.Device
@@ -8,7 +9,7 @@ namespace Disco.Models.UI.Device
DeviceExportOptions Options { get; set; }
string ExportSessionId { get; set; }
DeviceExportResult ExportSessionResult { get; set; }
ExportResult ExportSessionResult { get; set; }
IEnumerable<KeyValuePair<int, string>> DeviceBatches { get; set; }
IEnumerable<KeyValuePair<int, string>> DeviceModels { get; set; }