private static void AddImage(IDistributedNotification notification, ToastContent content) { if (string.IsNullOrEmpty(notification.ContentImageUrl) || !File.Exists(notification.ContentImageUrl)) { return; } var isError = notification.NotificationErrorType == DistributedNotificationErrorType.Error; if (isError) { content.Visual.BindingGeneric.HeroImage = new ToastGenericHeroImage { Source = notification.ContentImageUrl }; } else { content.Visual.BindingGeneric.Children.Add(new AdaptiveImage { Source = notification.ContentImageUrl }); } }
private static ToastContent SimpleToastContent(IDistributedNotification notification) { var isError = notification.NotificationErrorType == DistributedNotificationErrorType.Error; return(new ToastContent { Launch = notification.FeedbackArguments, ActivationType = ToastActivationType.Protocol, Duration = isError ? ToastDuration.Long : ToastDuration.Short, Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveText { Text = notification.Title, HintMaxLines = 1 }, new AdaptiveText { Text = notification.Content } } } } }); }
private ToastContent CreateToast(IDistributedNotification notification) { var content = SimpleToastContent(notification); AddAppLogo(notification, content); AddAttribution(notification, content); AddImage(notification, content); return(content); }
public DistributedNotificationViewModel(IDistributedNotification notification) { IconType = SetIconType(notification); BuildStatus = SetBuildStatus(notification); Messages = SetMessages(notification); var(width, height) = SetWidthAndHeight(notification); Width = width; Height = height; BigViewVisibility = GetBigViewVisibility(notification); SmallViewVisibility = BigViewVisibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; }
private IconType SetIconType(IDistributedNotification notification) { return(notification.NotificationType switch { DistributedNotificationType.Branch => IconType.Branch, DistributedNotificationType.Definition => IconType.Definition, DistributedNotificationType.Build => IconType.GroupingSolo, DistributedNotificationType.Builds => IconType.BuildNotification, DistributedNotificationType.GeneralError => IconType.Lightning, DistributedNotificationType.DefinitionAndBranch => IconType.GroupingSolo, _ => IconType.Info });
private static void AddAttribution(IDistributedNotification notification, ToastContent content) { if (string.IsNullOrEmpty(notification.Source)) { return; } content.Visual.BindingGeneric.Attribution = new ToastGenericAttributionText { Text = notification.Source }; }
private static void AddAppLogo(IDistributedNotification notification, ToastContent content) { if (string.IsNullOrEmpty(notification.AppIconUrl) || !File.Exists(notification.AppIconUrl)) { return; } content.Visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo { Source = notification.AppIconUrl, HintCrop = ToastGenericAppLogoCrop.None }; }
private BuildStatus SetBuildStatus(IDistributedNotification notification) { switch (notification.NotificationErrorType) { case DistributedNotificationErrorType.Error: return(BuildStatus.Failed); case DistributedNotificationErrorType.Success: return(BuildStatus.Succeeded); case DistributedNotificationErrorType.Cancel: return(BuildStatus.Cancelled); default: return(BuildStatus.None); } }
public void Clear(IDistributedNotification notification) { var tag = _toastNotificationFactory.NotificationTag(notification); var notifications = ToastNotificationManager.History.GetHistory(ApplicationId).ToList(); if (notifications.Any(n => n.Tag == tag)) { try { ToastNotificationManager.History.Remove(tag, Group, ApplicationId); } catch (Exception) { // ignored } } }
public void Process(IDistributedNotification notification) { _toastNotificationFactory.Process(notification); }
public DistributedNotificationReceivedEventArgs(IDistributedNotification distributedNotification) { DistributedNotification = distributedNotification; }
private Visibility GetBigViewVisibility(IDistributedNotification notification) { return(notification.NotificationErrorType == DistributedNotificationErrorType.Error ? Visibility.Visible : Visibility.Collapsed); }
public string NotificationTag(IDistributedNotification notification) => notification.BasedOnNotification?.ToString() ?? "";
public void Process(IDistributedNotification notification) { var toast = CreateToast(notification); PublishToast(toast, NotificationTag(notification)); }