diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-06 18:39:17 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-06 18:39:17 +0300 |
| commit | cff4a8079c4d352cfd47793c701650e62337ed6e (patch) | |
| tree | af145431e541f08ed99b1d3ae377d8a59faedc4f /Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | |
| parent | 776d934a1adc8c58301e56f6639afdeeccb0dda6 (diff) | |
| download | Tango-cff4a8079c4d352cfd47793c701650e62337ed6e.tar.gz Tango-cff4a8079c4d352cfd47793c701650e62337ed6e.zip | |
Working on PPC..
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs | 93 |
1 files changed, 88 insertions, 5 deletions
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<bool> CompletionSource { get; set; } + } + + private ConcurrentQueue<PendingMessageBox> _pendingMessageBoxes; + + public DefaultNotificationProvider() + { + _pendingMessageBoxes = new ConcurrentQueue<PendingMessageBox>(); + } + 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<bool> 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<bool> ShowMessageBox(MessageBoxVM vm) + { + TaskCompletionSource<bool> source = new TaskCompletionSource<bool>(); + + 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; + } + } } } } |
