Skip to content

Commit

Permalink
Merge pull request #23 from dynamicweb/mss/16537
Browse files Browse the repository at this point in the history
Mss/16537
  • Loading branch information
frederik5480 authored May 16, 2024
2 parents 97fb0ee + b6cd216 commit 4356064
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions src/CSVDestinationWriter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dynamicweb.Core;
using Dynamicweb.DataIntegration.Integration;
using Dynamicweb.DataIntegration.Integration.Interfaces;
using Dynamicweb.DataIntegration.ProviderHelpers;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -68,7 +69,7 @@ public CsvDestinationWriter(string path, Mapping mapping, bool firstRowContainsC
private bool initialized;
private readonly string path;
private readonly Encoding encoding = Encoding.UTF8;
private readonly CultureInfo cultureInfo;
private readonly CultureInfo cultureInfo = CultureInfo.CurrentCulture;
private readonly bool includeTimestampInFileName;

public virtual Mapping Mapping
Expand All @@ -93,22 +94,32 @@ private string GetStringToWrite(Dictionary<string, object> row, ColumnMapping co
{
if (columnMapping.HasScriptWithValue)
{
return quoteChar + columnMapping.GetScriptValue() + quoteChar + fieldDelimiter;
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);
}
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);
}
else
{
value = columnMapping.GetScriptValue();
}

return quoteChar + value + quoteChar + fieldDelimiter;
}
else if (row.TryGetValue(columnMapping.SourceColumn?.Name ?? "", out object rowValue))
{
if (columnMapping.SourceColumn.Type == typeof(DateTime))
{
if (DateTime.TryParse(columnMapping.ConvertInputValueToOutputValue(rowValue)?.ToString(), out var theDateTime))
{
if (cultureInfo != null)
{
return quoteChar + theDateTime.ToString("dd-MM-yyyy HH:mm:ss:fff", cultureInfo) + quoteChar + fieldDelimiter;
}
else
{
return quoteChar + theDateTime.ToString("dd-MM-yyyy HH:mm:ss:fff", CultureInfo.InvariantCulture) + quoteChar + fieldDelimiter;
}
return quoteChar + theDateTime.ToString("dd-MM-yyyy HH:mm:ss:fff", cultureInfo) + quoteChar + fieldDelimiter;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.10</Version>
<Version>10.0.11</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>CSV Provider</Title>
<Description>CSV Provider</Description>
Expand Down

0 comments on commit 4356064

Please sign in to comment.