aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
blob: e9de2538e0e123543510e1031c91467fe65f0616 (plain) pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
  <Profiles>
    <Profile Name="(Default)" />
  </Profiles>
  <Settings />
</SettingsFile>
n184' href='#n184'>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
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.PPC.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.Touch.Controls;
using Tango.SharedUI;
using System.Reflection;
using Tango.Core.DI;
using System.ComponentModel;
using System.Windows.Data;

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

        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 application bar items.
        /// </summary>
        public ObservableCollection<AppBarItem> AppBarItems { get; private set; }

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

        /// <summary>
        /// Gets the collection of taskbar items.
        /// </summary>
        public ObservableCollection<TaskBarItem> TaskBarItems { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class.
        /// </summary>
        public DefaultNotificationProvider()
        {
            NotificationsVisible = true;
            NotificationItems = new ObservableCollection<NotificationItem>();

            AppBarItems = new ObservableCollection<AppBarItem>();
            CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending));

            TaskBarItems = new ObservableCollection<TaskBarItem>();
            _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>();
            _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>();
            _appButtons = new List<AppButton>();

            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 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,
                Icon = TouchIconKind.AlertCircleOutline,
                Title = "Error",
                Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush,
                HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderErrorBrush"] as Brush,
            });
        }
        /// <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,
                Icon = TouchIconKind.AlertCircleOutline,
                Title = "Information",
                Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush,
                HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderInfoBrush"] as Brush,
            });
        }

        /// <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,
                Icon = TouchIconKind.AlertCircleOutline,
                Title = "Warning",
                Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush,
                HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderWarningBrush"] as Brush,
            });
        }

        /// <summary>
        /// Shows a question message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task<bool> ShowQuestion(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Icon = TouchIconKind.QuestionCircleRegular,
                Title = "Confirm",
                HasCancel = true,
                Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush,
                HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderQuestionBrush"] as Brush,
            });
        }

        /// <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,
                Icon = TouchIconKind.Check,
                Title = "Success",
                Brush = Application.Current.Resources["TangoMessageBoxSuccessBrush"] as Brush,
                HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderSuccessBrush"] as Brush,
            });
        }

        /// <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;
        }

        /// <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
        {
            TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();

            InvokeUI(() =>
            {
                view.DataContext = datacontext;

                TangoIOC.Default.Inject(datacontext);

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

                datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
                datacontext.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
        {
            TaskCompletionSource<T> source = new TaskCompletionSource<T>();

            InvokeUI(async () =>
            {
                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.");
                }

                T result = await ShowDialog<T>(datacontext, view);
                source.SetResult(result);
            });

            return source.Task;
        }

        /// <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
        {
            TaskCompletionSource<T> source = new TaskCompletionSource<T>();

            InvokeUI(async () =>
            {
                var result = await ShowDialog<T>(Activator.CreateInstance<T>());
                source.SetResult(result);
            });

            return source.Task;
        }

        /// <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; }

        /// <summary>
        /// Gets a value indicating whether this instance has application bar item.
        /// </summary>
        public bool HasAppBarItems
        {
            get { return AppBarItems.Count > 0; }
        }

        /// <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}'.");
            AppBarItems.Add(appBarItem);
            appBarItem.RemoveAction = () => PopAppBarItem(appBarItem);
            RaisePropertyChanged(nameof(HasAppBarItems));
            return appBarItem;
        }

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

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

        /// <summary>
        /// Pushes the task bar item.
        /// </summary>
        /// <param name="taskBarItem">The task bar item.</param>
        /// <returns></returns>
        public TaskBarItem PushTaskBarItem(TaskBarItem taskBarItem)
        {
            TaskBarItems.Add(taskBarItem);
            return taskBarItem;
        }

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

        /// <summary>
        /// Pops the task bar item.
        /// </summary>
        /// <param name="taskBarItem"></param>
        public void PopTaskBarItem(TaskBarItem taskBarItem)
        {
            TaskBarItems.Remove(taskBarItem);
        }

        /// <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();
        }
    }
}