├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── Prerequisites ├── Assemblies.md ├── HtmlAgilityPack.dll ├── LumiSoft.Net.dll ├── Microsoft.CSharp.dll ├── Microsoft.Office.Interop.Excel.dll ├── Microsoft.Office.Interop.PowerPoint.dll ├── Microsoft.Office.Interop.Word.dll ├── Microsoft.Vbe.Interop.dll ├── Microsoft.VisualBasic.dll ├── Newtonsoft.Json.dll ├── Office.dll ├── Oracle.DataAccess.dll ├── System.ComponentModel.DataAnnotations.dll ├── System.Data.DataSetExtensions.dll ├── System.Data.Entity.dll ├── System.Data.Linq.dll ├── System.Data.SQLite.dll ├── System.Data.SqlServerCe.dll ├── System.Data.dll ├── System.Drawing.dll ├── System.Management.dll ├── System.Transactions.dll ├── System.Xml.Linq.dll ├── System.Xml.dll ├── System.dll └── VCardLibrary.dll ├── README.md ├── SchemaMapperDLL.sln ├── SchemaMapperDLL ├── Classes │ ├── Converters │ │ ├── BaseClasses │ │ │ ├── BaseDbImport.cs │ │ │ ├── BaseImport.cs │ │ │ └── BaseImportusingOLEDB.cs │ │ ├── FlatFileImport.cs │ │ ├── HtmlImport.cs │ │ ├── JsonImport.cs │ │ ├── MsAccessImport.cs │ │ ├── MsExcelImport.cs │ │ ├── MsPowerPointImport.cs │ │ ├── MsWordImport.cs │ │ ├── MySQLImport.cs │ │ ├── OracleImport.cs │ │ ├── SQLiteImport.cs │ │ ├── SqlServerCeImport.cs │ │ ├── SqlServerImport.cs │ │ ├── XmlImport.cs │ │ └── vCardImport.cs │ ├── Exporters │ │ ├── BaseClasses │ │ │ ├── BaseDbExport.cs │ │ │ └── BaseFileExport.cs │ │ ├── FlatFileExport.cs │ │ ├── MySQLExport.cs │ │ ├── OracleExport.cs │ │ ├── SqlServerExport.cs │ │ └── XmlExport.cs │ ├── FileCleaners │ │ └── MsExcelCleaner.cs │ └── SchemaMapping │ │ ├── SchemaMapper.cs │ │ └── SchemaMapper_Column.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ └── Settings.settings ├── SchemaMapperDLL.csproj ├── SchemaMapperDLL.nuspec ├── app.config ├── nuget.exe └── packages.config ├── SchemaMapperDLLTest ├── App.config ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── SchemaMapperDLLTest.csproj └── sm_logo.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | 1. Fork it! 4 | 2. Create your feature branch: git checkout -b my-new-feature 5 | 3. Commit your changes: git commit -am 'Add some feature' 6 | 4. Push to the branch: git push origin my-new-feature 7 | 5. Submit a pull request :D 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Munchy Bytes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Prerequisites/Assemblies.md: -------------------------------------------------------------------------------- 1 | This folder contains the Assemblies needed to run SchemaMapper 2 | -------------------------------------------------------------------------------- /Prerequisites/HtmlAgilityPack.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/HtmlAgilityPack.dll -------------------------------------------------------------------------------- /Prerequisites/LumiSoft.Net.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/LumiSoft.Net.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.CSharp.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.CSharp.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.Office.Interop.Excel.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.Office.Interop.Excel.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.Office.Interop.PowerPoint.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.Office.Interop.PowerPoint.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.Office.Interop.Word.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.Office.Interop.Word.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.Vbe.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.Vbe.Interop.dll -------------------------------------------------------------------------------- /Prerequisites/Microsoft.VisualBasic.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Microsoft.VisualBasic.dll -------------------------------------------------------------------------------- /Prerequisites/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /Prerequisites/Office.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Office.dll -------------------------------------------------------------------------------- /Prerequisites/Oracle.DataAccess.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/Oracle.DataAccess.dll -------------------------------------------------------------------------------- /Prerequisites/System.ComponentModel.DataAnnotations.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.ComponentModel.DataAnnotations.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.DataSetExtensions.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.DataSetExtensions.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.Entity.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.Entity.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.Linq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.Linq.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.SQLite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.SQLite.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.SqlServerCe.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.SqlServerCe.dll -------------------------------------------------------------------------------- /Prerequisites/System.Data.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Data.dll -------------------------------------------------------------------------------- /Prerequisites/System.Drawing.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Drawing.dll -------------------------------------------------------------------------------- /Prerequisites/System.Management.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Management.dll -------------------------------------------------------------------------------- /Prerequisites/System.Transactions.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Transactions.dll -------------------------------------------------------------------------------- /Prerequisites/System.Xml.Linq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Xml.Linq.dll -------------------------------------------------------------------------------- /Prerequisites/System.Xml.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.Xml.dll -------------------------------------------------------------------------------- /Prerequisites/System.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/System.dll -------------------------------------------------------------------------------- /Prerequisites/VCardLibrary.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/Prerequisites/VCardLibrary.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SchemaMapper 2 | 3 | 4 | 5 | SchemaMapper is a data integration class library that facilitates data import process from external sources having different schema definitions. It replaces creating many integration services packages by writing few lines of codes. 6 | 7 | It imports tabular data from different data sources such as into a destination table with a user defined table schema after mapping columns between source and destination. 8 | 9 | SchemaMapper has the ability to read data from: 10 | 11 | - Excel worksheets *(.xls, .xlsx)* 12 | - Flat files *(.csv, .txt)* 13 | - Access databases *(.mdb, .accdb)* 14 | - Web pages *(.htm, .html)* 15 | - JSON files *(.json)* 16 | - XML files *(.xml)* 17 | - Powerpoint presentations *(.ppt, .pptx)* 18 | - Word documents *(.doc, .docx)* 19 | - Relational databases *(SQL Server, Oracle, MySQL, SQLite, SQL Server compact)* 20 | 21 | And it can export data into different destination types: 22 | 23 | - Flat files *(.csv, .txt)* 24 | - XML files *(.xml)* 25 | - Relational databases *(SQL Server, Oracle, MySQL)* 26 | 27 | In addition, it allows users to add new computed and fixed valued columns. 28 | 29 | ------------------------ 30 | 31 | ## Used technologies 32 | 33 | SchemaMapper utilizes from many technologies to read data from different source such as: 34 | 35 | - [Microsoft Office Interop libraries to import tables from Word and Powerpoint / Clean Excel files](https://www.microsoft.com/en-us/download/details.aspx?id=3508) 36 | - [Json.Net library](https://www.newtonsoft.com/json/help/html/Introduction.htm) to import JSON 37 | - [HtmlAgilityPack](https://html-agility-pack.net/) to import tables from HTML 38 | - [Microsoft Access database engine](https://www.microsoft.com/en-us/download/details.aspx?id=13255) to import data from Excel worksheets and Access databases. 39 | - [.NET framework 4.5.2](https://dotnet.microsoft.com/download/dotnet-framework/net452) 40 | - [MySQL .NET connector](https://dev.mysql.com/downloads/connector/net/8.0.html) to import and export data to MYSQL databases 41 | - [Oracle Data Provider for .NET](https://www.oracle.com/technetwork/cn/topics/dotnet/index-085163.html) to import and export data to Oracle databases 42 | - [System.Data.SQLite](https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki) to import data from SQLite databases 43 | - [SQL Server Compact 4.0 SP1 redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=30709) to import data from SQL Server CE databases 44 | 45 | *Note: The needed Assemblies are found in the Assemblies folder but it is recommended to install the assemblies related to the providers that you want to connect to from the official links (mentioned above) since they can requires more related assemblies* 46 | 47 | ------------------------ 48 | 49 | ## Project details 50 | 51 | SchemaMapper is composed of four main namespaces: 52 | 53 | - **Converters:** It reads data from external files into DataSet 54 | - **DataCleaners:** Cleans files before importing 55 | - **SchemaMapping:** Changes the imported data structure to a unified schema 56 | - **Exporters:** export tables to external sources 57 | ------------------------- 58 | 59 | ## Wiki 60 | 61 | - [Import data from multiple files into one SQL table step by step guide](https://github.com/munchy-bytes/SchemaMapper/wiki/Import-data-from-multiple-files-into-one-SQL-table-step-by-step-guide) 62 | - [Storing SchemaMapper information into XML 63 | ](https://github.com/munchy-bytes/SchemaMapper/wiki/Storing-SchemaMapper-information-into-XML) 64 | - [Using FileCleaner namespace to ignore reading additional empty cells in Excel](https://github.com/munchy-bytes/SchemaMapper/wiki/Using-FileCleaner-namespace-to-ignore-reading-additional-empty-cells-in-Excel) 65 | 66 | ------------------------- 67 | 68 | ## NuGet Package 69 | 70 | - [NuGet Gallery | SchemaMapper](https://www.nuget.org/packages/SchemaMapper/) 71 | 72 | ------------------------- 73 | 74 | ## External links 75 | 76 | - [Adding MySQL, SQLite, and Oracle support to SchemaMapper](https://medium.com/munchy-bytes/schemamapper-1-1-0-release-notes-9b1314825669) 77 | - [Announcing SchemaMapper a C# data integration class library](https://medium.com/munchy-bytes/announcing-schemamapper-a-c-data-integration-class-library-541dcfad4e2b) 78 | 79 | ------------------------- 80 | 81 | ## Credits 82 | 83 | Credits are for Munchy Bytes™ 84 | 85 | ------------------------- 86 | 87 | ## Examples 88 | 89 | ### (1) Converters: 90 | 91 | **Import data from Excel file (first worksheet)** 92 | 93 | ```cs 94 | using (SchemaMapperDLL.Classes.Converters.MsExcelImport smExcel = new SchemaMapperDLL.Classes.Converters.MsExcelImport(@"U:\Passwords.xlsx","",false)) 95 | { 96 | 97 | //Read Excel 98 | smExcel.BuildConnectionString(); 99 | var lst = smExcel.GetSheets(); 100 | DataTable dt = smExcel.GetTableByName(lst.First(), true, 0); 101 | return dt; 102 | } 103 | ``` 104 | 105 | **Import data from Excel file using paging** 106 | 107 | ```cs 108 | using (SchemaMapperDLL.Classes.Converters.MsExcelImport smExcel = new SchemaMapperDLL.Classes.Converters.MsExcelImport(@"U:\Passwords.xlsx", "", false)){ 109 | 110 | //Read Excel with pagging 111 | smExcel.BuildConnectionString(); 112 | var lst = smExcel.GetSheets(); 113 | 114 | int result = 1; 115 | int PagingStart = 1, PagingInterval = 10; 116 | 117 | while (result != 0){ 118 | 119 | DataTable dt = smExcel.GetTableByNamewithPaging(lst.First(), PagingStart, PagingInterval, out result, true, 0); 120 | 121 | PagingStart = PagingStart + PagingInterval; 122 | 123 | } 124 | 125 | } 126 | ``` 127 | 128 | **Import data from flat file (.txt, .csv)** 129 | 130 | ```cs 131 | using (SchemaMapperDLL.Classes.Converters.FlatFileImportTools smFlat = new SchemaMapperDLL.Classes.Converters.FlatFileImportTools(@"U:\Passwords.csv",true,0)) 132 | { 133 | 134 | //Read flat file structure 135 | smFlat.BuildDataTableStructure(); 136 | //Import data from flat file 137 | DataTable dt = smFlat.FillDataTable(); 138 | int Result = dt.Rows.Count; 139 | 140 | } 141 | ``` 142 | 143 | **Import data from word document** 144 | 145 | ```cs 146 | using (SchemaMapperDLL.Classes.Converters.MsWordImportTools smWord = new SchemaMapperDLL.Classes.Converters.MsWordImportTools(@"U:\DocumentTable.docx", true, 0)) 147 | { 148 | 149 | smWord.ImportWordTablesIntoList(";"); 150 | DataSet ds = smWord.ConvertListToTables(";"); 151 | 152 | int ct = ds.Tables.Count; 153 | } 154 | ``` 155 | 156 | ### (2) SchemaMapping 157 | 158 | **Initiate a SchemaMapper class** 159 | 160 | First you have to imports `SchemaMapperDLL.Classes.SchemaMapping` namespace. 161 | 162 | ```cs 163 | using SchemaMapperDLL.Classes.SchemaMapping; 164 | 165 | public SchemaMapper InitiateTestSchemaMapper(string schema, string table){ 166 | 167 | SchemaMapper smResult = new SchemaMapper(); 168 | 169 | smResult.TableName = table; 170 | smResult.SchemaName = schema; 171 | 172 | //Add variables 173 | smResult.Variables.Add(new Variable("@Today", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); 174 | 175 | 176 | //Define Columns 177 | SchemaMapper_Column smServerCol = new SchemaMapper_Column("Server_Name", SchemaMapper_Column.ColumnDataType.Text); 178 | SchemaMapper_Column smUserCol = new SchemaMapper_Column("User_Name", SchemaMapper_Column.ColumnDataType.Text); 179 | SchemaMapper_Column smPassCol = new SchemaMapper_Column("Password", SchemaMapper_Column.ColumnDataType.Text); 180 | 181 | //Define a column with Fixed Value 182 | SchemaMapper_Column smFixedValueCol = new SchemaMapper_Column("AddedDate", SchemaMapper_Column.ColumnDataType.Text,"@Today"); 183 | 184 | //Define a Column with Expression 185 | SchemaMapper_Column smExpressionCol = new SchemaMapper_Column("UserAndPassword",SchemaMapper_Column.ColumnDataType.Text,true,"[User_Name] + '|' + [Password]"); 186 | 187 | //Add columns to SchemaMapper 188 | smResult.Columns.Add(smServerCol); 189 | smResult.Columns.Add(smUserCol); 190 | smResult.Columns.Add(smPassCol); 191 | smResult.Columns.Add(smFixedValueCol); 192 | smResult.Columns.Add(smExpressionCol); 193 | 194 | //Add all possible input Columns Names for each Column 195 | smServerCol.MappedColumns.AddRange(new[] {"server","server name","servername","Server","Server Name","ServerName"}); 196 | smUserCol.MappedColumns.AddRange(new[] { "UserName", "User", "login", "Login", "User name" }); 197 | smPassCol.MappedColumns.AddRange(new[] { "Password","pass", "Pass", "password" }); 198 | 199 | //Added columns to ignore if found 200 | //Sys_SheetName and Sys_ExtraFields is an auto generated column when reading Excel file 201 | smResult.IgnoredColumns.AddRange(new[] { "Column1", "Sys_Sheetname", "Sys_ExtraFields", "Center Name" }); 202 | 203 | //Save Schema Mapper into xml 204 | smResult.WriteToXml(Environment.CurrentDirectory + "\\SchemaMapper\\1.xml",true); 205 | 206 | return smResult; 207 | 208 | } 209 | ``` 210 | 211 | **Change DataTable schema and insert into SQL using stored procedure with Table variable parameter** 212 | 213 | 214 | ```cs 215 | DataTable dt = ReadExcel(); 216 | 217 | using (SchemaMapper SM = InitiateTestSchemaMapper("dbo","PasswordsTable")) 218 | { 219 | 220 | bool result = SM.ChangeTableStructure(ref dt); 221 | string con = @"Data Source=.\SQLINSTANCE;Initial Catalog=tempdb;integrated security=SSPI;"; 222 | 223 | using (SchemaMapperDLL.Classes.Exporters.SqlServerExport exp = new SchemaMapperDLL.Classes.Exporters.SqlServerExport(con)) 224 | { 225 | exp.CreateDestinationTable(SM); 226 | exp.InsertToSQLUsingStoredProcedure(SM, dtExcel); 227 | } 228 | 229 | } 230 | 231 | ``` 232 | **Change DataTable schema and insert into SQL using BULK Insert** 233 | 234 | ```cs 235 | DataTable dt = ReadExcel(); 236 | 237 | using (SchemaMapper SM = new SchemaMapper(Environment.CurrentDirectory + "\\SchemaMapper\\1.xml")) 238 | { 239 | 240 | bool result = SM.ChangeTableStructure(ref dt); 241 | string con = @"Data Source=.\SQLINSTANCE;Initial Catalog=tempdb;integrated security=SSPI;"; 242 | 243 | using (SchemaMapperDLL.Classes.Exporters.SqlServerExport exp = new SchemaMapperDLL.Classes.Exporters.SqlServerExport(con)) 244 | { 245 | exp.CreateDestinationTable(SM ); 246 | exp.InsertUsingSQLBulk(SM, dtExcel); 247 | } 248 | 249 | } 250 | ``` 251 | 252 | **Read SchemaMapper class from Saved XML** 253 | 254 | ```cs 255 | using (SchemaMapper SM = new SchemaMapper("Environment.CurrentDirectory + "\\SchemaMapper\\1.xml")){ 256 | 257 | //write your code here 258 | 259 | } 260 | ``` 261 | -------------------------------------------------------------------------------- /SchemaMapperDLL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30002.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchemaMapperDLL", "SchemaMapperDLL\SchemaMapperDLL.csproj", "{687E3733-B82E-4CC7-9E83-9573407D01B7}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchemaMapperDLLTest", "SchemaMapperDLLTest\SchemaMapperDLLTest.csproj", "{04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|x64.ActiveCfg = Debug|x64 23 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|x64.Build.0 = Debug|x64 24 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|x86.ActiveCfg = Debug|x86 25 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Debug|x86.Build.0 = Debug|x86 26 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|x64.ActiveCfg = Release|x64 29 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|x64.Build.0 = Release|x64 30 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|x86.ActiveCfg = Release|x86 31 | {687E3733-B82E-4CC7-9E83-9573407D01B7}.Release|x86.Build.0 = Release|x86 32 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|x64.ActiveCfg = Debug|x64 35 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|x64.Build.0 = Debug|x64 36 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|x86.ActiveCfg = Debug|x86 37 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Debug|x86.Build.0 = Debug|x86 38 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|x64.ActiveCfg = Release|x64 41 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|x64.Build.0 = Release|x64 42 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|x86.ActiveCfg = Release|x86 43 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7}.Release|x86.Build.0 = Release|x86 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {75E0FD91-065E-4F1C-8064-753605749C36} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/BaseClasses/BaseDbImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SchemaMapper.Converters 9 | { 10 | public abstract class BaseDbImport 11 | { 12 | 13 | #region declaration 14 | 15 | public string ConnectionString { get; set; } 16 | public DataTable SQLTable { get; set; } 17 | public DataTable SchemaTable { get; set; } 18 | 19 | #endregion 20 | 21 | #region constructors 22 | 23 | public BaseDbImport() { 24 | 25 | ConnectionString = ""; 26 | SQLTable = new DataTable(); 27 | 28 | } 29 | 30 | #endregion 31 | 32 | #region Methods 33 | 34 | public abstract void getSchemaTable(); 35 | public abstract DataTable GetDataTable(string schema, string tablename); 36 | public abstract DataTable GetQueryResult(string sqlQuery); 37 | public abstract DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result); 38 | public abstract DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result); 39 | 40 | #endregion 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/BaseClasses/BaseImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace SchemaMapper.Converters 9 | { 10 | public abstract class BaseImport 11 | { 12 | 13 | #region declaration 14 | public string FilePath { get; set; } 15 | public DataSet Maindataset { get; set; } 16 | public bool HasHeader { get; set; } 17 | public int RowsToSkip { get; set; } 18 | 19 | #endregion 20 | 21 | #region abstract methods 22 | 23 | public BaseImport() { } 24 | 25 | #endregion 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/BaseClasses/BaseImportusingOLEDB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.OleDb; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | 8 | namespace SchemaMapper.Converters 9 | { 10 | public abstract class BaseImportusingOLEDB : BaseImport 11 | { 12 | 13 | #region declarations 14 | 15 | public DataTable SchemaTable { get; set; } 16 | public string ConnectionString { get; set; } 17 | 18 | #endregion 19 | 20 | #region constructors 21 | 22 | public BaseImportusingOLEDB() { } 23 | 24 | #endregion 25 | 26 | #region abstract functions 27 | 28 | public abstract DataSet FillAllTables(); 29 | public abstract void getSchemaTable(); 30 | public abstract void BuildConnectionString(); 31 | 32 | #endregion 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/FlatFileImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.VisualBasic; 4 | using System.Data; 5 | using Microsoft.VisualBasic.FileIO; 6 | 7 | namespace SchemaMapper.Converters 8 | { 9 | public class FlatFileImportTools : IDisposable 10 | { 11 | 12 | #region declaration 13 | 14 | private int m_intRowsToSkip = 0; 15 | private DataTable m_DataTable; 16 | private string m_strFilePath = string.Empty; 17 | private string m_strDelimiter = ""; 18 | private bool m_boolContainsHeader = false; 19 | private int m_intNumberOfColumns = 0; 20 | private bool m_FieldEnclosedInQuotes = false; 21 | private TextFieldParser tfpTxtParser; 22 | private string[] strFirstLine; 23 | private string[] m_strDelimiters = { ":", "|", ",", ";", "\t", "\r","\r\n", "\n" }; 24 | private int[] m_intEncodings = { 1256, 1200, 1201, 12000, 12001, 65000, 65001 }; 25 | private string[] m_strQualifiers = { "\"", "'" }; 26 | private string m_strDefaultDelimiter = ";"; 27 | private string[] m_strFirstLines = { "", "", "", "", "", "", "", "" }; 28 | private string m_strTextQualifier = string.Empty; 29 | private char[] chrsNumeric = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 30 | private char[] chrsUnwanted = { '\\', '-', '.', ' ', '`', '\'', Strings.Chr(34), '/', '+', '=', ',', '_', '|', '\t' }; 31 | private char[] chrsEnglishAlphabetic = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; 32 | private char[] chrsArabicAlphabetic = { 'ذ', 'ض', 'ص', 'ث', 'ق', 'ف', 'غ', 'ع', 'ه', 'خ', 'ح', 'ج', 'د', 'ش', 'س', 'ي', 'ب', 'ل', 'ا', 'ت', 'ن', 'م', 'ك', 'ط', 'ئ', 'ء', 'ؤ', 'ر', 'ى', 'ة', 'و', 'ز', 'ظ', 'إ', 'أ', 'آ' }; 33 | 34 | #endregion 35 | 36 | #region properties 37 | 38 | public string TextQualifier 39 | { 40 | get 41 | { 42 | return m_strTextQualifier; 43 | } 44 | } 45 | 46 | public bool FieldEnclosedInQuotes 47 | { 48 | get 49 | { 50 | return m_FieldEnclosedInQuotes; 51 | } 52 | } 53 | 54 | public int NumberOfColumns 55 | { 56 | get 57 | { 58 | return m_intNumberOfColumns; 59 | } 60 | } 61 | 62 | public string FilePath 63 | { 64 | get 65 | { 66 | return m_strFilePath; 67 | } 68 | } 69 | 70 | public string Delimiter 71 | { 72 | get 73 | { 74 | return m_strDelimiter; 75 | } 76 | } 77 | 78 | public bool FirstRowIsHeader 79 | { 80 | get 81 | { 82 | return m_boolContainsHeader; 83 | } 84 | } 85 | 86 | public DataTable DataTable 87 | { 88 | get 89 | { 90 | return m_DataTable; 91 | } 92 | } 93 | 94 | #endregion 95 | 96 | #region constructors 97 | 98 | public FlatFileImportTools(string strFilePath, bool ContainsHeader = false, int v_intRowsToSkip = 0) 99 | { 100 | m_DataTable = new DataTable(); 101 | 102 | m_intRowsToSkip = v_intRowsToSkip; 103 | m_strFilePath = strFilePath; 104 | m_boolContainsHeader = ContainsHeader; 105 | 106 | m_strDelimiter = DetectDelimiter(strFilePath); 107 | 108 | m_strTextQualifier = DetectTextQualifier(m_strDelimiter); 109 | 110 | m_FieldEnclosedInQuotes = string.IsNullOrEmpty(m_strTextQualifier) ? false : true; 111 | 112 | 113 | tfpTxtParser = new TextFieldParser(this.FilePath, DetectEncoding(this.FilePath)); 114 | tfpTxtParser.TextFieldType = FieldType.Delimited; 115 | tfpTxtParser.SetDelimiters(this.Delimiter.ToString()); 116 | tfpTxtParser.HasFieldsEnclosedInQuotes = this.FieldEnclosedInQuotes; 117 | 118 | if (m_intRowsToSkip > 0) 119 | { 120 | for (var i = 1; i <= m_intRowsToSkip; i++) 121 | 122 | tfpTxtParser.ReadLine(); 123 | } 124 | } 125 | 126 | 127 | 128 | 129 | 130 | 131 | #endregion 132 | 133 | #region "Methods" 134 | 135 | public void BuildDataTableStructure() 136 | { 137 | strFirstLine = tfpTxtParser.ReadFields(); 138 | m_intNumberOfColumns = GetColumnsCount(); 139 | 140 | for (var intCounter = 0; intCounter <= m_intNumberOfColumns - 1; intCounter++) 141 | { 142 | DataColumn dcCol = new DataColumn(); 143 | 144 | if (this.FirstRowIsHeader && strFirstLine.Length > intCounter) 145 | { 146 | dcCol.ColumnName = strFirstLine[intCounter].Trim(); 147 | dcCol.Caption = strFirstLine[intCounter].Trim(); 148 | } 149 | else 150 | { 151 | dcCol.ColumnName = "F" + intCounter.ToString(); 152 | dcCol.Caption = "F" + intCounter.ToString(); 153 | } 154 | 155 | m_DataTable.Columns.Add(dcCol); 156 | } 157 | } 158 | 159 | public void InsertLineIntoTable(string[] strLine) 160 | { 161 | int intColumns = 0; 162 | DataRow drRow; 163 | drRow = m_DataTable.NewRow(); 164 | 165 | if (m_intNumberOfColumns > strLine.Length) 166 | intColumns = strLine.Length; 167 | else 168 | intColumns = m_intNumberOfColumns; 169 | 170 | for (var intCounter = 0; intCounter <= intColumns - 1; intCounter++) 171 | drRow[intCounter] = strLine[intCounter]; 172 | 173 | m_DataTable.Rows.Add(drRow); 174 | } 175 | 176 | public DataTable FillDataTable() 177 | { 178 | if (!this.FirstRowIsHeader) 179 | InsertLineIntoTable(strFirstLine); 180 | 181 | while (tfpTxtParser.EndOfData == false) 182 | { 183 | string[] strCurrentLine; 184 | strCurrentLine = tfpTxtParser.ReadFields(); 185 | InsertLineIntoTable(strCurrentLine); 186 | } 187 | 188 | return DataTable; 189 | } 190 | 191 | public System.Text.Encoding DetectEncoding(string strFilePath) 192 | { 193 | foreach (int encoding in m_intEncodings) 194 | { 195 | using (System.IO.StreamReader txtReader = new System.IO.StreamReader(strFilePath, System.Text.Encoding.GetEncoding(encoding))) 196 | { 197 | string strFirstLine = txtReader.ReadLine(); 198 | 199 | while (string.IsNullOrEmpty(strFirstLine.Trim()) && !txtReader.EndOfStream) 200 | 201 | strFirstLine = txtReader.ReadLine(); 202 | 203 | txtReader.Close(); 204 | 205 | if (!strFirstLine.Contains("�") && !string.IsNullOrEmpty(strFirstLine.Trim()) && !strFirstLine.Contains("")) 206 | { 207 | if (strFirstLine.ToCharArray().Where(x => chrsArabicAlphabetic.Contains(x) | chrsEnglishAlphabetic.Contains(x) | chrsNumeric.Contains(x)).Count() > 0) 208 | 209 | return System.Text.Encoding.GetEncoding(encoding); 210 | 211 | // this.strFirstLine = strFirstLine; 212 | } 213 | } 214 | } 215 | 216 | return System.Text.Encoding.Unicode; 217 | } 218 | 219 | public void ExportDataTableToXml(string xmlPath) 220 | { 221 | m_DataTable.WriteXml(xmlPath); 222 | } 223 | 224 | public string DetectDelimiter(string strFilePath) 225 | { 226 | string strDelimiter = ""; 227 | int intMax = 0; 228 | 229 | 230 | using (System.IO.StreamReader txtReader = new System.IO.StreamReader(strFilePath)) 231 | { 232 | for (var intCount = m_intRowsToSkip; intCount <= m_intRowsToSkip + 7; intCount++) 233 | { 234 | if (txtReader.Peek() != -1) 235 | m_strFirstLines[intCount - m_intRowsToSkip] = txtReader.ReadLine(); 236 | else 237 | break; 238 | } 239 | 240 | txtReader.Close(); 241 | } 242 | 243 | foreach (string Str in m_strDelimiters) 244 | { 245 | string[] strArray = m_strFirstLines[0].Split(new string[] {Str},StringSplitOptions.None); 246 | 247 | if (strArray.Length > intMax) 248 | { 249 | strDelimiter = Str; 250 | intMax = strArray.Length; 251 | } 252 | } 253 | 254 | if (intMax == 1) 255 | return m_strDefaultDelimiter; 256 | else 257 | return strDelimiter; 258 | } 259 | 260 | public string DetectTextQualifier(string strDelimiter) 261 | { 262 | string r_strQualifier = string.Empty; 263 | 264 | foreach (string strQualifier in m_strQualifiers) 265 | { 266 | bool IsQualifier = true; 267 | 268 | foreach (string str in m_strFirstLines[0].Split(new string[] { Delimiter }, StringSplitOptions.None)) 269 | { 270 | if (!str.StartsWith(strQualifier) || !str.EndsWith(strQualifier)) 271 | { 272 | IsQualifier = false; 273 | 274 | break; 275 | } 276 | } 277 | 278 | if (IsQualifier == true) 279 | { 280 | r_strQualifier = strQualifier; 281 | break; 282 | } 283 | } 284 | 285 | 286 | 287 | 288 | return r_strQualifier; 289 | } 290 | 291 | public int GetColumnsCount() 292 | { 293 | int r_intResult = 0; 294 | 295 | foreach (string Str in m_strFirstLines) 296 | { 297 | if (Str.Split(new string[]{Delimiter},StringSplitOptions.None).Length > r_intResult) 298 | r_intResult = Str.Split(new string[] { Delimiter }, StringSplitOptions.None).Length; 299 | } 300 | 301 | return r_intResult; 302 | } 303 | 304 | #endregion 305 | 306 | private bool disposedValue = false; // To detect redundant calls 307 | 308 | // IDisposable 309 | protected virtual void Dispose(bool disposing) 310 | { 311 | if (!this.disposedValue) 312 | { 313 | if (disposing) 314 | { 315 | if (m_DataTable != null) 316 | m_DataTable.Dispose(); 317 | 318 | m_strFilePath = null; 319 | m_boolContainsHeader = default(bool); 320 | m_intNumberOfColumns = default(int); 321 | m_FieldEnclosedInQuotes = default(bool); 322 | tfpTxtParser.Dispose(); 323 | strFirstLine = null; 324 | } 325 | } 326 | this.disposedValue = true; 327 | } 328 | 329 | // This code added by Visual Basic to correctly implement the disposable pattern. 330 | public void Dispose() 331 | { 332 | // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. 333 | Dispose(true); 334 | GC.SuppressFinalize(this); 335 | } 336 | } 337 | } 338 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/HtmlImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Data; 4 | using HtmlAgilityPack; 5 | using System.Net; 6 | 7 | namespace SchemaMapper.Converters 8 | { 9 | 10 | public class HtmlImport: BaseImport, IDisposable 11 | { 12 | 13 | public HtmlImport(string htmlpath) 14 | { 15 | 16 | FilePath = htmlpath; 17 | 18 | } 19 | 20 | public DataSet GetDataSet() 21 | { 22 | 23 | 24 | string html = System.IO.File.ReadAllText(FilePath); 25 | 26 | html = WebUtility.HtmlDecode(html); 27 | HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument(); 28 | 29 | htmldoc.LoadHtml(html); 30 | 31 | var tables = htmldoc.DocumentNode.SelectNodes("//table//tr") 32 | .GroupBy(x => x.Ancestors("table").First()).ToList(); 33 | 34 | for (int i = 0; i == tables.Count - 1; i++) 35 | { 36 | 37 | var rows = tables[i].ToList(); 38 | Maindataset.Tables.Add(String.Format("Table {0}", i.ToString())); 39 | 40 | var headers = rows[0].Elements("th").Union(rows[0].Elements("td")).Select(x => new headerClass() 41 | { 42 | 43 | Name = x.InnerText.Trim(), 44 | Count = x.Attributes["colspan"] == null ? 1 : Convert.ToInt32(x.Attributes["colspan"].Value) 45 | 46 | }).ToList(); 47 | 48 | 49 | if (headers.Count > 0) 50 | { 51 | 52 | foreach (headerClass hr in headers) 53 | { 54 | for (int idx = 1; idx == hr.Count; idx++) 55 | { 56 | 57 | string postfix = hr.Count > 1 ? idx.ToString() : ""; 58 | Maindataset.Tables[i].Columns.Add(hr.Name + postfix); 59 | 60 | } 61 | 62 | } 63 | 64 | for (int j = 1; j <= rows.Count - 1; j++) 65 | { 66 | var row = rows[j]; 67 | var dr = row.Elements("td").Select(x => x.InnerText + GetLink(x)).ToArray(); 68 | Maindataset.Tables[i].Rows.Add(dr); 69 | 70 | 71 | } 72 | 73 | 74 | 75 | 76 | } 77 | } 78 | 79 | return Maindataset; 80 | } 81 | 82 | public string GetLink(HtmlNode html) 83 | { 84 | 85 | string strResult = ""; 86 | 87 | if (html.Attributes["href"] != null) 88 | { 89 | strResult = " (" + html.Attributes["href"].Value + ")"; 90 | 91 | } 92 | 93 | foreach (HtmlNode nd in html.ChildNodes) 94 | { 95 | 96 | if (nd.Attributes["href"] != null) { 97 | if (strResult == "") 98 | strResult = " (" + nd.Attributes["href"].Value + ")"; 99 | else 100 | strResult = strResult + Environment.NewLine + " (" + nd.Attributes["href"].Value + ")"; 101 | } 102 | } 103 | 104 | return strResult; 105 | 106 | } 107 | 108 | public void Dispose() 109 | { 110 | Maindataset.Dispose(); 111 | } 112 | } 113 | 114 | public class headerClass 115 | { 116 | 117 | 118 | public string Name { get; set; } 119 | public int Count { get; set; } 120 | 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/JsonImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Data; 4 | using Microsoft.VisualBasic; 5 | using Newtonsoft.Json; 6 | 7 | namespace SchemaMapper.Converters 8 | { 9 | public class JsonImport: BaseImport, IDisposable 10 | { 11 | 12 | private int[] m_intEncodings = { 1256, 1200, 1201, 12000, 12001, 65000, 65001 }; 13 | private char[] chrsNumeric = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 14 | private char[] chrsUnwanted = { '\\', '-', '.', ' ', '`', '\'', Strings.Chr(34), '/', '+', '=', ',', '_', '|', '\t' }; 15 | private char[] chrsEnglishAlphabetic = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; 16 | private char[] chrsArabicAlphabetic = { 'ذ', 'ض', 'ص', 'ث', 'ق', 'ف', 'غ', 'ع', 'ه', 'خ', 'ح', 'ج', 'د', 'ش', 'س', 'ي', 'ب', 'ل', 'ا', 'ت', 'ن', 'م', 'ك', 'ط', 'ئ', 'ء', 'ؤ', 'ر', 'ى', 'ة', 'و', 'ز', 'ظ', 'إ', 'أ', 'آ' }; 17 | 18 | public JsonImport(string JsonPath) 19 | { 20 | 21 | FilePath = JsonPath; 22 | } 23 | 24 | public DataSet ReadDataSetFromJson() 25 | { 26 | 27 | string strJson; 28 | using (System.IO.StreamReader srJson = new System.IO.StreamReader(FilePath, DetectEncoding(FilePath)) ) { 29 | 30 | strJson= srJson.ReadToEnd(); 31 | srJson.Close(); 32 | 33 | } 34 | 35 | Maindataset = JsonConvert.DeserializeObject(strJson); 36 | 37 | return Maindataset; 38 | 39 | } 40 | 41 | public System.Text.Encoding DetectEncoding(string strFilePath) 42 | { 43 | foreach (int encoding in m_intEncodings) 44 | { 45 | using (System.IO.StreamReader txtReader = new System.IO.StreamReader(strFilePath, System.Text.Encoding.GetEncoding(encoding))) 46 | { 47 | string strFirstLine = txtReader.ReadLine(); 48 | 49 | while (string.IsNullOrEmpty(strFirstLine.Trim()) && !txtReader.EndOfStream) 50 | 51 | strFirstLine = txtReader.ReadLine(); 52 | 53 | txtReader.Close(); 54 | 55 | if (!strFirstLine.Contains("�") && !string.IsNullOrEmpty(strFirstLine.Trim()) && !strFirstLine.Contains("")) 56 | { 57 | if (strFirstLine.ToCharArray().Where(x => chrsArabicAlphabetic.Contains(x) | chrsEnglishAlphabetic.Contains(x) | chrsNumeric.Contains(x)).Count() > 0) 58 | 59 | return System.Text.Encoding.GetEncoding(encoding); 60 | 61 | // this.strFirstLine = strFirstLine; 62 | } 63 | } 64 | } 65 | 66 | return System.Text.Encoding.Unicode; 67 | } 68 | 69 | public void Dispose() 70 | { 71 | Maindataset.Dispose(); 72 | } 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/MsAccessImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.OleDb; 4 | 5 | namespace SchemaMapper.Converters 6 | { 7 | public class MsAccessImport: BaseImportusingOLEDB,IDisposable 8 | { 9 | 10 | #region constructors 11 | 12 | public MsAccessImport(string accesspath) 13 | { 14 | FilePath = accesspath; 15 | } 16 | 17 | #endregion 18 | 19 | #region override methods 20 | 21 | public override DataSet FillAllTables() 22 | { 23 | 24 | if (SchemaTable == null) { getSchemaTable(); } 25 | 26 | string strTablename = string.Empty; 27 | BuildConnectionString(); 28 | 29 | using (OleDbConnection OleDBCon = new OleDbConnection(ConnectionString)) 30 | { 31 | if (OleDBCon.State != ConnectionState.Open) 32 | OleDBCon.Open(); 33 | 34 | foreach (DataRow schRow in SchemaTable.Rows) 35 | { 36 | strTablename = schRow["TABLE_NAME"].ToString().Trim('\''); 37 | 38 | try 39 | { 40 | 41 | string strcommand = string.Empty; 42 | 43 | DataTable dtTable = new DataTable(strTablename); 44 | 45 | strcommand = "SELECT * FROM [" + strTablename + "]"; 46 | 47 | using (OleDbCommand cmd = new OleDbCommand(strcommand, OleDBCon)) 48 | { 49 | cmd.CommandType = CommandType.Text; 50 | 51 | using (OleDbDataAdapter daGetDataFromSheet = new OleDbDataAdapter(cmd)) 52 | { 53 | daGetDataFromSheet.Fill(dtTable); 54 | } 55 | dtTable.PrimaryKey = null; 56 | Maindataset.Tables.Add(dtTable); 57 | } 58 | } 59 | catch (Exception ex) 60 | { 61 | throw new Exception(ex.Message + Environment.NewLine + String.Format("Table: {0}", strTablename), ex); 62 | } 63 | 64 | 65 | } 66 | 67 | } 68 | return Maindataset; 69 | } 70 | public DataTable GetDataTable(string Tablename) 71 | { 72 | 73 | if (SchemaTable == null) { getSchemaTable(); } 74 | 75 | using (OleDbConnection OleDBCon = new OleDbConnection(ConnectionString)) 76 | { 77 | if (OleDBCon.State != ConnectionState.Open) 78 | OleDBCon.Open(); 79 | 80 | //schRow["TABLE_NAME"].ToString().Trim('\''); 81 | 82 | try 83 | { 84 | 85 | string strcommand = string.Empty; 86 | 87 | DataTable dtTable = new DataTable(Tablename); 88 | 89 | strcommand = "SELECT * FROM [" + Tablename + "]"; 90 | 91 | using (OleDbCommand cmd = new OleDbCommand(strcommand, OleDBCon)) 92 | { 93 | cmd.CommandType = CommandType.Text; 94 | 95 | using (OleDbDataAdapter daGetDataFromSheet = new OleDbDataAdapter(cmd)) 96 | { 97 | 98 | daGetDataFromSheet.FillSchema(dtTable, SchemaType.Source); 99 | 100 | //foreach (DataColumn dCol in dtTable.Columns) 101 | //{ 102 | // if (dCol.DataType != typeof(System.String)) 103 | // dCol.DataType = typeof(System.String); 104 | //} 105 | 106 | daGetDataFromSheet.Fill(dtTable); 107 | } 108 | dtTable.PrimaryKey = null; 109 | return dtTable; 110 | } 111 | } 112 | catch (Exception ex) 113 | { 114 | throw ex; 115 | } 116 | 117 | } 118 | 119 | 120 | } 121 | 122 | public DataTable GetDataTableWithPaging(string Tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 123 | { 124 | 125 | if (SchemaTable == null) { getSchemaTable(); } 126 | 127 | using (OleDbConnection OleDBCon = new OleDbConnection(ConnectionString)) 128 | { 129 | if (OleDBCon.State != ConnectionState.Open) 130 | OleDBCon.Open(); 131 | 132 | //schRow["TABLE_NAME"].ToString().Trim('\''); 133 | 134 | try 135 | { 136 | 137 | string strcommand = string.Empty; 138 | 139 | DataTable dtTable = new DataTable(Tablename); 140 | 141 | strcommand = "SELECT * FROM [" + Tablename + "]"; 142 | 143 | using (OleDbCommand cmd = new OleDbCommand(strcommand, OleDBCon)) 144 | { 145 | cmd.CommandType = CommandType.Text; 146 | 147 | using (OleDbDataAdapter daGetDataFromSheet = new OleDbDataAdapter(cmd)) 148 | { 149 | 150 | daGetDataFromSheet.FillSchema(dtTable, SchemaType.Source); 151 | 152 | foreach (DataColumn dCol in dtTable.Columns) 153 | { 154 | if (dCol.DataType != typeof(System.String)) 155 | dCol.DataType = typeof(System.String); 156 | 157 | } 158 | 159 | r_result = daGetDataFromSheet.Fill(v_PagingStartRecord, v_PagingInterval, dtTable); 160 | } 161 | 162 | dtTable.PrimaryKey = null; 163 | return dtTable; 164 | } 165 | } 166 | catch (Exception ex) 167 | { 168 | throw ex; 169 | } 170 | 171 | } 172 | 173 | 174 | 175 | } 176 | public override void getSchemaTable() 177 | { 178 | using (OleDbConnection OleDBCon = new OleDbConnection(ConnectionString)) 179 | { 180 | if (OleDBCon.State != ConnectionState.Open) 181 | OleDBCon.Open(); 182 | 183 | SchemaTable = OleDBCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); 184 | 185 | OleDBCon.Close(); 186 | } 187 | 188 | } 189 | public override void BuildConnectionString() 190 | { 191 | ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath; 192 | } 193 | 194 | 195 | #endregion 196 | 197 | public void Dispose() 198 | { 199 | if (SchemaTable != null) 200 | SchemaTable.Dispose(); 201 | 202 | if (Maindataset != null) 203 | Maindataset.Dispose(); 204 | 205 | } 206 | 207 | } 208 | 209 | } -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/MsPowerPointImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using Microsoft.Office.Interop.PowerPoint; 4 | 5 | 6 | namespace SchemaMapper.Converters 7 | { 8 | public class MsPowerPointImport : BaseImport, IDisposable 9 | { 10 | 11 | public DataSet ImportTablesToDataSet() 12 | { 13 | 14 | Application appPPT = new Application(); 15 | appPPT.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; 16 | appPPT.Activate(); 17 | 18 | Presentation apPresentation = appPPT.Presentations.Open2007(FilePath, 19 | Microsoft.Office.Core.MsoTriState.msoFalse, 20 | Microsoft.Office.Core.MsoTriState.msoFalse, 21 | Microsoft.Office.Core.MsoTriState.msoTrue, 22 | Microsoft.Office.Core.MsoTriState.msoFalse); 23 | 24 | int intTables = 0; 25 | 26 | foreach (Slide pSlide in apPresentation.Slides) 27 | { 28 | 29 | foreach (Shape pShape in pSlide.Shapes) 30 | { 31 | 32 | if (pShape.HasTable.Equals(Microsoft.Office.Core.MsoTriState.msoTrue)) 33 | { 34 | 35 | intTables++; 36 | 37 | Table dt = pShape.Table; 38 | int intRowsCounter = 1 + RowsToSkip; 39 | System.Data.DataTable m_DataTable = new System.Data.DataTable("DT_" + intTables); 40 | int intColumnsCounter = 0; 41 | 42 | if (intRowsCounter > dt.Rows.Count) 43 | return null; 44 | 45 | if (HasHeader) 46 | { 47 | for (int i = 1; i == dt.Columns.Count; i++) 48 | { 49 | 50 | m_DataTable.Columns.Add(dt.Cell(intRowsCounter, i).Shape.TextFrame.HasText.Equals( Microsoft.Office.Core.MsoTriState.msoTrue) ? 51 | dt.Cell(intRowsCounter, i).Shape.TextFrame.TextRange.Text.Trim() : 52 | "F" + i.ToString()); 53 | 54 | } 55 | 56 | intRowsCounter++; 57 | 58 | } 59 | else 60 | { 61 | 62 | for (int i = 1; i == dt.Columns.Count; i++) 63 | { 64 | 65 | m_DataTable.Columns.Add("F" + i.ToString()); 66 | 67 | } 68 | 69 | } 70 | 71 | 72 | while (intRowsCounter <= dt.Rows.Count) 73 | { 74 | 75 | DataRow drRow = m_DataTable.NewRow(); 76 | 77 | for (intColumnsCounter = 1; intColumnsCounter == dt.Columns.Count; intColumnsCounter++) 78 | { 79 | 80 | drRow[intColumnsCounter - 1] = dt.Cell(intRowsCounter, intColumnsCounter).Shape.TextFrame.HasText.Equals(Microsoft.Office.Core.MsoTriState.msoTrue) ? 81 | dt.Cell(intRowsCounter, intColumnsCounter).Shape.TextFrame.TextRange.Text.Trim() : ""; 82 | 83 | } 84 | 85 | m_DataTable.Rows.Add(drRow); 86 | intRowsCounter++; 87 | 88 | } 89 | 90 | Maindataset.Tables.Add(m_DataTable); 91 | } 92 | 93 | 94 | } 95 | 96 | 97 | 98 | } 99 | 100 | apPresentation.Close(); 101 | appPPT.Quit(); 102 | 103 | System.Runtime.InteropServices.Marshal.ReleaseComObject(apPresentation); 104 | System.Runtime.InteropServices.Marshal.ReleaseComObject(appPPT); 105 | 106 | return Maindataset; 107 | 108 | } 109 | 110 | public void Dispose() 111 | { 112 | Maindataset.Dispose(); 113 | } 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/MsWordImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using Microsoft.VisualBasic; 7 | using System.Data; 8 | using Microsoft.Office.Interop.Word; 9 | using System.Management; 10 | 11 | namespace SchemaMapper.Converters 12 | { 13 | public class MsWordImportTools : IDisposable 14 | { 15 | 16 | #region decalrations 17 | 18 | private string m_computername = string.Empty; 19 | private string m_Username = string.Empty; 20 | 21 | private int m_intRowsToSkip = 0; 22 | private string m_strWordPath = string.Empty; 23 | private DataSet m_Maindataset = new DataSet(); 24 | // Private xmlConverter As New TableConverter 25 | private Application appWord = null; 26 | private Documents docsWord = null; 27 | private Document newDoc = null; 28 | private List m_lstTablesStrings = new List(); 29 | private bool m_HasHeader = false; 30 | 31 | 32 | 33 | 34 | #endregion 35 | 36 | #region properties 37 | 38 | public string WordDocumentPath 39 | { 40 | get 41 | { 42 | return m_strWordPath; 43 | } 44 | } 45 | 46 | public bool FirstRowContainsHeader 47 | { 48 | get 49 | { 50 | return m_HasHeader; 51 | } 52 | } 53 | 54 | public DataSet MainDataset 55 | { 56 | get 57 | { 58 | return m_Maindataset; 59 | } 60 | } 61 | #endregion 62 | 63 | #region constructors 64 | 65 | public MsWordImportTools(string DocumentPath, bool firstRowContainsHeader = false, int v_intRowsToSkip = 0) 66 | { 67 | m_strWordPath = DocumentPath; 68 | m_HasHeader = firstRowContainsHeader; 69 | m_computername = Environment.MachineName; 70 | m_Username = Environment.UserName; 71 | m_intRowsToSkip = v_intRowsToSkip; 72 | } 73 | 74 | #endregion 75 | 76 | #region Methods 77 | 78 | public void ExportDatasetToXml(string xmlPath) 79 | { 80 | m_Maindataset.WriteXml(xmlPath); 81 | } 82 | 83 | public void ImportWordTablesIntoListUsingConvertToText(char delimiter) 84 | { 85 | Range rngTable; 86 | string strTable = string.Empty; 87 | 88 | appWord = new Application(); 89 | appWord.Visible = false; 90 | 91 | docsWord = appWord.Documents; 92 | newDoc = docsWord.Open(this.WordDocumentPath); 93 | 94 | 95 | foreach (Table wTable in newDoc.Tables) 96 | { 97 | rngTable = wTable.ConvertToText(Separator: delimiter, NestedTables: true); 98 | // For Each wRow As Word.Row In wTable.Rows 99 | 100 | strTable = rngTable.Text; 101 | newDoc.Undo(); 102 | 103 | m_lstTablesStrings.Add(strTable); 104 | } 105 | 106 | newDoc.Close(SaveChanges: false); 107 | // docsWord.Close(SaveChanges:=False) 108 | appWord.Quit(SaveChanges: false); 109 | 110 | 111 | System.Runtime.InteropServices.Marshal.ReleaseComObject(newDoc); 112 | System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord); 113 | 114 | 115 | 116 | 117 | } 118 | 119 | public DataSet ConvertListToTables(string v_delimiter) 120 | { 121 | foreach (var strTable in m_lstTablesStrings) 122 | { 123 | int intColumnsCount = GetColumnsCount(strTable, v_delimiter); 124 | string[] strRows = strTable.Split(new string[]{Environment.NewLine},StringSplitOptions.None).Skip(m_intRowsToSkip).ToArray(); 125 | int intRowsCounter = 0; 126 | System.Data.DataTable dtTable = new System.Data.DataTable(); 127 | 128 | foreach (string drRow in strRows) 129 | { 130 | if (string.IsNullOrEmpty(drRow.Trim())) 131 | continue; 132 | 133 | string[] strCells = drRow.Split(new string[] { v_delimiter}, StringSplitOptions.None); 134 | 135 | 136 | 137 | if (m_HasHeader && intRowsCounter == 0) 138 | { 139 | for (var intCount = 0; intCount <= intColumnsCount - 1; intCount++) 140 | { 141 | DataColumn dtCol = new DataColumn(); 142 | 143 | if (strCells.Length <= intCount || string.IsNullOrEmpty(strCells[intCount])) 144 | { 145 | dtCol.ColumnName = "F" + intCount; 146 | dtCol.Caption = "F" + intCount; 147 | } 148 | else 149 | { 150 | dtCol.ColumnName = strCells[intCount].Trim(); 151 | // .Replace(" ", "_") 152 | 153 | dtCol.Caption = strCells[intCount].Trim(); 154 | } 155 | 156 | dtTable.Columns.Add(dtCol); 157 | } 158 | 159 | intRowsCounter += 1; 160 | continue; 161 | } 162 | else if (intRowsCounter == 0) 163 | { 164 | for (int intCount = 0; intCount <= intColumnsCount - 1; intCount++) 165 | { 166 | DataColumn dtCol = new DataColumn(); 167 | 168 | dtCol.ColumnName = "F" + intCount; 169 | dtCol.Caption = "F" + intCount; 170 | 171 | dtTable.Columns.Add(dtCol); 172 | } 173 | } 174 | // Try 175 | 176 | 177 | InsertArrayofStringIntoDataRow(strCells, ref dtTable); 178 | intRowsCounter += 1; 179 | } 180 | 181 | m_Maindataset.Tables.Add(dtTable); 182 | } 183 | 184 | return m_Maindataset; 185 | } 186 | 187 | public int GetColumnsCount(string strTable, string delimiter) 188 | { 189 | int r_intResult = 0; 190 | string[] strRows = strTable.Split(new string[] {Environment.NewLine},StringSplitOptions.None); 191 | 192 | for (var i = 0; i <= 8; i++) 193 | { 194 | if (strRows.Length > i) 195 | { 196 | string[] strCells = strRows[i].Split(new string[] { delimiter }, StringSplitOptions.None); 197 | 198 | if (strCells.Length > r_intResult) 199 | r_intResult = strCells.Length; 200 | } 201 | else 202 | break; 203 | } 204 | 205 | return r_intResult; 206 | } 207 | 208 | public void ImportWordTablesIntoList(string delimiter) 209 | { 210 | 211 | // Dim rngTable As Word.Range 212 | string strTable = string.Empty; 213 | 214 | appWord = new Application(); 215 | appWord.Visible = false; 216 | 217 | docsWord = appWord.Documents; 218 | newDoc = docsWord.Open(this.WordDocumentPath); 219 | 220 | 221 | foreach (Table wTable in newDoc.Tables) 222 | { 223 | string strText = string.Empty; 224 | var intRowCounter = 1; 225 | int intColumnIndex = 1; 226 | foreach (Cell wCell in wTable.Range.Cells) 227 | { 228 | if (wCell.RowIndex == intRowCounter) 229 | { 230 | for (var intCount = 1; intCount <= (wCell.ColumnIndex - intColumnIndex); intCount++) 231 | strText += delimiter; 232 | 233 | strText += CleaningCellText(wCell.Range.Text, delimiter); 234 | 235 | intColumnIndex = wCell.ColumnIndex; 236 | } 237 | else 238 | { 239 | strText += Environment.NewLine + CleaningCellText(wCell.Range.Text, delimiter); 240 | 241 | intColumnIndex = wCell.ColumnIndex; 242 | intRowCounter += 1; 243 | } 244 | } 245 | 246 | m_lstTablesStrings.Add(strText); 247 | } 248 | 249 | newDoc.Close(SaveChanges: false); 250 | // docsWord.Close(SaveChanges:=False) 251 | appWord.Quit(SaveChanges: false); 252 | 253 | System.Runtime.InteropServices.Marshal.ReleaseComObject(newDoc); 254 | System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord); 255 | 256 | } 257 | 258 | public string CleaningCellText(string v_strText, string delimiter) 259 | { 260 | string strText = v_strText.Trim(); 261 | 262 | strText = strText.Replace(Environment.NewLine, " "); 263 | strText = strText.Replace(Constants.vbCr, " "); 264 | strText = strText.Replace(Constants.vbLf, " "); 265 | strText = strText.Replace("", " "); 266 | strText = strText.Replace(delimiter, " "); 267 | strText = strText.Replace(" ", " ").Replace(" ", " "); 268 | 269 | return strText; 270 | } 271 | 272 | public void InsertArrayofStringIntoDataRow(string[] arrayStr, ref System.Data.DataTable dtTable) 273 | { 274 | DataRow dtRow; 275 | dtRow = dtTable.NewRow(); 276 | int intColCounter = 0; 277 | 278 | foreach (string strCell in arrayStr) 279 | { 280 | dtRow[intColCounter] = strCell; 281 | intColCounter += 1; 282 | } 283 | 284 | dtTable.Rows.Add(dtRow); 285 | } 286 | 287 | public void WriteToTxtFile(string strFilePath, System.Text.Encoding encoding) 288 | { 289 | StreamWriter fsWriteFile = new StreamWriter(strFilePath, true, encoding); 290 | 291 | int intCounter = 0; 292 | foreach (string Str in m_lstTablesStrings) 293 | { 294 | fsWriteFile.Write(Str); 295 | 296 | if (intCounter < m_lstTablesStrings.Count - 1) 297 | { 298 | fsWriteFile.Write(Environment.NewLine); 299 | fsWriteFile.Write("------------------------------"); 300 | fsWriteFile.Write(Environment.NewLine); 301 | } 302 | 303 | 304 | intCounter += 1; 305 | } 306 | 307 | fsWriteFile.Close(); 308 | } 309 | 310 | public void WriteToTxtFile(string strFilePath, int codepage) 311 | { 312 | StreamWriter fsWriteFile = new StreamWriter(strFilePath, true, System.Text.Encoding.GetEncoding(codepage)); 313 | 314 | int intCounter = 0; 315 | foreach (string Str in m_lstTablesStrings) 316 | { 317 | fsWriteFile.Write(Str); 318 | 319 | if (intCounter < m_lstTablesStrings.Count - 1) 320 | { 321 | fsWriteFile.Write(Environment.NewLine); 322 | fsWriteFile.Write("------------------------------"); 323 | fsWriteFile.Write(Environment.NewLine); 324 | } 325 | 326 | 327 | intCounter += 1; 328 | } 329 | 330 | fsWriteFile.Close(); 331 | } 332 | 333 | public void WriteToTxtFile(string strFilePath) 334 | { 335 | StreamWriter fsWriteFile = new StreamWriter(strFilePath, true); 336 | 337 | int intCounter = 0; 338 | foreach (string Str in m_lstTablesStrings) 339 | { 340 | fsWriteFile.Write(Str); 341 | 342 | if (intCounter < m_lstTablesStrings.Count - 1) 343 | { 344 | fsWriteFile.Write(Environment.NewLine); 345 | fsWriteFile.Write("------------------------------"); 346 | fsWriteFile.Write(Environment.NewLine); 347 | } 348 | 349 | 350 | intCounter += 1; 351 | } 352 | 353 | fsWriteFile.Close(); 354 | } 355 | 356 | 357 | 358 | #endregion 359 | 360 | private bool disposedValue = false; // To detect redundant calls 361 | 362 | // IDisposable 363 | protected virtual void Dispose(bool disposing) 364 | { 365 | if (!this.disposedValue) 366 | { 367 | if (disposing) 368 | { 369 | newDoc = null; 370 | docsWord = null; 371 | appWord = null; 372 | 373 | if (m_Maindataset != null) 374 | m_Maindataset.Dispose(); 375 | 376 | m_lstTablesStrings = null; 377 | // xmlConverter = Nothing 378 | m_strWordPath = null; 379 | m_HasHeader = default(Boolean); 380 | } 381 | } 382 | this.disposedValue = true; 383 | } 384 | 385 | // This code added by Visual Basic to correctly implement the disposable pattern. 386 | public void Dispose() 387 | { 388 | // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. 389 | Dispose(true); 390 | GC.SuppressFinalize(this); 391 | } 392 | } 393 | } 394 | 395 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/MySQLImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using MySql.Data.MySqlClient; 8 | 9 | namespace SchemaMapper.Converters 10 | { 11 | public class MySQLImport : BaseDbImport, IDisposable 12 | { 13 | #region constructors 14 | 15 | public MySQLImport(string connectionstring) 16 | { 17 | 18 | ConnectionString = connectionstring; 19 | 20 | } 21 | 22 | #endregion 23 | 24 | #region methods 25 | 26 | public override void getSchemaTable() 27 | { 28 | try 29 | { 30 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 31 | { 32 | 33 | if (sqlcon.State != ConnectionState.Open) 34 | sqlcon.Open(); 35 | 36 | SchemaTable = sqlcon.GetSchema("Tables"); 37 | 38 | 39 | } 40 | } 41 | catch (Exception ex) 42 | { 43 | throw ex; 44 | } 45 | 46 | } 47 | 48 | public override DataTable GetDataTable(string schema, string tablename) 49 | { 50 | try 51 | { 52 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 53 | { 54 | 55 | if (sqlcon.State != ConnectionState.Open) 56 | sqlcon.Open(); 57 | 58 | using (MySqlDataAdapter da = new MySqlDataAdapter("Select * From `" + schema + "`.`" + tablename + "`", sqlcon)) 59 | { 60 | 61 | da.Fill(SQLTable); 62 | 63 | } 64 | 65 | 66 | } 67 | } 68 | catch (Exception ex) 69 | { 70 | throw ex; 71 | } 72 | 73 | return SQLTable; 74 | } 75 | 76 | public DataTable GetQueryResult(MySqlCommand sqlcmd) 77 | { 78 | try 79 | { 80 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 81 | { 82 | 83 | if (sqlcon.State != ConnectionState.Open) 84 | sqlcon.Open(); 85 | 86 | sqlcmd.Connection = sqlcon; 87 | 88 | using (MySqlDataAdapter da = new MySqlDataAdapter(sqlcmd)) 89 | { 90 | 91 | da.Fill(SQLTable); 92 | 93 | } 94 | 95 | SQLTable.PrimaryKey = null; 96 | 97 | } 98 | } 99 | catch (Exception ex) 100 | { 101 | throw ex; 102 | } 103 | 104 | return SQLTable; 105 | } 106 | 107 | public override DataTable GetQueryResult(string sqlQuery) 108 | { 109 | try 110 | { 111 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 112 | { 113 | 114 | if (sqlcon.State != ConnectionState.Open) 115 | sqlcon.Open(); 116 | 117 | using (MySqlDataAdapter da = new MySqlDataAdapter(sqlQuery, sqlcon)) 118 | { 119 | 120 | da.Fill(SQLTable); 121 | 122 | } 123 | 124 | SQLTable.PrimaryKey = null; 125 | 126 | } 127 | } 128 | catch (Exception ex) 129 | { 130 | throw ex; 131 | } 132 | 133 | return SQLTable; 134 | } 135 | 136 | public override DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 137 | { 138 | try 139 | { 140 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 141 | { 142 | 143 | if (sqlcon.State != ConnectionState.Open) 144 | sqlcon.Open(); 145 | 146 | using (MySqlDataAdapter da = new MySqlDataAdapter("Select * From `" + schema + "`.`" + tablename + "`", sqlcon)) 147 | { 148 | 149 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 150 | 151 | } 152 | 153 | SQLTable.PrimaryKey = null; 154 | 155 | } 156 | } 157 | catch (Exception ex) 158 | { 159 | throw ex; 160 | } 161 | 162 | return SQLTable; 163 | } 164 | 165 | public override DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 166 | { 167 | try 168 | { 169 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 170 | { 171 | 172 | if (sqlcon.State != ConnectionState.Open) 173 | sqlcon.Open(); 174 | 175 | using (MySqlDataAdapter da = new MySqlDataAdapter(sqlQuery, sqlcon)) 176 | { 177 | 178 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 179 | 180 | } 181 | 182 | SQLTable.PrimaryKey = null; 183 | 184 | } 185 | } 186 | catch (Exception ex) 187 | { 188 | throw ex; 189 | } 190 | 191 | return SQLTable; 192 | } 193 | 194 | public DataTable GetDataTableWithPaging(MySqlCommand sqlcmd, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 195 | { 196 | try 197 | { 198 | 199 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 200 | { 201 | 202 | if (sqlcon.State != ConnectionState.Open) 203 | sqlcon.Open(); 204 | 205 | sqlcmd.Connection = sqlcon; 206 | 207 | using (MySqlDataAdapter da = new MySqlDataAdapter(sqlcmd)) 208 | { 209 | 210 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 211 | 212 | } 213 | 214 | SQLTable.PrimaryKey = null; 215 | 216 | } 217 | } 218 | catch (Exception ex) 219 | { 220 | throw ex; 221 | } 222 | 223 | return SQLTable; 224 | } 225 | 226 | #endregion 227 | 228 | public void Dispose() 229 | { 230 | 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/OracleImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Oracle.DataAccess.Client; 8 | using Oracle.DataAccess.Types; 9 | 10 | 11 | namespace SchemaMapper.Converters 12 | { 13 | public class OracleImport : BaseDbImport, IDisposable 14 | { 15 | 16 | #region constructors 17 | 18 | public OracleImport(string connectionstring) 19 | { 20 | 21 | ConnectionString = connectionstring; 22 | 23 | } 24 | 25 | #endregion 26 | 27 | #region methods 28 | 29 | public override void getSchemaTable() 30 | { 31 | try 32 | { 33 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 34 | { 35 | 36 | if (sqlcon.State != ConnectionState.Open) 37 | sqlcon.Open(); 38 | 39 | SchemaTable = sqlcon.GetSchema("Tables"); 40 | 41 | 42 | } 43 | } 44 | catch (Exception ex) 45 | { 46 | throw ex; 47 | } 48 | 49 | } 50 | 51 | public override DataTable GetDataTable(string schema, string tablename) 52 | { 53 | try 54 | { 55 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 56 | { 57 | 58 | if (sqlcon.State != ConnectionState.Open) 59 | sqlcon.Open(); 60 | 61 | using (OracleDataAdapter da = new OracleDataAdapter("Select * From \"" + schema + "\".\"" + tablename + "\"", sqlcon)) 62 | { 63 | 64 | da.Fill(SQLTable); 65 | 66 | } 67 | 68 | 69 | } 70 | } 71 | catch (Exception ex) 72 | { 73 | throw ex; 74 | } 75 | 76 | return SQLTable; 77 | } 78 | 79 | public override DataTable GetQueryResult(string sqlQuery) 80 | { 81 | try 82 | { 83 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 84 | { 85 | 86 | if (sqlcon.State != ConnectionState.Open) 87 | sqlcon.Open(); 88 | 89 | using (OracleDataAdapter da = new OracleDataAdapter(sqlQuery, sqlcon)) 90 | { 91 | 92 | da.Fill(SQLTable); 93 | 94 | } 95 | 96 | SQLTable.PrimaryKey = null; 97 | 98 | } 99 | } 100 | catch (Exception ex) 101 | { 102 | throw ex; 103 | } 104 | 105 | return SQLTable; 106 | } 107 | 108 | public override DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 109 | { 110 | try 111 | { 112 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 113 | { 114 | 115 | if (sqlcon.State != ConnectionState.Open) 116 | sqlcon.Open(); 117 | 118 | using (OracleDataAdapter da = new OracleDataAdapter("Select * From \"" + schema + "\".\"" + tablename + "\"", sqlcon)) 119 | { 120 | 121 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 122 | 123 | } 124 | 125 | SQLTable.PrimaryKey = null; 126 | 127 | } 128 | } 129 | catch (Exception ex) 130 | { 131 | throw ex; 132 | } 133 | 134 | return SQLTable; 135 | } 136 | 137 | public override DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 138 | { 139 | try 140 | { 141 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 142 | { 143 | 144 | if (sqlcon.State != ConnectionState.Open) 145 | sqlcon.Open(); 146 | 147 | using (OracleDataAdapter da = new OracleDataAdapter(sqlQuery, sqlcon)) 148 | { 149 | 150 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 151 | 152 | } 153 | 154 | SQLTable.PrimaryKey = null; 155 | 156 | } 157 | } 158 | catch (Exception ex) 159 | { 160 | throw ex; 161 | } 162 | 163 | return SQLTable; 164 | } 165 | 166 | public DataTable GetDataTableWithPaging(OracleCommand sqlcmd, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 167 | { 168 | try 169 | { 170 | 171 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 172 | { 173 | 174 | if (sqlcon.State != ConnectionState.Open) 175 | sqlcon.Open(); 176 | 177 | sqlcmd.Connection = sqlcon; 178 | 179 | using (OracleDataAdapter da = new OracleDataAdapter(sqlcmd)) 180 | { 181 | 182 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 183 | 184 | } 185 | 186 | SQLTable.PrimaryKey = null; 187 | 188 | } 189 | } 190 | catch (Exception ex) 191 | { 192 | throw ex; 193 | } 194 | 195 | return SQLTable; 196 | } 197 | 198 | public DataTable GetQueryResult(OracleCommand oracmd) 199 | { 200 | try 201 | { 202 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 203 | { 204 | 205 | if (sqlcon.State != ConnectionState.Open) 206 | sqlcon.Open(); 207 | 208 | oracmd.Connection = sqlcon; 209 | 210 | using (OracleDataAdapter da = new OracleDataAdapter(oracmd)) 211 | { 212 | 213 | da.Fill(SQLTable); 214 | 215 | } 216 | 217 | SQLTable.PrimaryKey = null; 218 | 219 | } 220 | } 221 | catch (Exception ex) 222 | { 223 | throw ex; 224 | } 225 | 226 | return SQLTable; 227 | } 228 | #endregion 229 | 230 | public void Dispose() 231 | { 232 | 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/SQLiteImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Data.SQLite; 8 | using System.Data.SQLite.Generic; 9 | 10 | namespace SchemaMapper.Converters 11 | { 12 | public class SQLiteImport : BaseDbImport, IDisposable 13 | { 14 | 15 | #region constructors 16 | 17 | public SQLiteImport(string connectionstring) 18 | { 19 | 20 | ConnectionString = connectionstring; 21 | 22 | } 23 | 24 | #endregion 25 | 26 | #region methods 27 | 28 | public override void getSchemaTable() 29 | { 30 | try 31 | { 32 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 33 | { 34 | 35 | if (sqlcon.State != ConnectionState.Open) 36 | sqlcon.Open(); 37 | 38 | SchemaTable = sqlcon.GetSchema("Tables"); 39 | 40 | 41 | } 42 | } 43 | catch (Exception ex) 44 | { 45 | throw ex; 46 | } 47 | 48 | } 49 | 50 | public override DataTable GetDataTable(string schema, string tablename) 51 | { 52 | try 53 | { 54 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 55 | { 56 | 57 | if (sqlcon.State != ConnectionState.Open) 58 | sqlcon.Open(); 59 | 60 | using (SQLiteDataAdapter da = new SQLiteDataAdapter("Select * From [" + schema + "].[" + tablename + "]", sqlcon)) 61 | { 62 | 63 | da.Fill(SQLTable); 64 | 65 | } 66 | 67 | 68 | } 69 | } 70 | catch (Exception ex) 71 | { 72 | throw ex; 73 | } 74 | 75 | return SQLTable; 76 | } 77 | 78 | public DataTable GetQueryResult(SQLiteCommand sqlcmd) 79 | { 80 | try 81 | { 82 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 83 | { 84 | 85 | if (sqlcon.State != ConnectionState.Open) 86 | sqlcon.Open(); 87 | 88 | sqlcmd.Connection = sqlcon; 89 | 90 | using (SQLiteDataAdapter da = new SQLiteDataAdapter(sqlcmd)) 91 | { 92 | 93 | da.Fill(SQLTable); 94 | 95 | } 96 | 97 | SQLTable.PrimaryKey = null; 98 | 99 | } 100 | } 101 | catch (Exception ex) 102 | { 103 | throw ex; 104 | } 105 | 106 | return SQLTable; 107 | } 108 | 109 | public override DataTable GetQueryResult(string sqlQuery) 110 | { 111 | try 112 | { 113 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 114 | { 115 | 116 | if (sqlcon.State != ConnectionState.Open) 117 | sqlcon.Open(); 118 | 119 | using (SQLiteDataAdapter da = new SQLiteDataAdapter(sqlQuery, sqlcon)) 120 | { 121 | 122 | da.Fill(SQLTable); 123 | 124 | } 125 | 126 | SQLTable.PrimaryKey = null; 127 | 128 | } 129 | } 130 | catch (Exception ex) 131 | { 132 | throw ex; 133 | } 134 | 135 | return SQLTable; 136 | } 137 | 138 | public override DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 139 | { 140 | try 141 | { 142 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 143 | { 144 | 145 | if (sqlcon.State != ConnectionState.Open) 146 | sqlcon.Open(); 147 | 148 | using (SQLiteDataAdapter da = new SQLiteDataAdapter("Select * From [" + schema + "].[" + tablename + "]", sqlcon)) 149 | { 150 | 151 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 152 | 153 | } 154 | 155 | SQLTable.PrimaryKey = null; 156 | 157 | } 158 | } 159 | catch (Exception ex) 160 | { 161 | throw ex; 162 | } 163 | 164 | return SQLTable; 165 | } 166 | 167 | public override DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 168 | { 169 | try 170 | { 171 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 172 | { 173 | 174 | if (sqlcon.State != ConnectionState.Open) 175 | sqlcon.Open(); 176 | 177 | using (SQLiteDataAdapter da = new SQLiteDataAdapter(sqlQuery, sqlcon)) 178 | { 179 | 180 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 181 | 182 | } 183 | 184 | SQLTable.PrimaryKey = null; 185 | 186 | } 187 | } 188 | catch (Exception ex) 189 | { 190 | throw ex; 191 | } 192 | 193 | return SQLTable; 194 | } 195 | 196 | public DataTable GetDataTableWithPaging(SQLiteCommand sqlcmd, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 197 | { 198 | try 199 | { 200 | using (SQLiteConnection sqlcon = new SQLiteConnection(ConnectionString)) 201 | { 202 | 203 | if (sqlcon.State != ConnectionState.Open) 204 | sqlcon.Open(); 205 | 206 | sqlcmd.Connection = sqlcon; 207 | 208 | using (SQLiteDataAdapter da = new SQLiteDataAdapter(sqlcmd)) 209 | { 210 | 211 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 212 | 213 | } 214 | 215 | SQLTable.PrimaryKey = null; 216 | 217 | } 218 | } 219 | catch (Exception ex) 220 | { 221 | throw ex; 222 | } 223 | 224 | return SQLTable; 225 | } 226 | 227 | #endregion 228 | 229 | public void Dispose() 230 | { 231 | 232 | } 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/SqlServerCeImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Data.SqlServerCe; 8 | using System.Data.SqlClient; 9 | 10 | 11 | namespace SchemaMapper.Converters 12 | { 13 | public class SqlServerCeImport : BaseDbImport, IDisposable 14 | { 15 | 16 | #region constructors 17 | 18 | public SqlServerCeImport(string connectionstring) 19 | { 20 | 21 | ConnectionString = connectionstring; 22 | 23 | } 24 | 25 | #endregion 26 | 27 | #region methods 28 | 29 | public override void getSchemaTable() 30 | { 31 | try 32 | { 33 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 34 | { 35 | 36 | if (sqlcon.State != ConnectionState.Open) 37 | sqlcon.Open(); 38 | 39 | using (SqlCeDataAdapter da = new SqlCeDataAdapter("Select * From Information_Schema.Tables", sqlcon)) 40 | { 41 | 42 | da.Fill(SchemaTable); 43 | 44 | } 45 | 46 | 47 | } 48 | } 49 | catch (Exception ex) 50 | { 51 | throw ex; 52 | } 53 | 54 | } 55 | 56 | public override DataTable GetDataTable(string schema, string tablename) 57 | { 58 | try 59 | { 60 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 61 | { 62 | 63 | if (sqlcon.State != ConnectionState.Open) 64 | sqlcon.Open(); 65 | 66 | SchemaTable = sqlcon.GetSchema("Tables"); 67 | 68 | 69 | } 70 | } 71 | catch (Exception ex) 72 | { 73 | throw ex; 74 | } 75 | 76 | return SQLTable; 77 | } 78 | 79 | public DataTable GetQueryResult(SqlCeCommand sqlcmd) 80 | { 81 | try 82 | { 83 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 84 | { 85 | 86 | if (sqlcon.State != ConnectionState.Open) 87 | sqlcon.Open(); 88 | 89 | sqlcmd.Connection = sqlcon; 90 | 91 | using (SqlCeDataAdapter da = new SqlCeDataAdapter(sqlcmd)) 92 | { 93 | 94 | da.Fill(SQLTable); 95 | 96 | } 97 | 98 | SQLTable.PrimaryKey = null; 99 | 100 | } 101 | } 102 | catch (Exception ex) 103 | { 104 | throw ex; 105 | } 106 | 107 | return SQLTable; 108 | } 109 | 110 | public override DataTable GetQueryResult(string sqlQuery) 111 | { 112 | try 113 | { 114 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 115 | { 116 | 117 | if (sqlcon.State != ConnectionState.Open) 118 | sqlcon.Open(); 119 | 120 | using (SqlCeDataAdapter da = new SqlCeDataAdapter(sqlQuery, sqlcon)) 121 | { 122 | 123 | da.Fill(SQLTable); 124 | 125 | } 126 | 127 | SQLTable.PrimaryKey = null; 128 | 129 | } 130 | } 131 | catch (Exception ex) 132 | { 133 | throw ex; 134 | } 135 | 136 | return SQLTable; 137 | } 138 | 139 | public override DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 140 | { 141 | try 142 | { 143 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 144 | { 145 | 146 | if (sqlcon.State != ConnectionState.Open) 147 | sqlcon.Open(); 148 | 149 | using (SqlCeDataAdapter da = new SqlCeDataAdapter("Select * From [" + schema + "].[" + tablename + "]", sqlcon)) 150 | { 151 | 152 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 153 | 154 | } 155 | 156 | SQLTable.PrimaryKey = null; 157 | 158 | } 159 | } 160 | catch (Exception ex) 161 | { 162 | throw ex; 163 | } 164 | 165 | return SQLTable; 166 | } 167 | 168 | public override DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 169 | { 170 | try 171 | { 172 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 173 | { 174 | 175 | if (sqlcon.State != ConnectionState.Open) 176 | sqlcon.Open(); 177 | 178 | using (SqlCeDataAdapter da = new SqlCeDataAdapter(sqlQuery, sqlcon)) 179 | { 180 | 181 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 182 | 183 | } 184 | 185 | SQLTable.PrimaryKey = null; 186 | 187 | } 188 | } 189 | catch (Exception ex) 190 | { 191 | throw ex; 192 | } 193 | 194 | return SQLTable; 195 | } 196 | 197 | public DataTable GetDataTableWithPaging(SqlCeCommand sqlcmd, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 198 | { 199 | try 200 | { 201 | using (SqlCeConnection sqlcon = new SqlCeConnection(ConnectionString)) 202 | { 203 | 204 | if (sqlcon.State != ConnectionState.Open) 205 | sqlcon.Open(); 206 | 207 | sqlcmd.Connection = sqlcon; 208 | 209 | using (SqlCeDataAdapter da = new SqlCeDataAdapter(sqlcmd)) 210 | { 211 | 212 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 213 | 214 | } 215 | 216 | SQLTable.PrimaryKey = null; 217 | 218 | } 219 | } 220 | catch (Exception ex) 221 | { 222 | throw ex; 223 | } 224 | 225 | return SQLTable; 226 | } 227 | 228 | #endregion 229 | 230 | public void Dispose() 231 | { 232 | 233 | } 234 | 235 | 236 | 237 | 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/SqlServerImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.SqlClient; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SchemaMapper.Converters 10 | { 11 | public class SqlServerImport : BaseDbImport, IDisposable 12 | { 13 | 14 | #region constructors 15 | 16 | public SqlServerImport(string connectionstring){ 17 | 18 | ConnectionString = connectionstring; 19 | 20 | } 21 | 22 | #endregion 23 | 24 | #region methods 25 | 26 | public override void getSchemaTable() 27 | { 28 | try 29 | { 30 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 31 | { 32 | 33 | if (sqlcon.State != ConnectionState.Open) 34 | sqlcon.Open(); 35 | 36 | SchemaTable = sqlcon.GetSchema("Tables"); 37 | 38 | 39 | } 40 | } 41 | catch (Exception ex) 42 | { 43 | throw ex; 44 | } 45 | 46 | } 47 | 48 | public override DataTable GetDataTable(string schema, string tablename) 49 | { 50 | try 51 | { 52 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 53 | { 54 | 55 | if (sqlcon.State != ConnectionState.Open) 56 | sqlcon.Open(); 57 | 58 | using (SqlDataAdapter da = new SqlDataAdapter("Select * From [" + schema + "].[" + tablename + "]", sqlcon)) 59 | { 60 | 61 | da.Fill(SQLTable); 62 | 63 | } 64 | 65 | 66 | } 67 | } 68 | catch (Exception ex) 69 | { 70 | throw ex; 71 | } 72 | 73 | return SQLTable; 74 | } 75 | 76 | public DataTable GetQueryResult(SqlCommand sqlcmd) 77 | { 78 | try 79 | { 80 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 81 | { 82 | 83 | if (sqlcon.State != ConnectionState.Open) 84 | sqlcon.Open(); 85 | 86 | sqlcmd.Connection = sqlcon; 87 | 88 | using (SqlDataAdapter da = new SqlDataAdapter(sqlcmd)) 89 | { 90 | 91 | da.Fill(SQLTable); 92 | 93 | } 94 | 95 | SQLTable.PrimaryKey = null; 96 | 97 | } 98 | } 99 | catch (Exception ex) 100 | { 101 | throw ex; 102 | } 103 | 104 | return SQLTable; 105 | } 106 | 107 | public override DataTable GetQueryResult(string sqlQuery) 108 | { 109 | try 110 | { 111 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 112 | { 113 | 114 | if (sqlcon.State != ConnectionState.Open) 115 | sqlcon.Open(); 116 | 117 | using (SqlDataAdapter da = new SqlDataAdapter(sqlQuery, sqlcon)) 118 | { 119 | 120 | da.Fill(SQLTable); 121 | 122 | } 123 | 124 | SQLTable.PrimaryKey = null; 125 | 126 | } 127 | } 128 | catch (Exception ex) 129 | { 130 | throw ex; 131 | } 132 | 133 | return SQLTable; 134 | } 135 | 136 | public override DataTable GetDataTableWithPaging(string schema, string tablename, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 137 | { 138 | try 139 | { 140 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 141 | { 142 | 143 | if (sqlcon.State != ConnectionState.Open) 144 | sqlcon.Open(); 145 | 146 | using (SqlDataAdapter da = new SqlDataAdapter("Select * From [" + schema + "].[" + tablename + "]", sqlcon)) 147 | { 148 | 149 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 150 | 151 | } 152 | 153 | SQLTable.PrimaryKey = null; 154 | 155 | } 156 | } 157 | catch (Exception ex) 158 | { 159 | throw ex; 160 | } 161 | 162 | return SQLTable; 163 | } 164 | 165 | public override DataTable GetDataTableWithPaging(string sqlQuery, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 166 | { 167 | try 168 | { 169 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 170 | { 171 | 172 | if (sqlcon.State != ConnectionState.Open) 173 | sqlcon.Open(); 174 | 175 | using (SqlDataAdapter da = new SqlDataAdapter(sqlQuery, sqlcon)) 176 | { 177 | 178 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 179 | 180 | } 181 | 182 | SQLTable.PrimaryKey = null; 183 | 184 | } 185 | } 186 | catch (Exception ex) 187 | { 188 | throw ex; 189 | } 190 | 191 | return SQLTable; 192 | } 193 | 194 | public DataTable GetDataTableWithPaging(SqlCommand sqlcmd, int v_PagingStartRecord, int v_PagingInterval, out int r_result) 195 | { 196 | try 197 | { 198 | 199 | using (SqlConnection sqlcon = new SqlConnection(ConnectionString)) 200 | { 201 | 202 | if (sqlcon.State != ConnectionState.Open) 203 | sqlcon.Open(); 204 | 205 | sqlcmd.Connection = sqlcon; 206 | 207 | using (SqlDataAdapter da = new SqlDataAdapter(sqlcmd)) 208 | { 209 | 210 | r_result = da.Fill(v_PagingStartRecord, v_PagingInterval, SQLTable); 211 | 212 | } 213 | 214 | SQLTable.PrimaryKey = null; 215 | 216 | } 217 | } 218 | catch (Exception ex) 219 | { 220 | throw ex; 221 | } 222 | 223 | return SQLTable; 224 | } 225 | 226 | #endregion 227 | 228 | public void Dispose() 229 | { 230 | 231 | } 232 | 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/XmlImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SchemaMapper.Converters 9 | { 10 | public class XmlImport : BaseImport, IDisposable 11 | { 12 | 13 | public XmlImport(string xmlpath) 14 | { 15 | 16 | 17 | FilePath = xmlpath; 18 | } 19 | 20 | 21 | public DataSet ReadDataSetFromXml(XmlReadMode ReadMode) 22 | { 23 | 24 | Maindataset.ReadXml(FilePath, ReadMode); 25 | 26 | return Maindataset; 27 | 28 | 29 | } 30 | 31 | public DataTable ReadDataTableFromXml() 32 | { 33 | 34 | DataTable dt = new DataTable(); 35 | dt.ReadXml(FilePath); 36 | 37 | return dt; 38 | 39 | 40 | } 41 | 42 | public void Dispose() 43 | { 44 | Maindataset.Dispose(); 45 | } 46 | 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Converters/vCardImport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Data; 4 | using LumiSoft.Net.Mime.vCard; 5 | using Fonlow.VCard; 6 | 7 | namespace SchemaMapper.Converters 8 | { 9 | public class vCardImport : BaseImport, IDisposable 10 | { 11 | 12 | 13 | public DataTable BuildTableStructure() 14 | { 15 | DataTable m_DataTable = new DataTable("DT"); 16 | 17 | m_DataTable.Columns.Add("Full Name"); 18 | m_DataTable.Columns.Add("Surname"); 19 | m_DataTable.Columns.Add("GivenName"); 20 | m_DataTable.Columns.Add("MiddleName"); 21 | m_DataTable.Columns.Add("Title"); 22 | m_DataTable.Columns.Add("Prefix"); 23 | m_DataTable.Columns.Add("Suffix"); 24 | m_DataTable.Columns.Add("Birthday"); 25 | m_DataTable.Columns.Add("Rev"); 26 | m_DataTable.Columns.Add("Organization"); 27 | m_DataTable.Columns.Add("Phones"); 28 | m_DataTable.Columns.Add("Emails"); 29 | m_DataTable.Columns.Add("URL"); 30 | m_DataTable.Columns.Add("Addresses"); 31 | m_DataTable.Columns.Add("Note"); 32 | 33 | return m_DataTable; 34 | } 35 | 36 | public DataTable ImportDataToDataTable() 37 | { 38 | 39 | DataTable dt = BuildTableStructure(); 40 | 41 | String Vcf = File.ReadAllText(FilePath); 42 | Fonlow.VCard.VCard vc = VCardReader.ParseText(Vcf); 43 | DataRow dr = dt.NewRow(); 44 | 45 | if (String.IsNullOrEmpty(vc.FormattedName) == false) 46 | { 47 | dr["Full Name"] = vc.FormattedName; 48 | } 49 | 50 | if (String.IsNullOrEmpty(vc.FormattedName) == false) 51 | { 52 | dr["Surname"] = vc.Surname; 53 | } 54 | 55 | if (String.IsNullOrEmpty(vc.GivenName) == false) 56 | { 57 | dr["GivenName"] = vc.GivenName; 58 | } 59 | 60 | if (String.IsNullOrEmpty(vc.MiddleName) == false) 61 | { 62 | dr["MiddleName"] = vc.MiddleName; 63 | } 64 | 65 | if (String.IsNullOrEmpty(vc.Title) == false) 66 | { 67 | dr["Title"] = vc.Title; 68 | } 69 | 70 | if (String.IsNullOrEmpty(vc.Prefix) == false) 71 | { 72 | dr["Prefix"] = vc.Prefix; 73 | } 74 | 75 | if (String.IsNullOrEmpty(vc.Suffix) == false) 76 | { 77 | dr["Suffix"] = vc.Suffix; 78 | } 79 | 80 | if (vc.Birthday > DateTime.MinValue) 81 | { 82 | dr["Birthday"] = vc.Birthday.ToLongDateString(); 83 | } 84 | 85 | if (vc.Rev > DateTime.MinValue) 86 | { 87 | dr["Rev"] = vc.Rev.ToLongDateString(); 88 | } 89 | 90 | if (String.IsNullOrEmpty(vc.Org) == false) 91 | { 92 | dr["Org"] = vc.Org; 93 | } 94 | 95 | for (int j = 0; j == vc.Phones.Count - 1; j++) 96 | { 97 | 98 | if (String.IsNullOrEmpty(dr["Phones"].ToString()) == false) 99 | { 100 | 101 | dr["Phones"] = dr["Phones"] + " | " + ("Phone " + vc.Phones[j].PhoneTypes.ToString("G") + " " + vc.Phones[j].HomeWorkTypes.ToString() + " (Preferred = " + 102 | (vc.Phones[j].Pref + ") =" + vc.Phones[j].Number)); 103 | } 104 | else 105 | { 106 | dr["Phones"] = ("Phone " + vc.Phones[j].PhoneTypes.ToString("G") + " " + vc.Phones[j].HomeWorkTypes.ToString() + " (Preferred = " + 107 | (vc.Phones[j].Pref + ") =" + vc.Phones[j].Number)); 108 | 109 | } 110 | 111 | } 112 | 113 | for (int j = 0; j == vc.Emails.Count - 1; j++) 114 | { 115 | 116 | if (String.IsNullOrEmpty(dr["Emails"].ToString()) == false) 117 | { 118 | 119 | dr["Emails"] = dr["Emails"] + " | " + ("Email " + " (Preferred = " + (vc.Emails[j].Pref.ToString()) + ") =" + vc.Emails[j].Address); 120 | } 121 | else 122 | { 123 | 124 | dr["Emails"] = ("Email " + " (Preferred = " + (vc.Emails[j].Pref.ToString()) + ") =" + vc.Emails[j].Address); 125 | } 126 | 127 | } 128 | 129 | for (int j = 0; j == vc.URLs.Count - 1; j++) 130 | { 131 | if (String.IsNullOrEmpty(dr["URL"].ToString()) == false) 132 | { 133 | 134 | dr["URL"] = dr["URL"] + " | " + ("URL " + vc.URLs[j].HomeWorkTypes.ToString() + " " + "=" + vc.URLs[j].Address); 135 | } 136 | else 137 | { 138 | 139 | dr["URL"] = ("URL " + vc.URLs[j].HomeWorkTypes.ToString() + " " + "=" + vc.URLs[j].Address); 140 | } 141 | 142 | 143 | } 144 | 145 | for (int j = 0; j == vc.Addresses.Count - 1; j++) 146 | { 147 | 148 | if (String.IsNullOrEmpty(dr["Addresses"].ToString()) == false) 149 | { 150 | dr["Addresses"] = dr["Addresses"] + " | " + ("Address " + vc.Addresses[j].HomeWorkType.ToString() + "=" + vc.Addresses[j].POBox + "," + vc.Addresses[j].Ext + 151 | ", " + vc.Addresses[j].Street + ", " + vc.Addresses[j].Locality + ", " + vc.Addresses[j].Region + ", " + 152 | vc.Addresses[j].Postcode + ", " + vc.Addresses[j].Country); 153 | 154 | } 155 | else 156 | { 157 | dr["Addresses"] = ("Address " + vc.Addresses[j].HomeWorkType.ToString() + "=" + vc.Addresses[j].POBox + "," + vc.Addresses[j].Ext + ", " + vc.Addresses[j].Street + ", " + 158 | vc.Addresses[j].Locality + ", " + vc.Addresses[j].Region + ", " + vc.Addresses[j].Postcode + ", " + vc.Addresses[j].Country); 159 | 160 | } 161 | 162 | 163 | } 164 | 165 | 166 | if (String.IsNullOrEmpty(vc.Note) == false) 167 | { 168 | dr["Note"] = ("Note=" + vc.Note); 169 | } 170 | 171 | dt.Rows.Add(dr); 172 | Maindataset.Tables.Add(dt); 173 | return dt; 174 | } 175 | 176 | 177 | public void ExtractImageToPath(string outputPath) 178 | { 179 | 180 | vCard vCphoto = new vCard(); 181 | vCphoto.Parse(FilePath); 182 | int ctr = 0; 183 | String strFileName = outputPath.TrimEnd('\\') + "\\" + System.IO.Path.GetFileNameWithoutExtension(FilePath); 184 | 185 | if (File.Exists(strFileName + ".jpeg") == true) 186 | { 187 | 188 | while (File.Exists(String.Format(strFileName + "_{0}.jpeg", ctr.ToString())) == true) 189 | { 190 | ctr = ctr + 1; 191 | } 192 | strFileName = String.Format(strFileName + "_{0}", ctr.ToString()); 193 | } 194 | vCphoto.Photo.Save(strFileName + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg); 195 | 196 | } 197 | 198 | 199 | public void Dispose() 200 | { 201 | Maindataset.Dispose(); 202 | 203 | } 204 | } 205 | 206 | 207 | } 208 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/BaseClasses/BaseDbExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using SchemaMapper; 8 | 9 | namespace SchemaMapper.Exporters 10 | { 11 | public abstract class BaseDbExport 12 | { 13 | 14 | public string ConnectionString { get; set; } 15 | 16 | 17 | public abstract string BuildCreateTableQuery(SchemaMapping.SchemaMapper schmapper); 18 | public abstract int CreateDestinationTable(SchemaMapping.SchemaMapper schmapper); 19 | public abstract string BuildInsertStatement(SchemaMapping.SchemaMapper schmapper, DataTable dt, int startindex, int rowscount); 20 | public abstract void InsertIntoDb(SchemaMapping.SchemaMapper schmapper, DataTable dt, int rowsperbatch = 10000); 21 | public abstract string BuildInsertStatementWithParameters(SchemaMapping.SchemaMapper schmapper, DataTable dt); 22 | public abstract void InsertIntoDbWithParameters(SchemaMapping.SchemaMapper schmapper, DataTable dt); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/BaseClasses/BaseFileExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SchemaMapper.Exporters 9 | { 10 | public abstract class BaseFileExport 11 | { 12 | 13 | public BaseFileExport() { } 14 | 15 | public string ExportDirectory { get; set; } 16 | 17 | public abstract void ExportDataTable(DataSet dsMain, int index); 18 | public abstract void ExportDataTable(DataSet dsMain, string tablename); 19 | public abstract void ExportDataTables(DataSet dsMain); 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/FlatFileExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace SchemaMapper.Exporters 10 | { 11 | public class FlatFileExport : BaseFileExport, IDisposable 12 | { 13 | 14 | string Extension { get; set; } 15 | 16 | #region constructors 17 | 18 | public FlatFileExport(string ExportDir, string extension = ".csv") 19 | { 20 | 21 | ExportDirectory = ExportDir; 22 | Extension = extension; 23 | 24 | } 25 | 26 | #endregion 27 | 28 | 29 | #region methods 30 | 31 | public void ExportDataTable(DataTable dtDataTable) 32 | { 33 | 34 | string FilePath = ExportDirectory.TrimEnd('\\') + "\\" + dtDataTable.TableName + Extension; 35 | 36 | StringBuilder sb = new StringBuilder(); 37 | 38 | IEnumerable columnNames = dtDataTable.Columns.Cast(). 39 | Select(column => column.ColumnName); 40 | sb.AppendLine(string.Join(",", columnNames)); 41 | 42 | foreach (DataRow row in dtDataTable.Rows) 43 | { 44 | IEnumerable fields = row.ItemArray.Select(field => 45 | string.Concat("\"", field.ToString().Replace("\"", "\"\""), "\"")); 46 | sb.AppendLine(string.Join(",", fields)); 47 | } 48 | 49 | File.WriteAllText(FilePath, sb.ToString()); 50 | } 51 | public override void ExportDataTable(DataSet dsMain, int index) 52 | { 53 | ExportDataTable(dsMain.Tables[index]); 54 | } 55 | public override void ExportDataTable(DataSet dsMain, string tablename) 56 | { 57 | ExportDataTable(dsMain.Tables[tablename]); 58 | } 59 | public override void ExportDataTables(DataSet dsMain) 60 | { 61 | foreach (DataTable dtTable in dsMain.Tables) 62 | { 63 | ExportDataTable(dtTable); 64 | } 65 | } 66 | 67 | #endregion 68 | 69 | 70 | public void Dispose() 71 | { 72 | 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/MySQLExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using MySql.Data.MySqlClient; 8 | using SchemaMapper.SchemaMapping; 9 | 10 | namespace SchemaMapper.Exporters 11 | { 12 | public class MySQLExport: BaseDbExport, IDisposable 13 | { 14 | public void Dispose() 15 | { 16 | 17 | } 18 | 19 | #region create destination table 20 | 21 | public override string BuildCreateTableQuery(SchemaMapper.SchemaMapping.SchemaMapper schmapper) 22 | { 23 | 24 | string strQuery = "create table if not exists `" + schmapper.SchemaName + "`.`" + schmapper.TableName + "`("; 25 | 26 | 27 | foreach (var Col in schmapper.Columns) 28 | { 29 | 30 | switch (Col.DataType) 31 | { 32 | case SchemaMapper_Column.ColumnDataType.Boolean: 33 | strQuery += "\"" + Col.Name + "\" tinyint(1) NULL ,"; 34 | break; 35 | case SchemaMapper_Column.ColumnDataType.Date: 36 | strQuery += "`" + Col.Name + "` datetime NULL ,"; 37 | break; 38 | case SchemaMapper_Column.ColumnDataType.Text: 39 | strQuery += "`" + Col.Name + "` varchar(255) NULL ,"; 40 | break; 41 | case SchemaMapper_Column.ColumnDataType.Number: 42 | strQuery += "`" + Col.Name + "` bigint NULL ,"; 43 | break; 44 | case SchemaMapper_Column.ColumnDataType.Memo: 45 | strQuery += "`" + Col.Name + "` varchar(4000) NULL ,"; 46 | break; 47 | } 48 | 49 | 50 | } 51 | 52 | strQuery = strQuery.TrimEnd(','); 53 | 54 | strQuery += ")"; 55 | 56 | 57 | return strQuery; 58 | } 59 | 60 | public override int CreateDestinationTable(SchemaMapper.SchemaMapping.SchemaMapper schmapper) 61 | { 62 | 63 | string cmd = BuildCreateTableQuery(schmapper); 64 | int result = 0; 65 | try 66 | { 67 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 68 | { 69 | 70 | if (sqlcon.State != ConnectionState.Open) 71 | sqlcon.Open(); 72 | 73 | using (MySqlCommand cmdCreateTable = new MySqlCommand(cmd)) 74 | { 75 | 76 | cmdCreateTable.CommandTimeout = 0; 77 | cmdCreateTable.Connection = sqlcon; 78 | result = cmdCreateTable.ExecuteNonQuery(); 79 | 80 | 81 | } 82 | 83 | 84 | } 85 | 86 | } 87 | catch (Exception ex) 88 | { 89 | throw ex; 90 | 91 | } 92 | 93 | return result; 94 | } 95 | 96 | #endregion 97 | 98 | #region Insert using SQL statement 99 | 100 | public override string BuildInsertStatement(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt, int startindex, int rowscount) 101 | { 102 | 103 | string strQuery = "INSERT INTO `" + schmapper.SchemaName + "`.`" + schmapper.TableName + "` ("; 104 | 105 | foreach (DataColumn dc in dt.Columns) 106 | { 107 | 108 | strQuery = strQuery + "`" + dc.ColumnName + "`,"; 109 | 110 | } 111 | 112 | strQuery = strQuery.TrimEnd(',') + ") VALUES "; 113 | 114 | int i = startindex; 115 | int lastrowindex = startindex + rowscount; 116 | 117 | for (i = startindex; i <= lastrowindex; i++) 118 | { 119 | strQuery = strQuery + "("; 120 | foreach (var Col in schmapper.Columns) 121 | { 122 | 123 | switch (Col.DataType) 124 | { 125 | 126 | case SchemaMapper_Column.ColumnDataType.Date: 127 | strQuery += "'" + MySqlHelper.EscapeString(((DateTime)dt.Rows[i][Col.Name]).ToString("yyyy-MM-dd HH:mm:ss")) + "',"; 128 | break; 129 | case SchemaMapper_Column.ColumnDataType.Text: 130 | case SchemaMapper_Column.ColumnDataType.Memo: 131 | strQuery += "'" + MySqlHelper.EscapeString(dt.Rows[i][Col.Name].ToString()) + "',"; 132 | break; 133 | case SchemaMapper_Column.ColumnDataType.Number: 134 | strQuery += MySqlHelper.EscapeString(dt.Rows[i][Col.Name].ToString()) + ","; 135 | break; 136 | 137 | } 138 | 139 | 140 | 141 | } 142 | 143 | strQuery = strQuery.TrimEnd(',') + "),"; 144 | } 145 | 146 | strQuery = strQuery.TrimEnd(','); 147 | return strQuery; 148 | } 149 | 150 | public override void InsertIntoDb(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt, int rowsperbatch = 10000) 151 | { 152 | 153 | try 154 | { 155 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 156 | { 157 | 158 | if (sqlcon.State != ConnectionState.Open) 159 | sqlcon.Open(); 160 | 161 | 162 | int totalcount = dt.Rows.Count; 163 | int currentindex = 0; 164 | 165 | 166 | 167 | while (currentindex < totalcount) 168 | { 169 | 170 | string strQuery = ""; 171 | 172 | if ((currentindex + rowsperbatch) >= totalcount) 173 | rowsperbatch = totalcount - currentindex - 1; 174 | 175 | strQuery = BuildInsertStatement(schmapper, dt, currentindex, rowsperbatch); 176 | 177 | using (MySqlCommand sqlcmd = new MySqlCommand(strQuery, sqlcon)) 178 | { 179 | 180 | sqlcmd.ExecuteNonQuery(); 181 | currentindex = currentindex + rowsperbatch; 182 | 183 | } 184 | 185 | 186 | } 187 | 188 | } 189 | } 190 | catch (Exception ex) 191 | { 192 | throw ex; 193 | } 194 | } 195 | 196 | public override string BuildInsertStatementWithParameters(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt) 197 | { 198 | 199 | string strQuery = "INSERT INTO `" + schmapper.SchemaName + "`.`" + schmapper.TableName + "` ("; 200 | string strValues = ""; 201 | 202 | foreach (DataColumn dc in dt.Columns) 203 | { 204 | 205 | strQuery = strQuery + "`" + dc.ColumnName + "`,"; 206 | strValues += "@" + dc.ColumnName + ","; 207 | } 208 | 209 | strQuery = strQuery.TrimEnd(',') + ") VALUES (" + strValues + ")"; 210 | 211 | return strQuery; 212 | } 213 | 214 | public override void InsertIntoDbWithParameters(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt) 215 | { 216 | 217 | try 218 | { 219 | 220 | using (MySqlConnection sqlcon = new MySqlConnection(ConnectionString)) 221 | { 222 | 223 | if (sqlcon.State != ConnectionState.Open) 224 | sqlcon.Open(); 225 | 226 | string strQuery = BuildInsertStatementWithParameters(schmapper, dt); 227 | 228 | using (MySqlTransaction trans = sqlcon.BeginTransaction()) 229 | { 230 | using (MySqlCommand sqlcmd = new MySqlCommand(strQuery, sqlcon, trans)) 231 | { 232 | sqlcmd.CommandType = CommandType.Text; 233 | 234 | 235 | foreach (var Col in schmapper.Columns) 236 | { 237 | 238 | 239 | switch (Col.DataType) 240 | { 241 | case SchemaMapper_Column.ColumnDataType.Date: 242 | sqlcmd.Parameters.Add("@" + Col.Name, MySqlDbType.DateTime); 243 | break; 244 | case SchemaMapper_Column.ColumnDataType.Text: 245 | sqlcmd.Parameters.Add("@" + Col.Name, MySqlDbType.VarChar); 246 | break; 247 | case SchemaMapper_Column.ColumnDataType.Memo: 248 | sqlcmd.Parameters.Add("@" + Col.Name, MySqlDbType.VarChar, 4000); 249 | break; 250 | case SchemaMapper_Column.ColumnDataType.Number: 251 | sqlcmd.Parameters.Add("@" + Col.Name, MySqlDbType.Int64); 252 | break; 253 | 254 | } 255 | 256 | } 257 | 258 | 259 | foreach (DataRow drrow in dt.Rows) 260 | { 261 | 262 | foreach (var Col in schmapper.Columns) 263 | { 264 | 265 | sqlcmd.Parameters["@" + Col.Name].Value = drrow[Col.Name]; 266 | 267 | } 268 | 269 | sqlcmd.ExecuteNonQuery(); 270 | 271 | } 272 | 273 | 274 | 275 | trans.Commit(); 276 | } 277 | } 278 | 279 | } 280 | } 281 | catch (Exception ex) 282 | { 283 | throw ex; 284 | } 285 | } 286 | 287 | #endregion 288 | 289 | 290 | public MySQLExport(string connectionstring) 291 | { 292 | 293 | ConnectionString = connectionstring; 294 | } 295 | 296 | 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/OracleExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using SchemaMapper; 7 | using System.Data; 8 | using Oracle.DataAccess.Client; 9 | using Oracle.DataAccess.Types; 10 | using SchemaMapper.SchemaMapping; 11 | 12 | namespace SchemaMapper.Exporters 13 | { 14 | public class OracleExport : BaseDbExport, IDisposable 15 | { 16 | 17 | public OracleExport(string connectionstring) 18 | { 19 | 20 | ConnectionString = connectionstring; 21 | } 22 | 23 | #region create destination table 24 | 25 | public override string BuildCreateTableQuery(SchemaMapping.SchemaMapper schmapper) 26 | { 27 | string strQuery = "create table \"" + schmapper.SchemaName + "\".\"" + schmapper.TableName + "\"("; 28 | 29 | 30 | foreach (var Col in schmapper.Columns) 31 | { 32 | 33 | switch (Col.DataType) 34 | { 35 | case SchemaMapper_Column.ColumnDataType.Boolean: 36 | strQuery += "\"" + Col.Name + "\" NUMBER(1) NULL ,"; 37 | break; 38 | case SchemaMapper_Column.ColumnDataType.Date: 39 | strQuery += "\"" + Col.Name + "\" DATETIME NULL ,"; 40 | break; 41 | case SchemaMapper_Column.ColumnDataType.Text: 42 | strQuery += "\"" + Col.Name + "\" VARCHAR2(255) NULL ,"; 43 | break; 44 | case SchemaMapper_Column.ColumnDataType.Number: 45 | strQuery += "\"" + Col.Name + "\" BIGINT NULL ,"; 46 | break; 47 | case SchemaMapper_Column.ColumnDataType.Memo: 48 | strQuery += "\"" + Col.Name + "\" VARCHAR2(4000) NULL ,"; 49 | break; 50 | } 51 | 52 | 53 | } 54 | 55 | strQuery = strQuery.TrimEnd(','); 56 | 57 | strQuery += ")"; 58 | 59 | 60 | return strQuery; 61 | } 62 | 63 | public override int CreateDestinationTable(SchemaMapping.SchemaMapper schmapper) 64 | { 65 | string cmd = BuildCreateTableQuery(schmapper); 66 | int result = 0; 67 | try 68 | { 69 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 70 | { 71 | 72 | if (sqlcon.State != ConnectionState.Open) 73 | sqlcon.Open(); 74 | 75 | using (OracleCommand cmdCreateTable = new OracleCommand(cmd)) 76 | { 77 | 78 | cmdCreateTable.CommandTimeout = 0; 79 | cmdCreateTable.Connection = sqlcon; 80 | result = cmdCreateTable.ExecuteNonQuery(); 81 | 82 | } 83 | 84 | 85 | } 86 | 87 | } 88 | catch (Exception ex) 89 | { 90 | throw ex; 91 | 92 | } 93 | 94 | return result; 95 | } 96 | 97 | #endregion 98 | 99 | #region Insert to Db using OracleBulk 100 | 101 | public void InsertUsingOracleBulk(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt) 102 | { 103 | 104 | 105 | try 106 | { 107 | using (var bulkCopy = new OracleBulkCopy(ConnectionString, OracleBulkCopyOptions.Default)) 108 | { 109 | 110 | foreach (DataColumn col in dt.Columns) 111 | { 112 | bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName); 113 | } 114 | 115 | bulkCopy.BulkCopyTimeout = 600; 116 | bulkCopy.DestinationTableName = "[" + schmapper.SchemaName + "].[" + schmapper.TableName + "]"; 117 | bulkCopy.WriteToServer(dt); 118 | } 119 | 120 | } 121 | catch (Exception ex) 122 | { 123 | throw ex; 124 | } 125 | } 126 | 127 | #endregion 128 | 129 | #region Insert using SQL statement 130 | 131 | public override string BuildInsertStatement(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt, int startindex, int rowscount) 132 | { 133 | 134 | string strQuery = "INSERT INTO \"" + schmapper.SchemaName + "\".\"" + schmapper.TableName + "\" ("; 135 | 136 | foreach (DataColumn dc in dt.Columns) 137 | { 138 | 139 | strQuery = strQuery + "\"" + dc.ColumnName + "\","; 140 | 141 | } 142 | 143 | strQuery = strQuery.TrimEnd(',') + ") VALUES "; 144 | 145 | int i = startindex; 146 | int lastrowindex = startindex + rowscount; 147 | 148 | for (i = startindex; i <= lastrowindex; i++) 149 | { 150 | strQuery = strQuery + "("; 151 | foreach (var Col in schmapper.Columns) 152 | { 153 | 154 | switch (Col.DataType) 155 | { 156 | 157 | case SchemaMapper_Column.ColumnDataType.Date: 158 | strQuery += "'" + ((DateTime)dt.Rows[i][Col.Name]).ToString("yyyy-MM-dd HH:mm:ss") + "',"; 159 | break; 160 | case SchemaMapper_Column.ColumnDataType.Text: 161 | case SchemaMapper_Column.ColumnDataType.Memo: 162 | strQuery += "'" + dt.Rows[i][Col.Name].ToString() + "',"; 163 | break; 164 | case SchemaMapper_Column.ColumnDataType.Number: 165 | strQuery += dt.Rows[i][Col.Name].ToString() + ","; 166 | break; 167 | 168 | } 169 | 170 | 171 | 172 | } 173 | 174 | strQuery = strQuery.TrimEnd(',') + "),"; 175 | } 176 | 177 | strQuery = strQuery.TrimEnd(','); 178 | return strQuery; 179 | } 180 | 181 | public override void InsertIntoDb(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt, int rowsperbatch = 10000) 182 | { 183 | 184 | try 185 | { 186 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 187 | { 188 | 189 | if (sqlcon.State != ConnectionState.Open) 190 | sqlcon.Open(); 191 | 192 | 193 | int totalcount = dt.Rows.Count; 194 | int currentindex = 0; 195 | 196 | while (currentindex < totalcount) 197 | { 198 | 199 | string strQuery = ""; 200 | 201 | if ((currentindex + rowsperbatch) >= totalcount) 202 | rowsperbatch = totalcount - currentindex - 1; 203 | 204 | strQuery = BuildInsertStatement(schmapper, dt, currentindex, rowsperbatch); 205 | 206 | using (OracleCommand sqlcmd = new OracleCommand(strQuery, sqlcon)) 207 | { 208 | 209 | sqlcmd.ExecuteNonQuery(); 210 | currentindex = currentindex + rowsperbatch; 211 | 212 | } 213 | 214 | 215 | } 216 | 217 | } 218 | } 219 | catch (Exception ex) 220 | { 221 | throw ex; 222 | } 223 | } 224 | 225 | public override string BuildInsertStatementWithParameters(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt) 226 | { 227 | 228 | string strQuery = "INSERT INTO \"" + schmapper.SchemaName + "\".\"" + schmapper.TableName + "\" ("; 229 | string strValues = ""; 230 | 231 | foreach (DataColumn dc in dt.Columns) 232 | { 233 | 234 | strQuery = strQuery + "\"" + dc.ColumnName + "\","; 235 | strValues += "@" + dc.ColumnName + ","; 236 | } 237 | 238 | strQuery = strQuery.TrimEnd(',') + ") VALUES (" + strValues + ")"; 239 | 240 | return strQuery; 241 | } 242 | 243 | public override void InsertIntoDbWithParameters(SchemaMapper.SchemaMapping.SchemaMapper schmapper, DataTable dt) 244 | { 245 | 246 | try 247 | { 248 | 249 | using (OracleConnection sqlcon = new OracleConnection(ConnectionString)) 250 | { 251 | 252 | if (sqlcon.State != ConnectionState.Open) 253 | sqlcon.Open(); 254 | 255 | string strQuery = BuildInsertStatementWithParameters(schmapper, dt); 256 | 257 | using (OracleTransaction trans = sqlcon.BeginTransaction()) 258 | { 259 | using (OracleCommand sqlcmd = new OracleCommand(strQuery, sqlcon)) 260 | { 261 | sqlcmd.CommandType = CommandType.Text; 262 | 263 | 264 | foreach (var Col in schmapper.Columns) 265 | { 266 | 267 | 268 | switch (Col.DataType) 269 | { 270 | case SchemaMapper_Column.ColumnDataType.Date: 271 | sqlcmd.Parameters.Add("@" + Col.Name, OracleDbType.Date); 272 | break; 273 | case SchemaMapper_Column.ColumnDataType.Text: 274 | sqlcmd.Parameters.Add("@" + Col.Name, OracleDbType.Varchar2); 275 | break; 276 | case SchemaMapper_Column.ColumnDataType.Memo: 277 | sqlcmd.Parameters.Add("@" + Col.Name, OracleDbType.Varchar2, 4000); 278 | break; 279 | case SchemaMapper_Column.ColumnDataType.Number: 280 | sqlcmd.Parameters.Add("@" + Col.Name, OracleDbType.Int64); 281 | break; 282 | 283 | } 284 | 285 | } 286 | 287 | 288 | foreach (DataRow drrow in dt.Rows) 289 | { 290 | 291 | foreach (var Col in schmapper.Columns) 292 | { 293 | 294 | sqlcmd.Parameters["@" + Col.Name].Value = drrow[Col.Name]; 295 | 296 | } 297 | 298 | sqlcmd.ExecuteNonQuery(); 299 | 300 | } 301 | 302 | 303 | 304 | trans.Commit(); 305 | } 306 | } 307 | 308 | } 309 | } 310 | catch (Exception ex) 311 | { 312 | throw ex; 313 | } 314 | } 315 | #endregion 316 | 317 | public void Dispose() 318 | { 319 | 320 | } 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/Exporters/XmlExport.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SchemaMapper.Exporters 9 | { 10 | public class XmlExport : BaseFileExport, IDisposable 11 | { 12 | 13 | 14 | public XmlWriteMode WriteMode { get; set; } 15 | 16 | #region constructors 17 | 18 | public XmlExport(string ExportDir, XmlWriteMode writemode = XmlWriteMode.WriteSchema) 19 | { 20 | 21 | WriteMode = writemode; 22 | ExportDirectory = ExportDir; 23 | 24 | } 25 | 26 | 27 | #endregion 28 | 29 | 30 | #region methods 31 | 32 | public override void ExportDataTable(DataSet dsMain, int index) 33 | { 34 | dsMain.Tables[index].WriteXml(ExportDirectory + "\\" + 35 | dsMain.Tables[index].TableName + ".xml", WriteMode, false); 36 | } 37 | 38 | public override void ExportDataTable(DataSet dsMain, string tablename) 39 | { 40 | dsMain.Tables[tablename].WriteXml(ExportDirectory + "\\" + 41 | tablename + DateTime.Now.ToString("yyyyMMddHHmmsss") + ".xml", WriteMode, false); 42 | } 43 | 44 | public override void ExportDataTables(DataSet dsMain) 45 | { 46 | foreach (DataTable dtTable in dsMain.Tables) 47 | { 48 | dtTable.WriteXml(ExportDirectory + "\\" + 49 | dtTable.TableName + DateTime.Now.ToString("yyyyMMddHHmmsss") + ".xml", WriteMode, false); 50 | } 51 | } 52 | 53 | public void ExportDataSet(DataSet dsMain) 54 | { 55 | dsMain.WriteXml(ExportDirectory + "\\" + 56 | DateTime.Now.ToString("yyyyMMddHHmmsss") + ".xml", WriteMode); 57 | } 58 | 59 | #endregion 60 | 61 | 62 | 63 | public void Dispose() 64 | { 65 | 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Classes/SchemaMapping/SchemaMapper_Column.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SchemaMapper.SchemaMapping 8 | { 9 | public class SchemaMapper_Column 10 | { 11 | #region properties 12 | 13 | public string Name { get; set; } 14 | public string FixedValue { get; set; } 15 | public bool IsExpression { get; set; } 16 | public string Expression { get; set; } 17 | public ColumnDataType DataType { get; set; } 18 | public List MappedColumns { get; set; } 19 | 20 | #endregion 21 | 22 | #region construtors 23 | 24 | //Column with expression 25 | public SchemaMapper_Column(string name, ColumnDataType datatype, bool isexpression, string expression) 26 | { 27 | 28 | Name = name; 29 | FixedValue = ""; 30 | IsExpression = isexpression; 31 | Expression = expression; 32 | DataType = datatype; 33 | MappedColumns = new List(); 34 | 35 | 36 | } 37 | 38 | //Normal Column 39 | public SchemaMapper_Column(string name, ColumnDataType datatype) 40 | { 41 | 42 | Name = name; 43 | FixedValue = ""; 44 | IsExpression = false; 45 | Expression = ""; 46 | DataType = datatype; 47 | MappedColumns = new List(); 48 | 49 | 50 | } 51 | 52 | //Column with fixed value 53 | public SchemaMapper_Column(string name, ColumnDataType datatype, string fixedValue) 54 | { 55 | 56 | Name = name; 57 | FixedValue = fixedValue; 58 | IsExpression = false; 59 | Expression = ""; 60 | DataType = datatype; 61 | MappedColumns = new List(); 62 | 63 | 64 | } 65 | 66 | //Column without any specifications 67 | public SchemaMapper_Column() 68 | { 69 | 70 | Name = ""; 71 | FixedValue = ""; 72 | IsExpression = false; 73 | Expression = ""; 74 | DataType = ColumnDataType.Text; 75 | MappedColumns = new List(); 76 | 77 | } 78 | #endregion 79 | 80 | #region methods 81 | 82 | public ColumnDataType GetCorrespondingDataType(string TypeName, int length) 83 | { 84 | 85 | switch (TypeName) 86 | { 87 | 88 | case "System.String": 89 | case "System.Char": 90 | 91 | if (length == 4000) 92 | return ColumnDataType.Memo; 93 | 94 | return ColumnDataType.Text; 95 | 96 | case "System.Int32": 97 | case "System.Int64": 98 | case "System.Int16": 99 | case "System.UInt64": 100 | case "System.UInt32": 101 | case "System.UInt16": 102 | case "System.Byte": 103 | case "System.SByte": 104 | case "System.Single": 105 | case "System.Double": 106 | case "System.Decimal": 107 | 108 | return ColumnDataType.Number; 109 | 110 | case "System.Boolean": 111 | 112 | return ColumnDataType.Boolean; 113 | 114 | 115 | case "System.DateTime": 116 | case "System.Date": 117 | case "System.TimeSpan": 118 | 119 | return ColumnDataType.Date; 120 | case "": 121 | 122 | throw new Exception("Data \"" + TypeName + "\"type not supported"); 123 | 124 | } 125 | 126 | return ColumnDataType.Text; 127 | 128 | } 129 | 130 | #endregion 131 | 132 | 133 | #region declarations 134 | public enum ColumnDataType 135 | { 136 | Text = 0, 137 | Memo = 1, 138 | Number = 2, 139 | Date = 3, 140 | Boolean = 4 141 | } 142 | #endregion 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SchemaMapper")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Munchy Bytes")] 12 | [assembly: AssemblyProduct("SchemaMapper")] 13 | [assembly: AssemblyCopyright("Copyright © Munchy Bytes 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("687e3733-b82e-4cc7-9e83-9573407d01b7")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.1.0.0")] 36 | [assembly: AssemblyFileVersion("1.1.0.0")] 37 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SchemaMapper.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] 29 | [global::System.Configuration.DefaultSettingValueAttribute("Data Source=|DataDirectory|\\Database\\SchemaMapperConfig.sdf")] 30 | public string MainConnectionString { 31 | get { 32 | return ((string)(this["MainConnectionString"])); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SchemaMapperDLL/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | <?xml version="1.0" encoding="utf-16"?> 7 | <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 8 | <ConnectionString>Data Source=|DataDirectory|\Database\SchemaMapperConfig.sdf</ConnectionString> 9 | <ProviderName>System.Data.SqlServerCe.4.0</ProviderName> 10 | </SerializableConnectionString> 11 | Data Source=|DataDirectory|\Database\SchemaMapperConfig.sdf 12 | 13 | 14 | -------------------------------------------------------------------------------- /SchemaMapperDLL/SchemaMapperDLL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {687E3733-B82E-4CC7-9E83-9573407D01B7} 9 | Library 10 | Properties 11 | SchemaMapper 12 | SchemaMapper 13 | v4.5.2 14 | 512 15 | 16 | 17 | 18 | 19 | 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | false 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | false 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | 7.3 45 | prompt 46 | MinimumRecommendedRules.ruleset 47 | 48 | 49 | bin\x86\Release\ 50 | TRACE 51 | true 52 | pdbonly 53 | x86 54 | 7.3 55 | prompt 56 | MinimumRecommendedRules.ruleset 57 | 58 | 59 | true 60 | bin\x64\Debug\ 61 | DEBUG;TRACE 62 | full 63 | x64 64 | 7.3 65 | prompt 66 | MinimumRecommendedRules.ruleset 67 | 68 | 69 | bin\x64\Release\ 70 | TRACE 71 | true 72 | pdbonly 73 | x64 74 | 7.3 75 | prompt 76 | MinimumRecommendedRules.ruleset 77 | 78 | 79 | 80 | ..\packages\BouncyCastle.1.8.3.1\lib\BouncyCastle.Crypto.dll 81 | 82 | 83 | ..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.dll 84 | 85 | 86 | ..\packages\EntityFramework.6.4.0\lib\net45\EntityFramework.SqlServer.dll 87 | 88 | 89 | ..\packages\Google.Protobuf.3.6.1\lib\net45\Google.Protobuf.dll 90 | 91 | 92 | ..\packages\HtmlAgilityPack.1.11.23\lib\Net45\HtmlAgilityPack.dll 93 | 94 | 95 | ..\..\..\..\..\..\Essentials\ProgAssemblies\LumiSoft.Net.dll 96 | 97 | 98 | 99 | ..\packages\MySql.Data.8.0.19\lib\net452\MySql.Data.dll 100 | 101 | 102 | ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll 103 | 104 | 105 | ..\packages\Oracle.DataAccess.x86.4.4.112.3\lib\Oracle.DataAccess.dll 106 | 107 | 108 | ..\packages\SSH.NET.2016.1.0\lib\net40\Renci.SshNet.dll 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | ..\packages\System.Data.SQLite.Core.1.0.112.0\lib\net451\System.Data.SQLite.dll 120 | 121 | 122 | ..\packages\System.Data.SQLite.EF6.1.0.112.0\lib\net451\System.Data.SQLite.EF6.dll 123 | 124 | 125 | ..\packages\System.Data.SQLite.Linq.1.0.112.0\lib\net451\System.Data.SQLite.Linq.dll 126 | 127 | 128 | ..\packages\System.Data.SqlServerCe_unofficial.4.0.8482.1\lib\net20\System.Data.SqlServerCe.dll 129 | True 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | ..\packages\MySql.Data.8.0.19\lib\net452\Ubiety.Dns.Core.dll 142 | 143 | 144 | ..\..\..\..\..\..\Essentials\ProgAssemblies\VCardLibrary.dll 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | True 178 | True 179 | Settings.settings 180 | 181 | 182 | 183 | 184 | 185 | {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} 186 | 2 187 | 4 188 | 0 189 | primary 190 | False 191 | True 192 | 193 | 194 | {00020813-0000-0000-C000-000000000046} 195 | 1 196 | 6 197 | 0 198 | primary 199 | False 200 | True 201 | 202 | 203 | {91493440-5A91-11CF-8700-00AA0060263B} 204 | 2 205 | 9 206 | 0 207 | primary 208 | False 209 | True 210 | 211 | 212 | {00020905-0000-0000-C000-000000000046} 213 | 8 214 | 4 215 | 0 216 | primary 217 | False 218 | True 219 | 220 | 221 | {0002E157-0000-0000-C000-000000000046} 222 | 5 223 | 3 224 | 0 225 | primary 226 | False 227 | True 228 | 229 | 230 | 231 | 232 | 233 | 234 | SettingsSingleFileGenerator 235 | Settings.Designer.cs 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 260 | -------------------------------------------------------------------------------- /SchemaMapperDLL/SchemaMapperDLL.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SchemaMapper 5 | 1.1.0.0 6 | Schema Mapper 7 | HadiFadl 8 | HadiFadl 9 | false 10 | MIT 11 | https://github.com/munchy-bytes/SchemaMapper 12 | A .NET class library to import data from different source into a unified destination 13 | https://github.com/munchy-bytes/SchemaMapper 14 | Copyright © Munchy Bytes 2020 15 | schema-mapping C# SQL 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /SchemaMapperDLL/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
7 | 8 | 9 |
12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /SchemaMapperDLL/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/SchemaMapperDLL/nuget.exe -------------------------------------------------------------------------------- /SchemaMapperDLL/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SchemaMapperTest 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.SuspendLayout(); 32 | // 33 | // Form1 34 | // 35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 37 | this.ClientSize = new System.Drawing.Size(417, 323); 38 | this.Name = "Form1"; 39 | this.Text = "Form1"; 40 | this.Load += new System.EventHandler(this.Form1_Load); 41 | this.ResumeLayout(false); 42 | 43 | } 44 | 45 | #endregion 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | using SchemaMapper.SchemaMapping; 6 | 7 | 8 | namespace SchemaMapperTest 9 | { 10 | public partial class Form1 : Form 11 | { 12 | public Form1() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | public void ImportDataFromSQLServerToOracle(string sqlcon, string oraclecon) 18 | { 19 | 20 | string[] TableNameFilter = new[] { "Table1", "Table2" }; 21 | SchemaMapper.Exporters.OracleExport expOralce = new SchemaMapper.Exporters.OracleExport(oraclecon); 22 | 23 | using (SchemaMapper.Converters.SqlServerCeImport ssImport = new SchemaMapper.Converters.SqlServerCeImport(sqlcon)) 24 | { 25 | 26 | ssImport.getSchemaTable(); 27 | 28 | foreach(DataRow drRowSchema in ssImport.SchemaTable.AsEnumerable().Where(x => 29 | TableNameFilter.Contains(x["TABLE_NAME"].ToString())).ToList()) 30 | { 31 | 32 | string SQLTableName = drRowSchema["TABLE_NAME"].ToString(); 33 | string SQLTableSchema = drRowSchema["TABLE_SCHEMA"].ToString(); 34 | 35 | DataTable dtSQL = ssImport.GetDataTable(SQLTableSchema, SQLTableName); 36 | 37 | using (SchemaMapper.SchemaMapping.SchemaMapper sm = new SchemaMapper.SchemaMapping.SchemaMapper(SQLTableSchema, SQLTableName)) 38 | { 39 | 40 | foreach (DataColumn dc in dtSQL.Columns) 41 | { 42 | 43 | SchemaMapper_Column smCol = new SchemaMapper_Column(); 44 | smCol.Name = dc.ColumnName; 45 | 46 | 47 | smCol.Name = dc.ColumnName; 48 | smCol.DataType = smCol.GetCorrespondingDataType(dc.DataType.ToString(), dc.MaxLength); 49 | 50 | sm.Columns.Add(smCol); 51 | 52 | } 53 | 54 | expOralce.CreateDestinationTable(sm); 55 | 56 | expOralce.InsertUsingOracleBulk(sm, dtSQL); 57 | 58 | //there are other methods such as : 59 | //expOralce.InsertIntoDb(sm, dtSQL, oraclecon); 60 | //expOralce.InsertIntoDbWithParameters(sm, dtSQL, oraclecon); 61 | 62 | } 63 | 64 | } 65 | 66 | 67 | 68 | 69 | } 70 | 71 | 72 | 73 | 74 | 75 | } 76 | public void ReadAccessIntoSQL() 77 | { 78 | 79 | 80 | 81 | using (SchemaMapper.Converters.MsAccessImport smAccess = new SchemaMapper.Converters.MsAccessImport(@"G:\Passwords.mdb")) 82 | { 83 | 84 | //Read Access 85 | smAccess.BuildConnectionString(); 86 | smAccess.getSchemaTable(); 87 | 88 | string con = @"Data Source=.\SQLInstance;Initial Catalog=tempdb;integrated security=SSPI;"; 89 | SchemaMapper.Exporters.SqlServerExport expSQL = new SchemaMapper.Exporters.SqlServerExport(con); 90 | 91 | using (SchemaMapper.SchemaMapping.SchemaMapper SM = new SchemaMapper.SchemaMapping.SchemaMapper("dbo", "Passwords")) 92 | { 93 | 94 | 95 | 96 | foreach (DataRow schRow in smAccess.SchemaTable.Rows) 97 | { 98 | string strTablename = schRow["TABLE_NAME"].ToString().Trim('\''); 99 | 100 | DataTable dt = smAccess.GetDataTable(strTablename); 101 | bool result = SM.ChangeTableStructure(ref dt); 102 | 103 | if (result == true) 104 | { 105 | expSQL.CreateDestinationTable(SM); 106 | expSQL.InsertUsingSQLBulk(SM,dt); 107 | } 108 | } 109 | 110 | 111 | 112 | } 113 | 114 | 115 | } 116 | 117 | } 118 | 119 | public DataTable ReadExcel() 120 | { 121 | 122 | 123 | using (SchemaMapper.Converters.MsExcelImport smExcel = new SchemaMapper.Converters.MsExcelImport(@"G:\Passwords.xlsx")) 124 | { 125 | 126 | //Read Excel 127 | smExcel.BuildConnectionString(); 128 | var lst = smExcel.GetSheets(); 129 | 130 | DataTable dt = smExcel.GetDataTable(lst.First(), true, 0); 131 | return dt; 132 | } 133 | 134 | 135 | 136 | } 137 | 138 | public SchemaMapper.SchemaMapping.SchemaMapper InitiateTestSchemaMapper(string schema, string table) 139 | { 140 | 141 | SchemaMapper.SchemaMapping.SchemaMapper smResult = new SchemaMapper.SchemaMapping.SchemaMapper(); 142 | 143 | smResult.TableName = table; 144 | smResult.SchemaName = schema; 145 | 146 | //Add variables 147 | smResult.Variables.Add(new SchemaMapper.SchemaMapping.Variable("@Today", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); 148 | 149 | 150 | //Add Columns 151 | 152 | SchemaMapper.SchemaMapping.SchemaMapper_Column smServerCol = new SchemaMapper.SchemaMapping.SchemaMapper_Column("Server_Name", 153 | SchemaMapper.SchemaMapping.SchemaMapper_Column.ColumnDataType.Text); 154 | SchemaMapper.SchemaMapping.SchemaMapper_Column smUserCol = new SchemaMapper.SchemaMapping.SchemaMapper_Column("User_Name", 155 | SchemaMapper.SchemaMapping.SchemaMapper_Column.ColumnDataType.Text); 156 | SchemaMapper.SchemaMapping.SchemaMapper_Column smPassCol = new SchemaMapper.SchemaMapping.SchemaMapper_Column("Password", 157 | SchemaMapper.SchemaMapping.SchemaMapper_Column.ColumnDataType.Text); 158 | 159 | //// Add column with Fixed Value 160 | SchemaMapper.SchemaMapping.SchemaMapper_Column smFixedValueCol = new SchemaMapper.SchemaMapping.SchemaMapper_Column("AddedDate", 161 | SchemaMapper.SchemaMapping.SchemaMapper_Column.ColumnDataType.Text, 162 | "@Today"); 163 | //// Add Column with Expression 164 | SchemaMapper.SchemaMapping.SchemaMapper_Column smExpressionCol = new SchemaMapper.SchemaMapping.SchemaMapper_Column("UserAndPassword", 165 | SchemaMapper.SchemaMapping.SchemaMapper_Column.ColumnDataType.Text, 166 | true, 167 | "[User_Name] + '|' + [Password]"); 168 | 169 | smResult.Columns.Add(smServerCol); 170 | smResult.Columns.Add(smUserCol); 171 | smResult.Columns.Add(smPassCol); 172 | smResult.Columns.Add(smFixedValueCol); 173 | smResult.Columns.Add(smExpressionCol); 174 | 175 | //Add all possible input Columns for each Column 176 | 177 | smServerCol.MappedColumns.AddRange(new[] { "server", "server name", "servername", "Server", "Server Name", "ServerName" }); 178 | smUserCol.MappedColumns.AddRange(new[] { "UserName", "User", "login", "Login", "User name" }); 179 | smPassCol.MappedColumns.AddRange(new[] { "Password", "pass", "Pass", "password" }); 180 | 181 | //Added columns to ignore if found 182 | //Sys_SheetName and Sys_ExtraFields is an auto generated column when reading Excel file 183 | smResult.IgnoredColumns.AddRange(new[] { "Column1", "Sys_Sheetname", "Sys_ExtraFields", "Center Name" }); 184 | 185 | //Save Schema Mapper into xml 186 | smResult.WriteToXml(Environment.CurrentDirectory + "\\SchemaMapper\\1.xml", true); 187 | 188 | return smResult; 189 | 190 | } 191 | 192 | private void Form1_Load(object sender, EventArgs e) 193 | { 194 | 195 | SchemaMapper.SchemaMapping.SchemaMapper smPasswords = new SchemaMapper.SchemaMapping.SchemaMapper("dbo", "Passwords"); 196 | 197 | //Define Server_Name , User_Name, Password columns 198 | SchemaMapper_Column smServerCol = new SchemaMapper_Column("Server_Name", SchemaMapper_Column.ColumnDataType.Text); 199 | SchemaMapper_Column smUserCol = new SchemaMapper_Column("User_Name", SchemaMapper_Column.ColumnDataType.Text); 200 | SchemaMapper_Column smPassCol = new SchemaMapper_Column("Password", SchemaMapper_Column.ColumnDataType.Text); 201 | 202 | //Define AddedDate column and fill it with a fixed value = Date.Now 203 | SchemaMapper_Column smAddedDate = new SchemaMapper_Column("AddedDate", SchemaMapper_Column.ColumnDataType.Date, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); 204 | 205 | //Define UserAndPassword column with and expression = [User_Name] + '|' + [Password] 206 | SchemaMapper_Column smUserPasswordCol = new SchemaMapper_Column("UserAndPassword", SchemaMapper_Column.ColumnDataType.Text, true, "[User_Name] + '|' + [Password]"); 207 | 208 | //Add columns to SchemaMapper 209 | smPasswords.Columns.Add(smServerCol); 210 | smPasswords.Columns.Add(smUserCol); 211 | smPasswords.Columns.Add(smPassCol); 212 | smPasswords.Columns.Add(smAddedDate); 213 | smPasswords.Columns.Add(smUserPasswordCol); 214 | 215 | //Add all possible input Columns Names for each Column 216 | smServerCol.MappedColumns.AddRange(new[] { "server", "SQL Instance", "Server Name" }); 217 | smUserCol.MappedColumns.AddRange(new[] { "username", "user", "Login" }); 218 | smPassCol.MappedColumns.AddRange(new[] { "Password", "pass", "password" }); 219 | 220 | //Sys_SheetName and Sys_ExtraFields are an auto generated columns while reading Excel file 221 | smPasswords.IgnoredColumns.AddRange(new[] { "ID", "AddedBy", "AddedDate", "Sys_Sheetname", "Sys_ExtraFields" }); 222 | 223 | 224 | //Excel file 225 | DataTable dtExcel; 226 | DataTable dtText; 227 | DataTable dtAccess; 228 | 229 | //Excel worksheet 230 | using (SchemaMapper.Converters.MsExcelImport smExcel = new SchemaMapper.Converters.MsExcelImport(@"D:\SchemaMapperTest\Password_Test.xlsx")) 231 | { 232 | //Read Excel 233 | smExcel.BuildConnectionString(); 234 | var lst = smExcel.GetSheets(); 235 | //Read only from the first worksheet and consider the first row as header 236 | dtExcel = smExcel.GetDataTable(lst.First(), true, 0); 237 | } 238 | 239 | //Flat file 240 | using (SchemaMapper.Converters.FlatFileImportTools smFlat = new SchemaMapper.Converters.FlatFileImportTools(@"D:\SchemaMapperTest\Password_Test.txt", true, 0)) 241 | { 242 | 243 | //Read flat file structure 244 | smFlat.BuildDataTableStructure(); 245 | //Import data from flat file 246 | dtText = smFlat.FillDataTable(); 247 | 248 | } 249 | 250 | //Access database 251 | 252 | using (SchemaMapper.Converters.MsAccessImport smAccess = new SchemaMapper.Converters.MsAccessImport(@"D:\SchemaMapperTest\Password_Test.accdb")) 253 | { 254 | 255 | //Build connection string and retrieve Access metadata 256 | smAccess.BuildConnectionString(); 257 | smAccess.getSchemaTable(); 258 | //Read data from Passwords table 259 | dtAccess = smAccess.GetDataTable("Passwords"); 260 | } 261 | 262 | smPasswords.ChangeTableStructure(ref dtExcel); 263 | smPasswords.ChangeTableStructure(ref dtText); 264 | smPasswords.ChangeTableStructure(ref dtAccess); 265 | 266 | string connectionstring = @"Data Source=vaio\dataserver;Initial Catalog=tempdb;integrated security=SSPI;"; 267 | SchemaMapper.Exporters.SqlServerExport expSQL = new SchemaMapper.Exporters.SqlServerExport(connectionstring); 268 | expSQL.CreateDestinationTable(smPasswords); 269 | 270 | expSQL.InsertUsingSQLBulk(smPasswords,dtExcel); 271 | expSQL.InsertUsingSQLBulk(smPasswords,dtText); 272 | expSQL.InsertUsingSQLBulk(smPasswords,dtAccess); 273 | 274 | 275 | 276 | 277 | 278 | } 279 | 280 | public void ReadExcelWithPagging() 281 | { 282 | 283 | using (SchemaMapper.Converters.MsExcelImport smExcel = new SchemaMapper.Converters.MsExcelImport(@"U:\Passwords.xlsx")) 284 | { 285 | 286 | //Read Excel with pagging 287 | smExcel.BuildConnectionString(); 288 | var lst = smExcel.GetSheets(); 289 | 290 | int result = 1; 291 | int PagingStart = 1, PagingInterval = 10; 292 | 293 | while (result != 0) 294 | { 295 | 296 | DataTable dt = smExcel.GetDataTableWithPaging(lst.First(), PagingStart, PagingInterval, out result, true, 0); 297 | PagingStart = PagingStart + PagingInterval; 298 | 299 | } 300 | 301 | } 302 | } 303 | 304 | public void ReadFlatFile() 305 | { 306 | 307 | using (SchemaMapper.Converters.FlatFileImportTools smFlat = new SchemaMapper.Converters.FlatFileImportTools(@"U:\Passwords.csv", true, 0)) 308 | { 309 | 310 | //Read Excel with pagging 311 | smFlat.BuildDataTableStructure(); 312 | 313 | DataTable dt = smFlat.FillDataTable(); 314 | 315 | int Result = dt.Rows.Count; 316 | } 317 | 318 | } 319 | 320 | public void ReadWordDocument() 321 | { 322 | using (SchemaMapper.Converters.MsWordImportTools smWord = new SchemaMapper.Converters.MsWordImportTools(@"U:\DocumentTable.docx", true, 0)) 323 | { 324 | 325 | smWord.ImportWordTablesIntoList(";"); 326 | DataSet ds = smWord.ConvertListToTables(";"); 327 | 328 | int ct = ds.Tables.Count; 329 | } 330 | } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace SchemaMapperTest 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SchemaMapperTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("SchemaMapperTest")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d3f566af-b7a6-4fd9-957f-ac5af1c089fc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SchemaMapperDLLTest.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SchemaMapperDLLTest.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SchemaMapperDLLTest.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SchemaMapperDLLTest/SchemaMapperDLLTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {04EEEF3C-55EE-47E7-92C7-3B5770E3B4A7} 8 | WinExe 9 | Properties 10 | SchemaMapperDLLTest 11 | SchemaMapperDLLTest 12 | v4.5.2 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | true 37 | bin\x86\Debug\ 38 | DEBUG;TRACE 39 | full 40 | x86 41 | 7.3 42 | prompt 43 | MinimumRecommendedRules.ruleset 44 | true 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | 7.3 53 | prompt 54 | MinimumRecommendedRules.ruleset 55 | true 56 | 57 | 58 | true 59 | bin\x64\Debug\ 60 | DEBUG;TRACE 61 | full 62 | x64 63 | 7.3 64 | prompt 65 | MinimumRecommendedRules.ruleset 66 | true 67 | 68 | 69 | bin\x64\Release\ 70 | TRACE 71 | true 72 | pdbonly 73 | x64 74 | 7.3 75 | prompt 76 | MinimumRecommendedRules.ruleset 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | Form 94 | 95 | 96 | Form1.cs 97 | 98 | 99 | 100 | 101 | Form1.cs 102 | 103 | 104 | ResXFileCodeGenerator 105 | Resources.Designer.cs 106 | Designer 107 | 108 | 109 | True 110 | Resources.resx 111 | True 112 | 113 | 114 | SettingsSingleFileGenerator 115 | Settings.Designer.cs 116 | 117 | 118 | True 119 | Settings.settings 120 | True 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | {687e3733-b82e-4cc7-9e83-9573407d01b7} 129 | SchemaMapperDLL 130 | 131 | 132 | 133 | 140 | -------------------------------------------------------------------------------- /sm_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/munchy-bytes/SchemaMapper/9705159b78647c76963101a61e8af4f55c12a4d5/sm_logo.png --------------------------------------------------------------------------------