1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.DAL.Remote.DB;
using Tango.Settings;
using Tango.Synchronization;
using Tango.Synchronization.Conversion;
namespace Tango.SQLiteGenerator.CLI
{
public enum Config
{
Default,
CopyAll,
}
class Program
{
static void Main(string[] args)
{
Console.Title = "Tango SQLite Generator";
#if DEBUG
args = new string[]
{
Path.GetFullPath( "..\\..\\..\\..\\DB\\Tango.db"),
"CopyAll"
};
#endif
String sqlitePath = args[0];
Config conf = args.Length > 1 ? (Config)Enum.Parse(typeof(Config), args[1]) : Config.Default;
sqlitePath = Path.GetFullPath(sqlitePath);
Console.WriteLine("Generating " + sqlitePath + "...");
bool completed = false;
String connectionString = SettingsManager.Default.GetOrCreate<CoreSettings>().DataBaseSource;
Console.WriteLine("Connecting to " + connectionString + "...");
connectionString = String.Format("Data Source={0};Initial Catalog=Tango;Integrated Security=SSPI;", connectionString);
List<SYNC_CONFIGURATIONS> sync_configurations = new List<SYNC_CONFIGURATIONS>();
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<TableSchema> schema)
{
List<TableSchema> updated = schema.Where(x => x.TableName.ToLower() != "sysdiagrams").ToList();
if (conf == Config.Default)
{
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);
}
else if (conf == Config.CopyAll)
{
updated.ForEach(x => x.CopyData = true);
}
return updated;
});
SqlServerToSQLiteConverter converter = new SqlServerToSQLiteConverter();
converter.GenerateForeignKeys = true;
converter.GenerateIndexes = true;
converter.ConvertSqlServerToSQLiteDatabase(connectionString, sqlitePath, null, handler, selectionHandler, null, false, false);
while (!completed)
{
Console.ReadLine();
}
}
}
}
|