aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-24 17:34:59 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-24 17:34:59 +0200
commitc20ae91e363924841c46558437303455414cd39b (patch)
tree39b8ade42ef07470afccfcfd355e969f09a1c253 /Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs
parent9e3bf3983895ec0ca9286f85f76f03048eb6ea55 (diff)
downloadTango-c20ae91e363924841c46558437303455414cd39b.tar.gz
Tango-c20ae91e363924841c46558437303455414cd39b.zip
PPC local data synchronizer utility.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs107
1 files changed, 107 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs b/Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs
new file mode 100644
index 000000000..091ef8f13
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.DataSynchronizer.CLI/Program.cs
@@ -0,0 +1,107 @@
+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 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 = "twine.database.windows.net";
+ source.Catalog = "Tango_DEV";
+ source.UserName = "Roy";
+ source.Password = "Aa123456";
+
+ using (ObservablesContext db = ObservablesContext.CreateDefault(source))
+ {
+ machineGuid = db.Machines.Where(x => x.SerialNumber == "LENA_TABLET").Take(1).Select(x => x.Guid).First();
+ }
+
+ target = new Core.DataSource();
+ target.Address = "localhost\\SQLPPC";
+ target.Catalog = "Tango";
+
+ OverrideData();
+ UpdateMachine();
+
+ 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);
+ }
+ }
+ }
+}