From dd724f118f584eea84a11af90292a88c62ecd022 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 29 Nov 2018 18:59:41 +0200 Subject: Working on Firmware upgrade ! --- .../FirmwareUpgrade/DefaultFirmwareUpgrader.cs | 56 ++++++++++++ .../Images/firmware_upgrade.png | Bin 0 -> 52803 bytes .../Tango.MachineStudio.UI.csproj | 12 ++- .../Tango.MachineStudio.UI/ViewModelLocator.cs | 4 + .../ViewModels/FirmwareUpgradeViewVM.cs | 100 +++++++++++++++++++++ .../Views/FirmwareUpgradeView.xaml | 88 ++++++++++++++++++ .../Views/FirmwareUpgradeView.xaml.cs | 28 ++++++ 7 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/FirmwareUpgrade/DefaultFirmwareUpgrader.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/firmware_upgrade.png create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/FirmwareUpgrade/DefaultFirmwareUpgrader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/FirmwareUpgrade/DefaultFirmwareUpgrader.cs new file mode 100644 index 000000000..5568c82ac --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/FirmwareUpgrade/DefaultFirmwareUpgrader.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.MachineStudio.Common.FirmwareUpgrade; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.UI.ViewModels; +using Tango.MachineStudio.UI.Views; + +namespace Tango.MachineStudio.UI.FirmwareUpgrade +{ + /// + /// Default firmware upgrade manager. + /// + /// + public class DefaultFirmwareUpgrader : IFirmwareUpgrader + { + private IStudioApplicationManager _applicationManager; + private INotificationProvider _notification; + + /// + /// Initializes a new instance of the class. + /// + public DefaultFirmwareUpgrader(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) + { + _applicationManager = applicationManager; + _notification = notificationProvider; + } + + /// + /// Performs a firmware upgrade. + /// + /// The TFP stream. + public Task PerformUpgrade(Stream tfpStream) + { + return _applicationManager.ConnectedMachine.UpgradeFirmware(tfpStream); + } + + /// + /// Invokes the upgrade dialog. + /// + public void InvokeUpgradeUI() + { + FirmwareUpgradeViewVM vm = new FirmwareUpgradeViewVM(_applicationManager.ConnectedMachine); + + _notification.ShowModalDialog(vm, (x) => + { + + }, () => { }); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/firmware_upgrade.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/firmware_upgrade.png new file mode 100644 index 000000000..fc0799143 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/firmware_upgrade.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 6e37a97a2..a9a0e1bb9 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -142,6 +142,7 @@ ConsoleWindow.xaml + HtmlWindow.xaml @@ -172,6 +173,7 @@ + @@ -193,6 +195,9 @@ ConnectionLostView.xaml + + FirmwareUpgradeView.xaml + LoadingView.xaml @@ -277,6 +282,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -505,6 +514,7 @@ + ChangeLog.txt @@ -599,7 +609,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\Microsoft.WITDataStore32.dll" "$(Ta - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index 8bb33d007..cac4ee0c0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -6,6 +6,7 @@ using Tango.Logging; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.EventLogging; +using Tango.MachineStudio.Common.FirmwareUpgrade; using Tango.MachineStudio.Common.Html; using Tango.MachineStudio.Common.JobRunsLogging; using Tango.MachineStudio.Common.Modules; @@ -17,6 +18,7 @@ using Tango.MachineStudio.Common.Threading; using Tango.MachineStudio.Common.Video; using Tango.MachineStudio.UI.Authentication; using Tango.MachineStudio.UI.Console; +using Tango.MachineStudio.UI.FirmwareUpgrade; using Tango.MachineStudio.UI.Html; using Tango.MachineStudio.UI.Modules; using Tango.MachineStudio.UI.Navigation; @@ -70,6 +72,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -85,6 +88,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs new file mode 100644 index 000000000..ce8b09aa4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -0,0 +1,100 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Integration.Operation; +using Tango.SharedUI; + +namespace Tango.MachineStudio.UI.ViewModels +{ + public class FirmwareUpgradeViewVM : DialogViewVM + { + private IMachineOperator _operator; + private FileStream _stream; + + private FirmwareUpgradeHandler _handler; + public FirmwareUpgradeHandler Handler + { + get { return _handler; } + set { _handler = value; RaisePropertyChangedAuto(); } + } + + private String _selectedFile; + public String SelectedFile + { + get { return _selectedFile; } + set { _selectedFile = value; RaisePropertyChangedAuto(); } + } + + private int _currentPage; + public int CurrentPage + { + get { return _currentPage; } + set { _currentPage = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand SelectCommand { get; set; } + + public RelayCommand UpgradeCommand { get; set; } + + public RelayCommand AbortCommand { get; set; } + + public FirmwareUpgradeViewVM(IMachineOperator machineOperator) : base() + { + _operator = machineOperator; + SelectCommand = new RelayCommand(BrowseForFile); + UpgradeCommand = new RelayCommand(StartUpgrade, () => SelectedFile != null); + AbortCommand = new RelayCommand(AbortUpgrade, () => Handler != null && Handler.Status != FirmwareUpgradeStatus.Validating && Handler.Status != FirmwareUpgradeStatus.Activating); + } + + private void BrowseForFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select tango firmware package file"; + dlg.Filter = "Tango Firmware Package|*.tfp"; + if (dlg.ShowDialog().Value) + { + SelectedFile = dlg.FileName; + InvalidateRelayCommands(); + } + } + + private async void StartUpgrade() + { + CurrentPage = 1; + + _stream = new FileStream(SelectedFile, FileMode.Open); + Handler = await _operator.UpgradeFirmware(_stream); + Handler.Progress += (_, e) => + { + InvokeUI(() => + { + AbortCommand.RaiseCanExecuteChanged(); + }); + }; + Handler.Completed += (_, __) => + { + _stream.Dispose(); + CurrentPage = 2; + }; + Handler.Canceled += (_, __) => + { + _stream.Dispose(); + }; + Handler.Failed += (_, __) => + { + _stream.Dispose(); + }; + + } + + private async void AbortUpgrade() + { + await Handler.Cancel(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml new file mode 100644 index 000000000..b69ad6a5b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + FIRMWARE UPGRADE + + + + + + + + + + + + + + + + + The upgrade wizard will help you upgrade the connected machine firmware version. + + Press 'SELECT' to browse for a .tfp file (Tango Firmware Package). + + + + + + + + + + + + + + + + Upgrading Machine Firmware + + + + + + + + + Firmware Upgrade Completed + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml.cs new file mode 100644 index 000000000..17220e615 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.UI.Views +{ + /// + /// Interaction logic for FirmwareUpgradeView.xaml + /// + public partial class FirmwareUpgradeView : UserControl + { + public FirmwareUpgradeView() + { + InitializeComponent(); + } + } +} -- cgit v1.3.1