From 4cabb5aabc490156b50cd02592926539d48a7af8 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 15 Dec 2019 01:09:46 +0200 Subject: Implmented InternalModule navigation for PPC. Fixed issue with TangoIOC.GetAllInstancedByBase. Implemented PowerOff Screen. --- .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 9e8a9fe34..e18354f89 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -10,6 +10,7 @@ using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; +using Tango.PPC.UI.Views; using Tango.PPC.UI.ViewsContracts; using Tango.SharedUI; @@ -121,6 +122,11 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand RestartApplicationCommand { get; set; } + /// + /// Gets or sets the power off command. + /// + public RelayCommand PowerOffCommand { get; set; } + #endregion #region Constructors @@ -146,6 +152,7 @@ namespace Tango.PPC.UI.ViewModels PowerCommand = new RelayCommand(() => IsPowerOpened = true); RestartApplicationCommand = new RelayCommand(RestartApplication); + PowerOffCommand = new RelayCommand(PowerOffMachine); } #endregion @@ -239,6 +246,12 @@ namespace Tango.PPC.UI.ViewModels } } + private async void PowerOffMachine() + { + IsMenuOpened = false; + await NavigationManager.NavigateTo(nameof(PowerOffView)); + } + #endregion #region Override Methods -- cgit v1.3.1 From 5ef0db61993e269caa1d1184ee0be2ae1c6ea393 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 15 Dec 2019 19:44:35 +0200 Subject: Implemented power down by user and from embedded button. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../AppBarItems/JobProgressAppBarItemView.xaml | 3 +- .../Tango.PPC.UI/AppBarItems/PowerOffAppBarItem.cs | 31 ++++++ .../AppBarItems/PowerOffAppBarItemView.xaml | 30 ++++++ .../AppBarItems/PowerOffAppBarItemView.xaml.cs | 28 ++++++ .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 10 +- .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 15 ++- .../PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs | 108 ++++++++++++++++++++- .../Tango.Emulations/Emulators/MachineEmulator.cs | 46 +++++++++ .../Operation/IMachineOperator.cs | 11 +++ .../Tango.Integration/Operation/MachineOperator.cs | 67 ++++++++++++- .../Operation/PowerDownHandler.cs | 77 +++++++++++++++ .../Operation/PowerDownStartedEventArgs.cs | 13 +++ .../Operation/PowerDownStatusChangedEventArgs.cs | 14 +++ .../Tango.Integration/Tango.Integration.csproj | 5 +- Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj | 12 ++- 17 files changed, 462 insertions(+), 8 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItem.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/PowerDownHandler.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/PowerDownStartedEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/PowerDownStatusChangedEventArgs.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 8c9c784e0..8bce1236f 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 2ddb0c5e9..9e9f5d60a 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/AppBarItems/JobProgressAppBarItemView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/AppBarItems/JobProgressAppBarItemView.xaml index d74eafb03..16c6a42be 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/AppBarItems/JobProgressAppBarItemView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/AppBarItems/JobProgressAppBarItemView.xaml @@ -5,7 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:local="clr-namespace:Tango.PPC.Jobs.AppBarItems" - mc:Ignorable="d" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:JobProgressAppBarItem, IsDesignTimeCreatable=False}"> + mc:Ignorable="d" + d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=local:JobProgressAppBarItem, IsDesignTimeCreatable=False}"> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItem.cs new file mode 100644 index 000000000..c2bdc3926 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItem.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Power; +using Tango.PPC.Common.Notifications; + +namespace Tango.PPC.UI.AppBarItems +{ + public class PowerOffAppBarItem : AppBarItem + { + private StartPowerDownResponse _status; + public StartPowerDownResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + /// + /// Gets or sets the view type. + /// + public override Type ViewType + { + get + { + return typeof(PowerOffAppBarItemView); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml new file mode 100644 index 000000000..9a9f8e912 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + % + Completed + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.xaml.cs new file mode 100644 index 000000000..fdd7bfc30 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/AppBarItems/PowerOffAppBarItemView.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.PPC.UI.AppBarItems +{ + /// + /// Interaction logic for PowerOffAppBarItemView.xaml + /// + public partial class PowerOffAppBarItemView : UserControl + { + public PowerOffAppBarItemView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 96891a8a9..49b0c81d1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -114,6 +114,10 @@ GlobalVersionInfo.cs + + + PowerOffAppBarItemView.xaml + @@ -222,6 +226,10 @@ RestartingSystemView.xaml + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -663,7 +671,7 @@ if $(ConfigurationName) == Debug copy /Y "$(TargetDir)Packages" "$(TargetDir)" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index e18354f89..d7717e6db 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -246,10 +246,23 @@ namespace Tango.PPC.UI.ViewModels } } + /// + /// Powers off the machine. + /// private async void PowerOffMachine() { IsMenuOpened = false; - await NavigationManager.NavigateTo(nameof(PowerOffView)); + if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?")) + { + try + { + await MachineProvider.MachineOperator.PowerDown(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error triggering power down."); + } + } } #endregion diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs index 0d58b472f..e3ab7d111 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/PowerOffViewVM.cs @@ -1,19 +1,40 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.Integration.Operation; +using Tango.PMR.Power; using Tango.PPC.Common; +using Tango.PPC.UI.AppBarItems; +using Tango.PPC.UI.Views; namespace Tango.PPC.UI.ViewModels { public class PowerOffViewVM : PPCViewModel { + private PowerDownHandler _handler; + private PowerOffAppBarItem _appBarItem; + private int _abortTries; + + private StartPowerDownResponse _status; + public StartPowerDownResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + public RelayCommand AbortCommand { get; set; } public PowerOffViewVM() { + _appBarItem = new PowerOffAppBarItem(); + _appBarItem.Pressed += (x, e) => + { + NavigationManager.NavigateTo(nameof(PowerOffView)); + }; AbortCommand = new RelayCommand(AbortPowerOff); } @@ -22,9 +43,92 @@ namespace Tango.PPC.UI.ViewModels } - private void AbortPowerOff() + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.PowerDownStarted += MachineOperator_PowerDownStarted; + } + + private void MachineOperator_PowerDownStarted(object sender, PowerDownStartedEventArgs e) + { + _abortTries = 0; + _handler = e.Handler; + + _handler.StatusChanged += OnStatusChanged; + _handler.Failed += OnFailed; + _handler.Completed += OnCompleted; + + InvokeUI(async () => + { + await NavigationManager.NavigateTo(nameof(PowerOffView)); + NotificationProvider.PushAppBarItem(_appBarItem); + }); + } + + private void OnStatusChanged(object sender, PowerDownStatusChangedEventArgs e) + { + Status = e.Status; + _appBarItem.Status = Status; + } + + private void OnCompleted(object sender, EventArgs e) + { + InvokeUI(async () => + { + if (IsVisible) + { + await NavigationManager.NavigateBack(); + } + + NotificationProvider.PopAppBarItem(_appBarItem); + }); + } + + private void OnFailed(object sender, Exception ex) { - NavigationManager.NavigateBack(); + InvokeUI(async () => + { + await NotificationProvider.ShowError($"An error occurred while powering off the machine.\n{ex.FlattenMessage()}"); + + if (IsVisible) + { + await NavigationManager.NavigateBack(); + } + + NotificationProvider.PopAppBarItem(_appBarItem); + }); + } + + private async void AbortPowerOff() + { + try + { + NotificationProvider.SetGlobalBusyMessage("Aborting machine power off..."); + await _handler.Abort(); + await NavigationManager.NavigateBack(); + NotificationProvider.PopAppBarItem(_appBarItem); + } + catch (Exception ex) + { + _abortTries++; + LogManager.Log(ex, "Power down abort error."); + NotificationProvider.ReleaseGlobalBusyMessage(); + await NotificationProvider.ShowError($"An error occurred while trying to abort the power off sequence.\n{ex.FlattenMessage()}"); + + if (_abortTries > 2) + { + if (IsVisible) + { + await NavigationManager.NavigateBack(); + } + + NotificationProvider.PopAppBarItem(_appBarItem); + } + } + finally + { + NotificationProvider.ReleaseGlobalBusyMessage(); + } } } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 36a2a2db5..e4b081e9e 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -32,6 +32,7 @@ using Tango.PMR.FirmwareUpgrade; using System.Diagnostics; using Tango.Core.ExtensionMethods; using Tango.PMR.MachineStatus; +using Tango.PMR.Power; namespace Tango.Emulations.Emulators { @@ -74,6 +75,7 @@ namespace Tango.Emulations.Emulators private String _current_job_resume_token; private FileUploadRequest _lastFileUploadRequest; private bool _isAfterReset; + private bool _abortPowerDown; #region Properties @@ -397,6 +399,12 @@ namespace Tango.Emulations.Emulators case MessageType.ActivateVersionRequest: HandleActivateVersionRequest(MessageFactory.ParseTangoMessageFromContainer(container)); break; + case MessageType.StartPowerDownRequest: + HandleStartPowerDownRequest(MessageFactory.ParseTangoMessageFromContainer(container)); + break; + case MessageType.AbortPowerDownRequest: + HandleAbortPowerDownRequest(MessageFactory.ParseTangoMessageFromContainer(container)); + break; } } @@ -1349,6 +1357,44 @@ namespace Tango.Emulations.Emulators }); } + private void HandleStartPowerDownRequest(TangoMessage request) + { + _abortPowerDown = false; + + Task.Factory.StartNew(async () => + { + MachineStatus.State = MachineState.PowerOff; + + for (int i = 0; i < 100; i++) + { + if (_abortPowerDown) return; + + await Task.Delay(200); + await Transporter.SendResponse(new StartPowerDownResponse() + { + ProgressPercentage = i++, + Message = $"Powering down {i}%..." + }, request.Container.Token); + } + + await Task.Delay(500); + + await Transporter.SendResponse(new StartPowerDownResponse() + { + ProgressPercentage = 100, + Message = "Machine is turned off", + State = PowerDownState.Completed + }, request.Container.Token, true); + }); + } + + private async void HandleAbortPowerDownRequest(TangoMessage request) + { + _abortPowerDown = true; + await Task.Delay(1000); + await Transporter.SendResponse(new AbortPowerDownResponse(), request.Container.Token); + } + #endregion #region Public Methods diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index 17576d2c5..b5b7b7393 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -193,6 +193,11 @@ namespace Tango.Integration.Operation /// event EventHandler PowerUpStarted; + /// + /// Occurs when power down has started. + /// + event EventHandler PowerDownStarted; + /// /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// @@ -443,5 +448,11 @@ namespace Tango.Integration.Operation /// /// StorageManager CreateStorageManager(); + + /// + /// Turns off the machine. + /// + /// + Task PowerDown(); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index bae0ec55e..e142066b6 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -41,6 +41,7 @@ using Tango.PMR.MachineStatus; using Newtonsoft.Json; using Tango.PMR.Integration; using System.Globalization; +using Tango.PMR.Power; namespace Tango.Integration.Operation { @@ -69,6 +70,7 @@ namespace Tango.Integration.Operation private bool _machineStatusSent; private EmbeddedLogItem _last_embedded_debug_log; private static RunningJobStatus _last_job_status; + private bool _isPowerDownRequestInProgress; public static String EmbeddedLogsFolder { get; private set; } public static String EmbeddedLogsTag { get; private set; } @@ -217,6 +219,11 @@ namespace Tango.Integration.Operation /// public event EventHandler PowerUpStarted; + /// + /// Occurs when power down has started. + /// + public event EventHandler PowerDownStarted; + #endregion #region Properties @@ -793,7 +800,7 @@ namespace Tango.Integration.Operation /// Called when the machine status has been update /// /// The response. - protected virtual void OnMachineStatusChanged(StartMachineStatusUpdateResponse response) + protected async virtual void OnMachineStatusChanged(StartMachineStatusUpdateResponse response) { if (response.Status == null) return; @@ -822,6 +829,14 @@ namespace Tango.Integration.Operation // break; case MachineState.PowerOff: Status = MachineStatuses.ShuttingDown; + if (!_isPowerDownRequestInProgress) + { + try + { + await PowerDown(); + } + catch { } + } break; case MachineState.Error: //Status = MachineStatuses.Error; @@ -3209,6 +3224,56 @@ namespace Tango.Integration.Operation await SendRequest(activateRequest, TimeSpan.FromSeconds(10)); } + /// + /// Turns off the machine. + /// + /// + public Task PowerDown() + { + _isPowerDownRequestInProgress = true; + + PowerDownHandler handler = new PowerDownHandler(new Task(() => + { + Thread.Sleep(2000); + var r = SendRequest(new AbortPowerDownRequest()).Result; + throw new InvalidOperationException(); + })); + + Task.Factory.StartNew(() => + { + Thread.Sleep(100); + + bool firstResponse = true; + + SendContinuousRequest(new StartPowerDownRequest()).ObserveOn(new NewThreadScheduler()).Subscribe((response) => + { + if (firstResponse) + { + firstResponse = false; + Status = MachineStatuses.ShuttingDown; + } + + handler.RaiseStatusChanged(response); + }, (ex) => + { + _isPowerDownRequestInProgress = false; + LogManager.Log(ex, "Power down error."); + handler.RaiseFailed(ex); + }, () => + { + _isPowerDownRequestInProgress = false; + handler.RaiseCompleted(); + }); + }); + + PowerDownStarted?.Invoke(this, new PowerDownStartedEventArgs() + { + Handler = handler, + }); + + return Task.FromResult(handler); + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PowerDownHandler.cs b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownHandler.cs new file mode 100644 index 000000000..03593d6c6 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownHandler.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PMR.Power; + +namespace Tango.Integration.Operation +{ + public class PowerDownHandler : ExtendedObject + { + private Task _abortTask; + + public event EventHandler StatusChanged; + public event EventHandler Failed; + public event EventHandler Completed; + + private StartPowerDownResponse _status; + public StartPowerDownResponse Status + { + get { return _status; } + set { _status = value; RaisePropertyChangedAuto(); } + } + + internal PowerDownHandler(Task abortTask) + { + _abortTask = abortTask; + + Status = new StartPowerDownResponse() + { + Message = "Powering down...", + State = PowerDownState.None, + }; + } + + internal void RaiseStatusChanged(StartPowerDownResponse status) + { + OnStatusChanged(status); + } + + internal void RaiseFailed(Exception ex) + { + OnFailed(ex); + } + + internal void RaiseCompleted() + { + OnCompleted(); + } + + private void OnStatusChanged(StartPowerDownResponse status) + { + Status = status; + StatusChanged?.Invoke(this, new PowerDownStatusChangedEventArgs() + { + Status = status + }); + } + + private void OnCompleted() + { + Completed?.Invoke(this, new EventArgs()); + } + + private void OnFailed(Exception ex) + { + Failed?.Invoke(this, ex); + } + + public async Task Abort() + { + _abortTask.Start(); + await _abortTask; + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStartedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStartedEventArgs.cs new file mode 100644 index 000000000..7dcd4fb39 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStartedEventArgs.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Operation +{ + public class PowerDownStartedEventArgs : EventArgs + { + public PowerDownHandler Handler { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStatusChangedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStatusChangedEventArgs.cs new file mode 100644 index 000000000..5c64b41a2 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/PowerDownStatusChangedEventArgs.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Power; + +namespace Tango.Integration.Operation +{ + public class PowerDownStatusChangedEventArgs : EventArgs + { + public StartPowerDownResponse Status { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index c3a6d3e43..5a4fcadf1 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -107,6 +107,9 @@ + + + @@ -195,7 +198,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj index ad4e8e170..c725a3121 100644 --- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj +++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj @@ -255,6 +255,11 @@ + + + + + @@ -292,6 +297,11 @@ + + + + + @@ -309,7 +319,7 @@ - + \ No newline at end of file -- cgit v1.3.1 From 9949e351e152a929da696ef2f0a1f8b1668e83fa Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 12 Jan 2020 15:56:50 +0200 Subject: Merged Beta+ fixes to master. --- .../Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs | 1 + .../Tango.PPC.Jobs/Views/JobProgressView.xaml | 2 + .../ViewModels/SystemViewVM.cs | 2 +- .../PPC/Tango.PPC.UI/MainWindow.xaml.cs | 20 +++++- .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 53 +++++++++++++- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 26 +++++-- .../Tango.AdvancedInstaller/InstallerBuilder.cs | 27 +++++++- Software/Visual_Studio/Tango.BL/Entities/Job.cs | 2 +- .../ExternalBridge/ExternalBridgeTcpClient.cs | 3 +- .../Tango.Integration/Operation/JobHandler.cs | 23 +++++-- .../Tango.Integration/Operation/MachineOperator.cs | 80 ++++++++++++++-------- Software/Visual_Studio/Tango.Logging/FileLogger.cs | 23 +++---- .../Tango.Touch/Styles/TouchButton.xaml | 5 ++ .../Tango.Transport/Tango.Transport.csproj | 3 +- .../Tango.Transport/TransportMessage.cs | 8 +++ .../Tango.Transport/TransporterBase.cs | 15 ++++ .../TransporterDisconnectedException.cs | 16 +++++ .../Utilities/Tango.JobRunsGenerator/Program.cs | 22 +++++- 18 files changed, 267 insertions(+), 64 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Transport/TransporterDisconnectedException.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs index 1de54b784..a2f67b2ba 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs @@ -178,6 +178,7 @@ namespace Tango.PPC.Jobs.ViewModels { if (_handler != null) { + _stop_job_btn.Pop(); _handler.Cancel(); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobProgressView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobProgressView.xaml index 2a21f772e..6bc1337b9 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobProgressView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobProgressView.xaml @@ -38,6 +38,8 @@ + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs index 13aeeb671..f3ffcda14 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs @@ -265,7 +265,7 @@ namespace Tango.PPC.Technician.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var jobRuns = await db.JobRuns.Where(x => x.MachineGuid == MachineProvider.Machine.Guid).ToListAsync(); + var jobRuns = await db.JobRuns.ToListAsync(); TotalDyeTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs index b90a1afff..dec58f336 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs @@ -61,6 +61,12 @@ namespace Tango.PPC.UI has_touch = true; } } + +#if !DEBUG + ForceTouch(); + has_touch = true; +#endif + #endif if (!has_touch) @@ -72,7 +78,7 @@ namespace Tango.PPC.UI gridMain.Height = 1280; viewBox.Child = gridMain; LockAspectRatio(); - this.SizeChanged += (x, y) => + this.SizeChanged += (x, y) => { LockAspectRatio(); }; @@ -81,6 +87,18 @@ namespace Tango.PPC.UI Closing += MainWindow_Closing; } + private void ForceTouch() + { + WindowStyle = WindowStyle.None; + ResizeMode = ResizeMode.NoResize; + WindowStartupLocation = WindowStartupLocation.Manual; + Topmost = false; // sure? + Left = 0; + Top = 0; + Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; + Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; + } + protected override void OnSourceInitialized(EventArgs e) { //var hwndSource = PresentationSource.FromVisual(this) as HwndSource; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index d7717e6db..2bb4e9286 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -23,6 +23,7 @@ namespace Tango.PPC.UI.ViewModels public class LayoutViewVM : PPCViewModel { private JobHandler _jobHandler; + private bool _resettingDevice; /// /// Gets or sets the module loader. @@ -127,6 +128,11 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand PowerOffCommand { get; set; } + /// + /// Gets or sets the reset command. + /// + public RelayCommand ResetCommand { get; set; } + #endregion #region Constructors @@ -152,7 +158,8 @@ namespace Tango.PPC.UI.ViewModels PowerCommand = new RelayCommand(() => IsPowerOpened = true); RestartApplicationCommand = new RelayCommand(RestartApplication); - PowerOffCommand = new RelayCommand(PowerOffMachine); + PowerOffCommand = new RelayCommand(PowerOffMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); + ResetCommand = new RelayCommand(ResetMachine, () => MachineProvider.MachineOperator.Status != MachineStatuses.Disconnected); } #endregion @@ -252,6 +259,7 @@ namespace Tango.PPC.UI.ViewModels private async void PowerOffMachine() { IsMenuOpened = false; + if (await NotificationProvider.ShowQuestion("Are you sure you wish to turn off the machine?")) { try @@ -261,10 +269,38 @@ namespace Tango.PPC.UI.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error triggering power down."); + await NotificationProvider.ShowError(ex.FlattenMessage()); } } } + /// + /// Resets the machine. + /// + private async void ResetMachine() + { + IsMenuOpened = false; + + if (!await NotificationProvider.ShowQuestion("Are you sure you want to reset the machine?")) return; + + try + { + _resettingDevice = true; + ResetCommand.RaiseCanExecuteChanged(); + await MachineProvider.MachineOperator.Reset(); + await NotificationProvider.ShowInfo("Machine was successfully restarted."); + } + catch (Exception ex) + { + await NotificationProvider.ShowError(ex.FlattenMessage()); + } + finally + { + _resettingDevice = false; + ResetCommand.RaiseCanExecuteChanged(); + } + } + #endregion #region Override Methods @@ -286,6 +322,21 @@ namespace Tango.PPC.UI.ViewModels } + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged; + } + + private void MachineOperator_StatusChanged(object sender, MachineStatuses e) + { + InvokeUI(() => + { + PowerOffCommand.RaiseCanExecuteChanged(); + ResetCommand.RaiseCanExecuteChanged(); + }); + } + #endregion #region Public Methods diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index b4f93fd0a..1700749c2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -130,6 +130,21 @@ + + +