diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-12 18:23:05 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-12 18:23:05 +0300 |
| commit | 819b2bc2094baac1ddf4e6e84cd308e96eb17d8e (patch) | |
| tree | 8b77801f6ccc5aea874583c334f3bf71ff6083d0 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup | |
| parent | da8c561c85c9ee296cb18796e5db95ca759d1063 (diff) | |
| parent | a4a2a94fe295f57c462eb3cd2c24c9ba512de5a6 (diff) | |
| download | Tango-819b2bc2094baac1ddf4e6e84cd308e96eb17d8e.tar.gz Tango-819b2bc2094baac1ddf4e6e84cd308e96eb17d8e.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup')
3 files changed, 50 insertions, 122 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs index 52fc5acd1..096431d63 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -10,8 +10,8 @@ namespace Tango.PPC.Common.MachineSetup { MachineSetupSteps CurrentStep { get; } event EventHandler<String> ProgressLog; - double UpdatingPackagesProgress { get; } - String UpdatingPackagesStatus { get; } + double DownloadingPackagesProgress { get; } + String DownloadingPackagesStatus { get; } event EventHandler<MachineSetupSteps> ProgressStep; Task Setup(String serialNumber, String hostAddress); } 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 dc5164465..72c6da515 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -30,21 +30,24 @@ namespace Tango.PPC.Common.MachineSetup get { return _currentStep; } set { - _currentStep = value; - RaisePropertyChangedAuto(); - ProgressStep?.Invoke(this, _currentStep); + if (_currentStep != value) + { + _currentStep = value; + RaisePropertyChangedAuto(); + ProgressStep?.Invoke(this, _currentStep); + } } } private double _downloadProgress; - public double UpdatingPackagesProgress + public double DownloadingPackagesProgress { get { return _downloadProgress; } private set { _downloadProgress = value; RaisePropertyChangedAuto(); } } private String _updatingPackagesStatus; - public String UpdatingPackagesStatus + public String DownloadingPackagesStatus { get { return _updatingPackagesStatus; } set { _updatingPackagesStatus = value; RaisePropertyChangedAuto(); } @@ -56,9 +59,9 @@ namespace Tango.PPC.Common.MachineSetup { //Connect to machine service and get matching packages for this machine. - CurrentStep = MachineSetupSteps.UpdatingPackages; - UpdatingPackagesProgress = 0; - UpdatingPackagesStatus = "Connecting to machine service..."; + CurrentStep = MachineSetupSteps.DownloadingPackage; + DownloadingPackagesProgress = 0; + DownloadingPackagesStatus = "Connecting to machine service..."; MachineSetupRequest request = new MachineSetupRequest(); request.SerialNumber = serialNumber; @@ -74,24 +77,20 @@ namespace Tango.PPC.Common.MachineSetup var _newPackageTempFolder = TemporaryManager.CreateFolder(); _newPackageTempFolder.Persist = true; - var software_package_folder = _newPackageTempFolder.CreateFolder(); - var embedded_package_folder = _newPackageTempFolder.CreateFolder(); - - //Download software package. var tempFile = TemporaryManager.CreateFile(".zip"); - UpdatingPackagesStatus = "Downloading application package..."; + DownloadingPackagesStatus = "Downloading software package..."; int fileSize = 0; - UpdatingPackagesProgress = 0; + DownloadingPackagesProgress = 0; using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => { InvokeUINow(() => { Thread.Sleep(10); - UpdatingPackagesProgress = ((double)current / (double)fileSize) * 100d; + DownloadingPackagesProgress = ((double)current / (double)fileSize) * 100d; }); })) { @@ -100,138 +99,67 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log("Connecting to FTP site: " + setup_response.FtpAddress); ftp.ConnectAsync().Wait(); LogManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(setup_response.ApplicationFtpFilePath); + fileSize = (int)ftp.GetFileSize(setup_response.FilePath); LogManager.Log("Download size: " + fileSize + " bytes."); LogManager.Log("Starting download..."); - ftp.DownloadAsync(fs, setup_response.ApplicationFtpFilePath).Wait(); + ftp.DownloadAsync(fs, setup_response.FilePath).Wait(); } } //Extract software package. - ZipFile.ExtractToDirectory(tempFile, software_package_folder); - - //Download embedded package. - tempFile = TemporaryManager.CreateFile(".zip"); - - UpdatingPackagesStatus = "Downloading embedded package..."; - - fileSize = 0; - UpdatingPackagesProgress = 0; - - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => - { - InvokeUINow(() => - { - Thread.Sleep(10); - UpdatingPackagesProgress = ((double)current / (double)fileSize) * 100d; - }); - })) - { - using (FtpClient ftp = new FtpClient(setup_response.FtpAddress, setup_response.UserName, setup_response.Password)) - { - LogManager.Log("Connecting to FTP site: " + setup_response.FtpAddress); - ftp.ConnectAsync().Wait(); - LogManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(setup_response.EmbeddedFtpFilePath); - LogManager.Log("Download size: " + fileSize + " bytes."); - LogManager.Log("Starting download..."); - ftp.DownloadAsync(fs, setup_response.EmbeddedFtpFilePath).Wait(); - } - } + ZipFile.ExtractToDirectory(tempFile, _newPackageTempFolder); - //Extract embedded package. - ZipFile.ExtractToDirectory(tempFile, embedded_package_folder); //Synchronize database - String remote_address = setup_response.DbAddress; - 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"); + String remote_address = setup_response.DbAddress; DbManager db = new DbManager(new SqlConnection(String.Format("Server={0};Integrated security=SSPI", localAddress))); - if (!db.Exists("Tango")) + if (!db.Exists(db_name)) { throw new InvalidProgramException("Database tango does not exists."); } - //Create schema configuration - ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.Schema); - - builder. - SetSourceServer(remote_address, 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; + db.ClearDb(db_name); //TODO: This is not working! - //Create override data configuration - builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.OverrideData); - - builder. - SetSourceServer(remote_address, db_name). - SetTargetServer(localAddress, db_name). - Synchronize(); + ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( + Path.Combine(_newPackageTempFolder, "Synchronization Scripts", "config.xml"), + Path.Combine(_newPackageTempFolder, "Synchronization Scripts"), + new ExaminerSequenceDataSource() + { + Address = remote_address, + DataBaseName = db_name, + IntegratedSecurity = true, + }, + new ExaminerSequenceDataSource() + { + Address = localAddress, + DataBaseName = db_name, + IntegratedSecurity = true, + }, serialNumber); - process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); - process.Progress += (x, msg) => + runner.Log += (x, msg) => { - ProgressLog?.Invoke(this, msg); + ProgressLog.Invoke(this, msg); }; - result = process.Execute().Result; - //Synchronization was successful - if (result.ExitCode != ExaminerProcessExitCode.Success) + runner.ScriptExecuting += (x, item) => { - throw new InvalidProgramException("Error while trying to synchronize data."); - } - - CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; - - //Provision Target - builder = new ExaminerConfigurationBuilder(ExaminerConfigurationType.ProvisionMachine); - - builder. - SetSourceServer(remote_address, db_name). - SetTargetServer(localAddress, db_name). - SetMachineSerialNumber(serialNumber). - Synchronize(); - - - process = new ExaminerProcess(builder.Build(), ExaminerProcessType.Data); - process.Progress += (x, msg) => - { - ProgressLog?.Invoke(this, msg); + if (item.Type == ExaminerSequenceItemType.Data && item.RequiresSerialNumber) + { + CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; + } + else if (item.Type == ExaminerSequenceItemType.Data) + { + CurrentStep = MachineSetupSteps.SynchronizingData; + } }; - result = process.Execute().Result; - //Synchronization was successful - if (result.ExitCode != ExaminerProcessExitCode.Success) - { - throw new InvalidProgramException("Error while trying to synchronize database schema."); - } + runner.Run().Wait(); }); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs index 1262eb248..3db1eb4b0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs @@ -10,7 +10,7 @@ namespace Tango.PPC.Common.MachineSetup public enum MachineSetupSteps { [Description("Downloading Package")] - UpdatingPackages, + DownloadingPackage, [Description("Synchronizing Schema")] SynchronizingSchema, [Description("Synchronizing Data")] |
