blob: e4fa011e8d5a2544098b2f929e6878ce7ef9d3c8 (
plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.SQLExaminer;
namespace Tango.PPC.DataSynchronizer.CLI
{
class Program
{
static void Main(string[] args)
{
DataSynchronizer synchronizer = new DataSynchronizer();
synchronizer.Synchronize();
Console.ReadLine();
}
}
public class DataSynchronizer
{
private const String REMOTE_ADDRESS = "twine.database.windows.net";
private const String REMOTE_CATALOG = "Tango_DEV"; //Tango_TEST
private const String REMOTE_USER_NAME = "Roy";
private const String REMOTE_PASSWORD = "Aa123456";
private const String LOCAL_ADDRESS = "localhost\\SQLPPC";
private const String LOCAL_CATALOG = "Tango"; //Tango_TEST
private const String MACHINE_SERIAL_NUMBER = "ROY_X1"; //ROY_TEST_MACHINE
private Core.DataSource source;
private Core.DataSource target;
private String machineGuid;
public void Synchronize()
{
try
{
Console.WriteLine("Starting PPC data synchronization...");
source = new Core.DataSource();
source.IntegratedSecurity = false;
source.Address = REMOTE_ADDRESS;
source.Catalog = REMOTE_CATALOG;
source.UserName = REMOTE_USER_NAME;
source.Password = REMOTE_PASSWORD;
using (ObservablesContext db = ObservablesContext.CreateDefault(source))
{
machineGuid = db.Machines.Where(x => x.SerialNumber == MACHINE_SERIAL_NUMBER).Take(1).Select(x => x.Guid).First();
}
target = new Core.DataSource();
target.Address = LOCAL_ADDRESS;
target.Catalog = LOCAL_CATALOG;
OverrideData();
UpdateMachine();
//ProvisionMachine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Synchronization Completed Successfully.");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.ToString());
}
}
private void OverrideData()
{
Console.WriteLine("Executing override data script...");
ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData);
builder.SetSource(source).SetTarget(target).Synchronize();
var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data);
process.Progress += (x, msg) =>
{
if (msg != null && !msg.Contains("SQL Examiner"))
{
Console.WriteLine(msg);
}
};
var result = process.Execute().Result;
if (result.ExitCode != ExaminerProcessExitCode.Success)
{
throw new InvalidOperationException(result.Output);
}
}
private void UpdateMachine()
{
Console.WriteLine("Executing update machine script...");
ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.UpdateMachine);
builder.SetSource(source).SetTarget(target).SetMachineSerialNumber(machineGuid).Synchronize();
var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data);
process.Progress += (x, msg) =>
{
if (msg != null && !msg.Contains("SQL Examiner"))
{
Console.WriteLine(msg);
}
};
var result = process.Execute().Result;
if (result.ExitCode != ExaminerProcessExitCode.Success)
{
throw new InvalidOperationException(result.Output);
}
}
private void ProvisionMachine()
{
Console.WriteLine("Executing provision machine script...");
ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine);
builder.SetSource(source).SetTarget(target).SetMachineSerialNumber(MACHINE_SERIAL_NUMBER).Synchronize();
var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data);
process.Progress += (x, msg) =>
{
if (msg != null && !msg.Contains("SQL Examiner"))
{
Console.WriteLine(msg);
}
};
var result = process.Execute().Result;
if (result.ExitCode != ExaminerProcessExitCode.Success)
{
throw new InvalidOperationException(result.Output);
}
}
}
}
|