public static XmlDocument GetToastXml(this ToastContentBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } #if TOAST return(builder.GetToastContent().GetXml()); #else return(new XmlDocument()); #endif }
public void ShowNotification(string text, string secondaryText = null) { var builder = new ToastContentBuilder().AddText(text); if (!string.IsNullOrWhiteSpace(secondaryText)) { builder.AddText(secondaryText); } Application.Current.Dispatcher.Invoke(() => { var toast = new ToastNotification(builder.GetToastContent().GetXml()); DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }); }
private static XmlDocument GeneratePayload(AccountDataItem account, ViewItemSchedule s) { var c = s.Class; var builder = new ToastContentBuilder() .AddToastActivationInfo(new ViewClassArguments() { LocalAccountId = account.LocalAccountId, ItemId = c.Identifier, LaunchSurface = LaunchSurface.Toast }.SerializeToString(), ToastActivationType.Foreground) .SetToastScenario(ToastScenario.Reminder) .AddText(c.Name) .AddText(string.Format(_timeToTime, _timeFormatter.Format(s.StartTime), _timeFormatter.Format(s.EndTime))); if (!string.IsNullOrWhiteSpace(s.Room)) { builder.AddText(s.Room); } builder.AddToastInput(new ToastSelectionBox("snoozeTime") { DefaultSelectionBoxItemId = "5", Items = { new ToastSelectionBoxItem("5", PowerPlannerResources.GetXMinutes(5)), new ToastSelectionBoxItem("10", PowerPlannerResources.GetXMinutes(10)), new ToastSelectionBoxItem("15", PowerPlannerResources.GetXMinutes(15)), new ToastSelectionBoxItem("30", PowerPlannerResources.GetXMinutes(30)), new ToastSelectionBoxItem("45", PowerPlannerResources.GetXMinutes(45)) } }); builder.AddButton(new ToastButtonSnooze() { SelectionBoxId = "snoozeTime" }); builder.AddButton(new ToastButtonDismiss()); return(builder.GetToastContent().GetXml()); }
public static ToastNotification CreateToastNotificationForMessage(DiscordMessage message) { var title = GetMessageTitle(message); var text = GetMessageContent(message); var channelName = GetChannelHeaderName(message.Channel); var animated = message.Author.AvatarHash?.StartsWith("a_") ?? false; var avatarUrl = message.Author.GetAvatarUrl(animated ? ImageFormat.Gif : ImageFormat.Png, 128); var replyString = message.Channel is DiscordDmChannel ? $"Reply to @{message.Author.Username}..." : $"Message #{message.Channel.Name}..."; var builder = new ToastContentBuilder() .AddHeader(message.ChannelId.ToString(), channelName, $"-channelId={message.ChannelId}") .AddAppLogoOverride(new Uri(avatarUrl), ToastGenericAppLogoCrop.Circle) .AddText(title, AdaptiveTextStyle.Title) .AddText(text, AdaptiveTextStyle.Caption) .AddInputTextBox("tbReply", replyString) .AddButton("tbReply", "Reply", ToastActivationType.Background, $"-channelId={message.ChannelId}") .AddToastActivationInfo($"-channelId={message.ChannelId} -messageId={message.Id}", ToastActivationType.Foreground) .AddCustomTimeStamp(message.Timestamp.DateTime); if (GetToastThumbnail(message, out var width, out var height, out var proxyUrl)) { Drawing.ScaleProportions(ref width, ref height, 640, 360); builder.AddHeroImage(new Uri(proxyUrl + $"?format=jpeg&width={(int)width}&height={(int)height}")); } var toastContent = builder.GetToastContent(); var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); return(new ToastNotification(doc) { NotificationMirroring = NotificationMirroring.Allowed, Group = message.Channel.Id.ToString(), RemoteId = message.Id.ToString(), }); }
private void ShowEjectNotification() { try { ToastNotificationManager.History.Remove("MergeVideoNotification"); ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("Transcode", ToastActivationType.Foreground) .AddText(Globalization.GetString("Eject_Toast_Text_1")) .AddText(Globalization.GetString("Eject_Toast_Text_2")) .AddText(Globalization.GetString("Eject_Toast_Text_3")); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); } catch (Exception ex) { LogTracer.Log(ex, "Toast notification could not be sent"); } }
private async void NavigationButton_Click(object sender, RoutedEventArgs e) { await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-broadfilesystemaccess")); try { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Reminder) .AddText(Globalization.GetString("Toast_BroadFileSystemAccess_Text_1")) .AddText(Globalization.GetString("Toast_BroadFileSystemAccess_Text_2")) .AddButton(Globalization.GetString("Toast_BroadFileSystemAccess_ActionButton_1"), ToastActivationType.Foreground, "Restart") .AddButton(new ToastButtonDismiss(Globalization.GetString("Toast_BroadFileSystemAccess_ActionButton_2"))); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); } catch (Exception ex) { LogTracer.Log(ex, "Toast notification could not be sent"); } finally { await ApplicationView.GetForCurrentView().TryConsolidateAsync(); } }
private void SendActivateToast() { if (IsInBackgroundMode && (FullTrustProcessController.IsAnyActionExcutingInAllControllers || GeneralTransformer.IsAnyTransformTaskRunning || QueueTaskController.IsAnyTaskRunningInController)) { try { ToastNotificationManager.History.Remove("EnterBackgroundTips"); if (PowerManager.EnergySaverStatus == EnergySaverStatus.On) { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Reminder) .AddToastActivationInfo("EnterBackgroundTips", ToastActivationType.Foreground) .AddText(Globalization.GetString("Toast_EnterBackground_Text_1")) .AddText(Globalization.GetString("Toast_EnterBackground_Text_2")) .AddText(Globalization.GetString("Toast_EnterBackground_Text_4")) .AddButton(new ToastButton(Globalization.GetString("Toast_EnterBackground_ActionButton"), "EnterBackgroundTips")) .AddButton(new ToastButtonDismiss(Globalization.GetString("Toast_EnterBackground_Dismiss"))); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml()) { Tag = "EnterBackgroundTips", Priority = ToastNotificationPriority.High }); } } catch (Exception ex) { LogTracer.Log(ex, "Toast notification could not be sent"); } } }
private void ShowUpdateNotification() { if (ApplicationData.Current.LocalSettings.Values["LanguageOverride"] is int LanguageIndex) { ToastNotificationManager.History.Clear(); switch (LanguageIndex) { case 0: { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("ms-windows-store://pdp/?productid=9N88QBQKF2RS", ToastActivationType.Protocol) .AddText("针对RX文件管理器的更新已发布!", AdaptiveTextStyle.Title) .AddText("包含最新的功能和改进", AdaptiveTextStyle.Subtitle) .AddText("点击以立即更新", AdaptiveTextStyle.Subtitle); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); break; } case 1: { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("ms-windows-store://pdp/?productid=9N88QBQKF2RS", ToastActivationType.Protocol) .AddText("An update for the RX-Explorer is available!", AdaptiveTextStyle.Title) .AddText("Includes the latest features and improvements", AdaptiveTextStyle.Subtitle) .AddText("Click to update now", AdaptiveTextStyle.Subtitle); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); break; } case 2: { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("ms-windows-store://pdp/?productid=9N88QBQKF2RS", ToastActivationType.Protocol) .AddText("Une mise à jour pour RX Explorer est disponible!", AdaptiveTextStyle.Title) .AddText("Comprend les dernières fonctionnalités et améliorations", AdaptiveTextStyle.Subtitle) .AddText("Cliquez pour mettre à jour maintenant", AdaptiveTextStyle.Subtitle); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); break; } case 3: { ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("ms-windows-store://pdp/?productid=9N88QBQKF2RS", ToastActivationType.Protocol) .AddText("RX檔案管家的更新已發布!", AdaptiveTextStyle.Title) .AddText("包括最新功能和改進", AdaptiveTextStyle.Subtitle) .AddText("點擊立即更新", AdaptiveTextStyle.Subtitle); ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); break; } } } }
private void ShowUpdateNotification() { if (ApplicationData.Current.LocalSettings.Values["LanguageOverride"] is int LanguageIndex) { ToastNotificationManager.History.Clear(); ToastContentBuilder Builder = new ToastContentBuilder() .SetToastScenario(ToastScenario.Default) .AddToastActivationInfo("ms-windows-store://pdp/?productid=9N88QBQKF2RS", ToastActivationType.Protocol); switch (LanguageIndex) { case 0: { Builder.AddText("针对RX文件管理器的更新已发布!", AdaptiveTextStyle.Title) .AddText("包含最新的功能和改进", AdaptiveTextStyle.Subtitle) .AddText("点击以立即更新", AdaptiveTextStyle.Subtitle); break; } case 1: { Builder.AddText("An update for the RX-Explorer is available!", AdaptiveTextStyle.Title) .AddText("Includes the latest features and improvements", AdaptiveTextStyle.Subtitle) .AddText("Click to update now", AdaptiveTextStyle.Subtitle); break; } case 2: { Builder.AddText("Une mise à jour pour RX Explorer est disponible!", AdaptiveTextStyle.Title) .AddText("Comprend les dernières fonctionnalités et améliorations", AdaptiveTextStyle.Subtitle) .AddText("Cliquez pour mettre à jour maintenant", AdaptiveTextStyle.Subtitle); break; } case 3: { Builder.AddText("RX檔案管家的更新已發布!", AdaptiveTextStyle.Title) .AddText("包括最新功能和改進", AdaptiveTextStyle.Subtitle) .AddText("點擊立即更新", AdaptiveTextStyle.Subtitle); break; } case 4: { Builder.AddText("¡Se ha lanzado una actualización para el administrador de archivos RX!", AdaptiveTextStyle.Title) .AddText("Contiene las últimas funciones y mejoras.", AdaptiveTextStyle.Subtitle) .AddText("Haga clic para actualizar ahora", AdaptiveTextStyle.Subtitle); break; } case 5: { Builder.AddText("Ein Update für den RX-Dateimanager wurde veröffentlicht!", AdaptiveTextStyle.Title) .AddText("Enthält die neuesten Funktionen und Verbesserungen", AdaptiveTextStyle.Subtitle) .AddText("Klicken Sie hier, um jetzt zu aktualisieren", AdaptiveTextStyle.Subtitle); break; } } ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(Builder.GetToastContent().GetXml())); } }
private async void NotiBootstrap() { var builder = new ToastContentBuilder(); try { var infos = await AppDiagnosticInfo.RequestInfoForAppAsync(); var resourceInfos = infos[0].GetResourceGroups(); await resourceInfos[0].StartSuspendAsync(); if (UWPAppEnvironment.toastNotifier == null) { UWPAppEnvironment.toastNotifier = ToastNotificationManager.CreateToastNotifier(); } var notiUWP = new NotiScheduleUWP(); notiUWP.CancelAll(); notiUWP.ScheduleAll(); builder.AddToastActivationInfo("BootNotiRegister", ToastActivationType.Foreground); builder.AddText(AppResources.BootAlarmRegisterSuccess); } catch (Exception) { builder.AddText(AppResources.BootAlarmRegisterFail); } finally { if (builder != null) { UWPAppEnvironment.toastNotifier.AddToSchedule(new ScheduledToastNotification(builder.GetToastContent().GetXml(), DateTime.Now.AddSeconds(3))); } await Task.Delay(3000); Exit(); } }