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
|
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
{
class Program
{
static void Main(string[] args)
{
String sqlitePath = args[0];
sqlitePath = Path.GetFullPath(sqlitePath);
bool completed = false;
String connectionString = SettingsManager.Default.GetOrCreate<CoreSettings>().SQLServerAddress;
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();
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();
}
}
}
}
|