diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-09 16:59:07 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-09 16:59:07 +0200 |
| commit | f7d320bcc6651d0c85bad73b52b14ba050a40c18 (patch) | |
| tree | 6f446d30c34da651e5cb2bed93caa0edc3a38f24 /Software/Visual_Studio/PPC | |
| parent | 58c791b68d9058516166cc26fc15563bd56ebeb6 (diff) | |
| download | Tango-f7d320bcc6651d0c85bad73b52b14ba050a40c18.tar.gz Tango-f7d320bcc6651d0c85bad73b52b14ba050a40c18.zip | |
Refactored PPC firmware upgrade.
Diffstat (limited to 'Software/Visual_Studio/PPC')
19 files changed, 255 insertions, 285 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs index a1f9f6d38..003229e65 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Application/IPPCApplicationManager.cs @@ -41,11 +41,6 @@ namespace Tango.PPC.Common.Application event EventHandler SetupRequired; /// <summary> - /// Occurs when firmware upgrade is required. - /// </summary> - event EventHandler FirmwareUpgradeRequired; - - /// <summary> /// Occurs when the application has encountered an error when initializing. /// </summary> event EventHandler<Exception> ApplicationInitializationError; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs index 362b3941b..d06cc4b74 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/ApplicationStates.cs @@ -16,17 +16,8 @@ namespace Tango.PPC.Common /// </summary> PreSetup = 0, /// <summary> - /// After the first setup has completed successfully and the updater utility should replace the application assemblies. - /// Updater utility should update the application assemblies and start the main application with startup arguments. - /// </summary> - SemiSetup = 1, - /// <summary> - /// The application has been updated and should start in firmware upgrade mode. - /// </summary> - FirmwareUpgrade = 2, - /// <summary> /// Application is ready to run as normal. /// </summary> - Ready = 3, + Ready = 1, } } 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 145335e09..896c7b921 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -11,10 +11,7 @@ namespace Tango.PPC.Common.MachineSetup /// </summary> public interface IMachineSetupManager { - /// <summary> - /// Gets the current setup step. - /// </summary> - MachineSetupSteps CurrentStep { get; } + MachineSetupProgress Status { get; } /// <summary> /// Occurs when there is a text log message available. @@ -22,19 +19,9 @@ namespace Tango.PPC.Common.MachineSetup event EventHandler<String> ProgressLog; /// <summary> - /// Gets the downloading packages step progress. - /// </summary> - double DownloadingPackagesProgress { get; } - - /// <summary> - /// Gets the downloading packages step status. - /// </summary> - String DownloadingPackagesStatus { get; } - - /// <summary> - /// Occurs when the <see cref="CurrentStep"/> has changed. + /// Occurs when the setup has made some progress. /// </summary> - event EventHandler<MachineSetupSteps> ProgressStep; + event EventHandler<MachineSetupProgress> Progress; /// <summary> /// Performs a machine setup using the specified serial number and machine service address. 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 02324b743..22da5c57e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -17,7 +17,9 @@ using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Synchronization; using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; using Tango.Settings; +using Tango.SharedUI.Helpers; using Tango.SQLExaminer; using Tango.Transport.Web; @@ -40,49 +42,17 @@ namespace Tango.PPC.Common.MachineSetup /// <summary> /// Occurs when the <see cref="CurrentStep" /> has changed. /// </summary> - public event EventHandler<MachineSetupSteps> ProgressStep; + public event EventHandler<MachineSetupProgress> Progress; #endregion #region Properties - private MachineSetupSteps _currentStep; - /// <summary> - /// Gets the current setup step. - /// </summary> - public MachineSetupSteps CurrentStep - { - get { return _currentStep; } - set - { - if (_currentStep != value) - { - _currentStep = value; - RaisePropertyChangedAuto(); - ProgressStep?.Invoke(this, _currentStep); - LogManager.Log("Machine Setup Manager Step: " + value.ToString()); - } - } - } - - private double _downloadProgress; - /// <summary> - /// Gets the downloading packages step progress. - /// </summary> - public double DownloadingPackagesProgress - { - get { return _downloadProgress; } - private set { _downloadProgress = value; RaisePropertyChangedAuto(); } - } - - private String _updatingPackagesStatus; - /// <summary> - /// Gets the downloading packages step status. - /// </summary> - public String DownloadingPackagesStatus + private MachineSetupProgress _status; + public MachineSetupProgress Status { - get { return _updatingPackagesStatus; } - set { _updatingPackagesStatus = value; RaisePropertyChangedAuto(); } + get { return _status; } + private set { _status = value; RaisePropertyChangedAuto(); } } #endregion @@ -95,17 +65,16 @@ namespace Tango.PPC.Common.MachineSetup /// <param name="serialNumber">The serial number.</param> /// <param name="machineServiceAddress">The machine service address.</param> /// <returns></returns> - public Task<MachineSetupResult> Setup(string serialNumber, string machineServiceAddress) + public async Task<MachineSetupResult> Setup(string serialNumber, string machineServiceAddress) { - return Task.Factory.StartNew<MachineSetupResult>(() => - { + TaskCompletionSource<MachineSetupResult> result = new TaskCompletionSource<MachineSetupResult>(); + try + { LogManager.Log($"Starting machine setup for serial number {serialNumber}..."); //Connect to machine service and get matching packages for this machine. - CurrentStep = MachineSetupSteps.DownloadingPackage; - DownloadingPackagesProgress = 0; - DownloadingPackagesStatus = "Connecting to machine service..."; + UpdateProgress("Downloading software package", "Connecting to machine service..."); LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); @@ -118,7 +87,7 @@ namespace Tango.PPC.Common.MachineSetup { using (var http = new ProtoWebClient()) { - setup_response = http.Post<MachineSetupRequest, MachineSetupResponse>(machineServiceAddress + "/api/Synchronization/MachineSetup", request).Result; + setup_response = await http.Post<MachineSetupRequest, MachineSetupResponse>(machineServiceAddress + "/api/Synchronization/MachineSetup", request); } } catch (Exception ex) @@ -139,31 +108,31 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Temporary package zip file created: {tempFile}."); - DownloadingPackagesStatus = "Downloading software package..."; - LogManager.Log("Downloading software package..."); long fileSize = 0; - DownloadingPackagesProgress = 0; + UpdateProgress("Downloading software package", "Downloading...", false); - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => + await Task.Factory.StartNew(() => { - InvokeUINow(() => + using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => + { + UpdateProgress("Downloading software package", "Downloading...", false, current, fileSize); + })) { - DownloadingPackagesProgress = ((double)current / (double)fileSize) * 100d; - }); - })) - { - LogManager.Log($"Connecting to storage blob with address {setup_response.BlobAddress}"); - CloudBlockBlob blob = new CloudBlockBlob(new Uri(setup_response.BlobAddress)); - LogManager.Log("Fetching blob attributes..."); - blob.FetchAttributes(); - fileSize = blob.Properties.Length; - LogManager.Log("Download size: " + fileSize + " bytes."); - LogManager.Log("Starting blob download..."); - blob.DownloadToStream(fs); - } + LogManager.Log($"Connecting to storage blob with address {setup_response.BlobAddress}"); + CloudBlockBlob blob = new CloudBlockBlob(new Uri(setup_response.BlobAddress)); + LogManager.Log("Fetching blob attributes..."); + blob.FetchAttributes(); + fileSize = blob.Properties.Length; + LogManager.Log("Download size: " + fileSize + " bytes."); + LogManager.Log("Starting blob download..."); + blob.DownloadToStream(fs); + } + }); + + UpdateProgress("Downloading software package", "Extracting package..."); LogManager.Log("Extracting downloaded zip file..."); //Extract software package. @@ -176,7 +145,7 @@ namespace Tango.PPC.Common.MachineSetup //Synchronize database - CurrentStep = MachineSetupSteps.SynchronizingSchema; + UpdateProgress("Updating Database", "Initializing..."); String db_name = "Tango"; String localAddress = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource.Address; @@ -184,12 +153,14 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Synchronizing database '{remote_address}\\{db_name}' => '{localAddress}\\{db_name}'..."); + UpdateProgress("Updating Database", "Connecting to local database..."); LogManager.Log($"Connecting to local database at {localAddress}..."); DbManager db = DbManager.FromAddress(localAddress); LogManager.Log($"Ensuring {db_name} database exists on the local machine..."); if (!db.Exists(db_name)) { + UpdateProgress("Updating Database", "Creating new database..."); LogManager.Log("Database does not exist. Creating new database..."); db.Create(db_name); } @@ -203,6 +174,7 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log("Initializing database manager..."); db = DbManager.FromAddressAndName(localAddress, db_name); + UpdateProgress("Updating Database", "Clearing current database..."); LogManager.Log("Clearing database..."); db.ClearDb(); @@ -211,6 +183,8 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Initializing {nameof(ExaminerSequenceConfigurationRunner)}..."); + UpdateProgress("Updating Database", "Initializing provisioning sequence..."); + ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( Path.Combine(_newPackageTempFolder, "Provision Scripts", "config.xml"), Path.Combine(_newPackageTempFolder, "Provision Scripts"), @@ -238,34 +212,87 @@ namespace Tango.PPC.Common.MachineSetup runner.ScriptExecuting += (x, item) => { LogManager.Log($"Executing script {item.ToString()}..."); - - if (item.Type == ExaminerSequenceItemType.Data && item.RequiresSerialNumber) - { - CurrentStep = MachineSetupSteps.SynchronizingMachineConfiguration; - } - else if (item.Type == ExaminerSequenceItemType.Data) - { - CurrentStep = MachineSetupSteps.SynchronizingData; - } + UpdateProgress("Updating Database", item.Name + "..."); }; LogManager.Log("Starting synchronization process..."); try { - runner.Run().Wait(); + await runner.Run(); LogManager.Log("Synchronization completed successfully!"); + UpdateProgress("Updating Database", "Database synchronization completed successfully."); } catch (Exception ex) { throw LogManager.Log(ex, "Setup manager error while trying to synchronize database."); } - return new MachineSetupResult() + //Updating firmware + UpdateProgress("Updating Firmware", "Connecting to firmware device..."); + LogManager.Log(""); + LogManager.Log("-------------------------------------------------------------------------"); + LogManager.Log("Updating Firmware..."); + var op = await DefaultMachineProvider.CreateMinimalMachineOperator(); + + 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 MachineSetupResult() + { + UpdatePackagePath = _newPackageTempFolder, + }); + }; + handler.Canceled += (_, __) => { - UpdatePackagePath = _newPackageTempFolder, + 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) + { + LogManager.Log(ex, "An error occurred in machine setup."); + result.SetException(ex); + } + + return await result.Task; + } + + #endregion + + #region Protected Methods + + protected virtual void UpdateProgress(String name, String message = "", bool isIntermediate = true, double progress = 0, double total = 0) + { + InvokeUINow(() => + { + Status = new MachineSetupProgress() + { + Name = name, + Message = message, + IsIntermediate = isIntermediate, + Progress = progress, + Total = total, + }; + + Progress?.Invoke(this, Status); }); + + UIHelper.DoEvents(); } #endregion diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupProgress.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupProgress.cs new file mode 100644 index 000000000..bd279b05c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupProgress.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.MachineSetup +{ + public class MachineSetupProgress : EventArgs + { + public double Progress { get; set; } + public double Total { get; set; } + public bool IsIntermediate { get; set; } + public String Name { get; set; } + public String Message { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs index ad24ad62d..f9887ea38 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupResult.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Integration.Upgrade; namespace Tango.PPC.Common.MachineSetup { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs deleted file mode 100644 index ec1db4826..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupSteps.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.PPC.Common.MachineSetup -{ - /// <summary> - /// Represents the various <see cref="IMachineSetupManager"/> steps. - /// </summary> - public enum MachineSetupSteps - { - [Description("Downloading Package")] - DownloadingPackage, - [Description("Synchronizing Schema")] - SynchronizingSchema, - [Description("Synchronizing Data")] - SynchronizingData, - [Description("Configuring Machine")] - SynchronizingMachineConfiguration - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs index 21fce7261..08124154b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs @@ -9,10 +9,7 @@ namespace Tango.PPC.Common.MachineUpdate { public interface IMachineUpdateManager { - /// <summary> - /// Gets the current setup step. - /// </summary> - MachineUpdateSteps CurrentStep { get; } + MachineUpdateProgress Status { get; } /// <summary> /// Occurs when there is a text log message available. @@ -20,19 +17,9 @@ namespace Tango.PPC.Common.MachineUpdate event EventHandler<String> ProgressLog; /// <summary> - /// Gets the downloading packages step progress. - /// </summary> - double DownloadingPackagesProgress { get; } - - /// <summary> - /// Gets the downloading packages step status. - /// </summary> - String DownloadingPackagesStatus { get; } - - /// <summary> - /// Occurs when the <see cref="CurrentStep"/> has changed. + /// Occurs when the update has made some progress. /// </summary> - event EventHandler<MachineUpdateSteps> ProgressStep; + event EventHandler<MachineUpdateProgress> Progress; /// <summary> /// Performs a machine update using the specified serial number and machine service address. 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 5fcb7e209..4932d1e72 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -15,7 +15,9 @@ using Tango.Core.Helpers; using Tango.Core.IO; using Tango.PMR.Synchronization; using Tango.PPC.Common.Application; +using Tango.PPC.Common.Connection; using Tango.Settings; +using Tango.SharedUI.Helpers; using Tango.SQLExaminer; using Tango.Transport.Web; @@ -24,6 +26,7 @@ namespace Tango.PPC.Common.MachineUpdate public class MachineUpdateManager : ExtendedObject, IMachineUpdateManager { private IPPCApplicationManager _app_manager; + private IMachineProvider _machineProvider; #region Events @@ -33,51 +36,19 @@ namespace Tango.PPC.Common.MachineUpdate public event EventHandler<string> ProgressLog; /// <summary> - /// Occurs when the <see cref="CurrentStep" /> has changed. + /// Occurs when the update has made some progress. /// </summary> - public event EventHandler<MachineUpdateSteps> ProgressStep; + public event EventHandler<MachineUpdateProgress> Progress; #endregion #region Properties - private MachineUpdateSteps _currentStep; - /// <summary> - /// Gets the current setup step. - /// </summary> - public MachineUpdateSteps CurrentStep + private MachineUpdateProgress _status; + public MachineUpdateProgress Status { - get { return _currentStep; } - set - { - if (_currentStep != value) - { - _currentStep = value; - RaisePropertyChangedAuto(); - ProgressStep?.Invoke(this, _currentStep); - LogManager.Log("Machine Setup Manager Step: " + value.ToString()); - } - } - } - - private double _downloadProgress; - /// <summary> - /// Gets the downloading packages step progress. - /// </summary> - public double DownloadingPackagesProgress - { - get { return _downloadProgress; } - private set { _downloadProgress = value; RaisePropertyChangedAuto(); } - } - - private String _updatingPackagesStatus; - /// <summary> - /// Gets the downloading packages step status. - /// </summary> - public String DownloadingPackagesStatus - { - get { return _updatingPackagesStatus; } - set { _updatingPackagesStatus = value; RaisePropertyChangedAuto(); } + get { return _status; } + private set { _status = value; RaisePropertyChangedAuto(); } } #endregion @@ -88,8 +59,9 @@ namespace Tango.PPC.Common.MachineUpdate /// Initializes a new instance of the <see cref="MachineUpdateManager"/> class. /// </summary> /// <param name="applicationManager">The application manager.</param> - public MachineUpdateManager(IPPCApplicationManager applicationManager) + public MachineUpdateManager(IPPCApplicationManager applicationManager, IMachineProvider machineProvider) { + _machineProvider = machineProvider; _app_manager = applicationManager; } @@ -103,17 +75,16 @@ namespace Tango.PPC.Common.MachineUpdate /// <param name="serialNumber">The serial number.</param> /// <param name="machineServiceAddress">The machine service address.</param> /// <returns></returns> - public Task<MachineUpdateResult> Update(string serialNumber, string machineServiceAddress) + public async Task<MachineUpdateResult> Update(string serialNumber, string machineServiceAddress) { - return Task.Factory.StartNew<MachineUpdateResult>(() => - { + TaskCompletionSource<MachineUpdateResult> result = new TaskCompletionSource<MachineUpdateResult>(); + try + { LogManager.Log($"Starting machine update for serial number {serialNumber}..."); //Connect to machine service and get matching packages for this machine. - CurrentStep = MachineUpdateSteps.DownloadingPackage; - DownloadingPackagesProgress = 0; - DownloadingPackagesStatus = "Connecting to machine service..."; + UpdateProgress("Downloading software package", "Connecting to machine service..."); LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); @@ -124,7 +95,7 @@ namespace Tango.PPC.Common.MachineUpdate using (var http = new ProtoWebClient()) { - update_response = http.Post<DownloadUpdateRequest, DownloadUpdateResponse>(machineServiceAddress + "/api/Synchronization/MachineUpdate", request).Result; + update_response = await http.Post<DownloadUpdateRequest, DownloadUpdateResponse>(machineServiceAddress + "/api/Synchronization/MachineUpdate", request); } LogManager.Log($"Machine update response received: {Environment.NewLine}{update_response.ToJsonString()}"); @@ -140,19 +111,14 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Temporary package zip file created: {tempFile}."); - DownloadingPackagesStatus = "Downloading software package..."; - LogManager.Log("Downloading software package..."); long fileSize = 0; - DownloadingPackagesProgress = 0; + UpdateProgress("Downloading software package", "Downloading...", false); using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => { - InvokeUINow(() => - { - DownloadingPackagesProgress = ((double)current / (double)fileSize) * 100d; - }); + UpdateProgress("Downloading software package", "Downloading...", false, current, fileSize); })) { LogManager.Log($"Connecting to storage blob with address {update_response.BlobAddress}"); @@ -165,6 +131,8 @@ namespace Tango.PPC.Common.MachineUpdate blob.DownloadToStream(fs); } + UpdateProgress("Downloading software package", "Extracting package..."); + LogManager.Log("Extracting downloaded zip file..."); //Extract software package. ZipFile.ExtractToDirectory(tempFile, _newPackageTempFolder); @@ -176,7 +144,7 @@ namespace Tango.PPC.Common.MachineUpdate //Synchronize database - CurrentStep = MachineUpdateSteps.SynchronizingSchema; + UpdateProgress("Updating Database", "Initializing..."); String db_name = "Tango"; String localAddress = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource.Address; @@ -184,6 +152,7 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Synchronizing database '{remote_address}\\{db_name}' => '{localAddress}\\{db_name}'..."); + UpdateProgress("Updating Database", "Connecting to local database..."); LogManager.Log("Initializing database manager..."); DbManager db = DbManager.FromAddressAndName(localAddress, db_name); @@ -198,6 +167,8 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Initializing {nameof(ExaminerSequenceConfigurationRunner)}..."); + UpdateProgress("Updating Database", "Initializing provisioning sequence..."); + ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner( Path.Combine(_newPackageTempFolder, "Update Scripts", "config.xml"), Path.Combine(_newPackageTempFolder, "Update Scripts"), @@ -225,34 +196,64 @@ namespace Tango.PPC.Common.MachineUpdate runner.ScriptExecuting += (x, item) => { LogManager.Log($"Executing script {item.ToString()}..."); - - if (item.Type == ExaminerSequenceItemType.Data && item.RequiresSerialNumber) - { - CurrentStep = MachineUpdateSteps.SynchronizingMachineConfiguration; - } - else if (item.Type == ExaminerSequenceItemType.Data) - { - CurrentStep = MachineUpdateSteps.SynchronizingData; - } + UpdateProgress("Updating Database", item.Name + "..."); }; LogManager.Log("Starting synchronization process..."); try { - runner.Run().Wait(); + await runner.Run(); LogManager.Log("Synchronization completed successfully!"); + UpdateProgress("Updating Database", "Database synchronization completed successfully."); } catch (Exception ex) { throw LogManager.Log(ex, "Setup manager error while trying to synchronize database."); } - return new MachineUpdateResult() + //Updating firmware + UpdateProgress("Updating Firmware", "Connecting to firmware device..."); + LogManager.Log(""); + LogManager.Log("-------------------------------------------------------------------------"); + LogManager.Log("Updating Firmware..."); + var op = _machineProvider.MachineOperator; + + 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) => { - UpdatePackagePath = _newPackageTempFolder, + 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); + }; + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred in machine update."); + result.SetException(ex); + } + + return await result.Task; } /// <summary> @@ -485,7 +486,7 @@ namespace Tango.PPC.Common.MachineUpdate /// <returns></returns> public Task<UpdatePackageFile> GetUpdatePackageFileInfo(string filePath) { - return Task.Factory.StartNew<UpdatePackageFile>(() => + return Task.Factory.StartNew<UpdatePackageFile>(() => { UpdatePackageFile file = new UpdatePackageFile(); var tempFolder = TemporaryManager.CreateFolder(); @@ -506,5 +507,28 @@ namespace Tango.PPC.Common.MachineUpdate } #endregion + + #region Protected Methods + + protected virtual void UpdateProgress(String name, String message = "", bool isIntermediate = true, double progress = 0, double total = 0) + { + InvokeUINow(() => + { + Status = new MachineUpdateProgress() + { + Name = name, + Message = message, + IsIntermediate = isIntermediate, + Progress = progress, + Total = total, + }; + + Progress?.Invoke(this, Status); + }); + + UIHelper.DoEvents(); + } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateProgress.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateProgress.cs new file mode 100644 index 000000000..7cb53b83e --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateProgress.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.MachineUpdate +{ + public class MachineUpdateProgress : EventArgs + { + public double Progress { get; set; } + public double Total { get; set; } + public bool IsIntermediate { get; set; } + public String Name { get; set; } + public String Message { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateSteps.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateSteps.cs deleted file mode 100644 index 9c4e9e425..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateSteps.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.PPC.Common.MachineUpdate -{ - public enum MachineUpdateSteps - { - [Description("Downloading Package")] - DownloadingPackage, - [Description("Synchronizing Schema")] - SynchronizingSchema, - [Description("Synchronizing Data")] - SynchronizingData, - [Description("Updating Configuration")] - SynchronizingMachineConfiguration, - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 8fe107074..bb8d3d2c4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -133,13 +133,13 @@ <Compile Include="IPPCView.cs" /> <Compile Include="MachineSetup\IMachineSetupManager.cs" /> <Compile Include="MachineSetup\MachineSetupManager.cs" /> + <Compile Include="MachineSetup\MachineSetupProgress.cs" /> <Compile Include="MachineSetup\MachineSetupResult.cs" /> - <Compile Include="MachineSetup\MachineSetupSteps.cs" /> <Compile Include="MachineUpdate\DbCompareResult.cs" /> <Compile Include="MachineUpdate\IMachineUpdateManager.cs" /> + <Compile Include="MachineUpdate\MachineUpdateProgress.cs" /> <Compile Include="MachineUpdate\MachineUpdateManager.cs" /> <Compile Include="MachineUpdate\MachineUpdateResult.cs" /> - <Compile Include="MachineUpdate\MachineUpdateSteps.cs" /> <Compile Include="MachineUpdate\UpdatePackageFile.cs" /> <Compile Include="Messages\JobRemovedMessage.cs" /> <Compile Include="Messages\JobSavedMessage.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index c5dab127c..f8a0fdc36 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -63,11 +63,6 @@ namespace Tango.PPC.UI.PPCApplication public event EventHandler SetupRequired; /// <summary> - /// Occurs when firmware upgrade is required. - /// </summary> - public event EventHandler FirmwareUpgradeRequired; - - /// <summary> /// Occurs when the main window content has been rendered. /// </summary> public event EventHandler ContentRendered; @@ -164,7 +159,7 @@ namespace Tango.PPC.UI.PPCApplication if (App.StartupArgs.Contains("-update_ok")) { LogManager.Log("Application started with '-update_ok' startup arguments. The application has been successfully updated."); - settings.ApplicationState = ApplicationStates.FirmwareUpgrade; + settings.ApplicationState = ApplicationStates.Ready; settings.Save(); } @@ -191,16 +186,11 @@ namespace Tango.PPC.UI.PPCApplication { try { - if (settings.ApplicationState == ApplicationStates.PreSetup || settings.ApplicationState == ApplicationStates.SemiSetup) + if (settings.ApplicationState == ApplicationStates.PreSetup) { LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking setup required event!"); SetupRequired?.Invoke(this, new EventArgs()); } - else if (settings.ApplicationState == ApplicationStates.FirmwareUpgrade) - { - LogManager.Log($"The application is in {settings.ApplicationState} state. database initialization skipped. Invoking firmware upgrade required event!"); - FirmwareUpgradeRequired?.Invoke(this, new EventArgs()); - } else { PostDbInitialize(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs index dea9cdac4..1cde1fe1a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -79,7 +79,6 @@ namespace Tango.PPC.UI.ViewModels public FirmwareUpgradeViewVM(IPPCApplicationManager applicationManager, IFirmwareUpgrader firmwareUpgrader) { _firmwareUpgrader = firmwareUpgrader; - applicationManager.FirmwareUpgradeRequired += ApplicationManager_FirmwareUpgradeRequired; CompleteCommand = new RelayCommand(Complete); TryAgainCommand = new RelayCommand(TryAgain); } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 02cc4ba33..16b1c05bc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -138,8 +138,6 @@ namespace Tango.PPC.UI.ViewModels public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager) { MachineSetupManager = machineSetupManager; - //MachineSetupManager.ProgressLog += (x, msg) => AppendLog(msg); - MachineSetupManager.ProgressStep += (x, step) => AppendLog(Environment.NewLine + "-----------" + step.ToDescription().ToUpper() + "-----------" + Environment.NewLine); HostAddress = Settings.MachineServiceAddress; SerialNumber = ""; @@ -171,6 +169,7 @@ namespace Tango.PPC.UI.ViewModels } var logger = new SimpleStringLogger(); + logger.Categories.Remove(LogCategory.Debug); LogManager.RegisterLogger(logger); logger.LogReceived += Logger_LogReceived; @@ -275,11 +274,9 @@ namespace Tango.PPC.UI.ViewModels try { _setup_result = await MachineSetupManager.Setup(SerialNumber, HostAddress); - Settings.ApplicationState = ApplicationStates.SemiSetup; - Settings.Save(); State = MachineSetupStates.Completed; LogManager.Log("Machine setup completed."); - CompleteSetup(); + await NavigateTo(MachineSetupView.SetupCompletedView); } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 108752976..c201bf555 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -167,7 +167,7 @@ namespace Tango.PPC.UI.ViewModels { _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, Settings.MachineServiceAddress); LogManager.Log("Machine update completed."); - CompleteUpdate(); + await NavigateTo(MachineUpdateView.UpdateCompletedView); } catch (Exception ex) { @@ -178,14 +178,13 @@ namespace Tango.PPC.UI.ViewModels else { await NavigateTo(MachineUpdateView.UpdateDbProgressView); - LogManager.Log("Starting database update..."); try { await MachineUpdateManager.UpdateDB(_db_compare_result); LogManager.Log("Database update completed."); - await NavigateTo(MachineUpdateView.UpToDateView); + await NavigateTo(MachineUpdateView.UpdateCompletedView); } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml index 82b211d4e..864d4aac9 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/FirmwareUpgradeView.xaml @@ -18,7 +18,7 @@ <Image Source="/Images/machine-update-firmware.png" Stretch="None" /> </StackPanel> - <controls:NavigationControl x:Name="navigationControl" TransitionType="Slide" KeepElementsAttached="True" Margin="0 20 0 0" SelectedIndex="2"> + <controls:NavigationControl x:Name="navigationControl" TransitionType="Slide" KeepElementsAttached="True" Margin="0 20 0 0" SelectedIndex="0"> <Grid controls:NavigationControl.NavigationName="FirmwareProgressView"> <StackPanel HorizontalAlignment="Center" Margin="0 0 0 0"> <TextBlock TextAlignment="Center" LineHeight="40" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml index 4ac6dab92..829f284de 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineSetupView.xaml @@ -32,7 +32,7 @@ <controls:NavigationControl x:Name="navigationControl" TransitionType="Slide" KeepElementsAttached="True" Margin="0 20 0 0" SelectedIndex="0"> <Grid controls:NavigationControl.NavigationName="WelcomeView"> - <StackPanel HorizontalAlignment="Center" Margin="0 100 0 0"> + <StackPanel HorizontalAlignment="Center" Margin="0 20 0 0"> <TextBlock TextAlignment="Center" LineHeight="40" Margin="20 0" TextWrapping="Wrap" FontSize="{StaticResource TangoTitleFontSize}"> <Run>Welcome to the machine setup wizard!</Run> <Run>In the next steps the software will gather required information, perform tests and apply an initial configuration to this machine.</Run> @@ -93,24 +93,10 @@ <Run>Please wait while we're setting up this machine.</Run> <Run>Do not turn off this PC.</Run> </TextBlock> - - <touch:TouchBusyIndicator Width="100" Height="100" Margin="0 80 0 0"> - <touch:TouchBusyIndicator.Style> - <Style TargetType="touch:TouchBusyIndicator"> - <Setter Property="IsIndeterminate" Value="False"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding State}" Value="Working"> - <Setter Property="IsIndeterminate" Value="True"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </touch:TouchBusyIndicator.Style> - </touch:TouchBusyIndicator> - <touch:TouchStepProgressBar FontSize="12" Width="720" Height="50" Margin="0 100 0 0" ItemsSource="{Binding Source={x:Type setup:MachineSetupSteps},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding MachineSetupManager.CurrentStep}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" /> - - <StackPanel Margin="100 100 100 0" Visibility="{Binding MachineSetupManager.CurrentStep,Converter={StaticResource EnumToVisibilityConverter},ConverterParameter='DownloadingPackage'}"> - <TextBlock Text="{Binding MachineSetupManager.DownloadingPackagesStatus,Mode=OneWay}"></TextBlock> - <touch:TouchProgressBar Margin="0 10 0 0" Height="10" Maximum="100" Value="{Binding MachineSetupManager.DownloadingPackagesProgress,Mode=OneWay}" /> + <StackPanel Margin="0 200 0 0"> + <TextBlock Text="{Binding MachineSetupManager.Status.Name,FallbackValue='Download Software Package'}" HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}"></TextBlock> + <TextBlock HorizontalAlignment="Center" Text="{Binding MachineSetupManager.Status.Message,FallbackValue='Connecting to machine service...'}" Margin="0 40 0 0"></TextBlock> + <touch:TouchProgressBar Margin="50 10" Height="10" IsIndeterminate="{Binding MachineSetupManager.Status.IsIntermediate}" Maximum="{Binding MachineSetupManager.Status.Total}" Value="{Binding MachineSetupManager.Status.Progress,Mode=OneWay}" /> </StackPanel> </StackPanel> </Grid> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineUpdateView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineUpdateView.xaml index 06a330675..ac0b9e36c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineUpdateView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineUpdateView.xaml @@ -119,13 +119,11 @@ <StackPanel> <TextBlock HorizontalAlignment="Center" Margin="0 40 0 0" FontSize="{StaticResource TangoHeaderFontSize}">Updating your machine</TextBlock> <TextBlock Margin="0 10 0 0" TextAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}" Foreground="{StaticResource TangoGrayBrush}">Do not turn off the machine</TextBlock> - - <touch:TouchBusyIndicator Width="100" Height="100" Margin="0 80 0 0" IsIndeterminate="{Binding IsVisible}"></touch:TouchBusyIndicator> - <touch:TouchStepProgressBar FontSize="10" Width="720" Height="50" Margin="0 100 0 0" ItemsSource="{Binding Source={x:Type update:MachineUpdateSteps},Converter={StaticResource EnumToItemsSourceConverter}}" SelectedValue="{Binding MachineUpdateManager.CurrentStep}" SelectedValuePath="Value" DisplayMemberPath="DisplayName" /> - - <StackPanel Margin="100 100 100 0" Visibility="{Binding MachineUpdateManager.CurrentStep,Converter={StaticResource EnumToVisibilityConverter},ConverterParameter='DownloadingPackage'}"> - <TextBlock Text="{Binding MachineUpdateManager.DownloadingPackagesStatus,Mode=OneWay}"></TextBlock> - <touch:TouchProgressBar Margin="0 10 0 0" Height="10" Maximum="100" Value="{Binding MachineUpdateManager.DownloadingPackagesProgress,Mode=OneWay}" /> + + <StackPanel Margin="0 200 0 0"> + <TextBlock Text="{Binding MachineUpdateManager.Status.Name,FallbackValue='Download Software Package'}" HorizontalAlignment="Center" FontSize="{StaticResource TangoTitleFontSize}"></TextBlock> + <TextBlock HorizontalAlignment="Center" Text="{Binding MachineUpdateManager.Status.Message,FallbackValue='Connecting to machine service...'}" Margin="0 40 0 0"></TextBlock> + <touch:TouchProgressBar Margin="50 10" Height="10" IsIndeterminate="{Binding MachineUpdateManager.Status.IsIntermediate}" Maximum="{Binding MachineUpdateManager.Status.Total}" Value="{Binding MachineUpdateManager.Status.Progress,Mode=OneWay}" /> </StackPanel> </StackPanel> </Grid> |
