From d278567561229b18bd68b4e02f8f841fc21ce3f1 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 6 Oct 2024 00:59:30 +0300 Subject: Added support for azure utils X4 firmware injection. --- .../ViewModels/EnvironmentFirmwareUpgradeViewVM.cs | 22 +++++++++- .../Views/EnvironmentFirmwareUpgradeView.xaml | 12 +++++- .../Tango.AzureUtils/Firmware/FirmwareManager.cs | 29 +++++++++---- .../Tango.AzureUtils/Storage/StorageManager.cs | 49 +++++++++++++++++----- 4 files changed, 92 insertions(+), 20 deletions(-) (limited to 'Software/Visual_Studio/Azure') diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentFirmwareUpgradeViewVM.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentFirmwareUpgradeViewVM.cs index 931182c90..743561e8b 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentFirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/ViewModels/EnvironmentFirmwareUpgradeViewVM.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows; using Tango.AzureUtils.Environment; using Tango.AzureUtils.Firmware; +using Tango.BL.Enumerations; using Tango.Core.Commands; namespace Tango.AzureUtils.UI.ViewModels @@ -32,6 +33,21 @@ namespace Tango.AzureUtils.UI.ViewModels set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); } } + private List _machineTypes; + public List MachineTypes + { + get { return _machineTypes; } + set { _machineTypes = value; RaisePropertyChangedAuto(); } + } + + private MachineTypes _selectedMachineType; + public MachineTypes SelectedMachineType + { + get { return _selectedMachineType; } + set { _selectedMachineType = value; RaisePropertyChangedAuto(); } + } + + private String _filePath; public String FilePath { @@ -53,6 +69,8 @@ namespace Tango.AzureUtils.UI.ViewModels { UpgradeFirmwareCommand = new RelayCommand(UpgradeFirmware, () => FilePath != null); BrowseFileCommand = new RelayCommand(BrowseFile); + + MachineTypes = Enum.GetValues(typeof(MachineTypes)).Cast().ToList(); } public override void OnAuthenticated(IAzure azure, List apps) @@ -68,7 +86,7 @@ namespace Tango.AzureUtils.UI.ViewModels private async void BrowseFile() { OpenFileDialog dlg = new OpenFileDialog(); - dlg.Title = "Select Tango Firmware Package"; + dlg.Title = "Select Firmware Package"; dlg.Filter = "Tango Firmware Package Files|*.tfp"; if (dlg.ShowDialog().Value) { @@ -93,7 +111,7 @@ namespace Tango.AzureUtils.UI.ViewModels IsFree = false; - await _firmwareManager.InjectFirmwarePackage(SelectedDeploymentSlot, FilePath, null); + await _firmwareManager.InjectFirmwarePackage(SelectedDeploymentSlot, SelectedMachineType, FilePath, null); } catch (Exception ex) { diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentFirmwareUpgradeView.xaml b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentFirmwareUpgradeView.xaml index 330d6b3a4..0e7ffc7a0 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentFirmwareUpgradeView.xaml +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils.UI/Views/EnvironmentFirmwareUpgradeView.xaml @@ -31,7 +31,17 @@ - + + + + Select Machine Type + + + + + + + Browse for .tfp file and press upgrade. diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Firmware/FirmwareManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Firmware/FirmwareManager.cs index ac8e52a65..6ab2c4544 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Firmware/FirmwareManager.cs +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Firmware/FirmwareManager.cs @@ -12,6 +12,8 @@ using Microsoft.Azure.Management.Fluent; using Tango.AzureUtils.Database; using Tango.AzureUtils.Storage; using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.PMR.FirmwareUpgrade; using Tango.PPC.Common.Publish; @@ -30,7 +32,7 @@ namespace Tango.AzureUtils.Firmware #region Firmware Injection - public async Task InjectFirmwarePackage(IWebAppBase slot, String tfpFile, String versionTag) + public async Task InjectFirmwarePackage(IWebAppBase slot, MachineTypes machineType, String tfpFile, String versionTag) { OnProgress(AzureUtilsStage.Firmware, $"Validating TFP package..."); @@ -46,11 +48,24 @@ namespace Tango.AzureUtils.Firmware throw new ValidationException($"The specified TFP package is invalid.\n{ex.FlattenMessage()}"); } - var ppcVersion = await _databaseManager.GetLatestPPCVersion(slot, null); + TangoVersion version = null; - if (Version.Parse(ppcVersion.FirmwareVersion) >= tfpPackage.GetMcuVersion()) + if (machineType == MachineTypes.TS1800) { - await RequestConfirmation($"The specified firmware version is '{tfpPackage.GetMcuVersion()}' while latest version is '{ppcVersion.FirmwareVersion}'. Do you wish to continue?"); + version = await _databaseManager.GetLatestPPCVersion(slot, null); + } + else if (machineType == MachineTypes.Eureka) + { + version = await _databaseManager.GetLatestEurekaVersion(slot, null); + } + else + { + throw new NotImplementedException("Machine type not supported for this action."); + } + + if (Version.Parse(version.FirmwareVersion) >= tfpPackage.GetMcuVersion()) + { + await RequestConfirmation($"The specified firmware version is '{tfpPackage.GetMcuVersion()}' while latest version is '{version.FirmwareVersion}'. Do you wish to continue?"); } OnProgress(AzureUtilsStage.Firmware, $"Retrieving '{slot.Name}' settings..."); @@ -60,7 +75,7 @@ namespace Tango.AzureUtils.Firmware var zipFile = TemporaryManager.CreateImaginaryFile(".zip"); - await _storageManager.DownloadLatestPPCVersion(slot, zipFile, versionTag); + await _storageManager.DownloadLatestVersion(slot, machineType, zipFile, versionTag); OnProgress(AzureUtilsStage.Firmware, $"Replacing firmware_package.tfp..."); await Task.Factory.StartNew(() => @@ -84,12 +99,12 @@ namespace Tango.AzureUtils.Firmware } }); - await _storageManager.ReplaceLatestPPCVersion(slot, zipFile, versionTag); + await _storageManager.ReplaceLatestPPCVersion(slot, machineType, zipFile, versionTag); OnProgress(AzureUtilsStage.Firmware, $"Updating firmware version on database..."); using (ObservablesContext db = ObservablesContext.CreateDefault(settings.ToDataSource())) { - var v = await db.TangoVersions.SingleOrDefaultAsync(x => x.Guid == ppcVersion.Guid); + var v = await db.TangoVersions.SingleOrDefaultAsync(x => x.Guid == version.Guid); v.FirmwareVersion = tfpPackage.GetMcuVersion().ToString(); await db.SaveChangesAsync(); } diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs index d16a3f90b..cb442b6b4 100644 --- a/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/Storage/StorageManager.cs @@ -10,6 +10,7 @@ using Microsoft.Azure.Management.Fluent; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; using Tango.AzureUtils.Database; +using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.IO; @@ -355,54 +356,82 @@ namespace Tango.AzureUtils.Storage } } - public async Task DownloadLatestPPCVersion(IWebAppBase app, String filePath, String versionTag) + public async Task DownloadLatestVersion(IWebAppBase app, MachineTypes machineType, String filePath, String versionTag) { OnProgress(AzureUtilsStage.Storage, $"Retrieving source and target settings..."); var settings = await app.GetMachineServiceSettingsAsync(); - var ppcVersion = await _databaseManager.GetLatestPPCVersion(app, versionTag); - OnProgress(AzureUtilsStage.Storage, $"Downloading PPC version '{ppcVersion.Version}'..."); + TangoVersion version = null; + + if (machineType == MachineTypes.TS1800) + { + version = await _databaseManager.GetLatestPPCVersion(app, versionTag); + } + else if (machineType == MachineTypes.Eureka) + { + version = await _databaseManager.GetLatestEurekaVersion(app, versionTag); + } + else + { + throw new NotImplementedException("Machine type not supported for this action."); + } + + OnProgress(AzureUtilsStage.Storage, $"Downloading {machineType.ToDescription()} version '{version.Version}'..."); var account = CloudStorageAccount.Parse(settings.STORAGE_ACCOUNT); var client = account.CreateCloudBlobClient(); var container = client.GetContainerReference(settings.TANGO_VERSIONS_CONTAINER); - var blob = container.GetBlockBlobReference(ppcVersion.BlobName); + var blob = container.GetBlockBlobReference(version.BlobName); await blob.FetchAttributesAsync(); var length = blob.Properties.Length; using (FileStreamWrapper st = new FileStreamWrapper(filePath, FileMode.Create, (progress) => { - OnProgress(AzureUtilsStage.Storage, $"Downloading PPC version '{ppcVersion.VersionAndTag}'...", progress, length, false); + OnProgress(AzureUtilsStage.Storage, $"Downloading {machineType.ToDescription()} version '{version.VersionAndTag}'...", progress, length, false); })) { await blob.DownloadToStreamAsync(st); } } - public async Task ReplaceLatestPPCVersion(IWebAppBase app, String filePath, String versionTag) + public async Task ReplaceLatestPPCVersion(IWebAppBase app, MachineTypes machineType, String filePath, String versionTag) { OnProgress(AzureUtilsStage.Storage, $"Retrieving source and target settings..."); var settings = await app.GetMachineServiceSettingsAsync(); - var ppcVersion = await _databaseManager.GetLatestPPCVersion(app, versionTag); - OnProgress(AzureUtilsStage.Storage, $"Uploading PPC version '{ppcVersion.VersionAndTag}'..."); + TangoVersion version = null; + + if (machineType == MachineTypes.TS1800) + { + version = await _databaseManager.GetLatestPPCVersion(app, versionTag); + } + else if (machineType == MachineTypes.Eureka) + { + version = await _databaseManager.GetLatestEurekaVersion(app, versionTag); + } + else + { + throw new NotImplementedException("Machine type not supported for this action."); + } + + OnProgress(AzureUtilsStage.Storage, $"Uploading {machineType.ToDescription()} version '{version.VersionAndTag}'..."); var account = CloudStorageAccount.Parse(settings.STORAGE_ACCOUNT); var client = account.CreateCloudBlobClient(); var container = client.GetContainerReference(settings.TANGO_VERSIONS_CONTAINER); - var blob = container.GetBlockBlobReference(ppcVersion.BlobName); + var blob = container.GetBlockBlobReference(version.BlobName); FileStreamWrapper st = null; using (st = new FileStreamWrapper(filePath, FileMode.Open, (progress) => { - OnProgress(AzureUtilsStage.Storage, $"Uploading PPC version '{ppcVersion.Version}'...", progress, st.Length, false); + OnProgress(AzureUtilsStage.Storage, $"Uploading {machineType.ToDescription()} version '{version.Version}'...", progress, st.Length, false); })) { await blob.UploadFromStreamAsync(st); -- cgit v1.3.1