Feature: MS Excel (xlsx) Import/Export
Microsoft Excel files can be used to import/export devices. Several import bugs were also fixed in the process.
This commit is contained in:
@@ -60,6 +60,9 @@
|
||||
<Compile Include="ClientServices\EnrolmentInformation\WirelessProfile.cs" />
|
||||
<Compile Include="ClientServices\EnrolmentInformation\WirelessProfileStore.cs" />
|
||||
<Compile Include="ClientServices\EnrolmentInformation\WirelessProfileTransformation.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\DocumentTemplatePackage.cs" />
|
||||
<Compile Include="Services\Jobs\LocationModes.cs" />
|
||||
<Compile Include="ClientServices\EnrolmentInformation\Certificate.cs" />
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Disco.Models.Services.Devices.Exporting
|
||||
{
|
||||
public class DeviceExportFieldMetadata
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string ColumnName { get; set; }
|
||||
public Type ValueType { get; set; }
|
||||
public Func<DeviceExportRecord, 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)
|
||||
{
|
||||
this.Name = Name;
|
||||
this.ValueType = ValueType;
|
||||
this.Accessor = Accessor;
|
||||
this.CsvEncoder = CsvEncoder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,7 @@ namespace Disco.Models.Services.Devices.Exporting
|
||||
public DeviceExportTypes ExportType { get; set; }
|
||||
public int? ExportTypeTargetId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Adds '=' to the beginning of the string to stop Excel removing the leading zeros
|
||||
/// </summary>
|
||||
public bool ExcelCsvFormat { get; set; }
|
||||
public bool ExcelFormat { get; set; }
|
||||
|
||||
// Device
|
||||
[Display(ShortName = "Device", Name = "Serial Number", Description = "The device serial number")]
|
||||
@@ -135,7 +132,7 @@ namespace Disco.Models.Services.Devices.Exporting
|
||||
return new DeviceExportOptions()
|
||||
{
|
||||
ExportType = DeviceExportTypes.All,
|
||||
ExcelCsvFormat = true,
|
||||
ExcelFormat = true,
|
||||
DeviceSerialNumber = true,
|
||||
ModelId = true,
|
||||
ProfileId = true,
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Disco.Models.Services.Devices.Exporting
|
||||
{
|
||||
public class DeviceExportResult
|
||||
{
|
||||
public MemoryStream CsvResult { get; set; }
|
||||
public MemoryStream Result { get; set; }
|
||||
public int RecordCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
public interface IDeviceImportColumn
|
||||
{
|
||||
int Index { get; }
|
||||
string Name { get; }
|
||||
DeviceImportFieldTypes Type { get; }
|
||||
Type Handler { get; }
|
||||
|
||||
IDeviceImportField GetHandlerInstance();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
@@ -10,11 +7,19 @@ namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
string SessionId { get; }
|
||||
string Filename { get; }
|
||||
List<Tuple<string, DeviceImportFieldTypes>> Header { get; }
|
||||
List<Tuple<string, DeviceImportFieldTypes, Func<string[], string>, Type>> ParsedHeaders { get; }
|
||||
List<string[]> RawData { get; }
|
||||
string DatasetName { get; }
|
||||
int ColumnCount { get; }
|
||||
IEnumerable<IDeviceImportColumn> Columns { get; }
|
||||
IDeviceImportColumn GetColumn(int Index);
|
||||
void SetColumnType(int Index, DeviceImportFieldTypes Type);
|
||||
int? GetColumnByType(DeviceImportFieldTypes FieldType);
|
||||
|
||||
List<IDeviceImportRecord> Records { get; }
|
||||
int AffectedRecords { get; }
|
||||
int RecordCount { get; }
|
||||
|
||||
IDeviceImportDataReader GetDataReader();
|
||||
IEnumerable<KeyValuePair<DeviceImportFieldTypes, Type>> GetFieldHandlers();
|
||||
|
||||
List<IDeviceImportRecord> Records { get; set; }
|
||||
int AffectedRecords { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
public interface IDeviceImportDataReader : IDisposable
|
||||
{
|
||||
void Reset();
|
||||
bool Read();
|
||||
|
||||
int Index { get; }
|
||||
|
||||
int GetRowNumber(int Index);
|
||||
|
||||
string GetString(int ColumnIndex);
|
||||
IEnumerable<string> GetStrings(int ColumnIndex);
|
||||
|
||||
bool TryGetNullableInt(int ColumnIndex, out int? value);
|
||||
|
||||
bool TryGetNullableBool(int ColumnIndex, out bool? value);
|
||||
|
||||
bool TryGetNullableDateTime(int ColumnIndex, out DateTime? value);
|
||||
|
||||
bool TestAllNotEmpty(int ColumnIndex);
|
||||
bool TestAllNullableInt(int ColumnIndex);
|
||||
bool TestAllInt(int ColumnIndex);
|
||||
bool TestAllNullableBool(int ColumnIndex);
|
||||
bool TestAllNullableDateTime(int ColumnIndex);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
|
||||
namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Disco.Models.Services.Devices.Importing
|
||||
{
|
||||
public interface IDeviceImportRecord
|
||||
{
|
||||
int Index { get; }
|
||||
string DeviceSerialNumber { get; }
|
||||
|
||||
IEnumerable<IDeviceImportField> Fields { get; }
|
||||
|
||||
Reference in New Issue
Block a user