Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mss/16537 #23

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading