aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.UI/Notifications/DefaultNotificationProvider.cs
blob: 7299a836d8a86e30d004def7b445c91b8fd6c0b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.FSE.Common.Notifications;
using Tango.Core;
using System.Collections.Concurrent;
using System.Windows.Media.Imaging;
using Tango.SharedUI.Helpers;
using System.Timers;
using Tango.Core.Commands;
using Tango.SharedUI;
using System.Reflection;
using Tango.Core.DI;
using System.ComponentModel;
using System.Windows.Data;
using MaterialDesignThemes.Wpf;
using Tango.FSE.Common.Core;
using Tango.FSE.Common.BugReporting;
using Tango.FSE.Common.FSEApplication;
using Tango.FSE.Common.DemoMode;
using Tango.FSE.Common;
using System.Threading;

namespace Tango.FSE.UI.Notifications
{
    /// <summary>
    /// Represents the default FSE notification provider.
    /// </summary>
    /// <seealso cref="Tango.Core.ExtendedObject" />
    /// <seealso cref="Tango.FSE.Common.Notifications.INotificationProvider" />
    public class DefaultNotificationProvider : ExtendedObject, INotificationProvider
    {
        private HashSet<String> _reportedExceptions;
        private ConcurrentQueue<PendingNotification<MessageBoxVM, bool>> _pendingMessageBoxes;
        private ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>> _pendingDialogs;
        private List<AppButton> _appButtons;

        [TangoInject(TangoInjectMode.WhenAvailable)]
        public IBugReporter BugReporter { get; set; }

        [TangoInject(TangoInjectMode.WhenAvailable)]
        private IDemoModeManager DemoModeManager { get; set; }

        private bool _notificationsVisible;
        /// <summary>
        /// Gets or sets a value indicating whether to allow notifications visibility.
        /// </summary>
        public bool NotificationsVisible
        {
            get { return _notificationsVisible; }
            set { _notificationsVisible = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Gets the collection of notification items.
        /// </summary>
        public ObservableCollection<NotificationItem> NotificationItems { get; private set; }

        /// <summary>
        /// Gets the notification items view.
        /// </summary>
        public ICollectionView NotificationItemsView { get; private set; }

        /// <summary>
        /// Gets the collection of task items.
        /// </summary>
        public ObservableCollection<TaskItem> TaskItems { get; private set; }

        /// <summary>
        /// Gets a value indicating whether there are any task items pending.
        /// </summary>
        public bool HasTaskItems
        {
            get { return TaskItems.Count > 0; }
        }

        /// <summary>
        /// Gets the collection of snack bar items.
        /// </summary>
        public ObservableCollection<SnackbarItem> SnackbarItems { get; private set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance has snack bar items.
        /// </summary>
        public bool HasSnackbarItems
        {
            get { return SnackbarItems.Count > 0; }
        }

        private bool _holsSnackbarItemsTimeout;
        /// <summary>
        /// Gets or sets a value indicating whether to delay the snackbar items closing timeout.
        /// </summary>
        public bool HoldSnackbarItemsTimeout
        {
            get { return _holsSnackbarItemsTimeout; }
            set
            {
                _holsSnackbarItemsTimeout = value;
                RaisePropertyChangedAuto();
                SnackbarItems.ToList().ForEach(x => x.HoldTimeout = value);
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class.
        /// </summary>
        public DefaultNotificationProvider()
        {
            NotificationsVisible = true;
            _reportedExceptions = new HashSet<string>();
            NotificationItems = new ObservableCollection<NotificationItem>();
            TaskItems = new ObservableCollection<TaskItem>();
            _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>();
            _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>();
            _appButtons = new List<AppButton>();
            SnackbarItems = new ObservableCollection<SnackbarItem>();

            PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x));

            NotificationItems.EnableCrossThreadOperations();

            NotificationItemsView = CollectionViewSource.GetDefaultView(NotificationItems);
            NotificationItemsView.SortDescriptions.Add(new SortDescription(nameof(NotificationItem.Priority), ListSortDirection.Descending));
        }

        private MessageBoxVM _currentMessageBox;
        /// <summary>
        /// Gets the current message box if any.
        /// </summary>
        public MessageBoxVM CurrentMessageBox
        {
            get { return _currentMessageBox; }
            private set
            {
                _currentMessageBox = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(HasMessageBox));
            }
        }

        /// <summary>
        /// Gets a value indicating whether a message box is available.
        /// </summary>
        public bool HasMessageBox
        {
            get
            {
                return CurrentMessageBox != null;
            }
        }

        private InputBoxVM _currentInputBox;
        /// <summary>
        /// Gets the current input box.
        /// </summary>
        public InputBoxVM CurrentInputBox
        {
            get { return _currentInputBox; }
            private set
            {
                _currentInputBox = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(HasInputBox));
            }
        }

        /// <summary>
        /// Gets a value indicating whether this instance has input box.
        /// </summary>
        public bool HasInputBox
        {
            get
            {
                return CurrentInputBox != null;
            }
        }

        private FrameworkElement _currentDialog;
        /// <summary>
        /// Gets the current dialog if any.
        /// </summary>
        public FrameworkElement CurrentDialog
        {
            get { return _currentDialog; }
            private set
            {
                _currentDialog = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(HasDialog));
            }
        }

