From 57ae9d131e898a35061507bc8497bcf648cf00d1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 8 Aug 2018 13:35:27 +0300 Subject: Working on machine setup ! --- .../MachineSetup/MachineSetupManager.cs | 115 ++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index a93a449f7..51c906019 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -1,12 +1,125 @@ using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.IO; +using Tango.Settings; +using Tango.SQLExaminer; namespace Tango.PPC.Common.MachineSetup { - class MachineSetupManager + public class MachineSetupManager : ExtendedObject, IMachineSetupManager { + public event EventHandler ProgressLog; + public event EventHandler ProgressStep; + + private MachineSetupSteps _currentStep; + public MachineSetupSteps CurrentStep + { + get { return _currentStep; } + set + { + _currentStep = value; + RaisePropertyChangedAuto(); + ProgressStep?.Invoke(this, _currentStep); + } + } + + public Task Setup(string serialNumber, string hostAddress) + { + return Task.Factory.StartNew(() => + { + CurrentStep = MachineSetupSteps.SynchronizingSchema; + + String db_name = "Tango"; + + String localAddress = SettingsManager.Default.GetOrCreate().DataBaseSource; + + var tempFolder = TemporaryManager.Default.CreateFolder("Machine Setup"); + String report_file = tempFolder.CreateImaginaryFile(".xml"); + String config_file = tempFolder.CreateImaginaryFile(".xml"); + + DbManager db = new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", localAddress))); + + if (!db.Exists("Tango")) + { + throw new InvalidProgramException("Database tango does not exists."); + } + + //Create schema configuration + ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema); + + builder. + SetSourceServer(hostAddress, db_name). + SetTargetServer(localAddress, db_name). + Synchronize(); + + //Synchronize Source schema with Target schema + + var process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Schema); + process.Progress += (x, msg) => + { + ProgressLog?.Invoke(this, msg); + }; + var result = process.Execute().Result; + + //Synchronization was successful + if (result.ExitCode != ExaminerProcessExitCode.Success) + { + throw new InvalidProgramException("Error while trying to synchronize database schema."); + } + + CurrentStep = MachineSetupSteps.SynchronizingData; + + //Create override data configuration + builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData); + + builder. + SetSourceServer(hostAddress, db_name). + SetTargetServer(localAddress, db_name). + Synchronize(); + + process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); + process.Progress += (x, msg) => + { + ProgressLog?.Invoke(this, msg); + }; + result = process.Execute().Result; + + //Synchronization was successful + if (result.ExitCode != ExaminerProcessExitCode.Success) + { + throw new InvalidProgramException("Error while trying to synchronize data."); + } + + CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; + + //Provision Target + builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine); + + builder. + SetSourceServer(hostAddress, db_name). + SetTargetServer(localAddress, db_name). + SetMachineSerialNumber(serialNumber). + Synchronize(); + + + process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); + process.Progress += (x, msg) => + { + ProgressLog?.Invoke(this, msg); + }; + result = process.Execute().Result; + + //Synchronization was successful + if (result.ExitCode != ExaminerProcessExitCode.Success) + { + throw new InvalidProgramException("Error while trying to synchronize database schema."); + } + }); + } } } -- cgit v1.3.1