diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c09122..8f23ade 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: Call common build and push on: push: - branches: [ "main" ] + branches: [ "main", "milestones/*" ] jobs: call-pushworkflow: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index cd436b9..d2dd4c6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - milestones/* jobs: call-workflow: diff --git a/src/ExcelDestinationWriter.cs b/src/ExcelDestinationWriter.cs index 07de069..0f85d51 100644 --- a/src/ExcelDestinationWriter.cs +++ b/src/ExcelDestinationWriter.cs @@ -90,49 +90,42 @@ public virtual void Write(Dictionary row) { if (columnMapping.HasScriptWithValue) { - string value; if (columnMapping.SourceColumn.Type == typeof(DateTime)) { - DateTime theDate = DateTime.Parse(columnMapping.GetScriptValue()); - value = theDate.ToString("dd-MM-yyyy HH:mm:ss:fff", _cultureInfo); + DateTime theDate = DateTime.Parse(columnMapping.GetScriptValue(), CultureInfo.InvariantCulture); + r[columnMapping.DestinationColumn.Name] = theDate.ToString("dd-MM-yyyy HH:mm:ss:fff", _cultureInfo); } else if (columnMapping.SourceColumn.Type == typeof(decimal) || columnMapping.SourceColumn.Type == typeof(double) || columnMapping.SourceColumn.Type == typeof(float)) { - value = ValueFormatter.GetFormattedValue(columnMapping.GetScriptValue(), _cultureInfo, columnMapping.ScriptType, columnMapping.ScriptValue); + r[columnMapping.DestinationColumn.Name] = ValueFormatter.GetFormattedValue(columnMapping.GetScriptValue(), _cultureInfo, columnMapping.ScriptType, columnMapping.ScriptValue); } else { - value = columnMapping.GetScriptValue(); + r[columnMapping.DestinationColumn.Name] = columnMapping.GetScriptValue(); } - - r[columnMapping.DestinationColumn.Name] = value; } - else if (row.TryGetValue(columnMapping.SourceColumn?.Name ?? "", out object rowValue)) + else if (row[columnMapping.SourceColumn.Name] == DBNull.Value) { - if (columnMapping.SourceColumn.Type == typeof(DateTime)) - { - if (DateTime.TryParse(columnMapping.ConvertInputValueToOutputValue(rowValue)?.ToString(), out var theDateTime)) - { - r[columnMapping.DestinationColumn.Name] = theDateTime.ToString("dd-MM-yyyy HH:mm:ss:fff", _cultureInfo); - } - else - { - r[columnMapping.DestinationColumn.Name] = DateTime.MinValue.ToString("dd-MM-yyyy HH:mm:ss:fff", CultureInfo.InvariantCulture); - } - } - if (rowValue == DBNull.Value) + r[columnMapping.DestinationColumn.Name] = "NULL"; + } + else if (columnMapping.SourceColumn.Type == typeof(DateTime)) + { + if (DateTime.TryParse(columnMapping.ConvertInputValueToOutputValue(row[columnMapping.SourceColumn.Name])?.ToString(), out var theDateTime)) { - r[columnMapping.DestinationColumn.Name] = "NULL"; + r[columnMapping.DestinationColumn.Name] = theDateTime.ToString("dd-MM-yyyy HH:mm:ss:fff", _cultureInfo); } else { - r[columnMapping.DestinationColumn.Name] = string.Format(_cultureInfo, "{0}", columnMapping.ConvertInputValueToOutputValue(rowValue)) ?? "NULL"; + r[columnMapping.DestinationColumn.Name] = DateTime.MinValue.ToString("dd-MM-yyyy HH:mm:ss:fff", CultureInfo.InvariantCulture); } } + else + { + r[columnMapping.DestinationColumn.Name] = string.Format(_cultureInfo, "{0}", columnMapping.ConvertInputValueToOutputValue(row[columnMapping.SourceColumn.Name])); + } } - tableForExcel.Rows.Add(r); } diff --git a/src/ExcelProvider.cs b/src/ExcelProvider.cs index f291b59..787e8c2 100644 --- a/src/ExcelProvider.cs +++ b/src/ExcelProvider.cs @@ -49,7 +49,7 @@ public string DestinationFile public override Schema GetOriginalDestinationSchema() { - return GetSchema(); + return schema = new Schema(); } public override bool SchemaIsEditable => true; @@ -97,7 +97,7 @@ public override Schema GetOriginalSourceSchema() return result; } - private string workingDirectory; + private string workingDirectory = SystemInformation.MapPath("/Files/"); public override string WorkingDirectory { get @@ -129,7 +129,6 @@ public override void UpdateSourceSettings(ISource source) { ExcelProvider newProvider = (ExcelProvider)source; SourceFile = newProvider.SourceFile; - DestinationFolder = newProvider.DestinationFolder; } public override string Serialize() @@ -146,13 +145,17 @@ public override string Serialize() return document.ToString(); } - public new virtual void SaveAsXml(XmlTextWriter xmlTextWriter) + void ISource.SaveAsXml(XmlTextWriter xmlTextWriter) { xmlTextWriter.WriteElementString("SourcePath", SourceFile); + (this as ISource).GetSchema().SaveAsXml(xmlTextWriter); + } + + void IDestination.SaveAsXml(XmlTextWriter xmlTextWriter) + { xmlTextWriter.WriteElementString("DestinationFile", DestinationFile); xmlTextWriter.WriteElementString("DestinationFolder", DestinationFolder); - xmlTextWriter.WriteElementString("WorkingDirectory", WorkingDirectory); - GetSchema().SaveAsXml(xmlTextWriter); + (this as IDestination).GetSchema().SaveAsXml(xmlTextWriter); } public new ISourceReader GetReader(Mapping mapping) @@ -184,8 +187,9 @@ public override void Close() public override void UpdateDestinationSettings(IDestination destination) { - ISource newProvider = (ISource)destination; - UpdateSourceSettings(newProvider); + ExcelProvider newProvider = (ExcelProvider)destination; + newProvider.DestinationFile = DestinationFile; + newProvider.DestinationFolder = DestinationFolder; } public override bool RunJob(Job job) @@ -277,12 +281,12 @@ private void GetSchemaForTableFromFile(Schema schema, Dictionary excelReaders, Schema schema, ExcelDestinationWriter writer) { this.schema = schema; @@ -370,6 +372,7 @@ public override void OverwriteSourceSchemaToOriginal() public override void OverwriteDestinationSchemaToOriginal() { + schema = new Schema(); } public override string ValidateDestinationSettings()