Skip to content

Commit

Permalink
Merge pull request #24 from dynamicweb/mss/19672-JobCulture
Browse files Browse the repository at this point in the history
made ExportCultureInfo Obsolete and changed logic in runjob to get cu…
  • Loading branch information
frederik5480 authored May 31, 2024
2 parents baae447 + dab2143 commit 1f0d2b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
30 changes: 13 additions & 17 deletions src/CSVProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public string DestinationQuoteCharacter
[AddInParameter("Destination encoding"), AddInParameterEditor(typeof(DropDownParameterEditor), "none=true"), AddInParameterGroup("Destination")]
public string DestinationEncoding { get; set; }

[AddInParameter("Destination format culture"), AddInParameterEditor(typeof(DropDownParameterEditor), "none=false"), AddInParameterGroup("Destination")]
public string ExportCultureInfo { get; set; } = CultureInfo.CurrentCulture.Name;
[Obsolete("Use job.Culture")]
public string ExportCultureInfo { get; set; }

[AddInParameter("Source decimal separator"), AddInParameterEditor(typeof(DropDownParameterEditor), "none=false"), AddInParameterGroup("Source")]
public string SourceDecimalSeparator
Expand Down Expand Up @@ -346,7 +346,6 @@ void IDestination.SaveAsXml(XmlTextWriter xmlTextWriter)
xmlTextWriter.WriteElementString("DestinationEncoding", DestinationEncoding);
}
xmlTextWriter.WriteElementString("SourceDecimalSeparator", _sourceDecimalSeparator);
xmlTextWriter.WriteElementString("ExportCultureInfo", ExportCultureInfo);
xmlTextWriter.WriteElementString("IncludeTimestampInFileName", IncludeTimestampInFileName.ToString(CultureInfo.CurrentCulture));
(this as IDestination).GetSchema().SaveAsXml(xmlTextWriter);
}
Expand Down Expand Up @@ -432,12 +431,6 @@ public CsvProvider(XmlNode xmlNode)
_sourceDecimalSeparator = node.FirstChild.Value;
}
break;
case "ExportCultureInfo":
if (node.HasChildNodes)
{
ExportCultureInfo = node.FirstChild.Value;
}
break;
case "DeleteSourceFiles":
if (node.HasChildNodes)
{
Expand Down Expand Up @@ -517,7 +510,6 @@ public override string Serialize()
root.Add(CreateParameterNode(GetType(), "Output string delimiter", DestinationQuoteCharacter.ToString(CultureInfo.CurrentCulture)));
root.Add(CreateParameterNode(GetType(), "Destination encoding", DestinationEncoding));
root.Add(CreateParameterNode(GetType(), "Source decimal separator", _sourceDecimalSeparator));
root.Add(CreateParameterNode(GetType(), "Destination format culture", ExportCultureInfo));
root.Add(CreateParameterNode(GetType(), "Delete source files", DeleteSourceFiles.ToString()));
root.Add(CreateParameterNode(GetType(), "Include timestamp in filename", IncludeTimestampInFileName.ToString(CultureInfo.CurrentCulture)));
root.Add(CreateParameterNode(GetType(), "Ignore defective rows", IgnoreDefectiveRows.ToString(CultureInfo.CurrentCulture)));
Expand Down Expand Up @@ -545,7 +537,6 @@ public override void UpdateDestinationSettings(IDestination destination)
_fieldDelimiter = newProvider._fieldDelimiter;
_quoteChar = newProvider._quoteChar;
DestinationEncoding = newProvider.DestinationEncoding;
ExportCultureInfo = newProvider.ExportCultureInfo;
IncludeTimestampInFileName = newProvider.IncludeTimestampInFileName;
}

Expand All @@ -555,7 +546,7 @@ public override bool RunJob(Job job)
Dictionary<string, object> sourceRow = null;
try
{
CultureInfo ci = GetCultureInfo();
CultureInfo ci = GetCultureInfo(job.Culture);

if (_destinationWriters == null)
{
Expand Down Expand Up @@ -622,9 +613,17 @@ private Encoding GetEncoding(string encoding)
return result;
}

private CultureInfo GetCultureInfo()
private CultureInfo GetCultureInfo(string culture)
{
return CultureInfo.GetCultureInfo(ExportCultureInfo) ?? CultureInfo.CurrentCulture;
try
{
return string.IsNullOrWhiteSpace(culture) ? CultureInfo.CurrentCulture : CultureInfo.GetCultureInfo(culture);
}
catch (CultureNotFoundException ex)
{
Logger?.Log(string.Format("Error getting culture: {0}. Using {1} instead", ex.Message, CultureInfo.CurrentCulture.Name));
}
return CultureInfo.CurrentCulture;
}

private string GetSourceFile()
Expand Down Expand Up @@ -724,9 +723,6 @@ public void WriteToSourceFile(string InputXML)
new(".", "."),
new(",", ",")
},
"Destination format culture" => CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Where(obj => !string.IsNullOrEmpty(obj.Name))
.Select(c => new ParameterOption(c.DisplayName, c.Name)),
_ => new List<ParameterOption>()
{
new("Unicode (UTF-8)", "UTF8"),
Expand Down
8 changes: 4 additions & 4 deletions src/Dynamicweb.DataIntegration.Providers.CsvProvider.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.11</Version>
<Version>10.4.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>CSV Provider</Title>
<Description>CSV Provider</Description>
Expand All @@ -14,7 +14,7 @@
<Copyright>Copyright © 2023 Dynamicweb Software A/S</Copyright>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -24,8 +24,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CsvHelper" Version="31.0.4" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.0.0" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.0.0" />
<PackageReference Include="Dynamicweb.DataIntegration" Version="10.4.0" />
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.4.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>

0 comments on commit 1f0d2b8

Please sign in to comment.