From cff4a8079c4d352cfd47793c701650e62337ed6e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 6 Jun 2018 18:39:17 +0300 Subject: Working on PPC.. --- .../Notifications/DefaultNotificationProvider.cs | 93 ++++++++++++++++++++-- .../PPC/Tango.PPC.UI/Notifications/MessageBox.xaml | 27 ++++--- 2 files changed, 105 insertions(+), 15 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs index dbaafa6bb..02e41e087 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs @@ -8,16 +8,37 @@ using System.Windows; using System.Windows.Media; using Tango.PPC.Common.Notifications; using Tango.Core; +using System.Collections.Concurrent; +using System.Windows.Media.Imaging; +using Tango.SharedUI.Helpers; namespace Tango.PPC.UI.Notifications { public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + private class PendingMessageBox + { + public MessageBoxVM VM { get; set; } + public TaskCompletionSource CompletionSource { get; set; } + } + + private ConcurrentQueue _pendingMessageBoxes; + + public DefaultNotificationProvider() + { + _pendingMessageBoxes = new ConcurrentQueue(); + } + private MessageBoxVM _currentMessageBox; public MessageBoxVM CurrentMessageBox { get { return _currentMessageBox; } - private set { _currentMessageBox = value; RaisePropertyChangedAuto(); } + private set + { + _currentMessageBox = value; + RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(HasMessageBox)); + } } public bool HasMessageBox @@ -30,22 +51,84 @@ namespace Tango.PPC.UI.Notifications public Task ShowError(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Error", + Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush, + }); } public Task ShowInfo(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Information", + Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush, + }); } public Task ShowWarning(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Warning", + Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush, + }); } public Task ShowQuestion(string message) { - throw new NotImplementedException(); + return ShowMessageBox(new MessageBoxVM() + { + Message = message, + Icon = ResourceHelper.GetImageFromResources("Images/MessageBox Icons/information.png"), + Title = "Confirm", + HasCancel = true, + Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush, + }); + } + + private Task ShowMessageBox(MessageBoxVM vm) + { + TaskCompletionSource source = new TaskCompletionSource(); + + vm.Accepted += () => { OnMessageBoxClosed(); source.SetResult(true); }; + vm.Canceled += () => { OnMessageBoxClosed(); source.SetResult(false); }; + + if (CurrentMessageBox == null) + { + CurrentMessageBox = vm; + } + else + { + _pendingMessageBoxes.Enqueue(new PendingMessageBox() + { + VM = vm, + CompletionSource = source, + }); + } + + return source.Task; + } + + private void OnMessageBoxClosed() + { + CurrentMessageBox = null; + + if (_pendingMessageBoxes.Count > 0) + { + PendingMessageBox p = null; + if (_pendingMessageBoxes.TryDequeue(out p)) + { + CurrentMessageBox = p.VM; + } + } } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml index a699902b8..07d3b11ac 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/MessageBox.xaml @@ -8,30 +8,37 @@ xmlns:vm="clr-namespace:Tango.PPC.Common.Notifications;assembly=Tango.PPC.Common" xmlns:local="clr-namespace:Tango.PanelPC.UI.Notifications" mc:Ignorable="d" - d:DesignHeight="200" d:DesignWidth="500" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> + d:DesignHeight="400" d:DesignWidth="800" d:DataContext="{d:DesignInstance vm:MessageBoxVM,IsDesignTimeCreatable=False}"> - + - + + - + - - + + - - CANCEL - OK - + + + + + + + + CANCEL + OK + -- cgit v1.3.1