From 40746c60fed9e70f3cb7f6f12f55595a77a1adfa Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 24 Feb 2019 19:04:47 +0200 Subject: Fixed PPC and Machine Studio issues before next release. Started working on Advanced Installer libraries. --- .../MachineUpdate/MachineUpdateManager.cs | 167 ++++++++++++--------- 1 file changed, 96 insertions(+), 71 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 6fd53bce2..2a53d765e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -203,7 +203,7 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Initializing {nameof(ExaminerSequenceConfigurationRunner)}..."); - UpdateProgress("Updating Database", "Initializing provisioning sequence..."); + UpdateProgress("Updating Database", "Initializing update sequence..."); ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( Path.Combine(_newPackageTempFolder, "Update Scripts", "config.xml"), @@ -318,62 +318,70 @@ namespace Tango.PPC.Common.MachineUpdate /// The serial number. /// The machine service address. /// - public Task UpdateDB(DbCompareResult dbCompareResult) + public Task UpdateDB(DbCompareResult dbCompareResult, String serialNumber) { return Task.Factory.StartNew(() => { LogManager.Log("Starting database update..."); - LogManager.Log("Looking for OverrideData script on application path..."); + LogManager.Log("Looking for update scripts configuration on application path..."); - String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "OverrideData.xml"); + String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "config.xml"); if (!File.Exists(config_file)) { - config_file = Path.Combine(PathHelper.GetStartupPath(), "Provision Scripts", "OverrideData.xml"); - } - - if (!File.Exists(config_file)) - { - throw LogManager.Log(new FileNotFoundException("Could not locate OverrideData.xml file on application folder.")); + throw LogManager.Log(new FileNotFoundException($"Could not locate '{config_file}' file on application folder.")); } UpdateDBResponse update_response = dbCompareResult.UpdateDBResponse; var localDataSource = SettingsManager.Default.GetOrCreate().DataSource; - LogManager.Log($"Overriding database static tables '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'..."); + LogManager.Log($"Updating database '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'..."); - ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(config_file); - builder.SetSource(update_response.DataSource); - builder.SetTarget(localDataSource); - builder.Synchronize(); + ExaminerSequenceConfiguration config_sequence = ExaminerSequenceConfiguration.FromFile(config_file); - var config = builder.Build(); - - ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data); - process.Progress += (x, msg) => + foreach (var item in config_sequence.Items.Where(x => x.Type == ExaminerSequenceItemType.Data).OrderBy(x => x.Index)) { - LogManager.Log(msg); - }; + LogManager.Log($"Executing update script '{item.FileName}...'"); - LogManager.Log("Starting synchronization process..."); - - try - { - var result = process.Execute().Result; + ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(Path.Combine(Path.GetDirectoryName(config_file), item.FileName)); + builder.SetSource(update_response.DataSource); + builder.SetTarget(localDataSource); - if (result.ExitCode != ExaminerProcessExitCode.Success) + if (item.RequiresSerialNumber) { - throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode))); + builder.SetMachineSerialNumber(serialNumber); } - LogManager.Log("Synchronization completed successfully!"); - } - catch (Exception ex) - { - throw LogManager.Log(ex, "Setup manager error while trying to update the database."); + builder.Synchronize(); + + var config = builder.Build(); + + ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data); + process.Progress += (x, msg) => + { + LogManager.Log(msg); + }; + + try + { + var result = process.Execute().Result; + + if (result.ExitCode != ExaminerProcessExitCode.Success) + { + throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode))); + } + + LogManager.Log("Script executed successfully."); + } + catch (Exception ex) + { + throw LogManager.Log(ex, "Setup manager error while trying to update the database."); + } } + + LogManager.Log("Update completed successfully."); }); } @@ -391,18 +399,13 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Checking if database update is required for serial number {serialNumber}..."); - LogManager.Log("Looking for OverrideData script on application path..."); + LogManager.Log("Looking for update scripts configuration on application path..."); - String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "OverrideData.xml"); + String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "config.xml"); if (!File.Exists(config_file)) { - config_file = Path.Combine(PathHelper.GetStartupPath(), "Provision Scripts", "OverrideData.xml"); - } - - if (!File.Exists(config_file)) - { - throw LogManager.Log(new FileNotFoundException("Could not locate OverrideData.xml file on application folder.")); + throw LogManager.Log(new FileNotFoundException($"Could not locate '{config_file}' file on application folder.")); } LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); @@ -420,53 +423,75 @@ namespace Tango.PPC.Common.MachineUpdate var localDataSource = SettingsManager.Default.GetOrCreate().DataSource; - LogManager.Log($"Comparing database static tables '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'..."); + LogManager.Log($"Comparing database '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'..."); var report_file = TemporaryManager.CreateFile(".xml"); - ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(config_file); - builder.SetSource(update_response.DataSource); - builder.SetTarget(localDataSource); - builder.SetReportFile(report_file); + ExaminerSequenceConfiguration config_sequence = ExaminerSequenceConfiguration.FromFile(config_file); - var config = builder.Build(); + bool has_differences = false; - ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data); - process.Progress += (x, msg) => + foreach (var item in config_sequence.Items.Where(x => x.Type == ExaminerSequenceItemType.Data).OrderBy(x => x.Index)) { - LogManager.Log(msg); - }; + LogManager.Log($"Executing update script '{item.FileName}...'"); - LogManager.Log("Starting comparison process..."); - LogManager.Log("Generating report on " + report_file); + ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(Path.Combine(Path.GetDirectoryName(config_file), item.FileName)); + builder.SetSource(update_response.DataSource); + builder.SetTarget(localDataSource); + builder.SetReportFile(report_file); - try - { - var result = process.Execute().Result; - - if (result.ExitCode != ExaminerProcessExitCode.Success) + if (item.RequiresSerialNumber) { - throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode))); + builder.SetMachineSerialNumber(serialNumber); } - LogManager.Log("Comparison completed successfully!"); - LogManager.Log("Loading report file..."); + var config = builder.Build(); - ExaminerDataReport report = ExaminerDataReport.FromFile(report_file); - report_file.Delete(); + ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data); + process.Progress += (x, msg) => + { + LogManager.Log(msg); + }; - LogManager.Log("Comparison summary: \n" + report.Totals.ToJsonString()); + LogManager.Log("Starting comparison process..."); + LogManager.Log("Generating report on " + report_file); - return new DbCompareResult() + try { - RequiresUpdate = report.HasDifferences, - UpdateDBResponse = update_response, - }; + var result = process.Execute().Result; + + if (result.ExitCode != ExaminerProcessExitCode.Success) + { + throw LogManager.Log(new InvalidDataException(String.Format("Update script has terminated with exit code '{0}'.", result.ExitCode))); + } + + LogManager.Log("Comparison completed successfully!"); + LogManager.Log("Loading report file..."); + + ExaminerDataReport report = ExaminerDataReport.FromFile(report_file); + report_file.Delete(); + + LogManager.Log("Comparison summary: \n" + report.Totals.ToJsonString()); + + if (report.HasDifferences) + { + has_differences = true; + break; + } + } + catch (Exception ex) + { + throw LogManager.Log(ex, "Update manager error while trying to compare the database."); + } } - catch (Exception ex) + + LogManager.Log("Comparison completed successfully."); + + return new DbCompareResult() { - throw LogManager.Log(ex, "Update manager error while trying to compare the database."); - } + RequiresUpdate = has_differences, + UpdateDBResponse = update_response, + }; }); } -- cgit v1.3.1 From 0c696317f92460cdbed77493f57523fbb617d65c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 24 Feb 2019 19:32:33 +0200 Subject: Fixed some issues with PPC update. --- .../MachineUpdate/MachineUpdateManager.cs | 80 +++++++++++++--------- .../PPC/Tango.PPC.Common/Publish/PPCPublisher.cs | 2 +- .../PPC/Tango.PPC.Publisher.UI/MainWindow.xaml | 8 +-- 3 files changed, 53 insertions(+), 37 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 2a53d765e..64827f15f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -113,13 +113,19 @@ namespace Tango.PPC.Common.MachineUpdate await Task.Delay(1000); IMachineOperator op = _machineProvider.MachineOperator; - if (op.State != Transport.TransportComponentState.Connected) - { - throw new InvalidOperationException("Could not perform an update while the machine is not connected."); - } - if (op.Status != MachineStatuses.ReadyToDye) + + if (_machineProvider.Machine.SetupFirmware) { - throw new InvalidOperationException($"Could not perform an update while the machine is in a {op.Status} status."); + LogManager.Log("Machine is configured to update firmware..."); + + if (op.State != Transport.TransportComponentState.Connected) + { + throw LogManager.Log(new InvalidOperationException("Could not perform an update while the machine is not connected.")); + } + if (op.Status != MachineStatuses.ReadyToDye) + { + throw LogManager.Log(new InvalidOperationException($"Could not perform an update while the machine is in a {op.Status} status.")); + } } //Connect to machine service and get matching packages for this machine. @@ -238,38 +244,48 @@ namespace Tango.PPC.Common.MachineUpdate } //Updating firmware - UpdateProgress("Updating Firmware", "Connecting to firmware device..."); - LogManager.Log(""); - LogManager.Log("-------------------------------------------------------------------------"); - LogManager.Log("Updating Firmware..."); - - UpdateProgress("Updating Firmware", "Loading firmware package..."); - var tfpPath = Path.Combine(_newPackageTempFolder, "firmware_package.tfp"); - var stream = new FileStream(tfpPath, FileMode.Open); - var handler = await op.UpgradeFirmware(stream); - handler.Failed += (_, ex) => + if (_machineProvider.Machine.SetupFirmware) { - stream.Dispose(); - result.SetException(ex); - }; - handler.Completed += (_, __) => + UpdateProgress("Updating Firmware", "Connecting to firmware device..."); + LogManager.Log(""); + LogManager.Log("-------------------------------------------------------------------------"); + LogManager.Log("Updating Firmware..."); + + UpdateProgress("Updating Firmware", "Loading firmware package..."); + var tfpPath = Path.Combine(_newPackageTempFolder, "firmware_package.tfp"); + var stream = new FileStream(tfpPath, FileMode.Open); + var handler = await op.UpgradeFirmware(stream); + handler.Failed += (_, ex) => + { + stream.Dispose(); + result.SetException(ex); + }; + handler.Completed += (_, __) => + { + UpdateProgress("Updating Firmware", "Firmware update completed successfully."); + stream.Dispose(); + result.SetResult(new MachineUpdateResult() + { + UpdatePackagePath = _newPackageTempFolder, + }); + }; + handler.Canceled += (_, __) => + { + stream.Dispose(); + result.SetException(new Exception("The operation has been canceled.")); + }; + handler.Progress += (_, e) => + { + UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); + }; + } + else { - UpdateProgress("Updating Firmware", "Firmware update completed successfully."); - stream.Dispose(); result.SetResult(new MachineUpdateResult() { UpdatePackagePath = _newPackageTempFolder, }); - }; - handler.Canceled += (_, __) => - { - stream.Dispose(); - result.SetException(new Exception("The operation has been canceled.")); - }; - handler.Progress += (_, e) => - { - UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); - }; + } } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs index 1a6c57607..e7f44f183 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs @@ -246,7 +246,7 @@ namespace Tango.PPC.Common.Publish using (ZipFile zip = new ZipFile()) { - zip.AddFile(Options.TfpPath, "/"); + zip.AddFile(Options.TfpPath, "/").FileName = "firmware_package.tfp"; String provision_dir = "Provision Scripts"; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindow.xaml index 1bdc062de..f29b6bd44 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindow.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindow.xaml @@ -60,15 +60,15 @@ - Local Version: - + Remote Version: + - Remote Version: - + Local Version: + -- cgit v1.3.1