diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-12 17:47:21 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-12 17:47:21 +0300 |
| commit | d26e810aa206bf850622ded5a0da76293cb12f13 (patch) | |
| tree | 38d8bcca3690c70f46a330aa0ec75adc964e500d /Software | |
| parent | e1802508c00e0cede200d3914c5b6e4587cb6963 (diff) | |
| download | Tango-d26e810aa206bf850622ded5a0da76293cb12f13.tar.gz Tango-d26e810aa206bf850622ded5a0da76293cb12f13.zip | |
FSE TFP.
Diffstat (limited to 'Software')
14 files changed, 446 insertions, 23 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_download.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_download.png Binary files differnew file mode 100644 index 000000000..d536d4a73 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_download.png diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_ready.png b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_ready.png Binary files differnew file mode 100644 index 000000000..3d25a5bdd --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Images/tfp_ready.png diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Tango.FSE.Upgrade.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Tango.FSE.Upgrade.csproj index bae2811ac..daca836b7 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Tango.FSE.Upgrade.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Tango.FSE.Upgrade.csproj @@ -206,6 +206,10 @@ <ItemGroup> <Resource Include="Images\machine-update2.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\tfp_download.png" /> + <Resource Include="Images\tfp_ready.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets" Condition="Exists('..\..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeViewVM.cs index cfe2e212c..c120b3f74 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeViewVM.cs @@ -118,7 +118,7 @@ namespace Tango.FSE.Upgrade.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error retrieving tango versions."); - await NotificationProvider.ShowError($"Error retrieving Tango version.\n{ex.FlattenMessage()}"); + await NotificationProvider.ShowError($"Error retrieving Tango versions.\n{ex.FlattenMessage()}"); } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/FirmwareUpgradeViewVM.cs index 4eecaaeb0..0a2d0fdb3 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/FirmwareUpgradeViewVM.cs @@ -3,11 +3,147 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.FSE.Common; +using Tango.FSE.Common.RemoteUpgrade; namespace Tango.FSE.Upgrade.ViewModels { public class FirmwareUpgradeViewVM : FSEViewModel { + private List<TangoVersion> _tangoVersions; + public List<TangoVersion> TangoVersions + { + get { return _tangoVersions; } + set { _tangoVersions = value; RaisePropertyChangedAuto(); } + } + + private TangoVersion _selectedVersion; + public TangoVersion SelectedVersion + { + get { return _selectedVersion; } + set { _selectedVersion = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private String _tfpFileLocation; + public String TfpFileLocation + { + get { return _tfpFileLocation; } + set { _tfpFileLocation = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private String _existingTfpFileLocation; + public String ExistingTfpFileLocation + { + get { return _existingTfpFileLocation; } + set { _existingTfpFileLocation = value; RaisePropertyChangedAuto(); } + } + + private RemoteUpgradeHandler _handler; + public RemoteUpgradeHandler Handler + { + get { return _handler; } + set { _handler = value; RaisePropertyChangedAuto(); } + } + + private bool _useExistingTfpFile; + public bool UseExistingTfpFile + { + get { return _useExistingTfpFile; } + set { _useExistingTfpFile = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + public RelayCommand SelectTfpFileLocationCommand { get; set; } + + public RelayCommand SelectExistingTfpFileLocationCommand { get; set; } + + public RelayCommand GeneratePackageCommand { get; set; } + + public FirmwareUpgradeViewVM() + { + SelectTfpFileLocationCommand = new RelayCommand(SelectTfpFileLocation, () => SelectedVersion != null); + SelectExistingTfpFileLocationCommand = new RelayCommand(SelectExistingTfpFileLocation); + GeneratePackageCommand = new RelayCommand(GeneratePackage, () => SelectedVersion != null && (TfpFileLocation != null || (UseExistingTfpFile && ExistingTfpFileLocation != null))); + Handler = new RemoteUpgradeHandler(null) { Message = "Ready" }; + } + + public override void OnBeforeNavigatedTo() + { + base.OnBeforeNavigatedTo(); + + if (UseExistingTfpFile && !MachineProvider.IsConnected) + { + UseExistingTfpFile = false; + } + } + + private async void SelectTfpFileLocation() + { + String fileName = $"firmware_package_v{SelectedVersion.FirmwareVersion}.tfp"; + var result = await StorageProvider.SaveFile("Select firmware package location", "Tango Firmware Package|*.tfp", fileName, ".tfp"); + if (result) + { + TfpFileLocation = result.SelectedItem; + } + } + + private async void SelectExistingTfpFileLocation() + { + var result = await StorageProvider.OpenFile("Select existing firmware package file", "Tango Firmware Package|*.tfp"); + if (result) + { + ExistingTfpFileLocation = result.SelectedItem; + } + } + + public async override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + if (TangoVersions == null) + { + try + { + TangoVersions = (await Services.TangoVersionsService.GetAllTangoVersions()).Take(10).ToList(); + SelectedVersion = TangoVersions.FirstOrDefault(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error retrieving tango versions."); + await NotificationProvider.ShowError($"Error retrieving Tango versions.\n{ex.FlattenMessage()}"); + } + } + } + + private async void GeneratePackage() + { + if (UseExistingTfpFile) + { + //Navigate to the firmware completion with the existing tfp file. + } + else + { + try + { + IsFree = false; + Handler = await RemoteUpgradeManager.CreateTfpFile(SelectedVersion, TfpFileLocation); + await Handler.WaitForCompletion(); + } + catch (OperationCanceledException) + { + //Aborted... + } + catch (Exception ex) + { + LogManager.Log("Error generating remote firmware upgrade package."); + await NotificationProvider.ShowError($"Error occurred while trying to generate the firmware upgrade package.\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/WelcomeViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/WelcomeViewVM.cs index b6e719667..eebe39707 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/WelcomeViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/WelcomeViewVM.cs @@ -71,23 +71,23 @@ namespace Tango.FSE.Upgrade.ViewModels } } - private void StartUpgrade() + private async void StartUpgrade() { if (IsApplicationUpdate) { - NavigationManager.NavigateWithObject< - UpgradeModule, - ApplicationUpgradeView, - ApplicationUpgradeViewVM.NavigationObject> - (new ApplicationUpgradeViewVM.NavigationObject() - { - ApplicationUpgradeMode = IsUpdateConnectedMachine ? ApplicationUpgradeViewVM.ApplicationUpgradeMode.ConnectedMachine : ApplicationUpgradeViewVM.ApplicationUpgradeMode.OtherMachine, - SelectedMachine = IsUpdateConnectedMachine ? MachineProvider.Machine : SelectedMachine - }); + await NavigationManager.NavigateWithObject< + UpgradeModule, + ApplicationUpgradeView, + ApplicationUpgradeViewVM.NavigationObject> + (new ApplicationUpgradeViewVM.NavigationObject() + { + ApplicationUpgradeMode = IsUpdateConnectedMachine ? ApplicationUpgradeViewVM.ApplicationUpgradeMode.ConnectedMachine : ApplicationUpgradeViewVM.ApplicationUpgradeMode.OtherMachine, + SelectedMachine = IsUpdateConnectedMachine ? MachineProvider.Machine : SelectedMachine + }); } else { - //Navigate to firmware view. + await NavigationManager.NavigateTo<UpgradeModule>(nameof(FirmwareUpgradeView)); } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/FirmwareUpgradeView.xaml index 38c7dc296..b899b4e04 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/FirmwareUpgradeView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/FirmwareUpgradeView.xaml @@ -3,13 +3,139 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:controls="clr-namespace:Tango.FSE.Common.Controls;assembly=Tango.FSE.Common" xmlns:global="clr-namespace:Tango.FSE.Upgrade" + xmlns:autoComplete="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" xmlns:vm="clr-namespace:Tango.FSE.Upgrade.ViewModels" xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.FSE.Upgrade.Views" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:FirmwareUpgradeViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.FirmwareUpgradeViewVM}" Background="{StaticResource FSE_PrimaryBackgroundBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> - <Grid> - + d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:FirmwareUpgradeViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.FirmwareUpgradeViewVM}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> + + <UserControl.Resources> + <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}"> + <Setter Property="Foreground" Value="{StaticResource FSE_PrimaryForegroundBrush}"></Setter> + <Style.Triggers> + <Trigger Property="IsEnabled" Value="False"> + <Setter Property="Foreground" Value="{StaticResource FSE_GrayBrush}"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </UserControl.Resources> + + <Grid IsEnabled="{Binding IsFree}"> + <StackPanel> + <TextBlock FontSize="{StaticResource FSE_LargeFontSize}">Firmware Upgrade</TextBlock> + + <TextBlock Margin="0 10 0 0" Foreground="{StaticResource FSE_GrayBrush}" LineHeight="20" Visibility="{Binding ResolutionService.IsHighResolution,Converter={StaticResource BooleanToVisibilityConverter}}"> + <Run>You chose to perform a machine firmware upgrade.</Run> + <LineBreak/> + <Run>The upgrade is done by downloading the specified Tango system version below and composing a .tfp file (Tango Firmware Package).</Run> + </TextBlock> + + <TextBlock Margin="0 20 0 0" Foreground="{StaticResource FSE_GrayBrush}" LineHeight="20"> + <Run>Once the .tfp file has been generated, you will be able to store that file on a removable storage which can be later inserted into a machine.</Run> + <LineBreak/> + <Run>In case you chose to upgrade the currently connected machine, you will be able to perform the upgrade remotely.</Run> + </TextBlock> + + <StackPanel Margin="0 20 0 0"> + <RadioButton x:Name="chkDownload" VerticalContentAlignment="Center" Cursor="Hand" Padding="30 0 0 0" IsChecked="{Binding UseExistingTfpFile,Converter={StaticResource BooleanInverseConverter},Mode=TwoWay}"> + <DockPanel> + <Image Source="../Images/tfp_download.png" Width="48" Height="48" /> + <TextBlock Margin="20 0 0 0" VerticalAlignment="Center">I want download and create a .tfp file from an existing version.</TextBlock> + </DockPanel> + </RadioButton> + + <DockPanel Margin="80 10 0 0" IsEnabled="{Binding ElementName=chkDownload,Path=IsChecked}" Width="800" HorizontalAlignment="Left"> + + <StackPanel Width="300"> + <TextBlock>Select the desired firmware version</TextBlock> + <ComboBox Margin="0 5 0 0" HorizontalContentAlignment="Stretch" FontSize="{StaticResource FSE_SmallFontSize}" material:ComboBoxAssist.ClassicMode="True" material:ComboBoxAssist.ShowSelectedItem="False" ItemsSource="{Binding TangoVersions}" SelectedItem="{Binding SelectedVersion}" Foreground="{StaticResource FSE_PrimaryAccentBrush}"> + <ComboBox.ItemTemplate> + <DataTemplate> + <DockPanel> + <TextBlock DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10 0 0 -4" Foreground="{StaticResource FSE_GrayBrush}" FontSize="{StaticResource FSE_SmallFontSize}"> + <Run>(</Run><Run Text="{Binding LastUpdated,Converter={StaticResource DateTimeUTCToShortDateConverter}}"></Run><Run>)</Run> + </TextBlock> + <StackPanel> + <TextBlock Margin="0 5 0 0"> + <Run Foreground="{StaticResource FSE_GrayBrush}">Firmware:</Run> + <Run>v</Run><Run Text="{Binding FirmwareVersion}"></Run> + </TextBlock> + </StackPanel> + </DockPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> + </StackPanel> + + <StackPanel Margin="0 0 0 0" Width="380"> + <TextBlock>Select where to save the firmware package (.tfp file)</TextBlock> + + <DockPanel Margin="0 5 0 0"> + <controls:IconButton ToolTip="Browse for .tfp file location" Margin="5 0 0 0" DockPanel.Dock="Right" Icon="FolderOpenOutline" Width="38" Height="38" Command="{Binding SelectTfpFileLocationCommand}" /> + <TextBox Height="25" FontSize="{StaticResource FSE_SmallFontSize}" Foreground="{StaticResource FSE_PrimaryAccentBrush}" IsReadOnly="True" Text="{Binding TfpFileLocation}" FlowDirection="RightToLeft"></TextBox> + </DockPanel> + </StackPanel> + </DockPanel> + + <RadioButton x:Name="chkExisting" IsEnabled="{Binding MachineProvider.IsConnected}" IsChecked="{Binding ElementName=chkDownload,Path=IsChecked,Converter={StaticResource BooleanInverseConverter},Mode=TwoWay}" Margin="0 20 0 0" VerticalContentAlignment="Center" Cursor="Hand" Padding="25 0 0 0"> + <DockPanel> + <Image Source="../Images/tfp_ready.png" Width="48" Height="48" /> + <TextBlock Margin="20 0 0 0" VerticalAlignment="Center">I already have the .tfp file and just want to upgrade the currently connected machine. (requires an active machine connection)</TextBlock> + </DockPanel> + </RadioButton> + + <StackPanel IsEnabled="{Binding ElementName=chkExisting,Path=IsChecked}" Margin="80 10 0 0" Width="380" HorizontalAlignment="Left"> + <TextBlock>Select an existing .tfp file on your computer</TextBlock> + + <DockPanel Margin="0 0 0 0"> + <controls:IconButton ToolTip="Browse for .tfp file" Margin="5 0 0 0" DockPanel.Dock="Right" Icon="FolderOpenOutline" Width="38" Height="38" Command="{Binding SelectExistingTfpFileLocationCommand}" /> + <TextBox FontSize="{StaticResource FSE_SmallFontSize}" Foreground="{StaticResource FSE_PrimaryAccentBrush}" IsReadOnly="True" Text="{Binding ExistingTfpFileLocation,Converter={StaticResource FilePathToFileNameConverter}}" VerticalContentAlignment="Bottom"></TextBox> + </DockPanel> + </StackPanel> + </StackPanel> + + <StackPanel HorizontalAlignment="Left" Width="1000"> + <StackPanel.Style> + <Style TargetType="StackPanel"> + <Setter Property="Margin" Value="0 80 0 0"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding ResolutionService.IsLowResolution}" Value="True"> + <Setter Property="Margin" Value="0 -5 0 0"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </StackPanel.Style> + + <DockPanel> + <Button Command="{Binding GeneratePackageCommand}" DockPanel.Dock="Right" HorizontalAlignment="Right" Width="250" Height="50" Style="{StaticResource FSE_RaisedButton_Dark_Hover}"> + <StackPanel Orientation="Horizontal"> + <material:PackIcon Width="32" Height="28" Kind="ClockFast" /> + <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" FontSize="{StaticResource FSE_LargeFontSize}"> + <TextBlock.Style> + <Style TargetType="TextBlock"> + <Setter Property="Text" Value="GENERATE PACKAGE"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding UseExistingTfpFile}" Value="True"> + <Setter Property="Text" Value="UPGRADE NOW"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBlock.Style> + </TextBlock> + </StackPanel> + </Button> + + <StackPanel VerticalAlignment="Bottom" Margin="0 0 40 0"> + <TextBlock Text="{Binding Handler.Message}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"></TextBlock> + <ProgressBar Margin="0 5 0 0" Minimum="0" Maximum="{Binding Handler.Maximum}" Value="{Binding Handler.Progress}" IsIndeterminate="{Binding Handler.IsIndeterminate}"></ProgressBar> + </StackPanel> + </DockPanel> + + <Rectangle StrokeThickness="1" Stroke="{StaticResource FSE_GrayBrush}" StrokeDashArray="4" Margin="0 10 0 0"></Rectangle> + </StackPanel> + </StackPanel> </Grid> </UserControl> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs index 98378585f..20bc9b3db 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs @@ -14,17 +14,25 @@ namespace Tango.FSE.Common.RemoteUpgrade /// Creates a Tango Update Package for the current connected machine. /// </summary> /// <param name="tangoVersion">The tango version.</param> - /// <param name="filePath">The file path.</param> + /// <param name="targetFilePath">The file path.</param> /// <returns></returns> - Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, String filePath); + Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, String targetFilePath); /// <summary> /// Creates a Tango Update Package for specified machine. /// </summary> /// <param name="tangoVersion">The tango version.</param> /// <param name="serialNumber">The machine serial number.</param> - /// <param name="filePath">The file path.</param> + /// <param name="targetFilePath">The file path.</param> /// <returns></returns> - Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, String serialNumber, String filePath); + Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, String serialNumber, String targetFilePath); + + /// <summary> + /// Creates a firmware upgrade package file. + /// </summary> + /// <param name="tangoVersion">The tango version.</param> + /// <param name="targetFilePath">The file path.</param> + /// <returns></returns> + Task<RemoteUpgradeHandler> CreateTfpFile(TangoVersion tangoVersion, String targetFilePath); } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Converters.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Converters.xaml index 19bf643c4..8c36100c1 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Converters.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Resources/Converters.xaml @@ -34,4 +34,5 @@ <converters:TimeSpanToSecondsConverter x:Key="TimeSpanToSecondsConverter" /> <converters:StringToTitleCaseConverter x:Key="StringToTitleCaseConverter" /> <converters:StringToOneLineConverter x:Key="StringToOneLineConverter" /> + <converters:FilePathToFileNameConverter x:Key="FilePathToFileNameConverter" /> </ResourceDictionary>
\ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs index 13ea597e1..83cf6ecf7 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs @@ -57,9 +57,9 @@ namespace Tango.FSE.UI.RemoteUpgrade /// Creates a Tango Update Package for the current connected machine. /// </summary> /// <param name="tangoVersion">The tango version.</param> - /// <param name="filePath">The file path.</param> + /// <param name="targetFilePath">The file path.</param> /// <returns></returns> - public Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, string filePath) + public Task<RemoteUpgradeHandler> CreateTupFile(TangoVersion tangoVersion, string targetFilePath) { if (MachineProvider.Machine == null) { @@ -323,5 +323,70 @@ namespace Tango.FSE.UI.RemoteUpgrade return Task.FromResult(handler); } + + /// <summary> + /// Creates a firmware upgrade package file. + /// </summary> + /// <param name="tangoVersion">The tango version.</param> + /// <param name="targetFilePath">The file path.</param> + /// <returns></returns> + public Task<RemoteUpgradeHandler> CreateTfpFile(TangoVersion tangoVersion, string targetFilePath) + { + RemoteUpgradeHandler handler = new RemoteUpgradeHandler(() => { }); //Abort Action ? + + ThreadFactory.StartNew(() => + { + Thread.Sleep(100); + + LogManager.Log("Generating tfp file..."); + LogManager.Log($"Tfp file: '{targetFilePath}.'"); + + try + { + LogManager.Log("Initializing..."); + handler.UpdateProgress("Initializing..."); + + handler.UpdateProgress($"Downloading firmware version '{tangoVersion.FirmwareVersion}'..."); + + LogManager.Log("Connecting to machine service..."); + + LogManager.Log("Requesting version download from machine service..."); + var response = WebClient.DownloadTangoVersion(new DownloadTangoVersionRequest() { TangoVersionGuid = tangoVersion.Guid }).Result; + + LogManager.Log($"Machine service response:\n{response.ToJsonString()}"); + + using (StorageBlobStream blobZipStream = new StorageBlobStream(response.BlobAddress)) + { + using (ZipFile zip = ZipFile.Read(blobZipStream.OpenRead())) + { + var tfpEntry = zip.Entries.SingleOrDefault(x => x.FileName == "firmware_package.tfp"); + + using (FileStream targetStream = new FileStream(targetFilePath, FileMode.Create)) + { + tfpEntry.Extract(targetStream); + } + } + } + + handler.UpdateProgress("Completed", false, 100, 100); + LogManager.Log("TFP file generation completed successfully."); + + handler.RaiseCompleted(); + } + catch (Exception ex) + { + LogManager.Log(ex, "TFP file generation failed."); + handler.UpdateProgress("Failed", false, 0, 100); + handler.RaiseFailed(ex); + } + finally + { + //Nothing right now.. + } + + }); + + return Task.FromResult(handler); + } } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Converters/FilePathToFileNameConverter.cs b/Software/Visual_Studio/Tango.SharedUI/Converters/FilePathToFileNameConverter.cs new file mode 100644 index 000000000..7c59f8de7 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Converters/FilePathToFileNameConverter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.SharedUI.Converters +{ + public class FilePathToFileNameConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + try + { + if (value != null) + { + return Path.GetFileName(value.ToString()); + } + } + catch + { + return value; + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index a649d0c1a..63bc3f833 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -112,6 +112,7 @@ <Compile Include="Converters\EnumToItemsSourceConverter.cs" /> <Compile Include="Converters\EnumToVisibilityConverter.cs" /> <Compile Include="Converters\EnumToXamlVectorConverter.cs" /> + <Compile Include="Converters\FilePathToFileNameConverter.cs" /> <Compile Include="Converters\IsEqualConverter.cs" /> <Compile Include="Converters\IsNotConverter.cs" /> <Compile Include="Converters\IsNullToVisibilityConverter.cs" /> @@ -256,7 +257,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index f83384097..8ed8c0345 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -151,6 +151,7 @@ <Compile Include="Web\IWebResponseMessage.cs" /> <Compile Include="Web\IWebTransportMessage.cs" /> <Compile Include="Web\StandardFileDownloader.cs" /> + <Compile Include="Web\StorageBlobStream.cs" /> <Compile Include="Web\TokenExpiredException.cs" /> <Compile Include="Web\StorageBlobDownloader.cs" /> <Compile Include="Web\WebFileDownloaderProgressEventArgs.cs" /> @@ -186,7 +187,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobStream.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobStream.cs new file mode 100644 index 000000000..f4cbf7f62 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobStream.cs @@ -0,0 +1,45 @@ +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class StorageBlobStream : IDisposable + { + public CloudBlockBlob Blob { get; private set; } + private Stream _blobStream; + + public String Address { get; private set; } + + private StorageBlobStream(CloudBlockBlob blob) + { + Blob = blob; + } + + public StorageBlobStream(String blobAddress) : this(new CloudBlockBlob(new Uri(blobAddress))) + { + Address = blobAddress; + } + + public Stream OpenRead() + { + _blobStream = Blob.OpenRead(); + return _blobStream; + } + + public Stream OpenWrite() + { + _blobStream = Blob.OpenWrite(); + return _blobStream; + } + + public void Dispose() + { + _blobStream?.Dispose(); + } + } +} |
