Example #1
0
        /// <summary>Handles opening of views that are notification messages</summary>
        /// <param name="context">The request context.</param>
        /// <param name="overrideTimeout">Overrides the theme's default notification timeout.</param>
        /// <returns>True of view was handled</returns>
        protected virtual bool HandleNotificationMessage(RequestContext context, TimeSpan?overrideTimeout = null)
        {
            var notificationResult = context.Result as NotificationMessageResult;

            if (notificationResult == null)
            {
                return(false);
            }

            var wrapper = new NotificationViewResultWrapper {
                Model = notificationResult.Model
            };

            if (notificationResult.View != null)
            {
                wrapper.View = notificationResult.View;
                notificationResult.View.DataContext = wrapper.Model;
            }
            else
            {
                wrapper.View = Controller.LoadView(StandardViews.Notification);
                if (wrapper.View != null)
                {
                    wrapper.View.DataContext = wrapper.Model;
                }
            }

            if (NotificationSort == NotificationSort.NewestFirst)
            {
                CurrentNotifications.Add(wrapper);
            }
            else
            {
                CurrentNotifications.Insert(0, wrapper);
            }

            while (CurrentNotifications.Count > MaximumNotificationCount)
            {
                // Handling this like a stack, popping the oldest one off
                if (NotificationSort == NotificationSort.NewestFirst)
                {
                    CurrentNotifications.RemoveAt(0);
                }
                else
                {
                    CurrentNotifications.RemoveAt(CurrentNotifications.Count - 1);
                }
            }
            CurrentNotificationsCount = CurrentNotifications.Count;

            RaiseEvent(new RoutedEventArgs(NotificationChangedEvent));

            var timeout = overrideTimeout ?? NotificationTimeout;

            wrapper.InternalTimer = new Timer(state => Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                CurrentNotifications.Remove(wrapper);
                CurrentNotificationsCount = CurrentNotifications.Count;
            })), null, timeout, new TimeSpan(-1));

            return(true);
        }
Example #2
0
        /* =============
         * = FUNCTIONS =
         * =============
         */



        private void SetMessenger()
        {
            Messenger.Default.Register <ConsoleNotification>(this, async(notification) =>
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                {
                    try
                    {
                        switch (notification.typeNotification)
                        {
                        case ConsoleTypeNotification.Error:
                            errors_list.Add(new ConsoleNotificationContent {
                                notifContent = notification, notifIcon = ""
                            });

                            if (ShowErrors)
                            {
                                CurrentNotifications.Insert(0, new ConsoleNotificationContent {
                                    notifContent = notification, notifIcon = ""
                                });
                            }
                            break;

                        case ConsoleTypeNotification.Information:
                            informations_list.Add(new ConsoleNotificationContent {
                                notifContent = notification, notifIcon = ""
                            });

                            if (ShowInformations)
                            {
                                CurrentNotifications.Insert(0, new ConsoleNotificationContent {
                                    notifContent = notification, notifIcon = ""
                                });
                            }

                            break;

                        case ConsoleTypeNotification.Result:
                            results_list.Add(new ConsoleNotificationContent {
                                notifContent = notification, notifIcon = ""
                            });

                            if (ShowResults)
                            {
                                CurrentNotifications.Insert(0, new ConsoleNotificationContent {
                                    notifContent = notification, notifIcon = ""
                                });
                            }

                            break;

                        case ConsoleTypeNotification.Warning:
                            warnings_list.Add(new ConsoleNotificationContent {
                                notifContent = notification, notifIcon = ""
                            });

                            if (ShowWarnings)
                            {
                                CurrentNotifications.Insert(0, new ConsoleNotificationContent {
                                    notifContent = notification, notifIcon = ""
                                });
                            }

                            break;
                        }

                        UpdateNotifsNumber();
                    }
                    catch { }
                });
            });

            Messenger.Default.Register <EditorViewNotification>(this, (notification_ui) =>
            {
                try
                {
                    SetTheme();
                }
                catch { }
            });
        }