Skip to content

Commit

Permalink
merged master into branch to handle conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasSort committed Jun 3, 2024
2 parents 6541d98 + 3651429 commit a348ed9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Call common build and push

on:
push:
branches: [ "main" ]
branches: [ "main", "milestones/*" ]

jobs:
call-pushworkflow:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- milestones/*

jobs:
call-workflow:
Expand Down
39 changes: 16 additions & 23 deletions src/ExcelDestinationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,42 @@ public virtual void Write(Dictionary<string, object> 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);
}

Expand Down
47 changes: 25 additions & 22 deletions src/ExcelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public string DestinationFile

public override Schema GetOriginalDestinationSchema()
{
return GetSchema();
return schema = new Schema();
}

public override bool SchemaIsEditable => true;
Expand Down Expand Up @@ -97,7 +97,7 @@ public override Schema GetOriginalSourceSchema()
return result;
}

private string workingDirectory;
private string workingDirectory = SystemInformation.MapPath("/Files/");
public override string WorkingDirectory
{
get
Expand Down Expand Up @@ -129,7 +129,6 @@ public override void UpdateSourceSettings(ISource source)
{
ExcelProvider newProvider = (ExcelProvider)source;
SourceFile = newProvider.SourceFile;
DestinationFolder = newProvider.DestinationFolder;
}

public override string Serialize()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -277,12 +281,12 @@ private void GetSchemaForTableFromFile(Schema schema, Dictionary<string, ExcelRe
columnCount = dt.Columns.Count;
}
foreach (System.Data.DataColumn c in dt.Columns)
{
{
Column column = new Column(c.ColumnName, c.DataType, excelTable);
if(!string.IsNullOrEmpty(c.Caption) && !string.Equals(c.Caption, c.ColumnName, StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrEmpty(c.Caption) && !string.Equals(c.Caption, c.ColumnName, StringComparison.OrdinalIgnoreCase))
{
column.NameWithWhitespaceStripped = c.Caption;
}
}
excelTable.AddColumn(column);
}

Expand All @@ -298,12 +302,15 @@ private void GetSchemaForTableFromFile(Schema schema, Dictionary<string, ExcelRe
}
}

public override Schema GetSchema()
Schema IDestination.GetSchema()
{
if (schema == null)
{
schema = GetOriginalSourceSchema();
}
schema ??= new Schema();
return schema;
}

Schema ISource.GetSchema()
{
schema ??= GetOriginalSourceSchema();
return schema;
}

Expand Down Expand Up @@ -342,16 +349,11 @@ public ExcelProvider(XmlNode xmlNode)
DestinationFolder = node.FirstChild.Value;
}
break;
case "WorkingDirectory":
if (node.HasChildNodes)
{
WorkingDirectory = node.FirstChild.Value;
}
break;

}
}
}

internal ExcelProvider(Dictionary<string, ExcelReader> excelReaders, Schema schema, ExcelDestinationWriter writer)
{
this.schema = schema;
Expand All @@ -370,6 +372,7 @@ public override void OverwriteSourceSchemaToOriginal()

public override void OverwriteDestinationSchemaToOriginal()
{
schema = new Schema();
}

public override string ValidateDestinationSettings()
Expand Down

0 comments on commit a348ed9

Please sign in to comment.