From 765542d227f6d9ce810eb8b1823b2f2f25bd1b00 Mon Sep 17 00:00:00 2001 From: Roberto T <61755417+RobertGlobant20@users.noreply.github.com> Date: Mon, 25 Mar 2024 08:16:23 -0700 Subject: [PATCH] DYN-6619-Localizing Stream Writer Exception2 (#15041) * DYN-6619-Localizing-StreamWriter-Exception (#15001) Localizing System StreamWriter exception * DYN-6619-Localizing-StreamWriter-Exception Localizing System StreamWriter exception --- src/Libraries/DSOffice/CSVNodes.cs | 27 ++-- src/Libraries/DSOffice/DSOffice.csproj | 14 ++ .../DSOffice/Properties/Resources.Designer.cs | 72 ++++++++++ .../DSOffice/Properties/Resources.en-US.resx | 123 ++++++++++++++++++ .../DSOffice/Properties/Resources.resx | 123 ++++++++++++++++++ 5 files changed, 351 insertions(+), 8 deletions(-) create mode 100644 src/Libraries/DSOffice/Properties/Resources.Designer.cs create mode 100644 src/Libraries/DSOffice/Properties/Resources.en-US.resx create mode 100644 src/Libraries/DSOffice/Properties/Resources.resx diff --git a/src/Libraries/DSOffice/CSVNodes.cs b/src/Libraries/DSOffice/CSVNodes.cs index 45b22ff930b..4f4e8c31f52 100644 --- a/src/Libraries/DSOffice/CSVNodes.cs +++ b/src/Libraries/DSOffice/CSVNodes.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using DSOffice.Properties; namespace DSOffice { @@ -20,20 +21,30 @@ public static partial class Data /// write,text,file public static void ExportCSV(string filePath, object[][] data) { - using (var writer = new StreamWriter(DSCore.IO.FileSystem.AbsolutePath(filePath))) + try { - foreach (var line in data) + using (var writer = new StreamWriter(DSCore.IO.FileSystem.AbsolutePath(filePath))) { - int count = 0; - foreach (var entry in line) + foreach (var line in data) { - writer.Write(entry); - if (++count < line.Length) - writer.Write(","); + int count = 0; + foreach (var entry in line) + { + writer.Write(entry); + if (++count < line.Length) + writer.Write(","); + } + writer.WriteLine(); } - writer.WriteLine(); } } + catch (Exception ex) + { + if (ex is DirectoryNotFoundException) + throw new Exception(Resources.StreamWriterNotFoundException); + else + throw; + } } /// diff --git a/src/Libraries/DSOffice/DSOffice.csproj b/src/Libraries/DSOffice/DSOffice.csproj index d01d11d7444..3041e7addb3 100644 --- a/src/Libraries/DSOffice/DSOffice.csproj +++ b/src/Libraries/DSOffice/DSOffice.csproj @@ -26,6 +26,11 @@ + + True + True + Resources.resx + @@ -53,6 +58,15 @@ CoreNodes + + + ResXFileCodeGenerator + + + ResXFileCodeGenerator + Resources.Designer.cs + + diff --git a/src/Libraries/DSOffice/Properties/Resources.Designer.cs b/src/Libraries/DSOffice/Properties/Resources.Designer.cs new file mode 100644 index 00000000000..c54680ab6d7 --- /dev/null +++ b/src/Libraries/DSOffice/Properties/Resources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DSOffice.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DSOffice.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to The file or directory cannot be found. + /// + internal static string StreamWriterNotFoundException { + get { + return ResourceManager.GetString("StreamWriterNotFoundException", resourceCulture); + } + } + } +} diff --git a/src/Libraries/DSOffice/Properties/Resources.en-US.resx b/src/Libraries/DSOffice/Properties/Resources.en-US.resx new file mode 100644 index 00000000000..c09dcdee58b --- /dev/null +++ b/src/Libraries/DSOffice/Properties/Resources.en-US.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The file or directory cannot be found + + \ No newline at end of file diff --git a/src/Libraries/DSOffice/Properties/Resources.resx b/src/Libraries/DSOffice/Properties/Resources.resx new file mode 100644 index 00000000000..c09dcdee58b --- /dev/null +++ b/src/Libraries/DSOffice/Properties/Resources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The file or directory cannot be found + + \ No newline at end of file