public static void UnscheduleAlarm(Alarm alarmToUnschedule) { ScheduledToastNotification foundNotification = FindToastNotificationForID(GetAlarmNotificationID(alarmToUnschedule)); if (foundNotification != null) { toastNotifier.RemoveFromSchedule(foundNotification); } }
public void CancelScheduled(Guid id) { var group = GetGroup(id); Logger.Current.Info($"Remove from schedule '{group}'"); foreach (var toast in notifier.GetScheduledToastNotifications()) { if (toast.Group == group) { notifier.RemoveFromSchedule(toast); } } }
private void DeleteNotification() { if (NotificationListView.SelectedItem == null) { ShowMessage("Brak wybranego elementu."); } else { NotificationItem notItem = NotificationListView.SelectedItem as NotificationItem; String id = notItem.Id; ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); List <ScheduledToastNotification> initialList = new List <ScheduledToastNotification>(); initialList = notifier.GetScheduledToastNotifications().ToList(); foreach (ScheduledToastNotification item in initialList) { if (item.Id == id) { notifier.RemoveFromSchedule(item); break; } } NotificationList.Remove(notItem); } }
private void ClearToast() { foreach (ScheduledToastNotification toast in _notifier.GetScheduledToastNotifications()) { _notifier.RemoveFromSchedule(toast); } }
/// <summary> /// Event Handler for the Expiration Reminder Slider when user changes the value /// Enables alarm /// </summary> /// <param name="sender"> Object which indicates where the event occured </param> /// <param name="e"> An object that contains information about the event </param> void ExpirationReminderSlider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { ExpirationReminderSlider.Value = Math.Round(ExpirationReminderSlider.Value, 0); if (ExpirationReminderSlider.Value == 1) { customAlarmScheduledToast = new ScheduledToastNotification(toastXml, new DateTime(MainSettings.GetValueOrDefault("TimeReminderKeyName", DateTime.Now.Ticks + 20000000))); toastNotifier.AddToSchedule(customAlarmScheduledToast); ExpirationTimeLabel.Foreground = (SolidColorBrush)App.Current.Resources["PhoneAccentBrush"]; return; } else { //if(toastNotifier.GetScheduledToastNotifications[0].equals(customAlarmScheduledToast)) { toastNotifier.RemoveFromSchedule(customAlarmScheduledToast); } } if ((Visibility)App.Current.RequestedTheme == Windows.UI.Xaml.Visibility.Collapsed) { ExpirationTimeLabel.Foreground = new SolidColorBrush(Colors.WhiteSmoke); } else { ExpirationTimeLabel.Foreground = new SolidColorBrush(Colors.DarkGray); } }
/// <summary> /// Cancels the scheduled display of a specified ScheduledToastNotification. /// </summary> /// <param name="scheduledToast">The notification to remove from the schedule.</param> public void RemoveFromSchedule(ScheduledToastNotification scheduledToast) { #if WIN32 PreprocessScheduledToast(scheduledToast); #endif _notifier.RemoveFromSchedule(scheduledToast); }
public void RemoveScheduled(ToastId toastId) { var notification = notifier.GetScheduledToastNotifications().Where(n => n.Tag == toastId.Tag && n.Group == toastId.Group).FirstOrDefault(); if (notification != null) { notifier.RemoveFromSchedule(notification); } }
/// <summary> /// Cancels the specified notification identifier. /// </summary> /// <param name="notificationId">The notification identifier.</param> public void Cancel(object notificationId) { string id = notificationId as string; if (string.IsNullOrEmpty(id)) { return; } foreach (var n in notifier.GetScheduledToastNotifications()) { if (n.Id == id) { notifier.RemoveFromSchedule(n); break; } } }
private static void RemoveNotification(ToastNotifier notifier, string notificationId) { var notifications = notifier.GetScheduledToastNotifications(); var countdownNotifications = notifications.Where(x => x.Id == notificationId); foreach (var notification in countdownNotifications) { notifier.RemoveFromSchedule(notification); } }
public void Remove(ListBox display) { if (display.SelectedIndex > -1) { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.RemoveFromSchedule(notifier.GetScheduledToastNotifications().Where( p => p.Id.Equals(((Item)display.SelectedItem).Id)).SingleOrDefault()); display.Items.RemoveAt(display.SelectedIndex); } }
public void ClearAllNotifications() { if (_notificationManager != null) { var scheduledNotifications = _notificationManager.GetScheduledToastNotifications(); foreach (var notification in scheduledNotifications) { _notificationManager.RemoveFromSchedule(notification); } } }
/// <summary> /// Cancel a local notification /// </summary> /// <param name="id">Id of the notification to cancel</param> public void Cancel(int id) { var scheduledNotifications = _manager.GetScheduledToastNotifications(); var notification = scheduledNotifications.FirstOrDefault(n => n.Id.Equals(id.ToString(), StringComparison.OrdinalIgnoreCase)); if (notification != null) { _manager.RemoveFromSchedule(notification); } }
public static void UnScheduleToast(string idToast) { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> scheduled = notifier.GetScheduledToastNotifications(); var q = from ScheduledToastNotification toast in scheduled where toast.Id == idToast select toast; foreach (ScheduledToastNotification t in q) { notifier.RemoveFromSchedule(t); } }
public static void RemoveAllScheduledToasts() { // Create the toast notifier ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); // Get the list of scheduled toasts that haven't appeared yet IReadOnlyList <ScheduledToastNotification> scheduledToasts = notifier.GetScheduledToastNotifications(); foreach (var item in scheduledToasts) { notifier.RemoveFromSchedule(item); } }
public static void DeleteScheduledNotification(string id) { ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> scheduled = toastNotifier.GetScheduledToastNotifications(); foreach (ScheduledToastNotification notify in scheduled) { if (notify.Id == id) { toastNotifier.RemoveFromSchedule(notify); } } }
/// <summary> /// Remove Reminder for specific ToDo /// </summary> /// <param name="tdItem">ToDo item</param> public static void Remove(ToDo tdItem) { ToastNotifier updater = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> scheduled = updater.GetScheduledToastNotifications(); for (var i = 0; i < scheduled.Count; i++) { if (scheduled[i].Id == tdItem.UniqueId) { updater.RemoveFromSchedule(scheduled[i]); } } }
public static void DisableAllBossNotifications() { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> scheduledToasts = notifier.GetScheduledToastNotifications(); foreach (var toast in scheduledToasts) { if (BossExists(toast.Group)) { notifier.RemoveFromSchedule(toast); } } }
private static void DeleteExistingNotification(ToastNotifier toastNotifier, string notificationId) { if (string.IsNullOrWhiteSpace(notificationId)) { return; } var scheduledNotificaitons = toastNotifier.GetScheduledToastNotifications(); var existingNotificaiton = scheduledNotificaitons.SingleOrDefault(n => n.Id == notificationId); if (existingNotificaiton != null) { toastNotifier.RemoveFromSchedule(existingNotificaiton); } }
public static void CancelNotification(int id) { string strId = "id" + id; ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); foreach (var it in toastNotifier.GetScheduledToastNotifications()) { if (it.Id == strId) { toastNotifier.RemoveFromSchedule(it); } } UnregisterNotification(id); }
static void Schedule( ToastNotifier notifier, XmlDocument doc) { var notification = new ScheduledToastNotification(doc, DateTimeOffset.Now.AddMinutes(1)); notification.Tag = START_NOTIFICATION_ID; notification.ExpirationTime = DateTimeOffset.Now.AddMinutes(2); notification.SuppressPopup = true; notifier.AddToSchedule(notification); notifier.ScheduledToastNotificationShowing += (_, a) => { notifier.RemoveFromSchedule(notification); Schedule(notifier, doc); }; }
public static void CancelAllNotifications() { ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); foreach (var it in toastNotifier.GetScheduledToastNotifications()) { toastNotifier.RemoveFromSchedule(it); } var settings = ApplicationData.Current.LocalSettings; foreach (var it in new List <string>(settings.Values.Keys)) { if (it.StartsWith(STORE_KEY_PREFIX)) { settings.Values.Remove(it); } } }
private void delToast() { // Set up the notification text. var toastXml = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(Windows.UI.Notifications.ToastTemplateType.ToastText02); var strings = toastXml.GetElementsByTagName("text"); strings[0].AppendChild(toastXml.CreateTextNode(param.stype)); strings[1].AppendChild(toastXml.CreateTextNode("Время: " + param.dateTime.ToString())); try { var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, param.dateTime); ToastNotifier not = ToastNotificationManager.CreateToastNotifier(); not.RemoveFromSchedule(toast); } catch (Exception ex) { } }
public static void SetNotificationsEnabled(bool enabled) { var settings = ApplicationData.Current.LocalSettings; settings.Values[DISABLED_KEY] = !enabled; if (!enabled) { ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); foreach (var it in toastNotifier.GetScheduledToastNotifications()) { toastNotifier.RemoveFromSchedule(it); } long currentTime = GetCurrentUnixTimeSeconds(); foreach (var it in new List <string>(settings.Values.Keys)) { if (it.StartsWith(STORE_KEY_PREFIX)) { ApplicationDataCompositeValue registeredNotification = (ApplicationDataCompositeValue)settings.Values[it]; int intervalSeconds = (int)registeredNotification["intervalSeconds"]; if (intervalSeconds > 0) { //Repeated int lastTriggerInSecondsFromNow = (int)((long)registeredNotification["lastTriggerInSeconds"] - currentTime); lastTriggerInSecondsFromNow %= intervalSeconds; if (lastTriggerInSecondsFromNow > 0) { lastTriggerInSecondsFromNow -= intervalSeconds; } registeredNotification["lastTriggerInSeconds"] = currentTime + lastTriggerInSecondsFromNow; settings.Values[it] = registeredNotification; } } } } else { Reschedule(true); } }
// 删除指定的 ScheduledToastNotification 对象 private void btnRemoveScheduledToast_Click(object sender, RoutedEventArgs e) { string notificationId = (string)(sender as FrameworkElement).Tag; // 获取当前 app 的全部 ScheduledToastNotification 对象列表 ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> notifications = toastNotifier.GetScheduledToastNotifications(); int notificationCount = notifications.Count; for (int i = 0; i < notificationCount; i++) { if (notifications[i].Id == notificationId) { // 从计划列表中移除指定的 ScheduledToastNotification 对象 toastNotifier.RemoveFromSchedule(notifications[i]); break; } } ShowScheduledToasts(); }
public static void UpdateWhenRunning() { var settings = ApplicationData.Current.LocalSettings; settings.Values[LAST_TIME_UPDATED_WHEN_RUNNING_KEY] = GetCurrentUnixTimeSeconds(); if (NotificationsEnabled()) { DateTime minTime = DateTime.Now.AddSeconds(CancelInAdvanceSecondsIfDontShowWhenRunning); if (settings.Values.ContainsKey(DONT_SHOW_WHEN_RUNNING_KEY) && (bool)settings.Values[DONT_SHOW_WHEN_RUNNING_KEY]) { ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(); foreach (var it in toastNotifier.GetScheduledToastNotifications()) { if (it.DeliveryTime < minTime) { toastNotifier.RemoveFromSchedule(it); } } } } }
// Remove the notification by checking the list of scheduled notifications for a notification with matching ID. // While it would be possible to manage the notifications by storing a reference to each notification, such practice // causes memory leaks by not allowing the notifications to be collected once they have shown. // It's important to create unique IDs for each notification if they are to be managed later. void Remove_Click(object sender, RoutedEventArgs e) { IList <Object> items = ItemGridView.SelectedItems; for (int i = 0; i < items.Count; i++) { NotificationData item = (NotificationData)items[i]; String itemId = item.ItemId; if (item.IsTile) { TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication(); IReadOnlyList <ScheduledTileNotification> scheduled = updater.GetScheduledTileNotifications(); for (int j = 0; j < scheduled.Count; j++) { if (scheduled[j].Id == itemId) { updater.RemoveFromSchedule(scheduled[j]); } } } else { ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); IReadOnlyList <ScheduledToastNotification> scheduled = notifier.GetScheduledToastNotifications(); for (int j = 0; j < scheduled.Count; j++) { if (scheduled[j].Id == itemId) { notifier.RemoveFromSchedule(scheduled[j]); } } } } rootPage.NotifyUser("Removed selected scheduled notifications", NotifyType.StatusMessage); RefreshListView(); }
private void SetupToast() { var notifications = notificationManager.GetScheduledToastNotifications(); for (int i = 0; i < notifications.Count; i++) { notificationManager.RemoveFromSchedule(notifications[i]); } string title = "ClockOutCalculator"; string content = "Ora di uscire!"; string image = "https://picsum.photos/360/202?image=883"; string logo = "ms-appx:///Assets/2048-200.png"; // Construct the visuals of the toast ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = title }, new AdaptiveText() { Text = content }, new AdaptiveImage() { Source = image } }, AppLogoOverride = new ToastGenericAppLogo() { Source = logo, HintCrop = ToastGenericAppLogoCrop.Circle } } }; int conversationId = 384928; ToastContent toastContent = new ToastContent() { Visual = visual, // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "viewConversation" }, { "conversationId", conversationId.ToString() } }.ToString() }; DateTimeOffset toastTime = new DateTimeOffset(DateTime.Today.Add(clockOut)); if (toastTime.CompareTo(DateTimeOffset.Now) > 0) { toast = new ScheduledToastNotification(toastContent.GetXml(), toastTime) { Tag = "18365", Group = "clockOutPosts", ExpirationTime = DateTime.Today.Add(clockOut).AddHours(1) }; // And create the toast notification notificationManager.AddToSchedule(toast); } }
public void Dispose() => toastNotifier.RemoveFromSchedule(toastNotification);
private async void SetLogFile(object sender, RoutedEventArgs e) { progress.Visibility = Visibility.Visible; App.DisableSelection = true; App.SgstBox.IsEnabled = false; FileOpenPicker open = new FileOpenPicker(); open.FileTypeFilter.Add(".elog"); StorageFile file = await open.PickSingleFileAsync(); if (file != null) { string text; if (add.IsChecked.Value) { text = App.Eng ? "Irrevocable operation. New records will be added to the current log." : "Необратимая операция. Новые записи будут добавлены в текущий журнал."; } else { text = App.Eng ? "Irrevocable operation. Current log will be erased." : "Необратимая операция. Текущий журнал будет удален."; } MessageDialog dialog = new MessageDialog(text); string proceed, cancel; if (App.Eng) { proceed = "Proceed"; cancel = "Cancel"; } else { proceed = "Продолжить"; cancel = "Отмена"; } bool consent = false; dialog.Commands.Add(new UICommand(proceed, x => consent = true)); dialog.Commands.Add(new UICommand(cancel)); await dialog.ShowAsync(); if (!consent) { App.DisableSelection = false; App.SgstBox.IsEnabled = true; progress.Visibility = Visibility.Collapsed; return; } file = await file.CopyAsync(ApplicationData.Current.TemporaryFolder, "events.elog", NameCollisionOption.ReplaceExisting); using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite)) { using (DataReader reader = new DataReader(stream.GetInputStreamAt(0))) { await reader.LoadAsync((uint)code.Length); byte[] coded = new byte[code.Length]; for (int i = 0; i < coded.Length; i++) { coded[i] = (byte)(reader.ReadByte() ^ code[i]); } using (DataWriter writer = new DataWriter(stream.GetOutputStreamAt(0))) writer.WriteBytes(coded); } } StorageFolder folder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("temp", CreationCollisionOption.ReplaceExisting); try { await Task.Run(() => ZipFile.ExtractToDirectory(file.Path, folder.Path)); } catch { await(new MessageDialog("Wrong file format!")).ShowAsync(); await file.DeleteAsync(); await folder.DeleteAsync(); App.DisableSelection = false; App.SgstBox.IsEnabled = true; progress.Visibility = Visibility.Collapsed; return; } await file.DeleteAsync(); if (add.IsChecked.Value) { XmlDocument doc = await XmlDocument.LoadFromFileAsync(await folder.GetFileAsync("data.xml")); IXmlNode root = doc.FirstChild; StorageFolder Icons = await folder.TryGetItemAsync("Icons") as StorageFolder; StorageFolder Videos = await folder.TryGetItemAsync("Videos") as StorageFolder; StorageFolder Audios = await folder.TryGetItemAsync("Audios") as StorageFolder; StorageFolder Inks = await folder.TryGetItemAsync("Inks") as StorageFolder; StorageFolder locIcons = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Icons", CreationCollisionOption.OpenIfExists); StorageFolder locVideos = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Videos", CreationCollisionOption.OpenIfExists); StorageFolder locAudios = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Audios", CreationCollisionOption.OpenIfExists); StorageFolder locInks = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Inks", CreationCollisionOption.OpenIfExists); foreach (IXmlNode evntNode in root.ChildNodes) { Event evnt = new Event(evntNode); if (evnt.IsPast && !evnt.Keep) { continue; } if (App.Storage.Exist(evnt.Guid)) { continue; } if (evnt.IconPath.AbsoluteUri != "ms-appx:///Assets/item.png") { StorageFile iconFile = await Icons.GetFileAsync(Path.GetFileName(evnt.IconPath.AbsolutePath)); await iconFile.CopyAsync(locIcons); } switch (evnt.MediaMessageType) { case MediaMessageType.Video: StorageFile videoFile = await Videos.GetFileAsync(Path.GetFileName(evnt.MediaMessageUri.AbsolutePath)); await videoFile.CopyAsync(locVideos); break; case MediaMessageType.Voice: StorageFile audioFile = await Audios.GetFileAsync(Path.GetFileName(evnt.MediaMessageUri.AbsolutePath)); await audioFile.CopyAsync(locAudios); break; } if (evnt.HasStroke) { await(await Inks.GetFileAsync(evnt.Guid.ToString() + ".gif")).CopyAsync(locInks); } if (!evnt.IsPast && evnt.Alarm != null) { var xml = App.FormNotification(evnt.Name, evnt.Message, evnt.IconPath.AbsoluteUri, evnt.Guid.ToString()); ScheduledToastNotification notification = new ScheduledToastNotification(xml, evnt.Alarm.Value); _notifier.AddToSchedule(notification); } await evnt.SaveToFileAsync(); App.Storage.AddEvent(evnt); } } else { foreach (var item in await ApplicationData.Current.LocalFolder.GetItemsAsync()) { await item.DeleteAsync(); } var notifs = _notifier.GetScheduledToastNotifications(); foreach (var notif in notifs) { _notifier.RemoveFromSchedule(notif); } foreach (var item in await folder.GetItemsAsync()) { if (item.IsOfType(StorageItemTypes.File)) { await((StorageFile)item).MoveAsync(ApplicationData.Current.LocalFolder); } else if (item.IsOfType(StorageItemTypes.Folder)) { StorageFolder fld = (StorageFolder)item; StorageFolder locfld = await ApplicationData.Current.LocalFolder.CreateFolderAsync(fld.DisplayName); foreach (var itm in await fld.GetFilesAsync()) { await itm.MoveAsync(locfld); } } } App.Storage = await EventStorage.DeserializeAsync(); foreach (var year in App.Storage.CallendarActive) { foreach (var mnth in year.Months) { foreach (var evnt in mnth.Events) { if (evnt.Alarm != null) { var xml = App.FormNotification(evnt.Name, evnt.Message, evnt.IconPath.AbsoluteUri, evnt.Guid.ToString()); ScheduledToastNotification notification = new ScheduledToastNotification(xml, evnt.Alarm.Value); _notifier.AddToSchedule(notification); } } } } } await folder.DeleteAsync(); } App.DisableSelection = false; App.SgstBox.IsEnabled = true; progress.Visibility = Visibility.Collapsed; }