|
@@ -11,6 +11,16 @@ using System.Text;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
|
+ public class CreateTableArgs
|
|
|
+ {
|
|
|
+ public Stream Stream { get; set; }
|
|
|
+
|
|
|
+ public CreateTableArgs(Stream stream)
|
|
|
+ {
|
|
|
+ Stream = stream;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public class LoadDataArgs
|
|
|
{
|
|
|
public Stream Stream { get; set; }
|
|
@@ -50,7 +60,7 @@ using PRSDesktop;
|
|
|
public class Module
|
|
|
{
|
|
|
// Initialise a table with the necessary columns.
|
|
|
- public CoreTable CreateTable()
|
|
|
+ public CoreTable CreateTable(CreateTableArgs args)
|
|
|
{
|
|
|
var table = new CoreTable();
|
|
|
table.Columns.Add(new CoreColumn { ColumnName = ..., DataType = typeof(string) });
|
|
@@ -78,6 +88,7 @@ public class Module
|
|
|
#region Script
|
|
|
|
|
|
private ScriptDocument? _script;
|
|
|
+
|
|
|
private ScriptDocument? Script
|
|
|
{
|
|
|
get
|
|
@@ -173,7 +184,12 @@ public class Module
|
|
|
[MemberNotNullWhen(true, nameof(_table))]
|
|
|
public override bool ReadHeader()
|
|
|
{
|
|
|
- _table = CreateTableMethod.Invoke(ScriptObject, Array.Empty<object?>()) as CoreTable;
|
|
|
+ if (_stream is null)
|
|
|
+ {
|
|
|
+ throw new Exception("Cannot read header before Open() is called.");
|
|
|
+ }
|
|
|
+ var args = new CreateTableArgs(_stream);
|
|
|
+ _table = CreateTableMethod.Invoke(ScriptObject, new object[] { args }) as CoreTable;
|
|
|
if(_table is not null)
|
|
|
{
|
|
|
Fields = _table.Columns.Select(x => x.ColumnName).ToArray();
|
|
@@ -211,19 +227,9 @@ public class Module
|
|
|
{
|
|
|
EnsureData();
|
|
|
var row = _table.Rows[rowIdx];
|
|
|
- return Mappings.ToDictionary(
|
|
|
- x => x.Property,
|
|
|
- x =>
|
|
|
- {
|
|
|
- if (!string.IsNullOrWhiteSpace(x.Field))
|
|
|
- {
|
|
|
- return row[x.Field]?.ToString() ?? "";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return x.Constant;
|
|
|
- }
|
|
|
- });
|
|
|
+ return _table.Columns.ToDictionary(
|
|
|
+ x => x.ColumnName,
|
|
|
+ x => row[x.ColumnName]?.ToString() ?? "");
|
|
|
}
|
|
|
}
|
|
|
}
|