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