Explorar el Código

QDR.QDR.FND.Common: New

      - Add CsvHelper to read CSV files
Dalibor Votruba hace 6 años
padre
commit
dde09c3249

+ 1 - 0
Common/Common.csproj

@@ -53,6 +53,7 @@
     <Compile Include="Cache\Cache.cs" />
     <Compile Include="Cache\VolatileCache.cs" />
     <Compile Include="Console\ConsoleWriter.cs" />
+    <Compile Include="Data\CsvHelper.cs" />
     <Compile Include="Data\Extensions\SqlCommandExt.cs" />
     <Compile Include="Object\Singleton.cs" />
     <Compile Include="Object\WeakReference.cs" />

+ 44 - 0
Common/Data/CsvHelper.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Data;
+using System.IO;
+
+namespace Quadarax.Foundation.Common.Data
+{
+    public static class CsvHelper
+    {
+        /// <summary>
+        /// Read CSV file and creates <see cref="DataTable"/> with filled content.
+        /// <remarks>
+        /// This method expects first header row.
+        /// </remarks>
+        /// </summary>
+        /// <param name="csvFile">(*.csv) full file name.</param>
+        /// <param name="delimiter">Delimiter character</param>
+        /// <returns>New created DataTable with content.</returns>
+        public static DataTable CsvToDataTable(string csvFile, string delimiter)
+        {
+            var dt = new DataTable();
+            using (var sr = new StreamReader(csvFile))
+            {
+                var headers = sr.ReadLine().Split(new string[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
+                foreach (var header in headers)
+                {
+                    dt.Columns.Add(header);
+                }
+
+                while (!sr.EndOfStream)
+                {
+                    var rows = sr.ReadLine().Split(new[] { delimiter }, StringSplitOptions.None);
+                    var dr = dt.NewRow();
+                    for (var i = 0; i < headers.Length; i++)
+                    {
+                        dr[i] = rows[i];
+                    }
+
+                    dt.Rows.Add(dr);
+                }
+            }
+            return dt;
+        }
+    }
+}

+ 3 - 3
Common/Properties/AssemblyInfo.cs

@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("Quadarax")]
 [assembly: AssemblyProduct("Quadarax.Foundation")]
-[assembly: AssemblyCopyright("Copyright © Quadarax 2019")]
+[assembly: AssemblyCopyright("Copyright © Quadarax 2020")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.7")]
-[assembly: AssemblyFileVersion("1.0.0.7")]
+[assembly: AssemblyVersion("1.0.0.8")]
+[assembly: AssemblyFileVersion("1.0.0.8")]

+ 4 - 4
Common/QDR.FND.Common.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Quadarax.Foundation.Common</id>
-    <version>1.0.0.7</version>
+    <version>1.0.0.8</version>
     <title>Quadarax.Foundation.Common</title>
     <authors>Dalibor Votruba, Quadarax</authors>
     <owners>Dalibor Votruba</owners>
@@ -11,9 +11,9 @@
     <requireLicenseAcceptance>false</requireLicenseAcceptance>
     <description>Implementations of simple patterns and misc. extensions.</description>
     <releaseNotes>
-      27.12.2019 v.1.0.0.7
-      Fix
-      - Fix Secure class to work with empty strings
+      27.12.2019 v.1.0.0.8
+      New
+      - Add CsvHelper to read CSV files
     </releaseNotes>
     <copyright>Copyright (c) 2020 Quadarax</copyright>
     <tags>quadarax, foundation, common, qdr, fnd, library, extensions</tags>

+ 4 - 0
Common/ReleaseNote.txt

@@ -1,3 +1,7 @@
+27.12.2019 v.1.0.0.8
+New
+ - Add CsvHelper to read CSV files
+
 27.12.2019 v.1.0.0.7
 Fix
  - Fix Secure class to work with empty strings