private void OnNotificationViewUnloaded(object sender, EventArgs e) { var notificationControl = sender as NotificationView; if (notificationControl == null) { return; } var notification = notificationControl.DataContext as INotification; if (notification == null) { var notificationViewModel = notificationControl.DataContext as NotificationViewModel; if (notificationViewModel == null) { notificationViewModel = notificationControl.ViewModel as NotificationViewModel; } if (notificationViewModel != null) { notification = notificationViewModel.Notification; } } if (notification != null) { CurrentNotifications.Remove(notification); ClosedNotification?.Invoke(this, new NotificationEventArgs(notification)); } }
public void ShowNotification(INotification notification) { Argument.IsNotNull(() => notification); if (IsSuspended) { Log.Debug("Notifications are suspended, queueing notification"); _notificationsQueue.Enqueue(notification); return; } _dispatcherService.BeginInvoke(() => { EnsureMainWindow(); var hasActiveWindows = HasActiveWindows(); if (!hasActiveWindows && notification.Priority <= NotificationPriority.Normal) { Log.Debug($"Not showing notification '{notification}' since priority is '{notification.Priority}' and app has no active windows."); return; } Log.Debug("Showing notification '{0}'", notification); var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count); var popup = new Popup(); popup.AllowsTransparency = true; popup.Placement = PlacementMode.Custom; popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) => { var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X); var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y); var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None); var ttplaces = new[] { popupPlacement }; return(ttplaces); }; var notificationViewModel = _viewModelFactory.CreateViewModel <NotificationViewModel>(notification, null); notificationViewModel.ClosedAsync += async(sender, e) => popup.IsOpen = false; var notificationView = new NotificationView(); notificationView.DataContext = notificationViewModel; notificationView.Unloaded += OnNotificationViewUnloaded; popup.Child = notificationView; popup.IsOpen = true; OpenedNotification?.Invoke(this, new NotificationEventArgs(notification)); CurrentNotifications.Add(notification); }); }
public void ShowNotification(INotification notification) { Argument.IsNotNull(() => notification); if (IsSuspended) { Log.Debug("Notifications are suspended, queueing notification"); _notificationsQueue.Enqueue(notification); return; } EnsureMainWindow(); _dispatcherService.BeginInvoke(() => { Log.Debug("Showing notification '{0}'", notification); var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count); var popup = new Popup(); popup.AllowsTransparency = true; popup.Placement = PlacementMode.Custom; popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) => { var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X); var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y); var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None); var ttplaces = new [] { popupPlacement }; return(ttplaces); }; //popup.Placement = PlacementMode.AbsolutePoint; //popup.PlacementRectangle = new Rect(notificationLocation.X, notificationLocation.Y, NotificationSize.Width, NotificationSize.Height); var notificationViewModel = _viewModelFactory.CreateViewModel <NotificationViewModel>(notification); notificationViewModel.ClosedAsync += async(sender, e) => popup.IsOpen = false; // TODO: consider factory var notificationView = new NotificationView(); notificationView.DataContext = notificationViewModel; notificationView.Unloaded += OnNotificationViewUnloaded; popup.Child = notificationView; popup.IsOpen = true; OpenedNotification.SafeInvoke(this, new NotificationEventArgs(notification)); CurrentNotifications.Add(notification); }); }
private void RefreshNotificationsList() { CurrentNotifications.Clear(); List <ConsoleNotificationContent> temp_list = new List <ConsoleNotificationContent>(); if (ShowErrors) { foreach (var element in errors_list) { temp_list.Add(element); } } if (ShowInformations) { foreach (var element in informations_list) { temp_list.Add(element); } } if (ShowResults) { foreach (var element in results_list) { temp_list.Add(element); } } if (ShowWarnings) { foreach (var element in warnings_list) { temp_list.Add(element); } } temp_list.Sort((a, b) => b.notifDate.CompareTo(a.notifDate)); foreach (var element in temp_list) { CurrentNotifications.Add(element); } }
/// <summary> /// Clears all notifications /// </summary> public void ClearNotifications() { CurrentNotifications.Clear(); CurrentNotificationsCount = CurrentNotifications.Count; RaiseEvent(new RoutedEventArgs(NotificationChangedEvent)); }
/// <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); }
/* ============= * = 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 { } }); }