        private AppButton _currentAppButton;
        /// <summary>
        /// Gets the current app button.
        /// </summary>
        public AppButton CurrentAppButton
        {
            get { return _currentAppButton; }
            private set { _currentAppButton = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Gets a value indicating whether a dialog is available.
        /// </summary>
        public bool HasDialog
        {
            get
            {
                return CurrentDialog != null;
            }
        }

        /// <summary>
        /// Shows an error message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowError(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Error",
                Type = MessageType.Error,
            });
        }

        /// <summary>
        /// Shows an information message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowInfo(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Information",
                Type = MessageType.Info,
            });
        }

        /// <summary>
        /// Shows warning message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowWarning(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Warning",
                Type = MessageType.Warning,
            });
        }

        /// <summary>
        /// Shows a question message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task<bool> ShowQuestion(string message, String okText = null, String cancelText = null)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Confirm",
                HasCancel = true,
                Type = MessageType.Question,
                OKText = okText != null ? okText : "YES",
                CancelText = cancelText != null ? cancelText : "NO"
            });
        }

        /// <summary>
        /// Shows a warning question message box.
        /// </summary>
        /// <param name="message">The message.</param>
        public Task<bool> ShowWarningQuestion(String message, String okText = null, String cancelText = null)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Warning",
                HasCancel = true,
                Type = MessageType.Warning,
                OKText = okText != null ? okText : "YES",
                CancelText = cancelText != null ? cancelText : "NO"
            });
        }

        /// <summary>
        /// Shows a success message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowSuccess(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Title = "Success",
                Type = MessageType.Success,
            });
        }

        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="vm">The view model.</param>
        /// <returns></returns>
        private Task<bool> ShowMessageBox(MessageBoxVM vm)
        {
            ReleaseGlobalBusyMessage();

            LogManager.Log($"Displaying MessagBox '{vm.Message}'.");

            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 PendingNotification<MessageBoxVM, bool>(vm, source));
            }

            return source.Task;
        }

        public Task<InputBoxResult> ShowInputBox(string title, string message, PackIconKind icon = PackIconKind.InformationOutline, string defaultInput = null, string inputHint = null, int? maxChars = null, string okText = null, string cancelText = null, Func<String, String> validationFunc = null)
        {
            TaskCompletionSource<InputBoxResult> source = new TaskCompletionSource<InputBoxResult>();

            InputBoxVM vm = new InputBoxVM();
            vm.Title = title;
            vm.Message = message;
            vm.Icon = icon;
            vm.Input = defaultInput;
            vm.InputHint = inputHint;
            vm.ValidationFunction = validationFunc;

            if (maxChars != null)
            {
                vm.MaxCharacters = maxChars.Value;
            }
            if (okText != null)
            {
                vm.OKText = okText;
            }
            if (cancelText != null)
            {
                vm.CancelText = cancelText;
            }

            vm.Accepted += () =>
            {
                CurrentInputBox = null;
                source.SetResult(new InputBoxResult() { Confirmed = true, Input = vm.Input });
            };
            vm.Canceled += () =>
            {
                CurrentInputBox = null;
                source.SetResult(new InputBoxResult() { Confirmed = false, Input = vm.Input });
            };

            CurrentInputBox = vm;

            return source.Task;
        }

        /// <summary>
        /// Called when the message box has been closed.
        /// </summary>
        private void OnMessageBoxClosed()
        {
            LogManager.Log("MessageBox closed.");

            CurrentMessageBox = null;

            if (_pendingMessageBoxes.Count > 0)
            {
                PendingNotification<MessageBoxVM, bool> p = null;
                if (_pendingMessageBoxes.TryDequeue(out p))
                {
                    CurrentMessageBox = p.Item;
                }
            }
        }

        /// <summary>
        /// Inserts the notification item to the bottom of the notifications collection.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public NotificationItem PushNotification(NotificationItem item)
        {
            LogManager.Log($"Pushing NotificationItem '{item.GetType().Name}'.");
            item.RemoveAction = () => { PopNotification(item); };
            NotificationItems.Insert(0, item);
            RaisePropertyChanged(nameof(HasNotificationItems));
            return item;
        }

        /// <summary>
        /// Pushes the notification.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public NotificationItem PushNotification<T>() where T : NotificationItem
        {
            return PushNotification(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Removed the specified notification item.
        /// </summary>
        /// <param name="item">The item.</param>
        public void PopNotification(NotificationItem item)
        {
            LogManager.Log($"Popping out NotificationItem '{item.GetType().Name}'.");
            NotificationItems.Remove(item);
            RaisePropertyChanged(nameof(HasNotificationItems));
        }

        /// <summary>
        /// Gets a value indicating whether this instance has notification items.
        /// </summary>
        public bool HasNotificationItems
        {
            get
            {
                return NotificationItems.Count > 0;
            }
        }

        /// <summary>
        /// Gets the pop notification command.
        /// </summary>
        public RelayCommand<NotificationItem> PopNotificationCommand { get; private set; }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datacontext">The data context.</param>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
        {
            LogManager.Log($"Invoking dialog '{view.GetType().Name}'...");

            view.DataContext = datacontext;

            TangoIOC.Default.Inject(datacontext);

            view.Loaded += (_, __) =>
            {
                view.DataContext = datacontext;
                datacontext.OnShow();
            };

            TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
            bool completed = false;

            datacontext.Accepted += () =>
            {
                if (!completed)
                {
                    completed = true;
                    LogManager.Log($"Dialog '{view.GetType().Name}' accepted.");
                    OnDialogClosed();
                    source.SetResult(datacontext);
                }
            };
            datacontext.Canceled += () =>
            {
                if (!completed)
                {
                    completed = true;
                    LogManager.Log($"Dialog '{view.GetType().Name}' canceled.");
                    OnDialogClosed();
                    source.SetResult(datacontext);
                }
            };

            if (CurrentDialog == null)
            {
                CurrentDialog = view;
            }
            else
            {
                _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
            }

            var result = await source.Task;
            return result as T;
        }

        /// <summary>
        /// Called when [dialog closed].
        /// </summary>
        private void OnDialogClosed()
        {
            CurrentDialog = null;

            if (_pendingDialogs.Count > 0)
            {
                PendingNotification<DialogAndView, DialogViewVM> p = null;
                if (_pendingDialogs.TryDequeue(out p))
                {
                    CurrentDialog = p.Item.View;
                }
            }
        }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// The notification provider will try to locate the view automatically using conventions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datacontext">The data context.</param>
        /// <returns></returns>
        public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM
        {
            var callingAssembly = datacontext.GetType().Assembly;
            String viewName = datacontext.GetType().FullName.Replace("VM", "");
            var viewType = callingAssembly.GetType(viewName);

            if (viewType == null)
            {
                throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
            }

            var view = Activator.CreateInstance(viewType) as FrameworkElement;

            if (view == null)
            {
                throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
            }

            return ShowDialog<T>(datacontext, view);
        }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// The data context instance will be automatically created.
        /// The notification provider will try to locate the view automatically using conventions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public Task<T> ShowDialog<T>() where T : DialogViewVM
        {
            return ShowDialog<T>(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Sets the global busy message.
        /// </summary>
        /// <param name="message">The message.</param>
        public void SetGlobalBusyMessage(string message)
        {
            GlobalBusyMessage = message;
            IsInGlobalBusyState = true;

            RaisePropertyChanged(nameof(IsInGlobalBusyState));
            RaisePropertyChanged(nameof(GlobalBusyMessage));
        }

        /// <summary>
        /// Releases the global busy message.
        /// </summary>
        public void ReleaseGlobalBusyMessage()
        {
            GlobalBusyMessage = null;
            IsInGlobalBusyState = false;

            RaisePropertyChanged(nameof(IsInGlobalBusyState));
            RaisePropertyChanged(nameof(GlobalBusyMessage));
        }

        /// <summary>
        /// Gets the current global busy message.
        /// </summary>
        public string GlobalBusyMessage { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is in global busy state.
        /// </summary>
        public bool IsInGlobalBusyState { get; private set; }

        private AppBarItem _currentAppBarItem;
        /// <summary>
        /// Gets the current application bar item.
        /// </summary>
        public AppBarItem CurrentAppBarItem
        {
            get { return _currentAppBarItem; }
            set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); }
        }

        /// <summary>
        /// Gets a value indicating whether this instance has application bar item.
        /// </summary>
        public bool HasAppBarItem
        {
            get { return CurrentAppBarItem != null; }
        }

        /// <summary>
        /// Pushes the application bar item.
        /// </summary>
        /// <param name="appBarItem">The application bar item.</param>
        /// <returns></returns>
        public AppBarItem PushAppBarItem(AppBarItem appBarItem)
        {
            LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'.");
            CurrentAppBarItem = appBarItem;
            appBarItem.RemoveAction = () => PopAppBarItem(appBarItem);
            return appBarItem;
        }

        /// <summary>
        /// Pushes the application bar item.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public AppBarItem PushAppBarItem<T>() where T : AppBarItem
        {
            return PushAppBarItem(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Pops the application bar item.
        /// </summary>
        /// <param name="appBarItem">The application bar item.</param>
        public void PopAppBarItem(AppBarItem appBarItem)
        {
            LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'.");
            CurrentAppBarItem = null;
        }

        /// <summary>
        /// Pushes the task item.
        /// </summary>
        /// <param name="taskBarItem">The task bar item.</param>
        /// <returns></returns>
        public TaskItem PushTaskItem(TaskItem taskBarItem)
        {
            InvokeUI(() =>
            {
                TaskItems.Add(taskBarItem);
                RaisePropertyChanged(nameof(HasTaskItems));
            });
            return taskBarItem;
        }

        /// <summary>
        /// Handles the Push Task Item event.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public TaskItem PushTaskItem<T>() where T : TaskItem
        {
            return PushTaskItem(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Pushes the task item with the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="canCancel">Indicates whether the cancel button will be enabled.</param>
        /// <param name="cancelAction">Specify the action to execute when cancel button is pressed.</param>
        /// <returns></returns>
        public TaskItem PushTaskItem(String message, bool canCancel = false, Action cancelAction = null)
        {
            if (canCancel || cancelAction != null)
            {
                return PushTaskItem(new TaskItem(message, cancelAction));
            }
            else
            {
                return PushTaskItem(new TaskItem(message));
            }
        }

        /// <summary>
        /// Pops the task item.
        /// </summary>
        /// <param name="taskBarItem"></param>
        public void PopTaskItem(TaskItem taskBarItem)
        {
            InvokeUI(() =>
            {
                TaskItems.Remove(taskBarItem);
                RaisePropertyChanged(nameof(HasTaskItems));
            });
        }

        /// <summary>
        /// Pushes the app button.
        /// </summary>
        /// <param name="appButton">The app button.</param>
        public void PushAppButton(AppButton appButton)
        {
            _appButtons.Insert(0, appButton);
            CurrentAppButton = appButton;
        }

        /// <summary>
        /// Pops the app button.
        /// </summary>
        /// <param name="appButton">The app button.</param>
        public void PopAppButton(AppButton appButton)
        {
            _appButtons.RemoveAll(x => x == appButton);

            CurrentAppButton = _appButtons.FirstOrDefault();
        }

        /// <summary>
        /// Pushes the snack bar item.
        /// </summary>
        /// <param name="snackbarItem">The snack bar item.</param>
        /// <returns></returns>
        public SnackbarItem PushSnackbarItem(SnackbarItem snackbarItem)
        {
            InvokeUI(() =>
            {
                SnackbarItems.Insert(0, snackbarItem);
                RaisePropertyChanged(nameof(HasSnackbarItems));
            });
            return snackbarItem;
        }

        /// <summary>
        /// Pushes the snack bar item.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="title">The title.</param>
        /// <param name="canClose">if set to <c>true</c> [can close].</param>
        /// <param name="message">The message.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="closeAction">The close action.</param>
        /// <param name="pressAction">The press action.</param>
        /// <returns></returns>
        public SnackbarItem PushSnackbarItem(MessageType type, String title, bool canClose, String message = null, TimeSpan? timeout = null, Action closeAction = null, Action pressAction = null)
        {
            if (pressAction == null && (type == MessageType.Error || type == MessageType.Warning))
            {
                pressAction = () =>
                {
                    if (type == MessageType.Error)
                    {
                        ShowError((title.EndsWith(".") ? title : title + ".") + "\n" + message);
                    }
                    else if (type == MessageType.Warning)
                    {
                        ShowError((title.EndsWith(".") ? title : title + ".") + "\n" + message);
                    }
                };
            }

            return PushSnackbarItem(new SnackbarItem(type, title, canClose, message, timeout, closeAction, pressAction));
        }

        /// <summary>
        /// Display a new error SnackBar. Pressing the snack bar will display the issue reporting dialog.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="messageType">The message type.</param>
        /// <returns></returns>
        public SnackbarItem PushErrorReportingSnackbar(Exception exception, String title, String message, MessageType messageType = MessageType.BugReport)
        {
            String exceptionText = exception.ToString();

            if (!_reportedExceptions.Contains(exceptionText))
            {
                _reportedExceptions.Add(exceptionText);

                return PushSnackbarItem(messageType, title, true, $"{message}\nTap to report this issue.", null, null, () =>
                 {
                     BugReporter.ShowBugReportDialog(new Bug()
                     {
                         Type = BugType.FSE,
                         Description = message,
                         Exception = exception,
                         Title = title + " - " + message,
                     });
                 });
            }
            else
            {
                return PushSnackbarItem(messageType == MessageType.BugReport ? MessageType.Error : messageType, title, true, $"{message}.", TimeSpan.FromSeconds(10), null, () =>
                {
                    ShowInfo("This error has been reported to the development team.");
                });
            }
        }

        /// <summary>
        /// Displays a indeterminate progress Snackbar. Should use <see cref="M:Tango.FSE.Common.Notifications.SnackbarItem.ProgressCompleted(System.String,System.Nullable{System.TimeSpan})" /> and <see cref="M:Tango.FSE.Common.Notifications.SnackbarItem.ProgressFailed(System.String,System.Nullable{System.TimeSpan})" />.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public SnackbarItem PushProgressSnackbar(String title, String message)
        {
            SnackbarItem item = new SnackbarItem(MessageType.Busy, title, false, message, null, () => { }, () => { });
            item.IsProgress = true;
            PushSnackbarItem(item);
            return item;
        }

        /// <summary>
        /// Pops the snack bar item.
        /// </summary>
        /// <param name="snackbarItem">The snack bar item.</param>
        public void PopSnackbarItem(SnackbarItem snackbarItem)
        {
            InvokeUI(() =>
            {
                SnackbarItems.Remove(snackbarItem);
                RaisePropertyChanged(nameof(HasSnackbarItems));
            });
        }

        /// <summary>
        /// Called when is ready and user is logged-in. (happens every time a user logs-in)
        /// </summary>
        /// <param name="applicationManager"></param>
        public void OnApplicationReady(IFSEApplicationManager applicationManager)
        {
            if (applicationManager.DemoMode)
            {
                DemoModeManager.InsertCommand(() =>
                {
                    ShowInfo("This is a standard information message.");
                }, "Emulate Info Message", "Emulates a standard information message box.");

                DemoModeManager.InsertCommand(() =>
                {
                    ShowWarning("Something bad is about to happen.");
                }, "Emulate Warning Message", "Emulates a standard warning message box.");

                DemoModeManager.InsertCommand(() =>
                {
                    ShowWarningQuestion("Something bad is about to happen. Are you sure?");
                }, "Emulate Warning Question Message", "Emulates a standard warning question message box.");

                DemoModeManager.InsertCommand(() =>
                {
                    ShowError("Something bad happened.");
                }, "Emulate Error Message", "Emulates a standard error message box.");

                DemoModeManager.InsertCommand(() =>
                {
                    ShowSuccess("The operation completed successfully.");
                }, "Emulate Success Message", "Emulates a standard success message box.");

                DemoModeManager.InsertCommand(() =>
                {
                    PushSnackbarItem(MessageType.Info, "Some Information", true, "This is a standard information message.\nTap to see more details.", TimeSpan.FromSeconds(5), null, () =>
                    {
                        ShowInfo("This is a standard information message.");
                    });
                }, "Emulate Info Snackbar", "Creates an information snackbar with timeout and press action.");

                DemoModeManager.InsertCommand(() =>
                {
                    PushSnackbarItem(MessageType.Warning, "Some Warning", true, "This is a standard warning message.\nTap to see more details.", TimeSpan.FromSeconds(5), null, () =>
                    {
                        ShowWarning("This is a standard warning message.");
                    });
                }, "Emulate Warning Snackbar", "Creates a warning snackbar with timeout and press action.");

                DemoModeManager.InsertCommand(() =>
                {
                    PushSnackbarItem(MessageType.Error, "Fake Error Occurred", false, "This is a standard error message.\nTap to see more details.", null, null, () =>
                     {
                         ShowError("This is a standard warning message.");
                     });
                }, "Emulate Error Snackbar", "Creates an error snackbar with no timeout and no ability to close.");

                DemoModeManager.InsertCommand(() =>
                {
                    PushSnackbarItem(MessageType.Success, "Operation Completed", true, "This is a standard success message.\nTap to close", TimeSpan.FromSeconds(5));
                }, "Emulate Success Snackbar", "Creates a success snackbar with timeout and close press action.");

                DemoModeManager.InsertCommand(() =>
                {
                    var snackbar = PushProgressSnackbar("Background Operation", "The application is doing stuff in the background...");

                    Task.Factory.StartNew(() =>
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            snackbar.Message = $"The application is doing stuff in the background ({i}/100)...";
                            Thread.Sleep(50);
                        }

                        snackbar.ProgressCompleted("Operation completed.", TimeSpan.FromSeconds(2));
                    });

                }, "Emulate Progress Snackbar", "Creates a success snackbar with timeout and close press action.");

                DemoModeManager.InsertCommand(() =>
                {
                    throw new TimeoutException("This is a fake exception.");
                }, "Emulate Bug Reporting Error", "Creates a snackbar notification with a fake error and bug reporting option.");
            }
        }
    }
}