From 8e875c7d05720f92ead97b75f3367555a5153dff Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Tue, 24 Dec 2019 13:49:20 +0200 Subject: Implementing the new Machine Studio ActionLogs module. Related Work Items: #2213 --- .../Tango.MachineStudio.ActionLogs/App.xaml | 12 ++ .../Tango.MachineStudio.ActionLogs.csproj | 4 + .../ViewModels/MainViewVM.cs | 75 +++++-- .../Views/MainView.xaml | 215 ++++++++++++++------- 4 files changed, 225 insertions(+), 81 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/App.xaml (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/App.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/App.xaml new file mode 100644 index 000000000..3ab646c7c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/App.xaml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj index 1a5d06616..0d6fa213c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Tango.MachineStudio.ActionLogs.csproj @@ -82,6 +82,10 @@ MainView.xaml + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index a550a1911..5f2d86b40 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -2,14 +2,18 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using Tango.BL; using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.BL.ValueObjects; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.MachineStudio.Common; using Tango.SharedUI.Components; @@ -17,6 +21,8 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels { public class MainViewVM : StudioViewModel { + #region properties + private DateTime _startSelectedDate; public DateTime StartSelectedDate { @@ -49,48 +55,83 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels public SelectedObjectCollection SelectedActionLogTypes { get { return _selectedActionLogTypes; } - set { _selectedActionLogTypes = value; RaisePropertyChanged(nameof(SelectedActionLogTypes)); } + set { _selectedActionLogTypes = value; + RaisePropertyChanged(nameof(SelectedActionLogTypes)); } } + private ActionLog _selectedActionLog = null; + public ActionLog SelectedActionLog + { + get { return _selectedActionLog; } + set { _selectedActionLog = value; + SelectedItemChanged(); + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + } + } + + private ActionLogDifference _differenceObject; + public ActionLogDifference DifferenceObject + { + get { return _differenceObject; } + set { _differenceObject = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRunning; + public bool IsRunning + { + get { return _isRunning; } + set { _isRunning = value; } + } + + #endregion + public RelayCommand SearchCommand { get; set; } public RelayCommand CopyToClipBoardCommand { get; set; } public MainViewVM() { ActionLogs = new ObservableCollection(); - SearchCommand = new RelayCommand(Search); - CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard); - DateTime now = DateTime.Now; ; + SearchCommand = new RelayCommand(GetActionLogs, ()=> !IsRunning); + CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); + DateTime now = DateTime.Now; StartSelectedDate = now.AddMonths(-1); EndSelectedDate = now; - + _isRunning = false; var source = Enum.GetValues(typeof(ActionLogType)).Cast().ToObservableCollection(); var syncedSource = Enum.GetValues(typeof(ActionLogType)).Cast().ToObservableCollection(); SelectedActionLogTypes = new SelectedObjectCollection(source, syncedSource); - - //SelectedActionLogTypes.ToList().ForEach(x => x.IsSelected = true); } public override void OnApplicationReady() { } - - private void Search() - { - GetActionLogs(); - } + private void CopyToClipBoard() { + DataObject data = new DataObject(SelectedActionLog.DifferenceObject.ToJsonString()); + System.Windows.Clipboard.SetDataObject(data); + } + + /// + /// New Database Query with search parameters. Initialization ActionLogs property. + /// private async void GetActionLogs() { string filter = SearchFilter?.ToLower(); + if (String.IsNullOrWhiteSpace(filter)) filter = null; + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated < EndSelectedDate && x.LastUpdated >= StartSelectedDate) + DateTime startUtc = StartSelectedDate.ToUniversalTime(); + DateTime endUtc = EndSelectedDate.ToUniversalTime() + DateTime.Now.TimeOfDay; + IsRunning = true; + ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc.Date)) .WithUsers() .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) .Query(y => y.Where @@ -99,7 +140,15 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) .BuildAsync(); + IsRunning = false; } } + + private void SelectedItemChanged() + { + if (SelectedActionLog == null || SelectedActionLog.DifferenceObject== null) + return; + DifferenceObject = SelectedActionLog.DifferenceObject; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml index 53db8c11d..60ce2560c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml @@ -3,19 +3,19 @@ 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:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:local="clr-namespace:Tango.MachineStudio.ActionLogs.Views" xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:vm="clr-namespace:Tango.MachineStudio.ActionLogs.ViewModels" xmlns:global="clr-namespace:Tango.MachineStudio.ActionLogs" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" - xmlns:localConverters="clr-namespace:Tango.MachineStudio.ActionLogs.Converters" + xmlns:diff="clr-namespace:Tango.BL.ValueObjects;assembly=Tango.BL" mc:Ignorable="d" d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> - + - @@ -23,70 +23,80 @@ - + - + - - + + - - - Start Date: - - - - End Date: - - - - - - - - - - - - Select Actions - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + Start Date: + + + + End Date: + + + + + + + + + + + + + + () + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + SelectedItem="{Binding SelectedActionLog}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" FontSize="11"> + + + - - - + + + - - + + + - - - - + + + + + + + + + + + + Object Changes + + + + + + + + + + + + + + + + + + : + + | + + + + + + + + + -- cgit v1.3.1 From 10a79597b2164b6d71d13a0c50c0fc190b322f14 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 25 Dec 2019 12:23:34 +0200 Subject: added offline firmware updates support. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/MachineUpdatesViewVM.cs | 16 ++ .../Views/MachineUpdateDetailsDialog.xaml | 3 + .../Views/MachineUpdatesView.xaml | 7 +- .../Dialogs/UpdateDetailsView.xaml | 3 + .../Tango.PPC.Technician/Views/UpdatesView.xaml | 3 + .../MachineUpdate/MachineUpdateManager.cs | 229 ++++++++++++++------- .../DefaultMachineDataSynchronizer.cs | 2 +- .../Visual_Studio/Tango.BL/Entities/TangoUpdate.cs | 22 +- .../Tango.BL/Enumerations/TangoUpdateStatuses.cs | 7 + 15 files changed, 210 insertions(+), 82 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index d5aa07375..4ebfde2f5 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 4f5cad336..85465a448 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 183ae0d56..3ea4b1689 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 7e66b1381..39ccc6dd7 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 8afd77e9d..5bceaa440 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 31e149076..17f66fd24 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs index e1e9ee561..41bcc2a87 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MachineUpdatesViewVM.cs @@ -80,6 +80,20 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _displaySynchronizations = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } + private bool _displayOfflineUpdates; + public bool DisplayOfflineUpdates + { + get { return _displayOfflineUpdates; } + set { _displayOfflineUpdates = value; RaisePropertyChangedAuto(); OnFilterChanged(); } + } + + private bool _displayFirmwareUpgrades; + public bool DisplayFirmwareUpgrades + { + get { return _displayFirmwareUpgrades; } + set { _displayFirmwareUpgrades = value; RaisePropertyChangedAuto(); OnFilterChanged(); } + } + #endregion #region Commands @@ -158,6 +172,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels if (!DisplayApplicationUpdates && update.IsUpdate) return false; if (!DisplayDatabaseUpdates && update.IsDataBase) return false; if (!DisplaySynchronizations && update.IsSynchronization) return false; + if (!DisplayOfflineUpdates && update.IsOfflineUpdate) return false; + if (!DisplayFirmwareUpgrades && update.IsOfflineFirmwareUpgrade) return false; return true; } else diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdateDetailsDialog.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdateDetailsDialog.xaml index 1e7b03fed..0e793dc6a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdateDetailsDialog.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdateDetailsDialog.xaml @@ -46,6 +46,9 @@ + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdatesView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdatesView.xaml index 65a5a569f..bd272718d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdatesView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineUpdatesView.xaml @@ -11,7 +11,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.MachineStudio.MachineDesigner.Views" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1280" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> + d:DesignHeight="720" d:DesignWidth="1500" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> @@ -40,6 +40,8 @@ Software Updates Database Updates Synchronizations + Offline Updates + Offline Firmware Upgrades @@ -77,6 +79,9 @@ + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Dialogs/UpdateDetailsView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Dialogs/UpdateDetailsView.xaml index 1f0f57be0..ccf2062c1 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Dialogs/UpdateDetailsView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Dialogs/UpdateDetailsView.xaml @@ -39,6 +39,9 @@ + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/UpdatesView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/UpdatesView.xaml index df2e2d65f..501632bfa 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/UpdatesView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/UpdatesView.xaml @@ -63,6 +63,9 @@ + + + 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 7228c53d3..ded4d1dae 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -252,6 +252,7 @@ namespace Tango.PPC.Common.MachineUpdate update.EndDate = DateTime.UtcNow; update.FailedReason = ex.FlattenMessage(); update.FailedLog = logs; + db.TangoUpdates.Add(update); await db.SaveChangesAsync(); } } @@ -277,6 +278,7 @@ namespace Tango.PPC.Common.MachineUpdate update.EndDate = DateTime.UtcNow; update.FailedReason = ex.FlattenMessage(); update.FailedLog = logs; + db.TangoUpdates.Add(update); await db.SaveChangesAsync(); } } @@ -362,6 +364,7 @@ namespace Tango.PPC.Common.MachineUpdate update.UpdateStatus = BL.Enumerations.TangoUpdateStatuses.UpdateCompleted; update.StartDate = _updateStartDate; update.EndDate = DateTime.UtcNow; + db.TangoUpdates.Add(update); await db.SaveChangesAsync(); } } @@ -385,6 +388,7 @@ namespace Tango.PPC.Common.MachineUpdate update.UpdateStatus = BL.Enumerations.TangoUpdateStatuses.OfflineUpdateCompleted; update.StartDate = _updateStartDate; update.EndDate = DateTime.UtcNow; + db.TangoUpdates.Add(update); await db.SaveChangesAsync(); } } @@ -461,6 +465,7 @@ namespace Tango.PPC.Common.MachineUpdate update.EndDate = DateTime.UtcNow; update.FailedReason = ex.FlattenMessage(); update.FailedLog = logs; + db.TangoUpdates.Add(update); db.SaveChanges(); } } @@ -504,6 +509,7 @@ namespace Tango.PPC.Common.MachineUpdate update.UpdateStatus = BL.Enumerations.TangoUpdateStatuses.DatabaseCompleted; update.StartDate = _updateStartDate; update.EndDate = DateTime.UtcNow; + db.TangoUpdates.Add(update); db.SaveChanges(); } } @@ -517,19 +523,63 @@ namespace Tango.PPC.Common.MachineUpdate _isUpdating = false; } - private void OnFailed(Exception ex, TaskCompletionSource completionSource) + private void OnFailed(Exception ex, TaskCompletionSource completionSource, String firmwareVersion) { LogManager.Log(ex, "An error occurred in firmware upgrade."); completionSource.SetException(ex); String logs = GetLogsStringAndClear(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + TangoUpdate update = new TangoUpdate(); + update.ApplicationVersion = _app_manager.Version.ToString(); + update.FirmwareVersion = firmwareVersion; + update.MachineGuid = _machineProvider.Machine.Guid; + update.UpdateStatus = BL.Enumerations.TangoUpdateStatuses.OfflineFirmwareUpgradeFailed; + update.StartDate = _updateStartDate; + update.EndDate = DateTime.UtcNow; + update.FailedReason = ex.FlattenMessage(); + update.FailedLog = logs; + db.TangoUpdates.Add(update); + db.SaveChanges(); + } + } + catch (Exception exx) + { + LogManager.Log(exx, "Error saving firmware upgrade information to database."); + } + _isUpdating = false; } - private void OnCompleted(TaskCompletionSource completionSource) + private void OnCompleted(TaskCompletionSource completionSource, String firmwareVersion) { LogManager.Log("Firmware upgrade completed successfully."); completionSource.SetResult(true); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + TangoUpdate update = new TangoUpdate(); + update.ApplicationVersion = _app_manager.Version.ToString(); + update.FirmwareVersion = firmwareVersion; + update.MachineGuid = _machineProvider.Machine.Guid; + update.UpdateStatus = BL.Enumerations.TangoUpdateStatuses.OfflineFirmwareUpgradeCompleted; + update.StartDate = _updateStartDate; + update.EndDate = DateTime.UtcNow; + db.TangoUpdates.Add(update); + db.SaveChanges(); + } + } + catch (Exception exx) + { + LogManager.Log(exx, "Error saving firmware upgrade information to database."); + } + _isUpdating = false; } @@ -835,81 +885,6 @@ namespace Tango.PPC.Common.MachineUpdate return await result.Task; } - public async Task UpdateFromTFP(String fileName) - { - _updateStartDate = DateTime.UtcNow; - _logs.Clear(); - - TaskCompletionSource result = new TaskCompletionSource(); - - try - { - _isUpdating = true; - - LogManager.Log("Verifying machine connection and state..."); - - UpdateProgress("Verifying machine state", "Initializing..."); - - await Task.Delay(1000); - - IMachineOperator op = _machineProvider.MachineOperator; - - if (op.State != Transport.TransportComponentState.Connected) - { - throw LogManager.Log(new InvalidOperationException("Could not perform a firmware upgrade while the machine is not connected.")); - } - if (!op.CanPrint) - { - throw LogManager.Log(new InvalidOperationException($"Could not perform a firmware upgrade while the machine is in {op.Status} status.")); - } - - UpdateProgress("Updating Firmware", "Connecting to firmware device..."); - LogManager.Log(""); - LogManager.Log("-------------------------------------------------------------------------"); - LogManager.Log("Updating Firmware..."); - - UpdateProgress("Updating Firmware", "Loading firmware package..."); - var stream = new FileStream(fileName, FileMode.Open); - - if (!_machineProvider.Machine.IsDemo) - { - op.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; - } - else - { - op.FirmwareUpgradeMode = FirmwareUpgradeModes.TFP_PACKAGE; - } - - var handler = await op.UpgradeFirmware(stream); - handler.Failed += (_, ex) => - { - stream.Dispose(); - OnFailed(ex, result); - }; - handler.Completed += (_, __) => - { - UpdateProgress("Updating Firmware", "Firmware update completed successfully."); - stream.Dispose(); - OnCompleted(result); - }; - handler.Canceled += (_, __) => - { - stream.Dispose(); - OnFailed(new Exception("The operation has been canceled."), result); - }; - handler.Progress += (_, e) => - { - UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); - }; - } - catch (Exception ex) - { - OnFailed(ex, result); - } - - await result.Task; - } - /// /// Checks if any update are available for the specified machine serial number. /// @@ -1494,6 +1469,106 @@ namespace Tango.PPC.Common.MachineUpdate return await result.Task; } + /// + /// Performs a firmware upgrade from the specified TFP file. + /// + /// Name of the file. + /// + /// + /// Could not perform a firmware upgrade while the machine is not connected. + /// or + /// + public async Task UpdateFromTFP(String fileName) + { + _updateStartDate = DateTime.UtcNow; + _logs.Clear(); + + TaskCompletionSource result = new TaskCompletionSource(); + + String version = String.Empty; + Stream stream = null; + + try + { + _isUpdating = true; + + IMachineOperator op = _machineProvider.MachineOperator; + + UpdateProgress("Updating Firmware", "Loading firmware package..."); + stream = new FileStream(fileName, FileMode.Open); + + var packageInfo = await op.GetFirmwarePackageInfo(stream); + stream.Position = 0; + version = packageInfo.FileDescriptors.FirstOrDefault(x => x.Destination == PMR.FirmwareUpgrade.VersionFileDestination.Mcu)?.Version; + + LogManager.Log("Verifying machine connection and state..."); + + UpdateProgress("Verifying machine state", "Initializing..."); + + await Task.Delay(1000); + + if (op.State != Transport.TransportComponentState.Connected) + { + throw LogManager.Log(new InvalidOperationException("Could not perform a firmware upgrade while the machine is not connected.")); + } + if (!op.CanPrint) + { + throw LogManager.Log(new InvalidOperationException($"Could not perform a firmware upgrade while the machine is in {op.Status} status.")); + } + + UpdateProgress("Updating Firmware", "Connecting to firmware device..."); + LogManager.Log(""); + LogManager.Log("-------------------------------------------------------------------------"); + LogManager.Log("Updating Firmware..."); + + if (!_machineProvider.Machine.IsDemo) + { + op.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; + } + else + { + op.FirmwareUpgradeMode = FirmwareUpgradeModes.TFP_PACKAGE; + } + + var handler = await op.UpgradeFirmware(stream); + handler.Failed += (_, ex) => + { + stream.Dispose(); + OnFailed(ex, result, version); + }; + handler.Completed += (_, __) => + { + UpdateProgress("Updating Firmware", "Firmware update completed successfully."); + stream.Dispose(); + OnCompleted(result, version); + }; + handler.Canceled += (_, __) => + { + stream.Dispose(); + OnFailed(new Exception("The operation has been canceled."), result, version); + }; + handler.Progress += (_, e) => + { + UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total); + }; + } + catch (Exception ex) + { + try + { + if (stream != null) + { + stream.Dispose(); + } + } + catch { } + + OnFailed(ex, result, version); + } + + await result.Task; + } + /// /// Gets the update package file information. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs index 7520026e4..675f55aa5 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Synchronization/DefaultMachineDataSynchronizer.cs @@ -197,7 +197,7 @@ namespace Tango.PPC.Common.Synchronization { LogManager.Log("Checking Offline Updates..."); - var tangoUpdates = await db.TangoUpdates.Where(x => !x.IsSynchronized && (x.Status == (int)TangoUpdateStatuses.OfflineUpdateCompleted || x.Status == (int)TangoUpdateStatuses.OfflineUpdateFailed)).Take(MaxOfflineUpdates).OrderByDescending(x => x.LastUpdated).ToListAsync(); + var tangoUpdates = await db.TangoUpdates.Where(x => !x.IsSynchronized && (x.Status == (int)TangoUpdateStatuses.OfflineUpdateCompleted || x.Status == (int)TangoUpdateStatuses.OfflineUpdateFailed || x.Status == (int)TangoUpdateStatuses.OfflineFirmwareUpgradeCompleted || x.Status == (int)TangoUpdateStatuses.OfflineFirmwareUpgradeFailed)).Take(MaxOfflineUpdates).OrderByDescending(x => x.LastUpdated).ToListAsync(); List dtos = new List(); foreach (var tangoUpdate in tangoUpdates) diff --git a/Software/Visual_Studio/Tango.BL/Entities/TangoUpdate.cs b/Software/Visual_Studio/Tango.BL/Entities/TangoUpdate.cs index f290618cb..d5b10ee45 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/TangoUpdate.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/TangoUpdate.cs @@ -91,6 +91,19 @@ namespace Tango.BL.Entities } } + [NotMapped] + [JsonIgnore] + public bool IsOfflineFirmwareUpgrade + { + get + { + return + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeStarted || + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeCompleted || + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeFailed; + } + } + [NotMapped] [JsonIgnore] public bool IsStarted @@ -102,7 +115,8 @@ namespace Tango.BL.Entities UpdateStatus == TangoUpdateStatuses.UpdateStarted || UpdateStatus == TangoUpdateStatuses.DatabaseStarted || UpdateStatus == TangoUpdateStatuses.SynchronizationStarted || - UpdateStatus == TangoUpdateStatuses.OfflineUpdateStarted; + UpdateStatus == TangoUpdateStatuses.OfflineUpdateStarted || + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeStarted; } } @@ -117,7 +131,8 @@ namespace Tango.BL.Entities UpdateStatus == TangoUpdateStatuses.UpdateCompleted || UpdateStatus == TangoUpdateStatuses.DatabaseCompleted || UpdateStatus == TangoUpdateStatuses.SynchronizationCompleted || - UpdateStatus == TangoUpdateStatuses.OfflineUpdateCompleted; + UpdateStatus == TangoUpdateStatuses.OfflineUpdateCompleted || + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeCompleted; } } @@ -132,7 +147,8 @@ namespace Tango.BL.Entities UpdateStatus == TangoUpdateStatuses.UpdateFailed || UpdateStatus == TangoUpdateStatuses.DatabaseFailed || UpdateStatus == TangoUpdateStatuses.SynchronizationFailed || - UpdateStatus == TangoUpdateStatuses.OfflineUpdateFailed; + UpdateStatus == TangoUpdateStatuses.OfflineUpdateFailed || + UpdateStatus == TangoUpdateStatuses.OfflineFirmwareUpgradeFailed; } } diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/TangoUpdateStatuses.cs b/Software/Visual_Studio/Tango.BL/Enumerations/TangoUpdateStatuses.cs index 5fdf24e22..9db075623 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/TangoUpdateStatuses.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/TangoUpdateStatuses.cs @@ -43,5 +43,12 @@ namespace Tango.BL.Enumerations OfflineUpdateCompleted = 401, [Description("Offline update failed")] OfflineUpdateFailed = 402, + + [Description("Offline firmware upgrade started but did not complete")] + OfflineFirmwareUpgradeStarted = 500, + [Description("Offline firmware upgrade completed successfully")] + OfflineFirmwareUpgradeCompleted = 501, + [Description("Offline firmware upgrade failed")] + OfflineFirmwareUpgradeFailed = 502, } } -- cgit v1.3.1