From 6a8a50b01383cf724822c3eb0135c1729fb2daed Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 25 Jan 2018 16:17:55 +0200 Subject: Implemented SQL Server To SQLite Conversion Utility!!! Added missing synchronization tables to remote synchronization. Updated DAL.Local. --- .../Utilities/Tango.SQLiteGenerator.CLI/Program.cs | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs (limited to 'Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs') diff --git a/Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs new file mode 100644 index 000000000..242cdcfa9 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DAL.Remote.DB; +using Tango.Settings; +using Tango.Synchronization; +using Tango.Synchronization.Conversion; + +namespace Tango.SQLiteGenerator.CLI +{ + class Program + { + static void Main(string[] args) + { + String sqlitePath = args[0]; + + sqlitePath = Path.GetFullPath(sqlitePath); + + bool completed = false; + + String connectionString = SettingsManager.Default.DataBase.SQLServerAddress; + + Console.WriteLine("Connecting to " + connectionString + "..."); + + connectionString = String.Format("Data Source={0};Initial Catalog=Tango;Integrated Security=SSPI;", connectionString); + + List sync_configurations = new List(); + + using (RemoteDB db = RemoteDB.CreateDefault()) + { + sync_configurations = db.SYNC_CONFIGURATIONS.ToList(); + } + + SqlConversionHandler handler = new SqlConversionHandler(delegate (bool done, bool success, int percent, string msg) + { + Console.WriteLine(String.Format("{0} [%{1}]", msg, percent)); + + if (done) + { + if (success) + { + Console.WriteLine("SQLite database has been generated successfully on " + sqlitePath); + Environment.Exit(0); + } + else + { + Console.WriteLine("SQLite database generation failed!"); + Environment.Exit(-1); + } + + completed = true; + } + }); + + SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate (List schema) + { + List updated = schema.Where(x => x.TableName.ToLower() != "sysdiagrams").ToList(); + + updated + .Where(table => sync_configurations.Where(config => (SyncConfiguration)config.SYNC_TYPE == SyncConfiguration.OverwriteLocal).ToList() + .Exists(config => config.TABLE_NAME == table.TableName)).ToList().ForEach(x => x.CopyData = true); + + return updated; + }); + + SqlServerToSQLiteConverter converter = new SqlServerToSQLiteConverter(); + + converter.ConvertSqlServerToSQLiteDatabase(connectionString, sqlitePath, null, handler, selectionHandler, null, false, false); + + while (!completed) + { + Console.ReadLine(); + } + } + } +} -- cgit v1.3.1