diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-08 13:35:27 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-08 13:35:27 +0300 |
| commit | 57ae9d131e898a35061507bc8497bcf648cf00d1 (patch) | |
| tree | 91e5c55fdcced791f509b24d13c4a73294a295f2 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs | |
| parent | 8dac70e25c92eea8278c564615509386a1a0182d (diff) | |
| download | Tango-57ae9d131e898a35061507bc8497bcf648cf00d1.tar.gz Tango-57ae9d131e898a35061507bc8497bcf648cf00d1.zip | |
Working on machine setup !
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs | 115 |
1 files changed, 114 insertions, 1 deletions
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<string> ProgressLog; + public event EventHandler<MachineSetupSteps> 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<CoreSettings>().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."); + } + }); + } } } |
