예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        // 显示当前 app 的全部 ScheduledToastNotification 列表
        private void ShowScheduledToasts()
        {
            // 获取当前 app 的全部 ScheduledToastNotification 对象列表
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            IReadOnlyList <ScheduledToastNotification> notifications = toastNotifier.GetScheduledToastNotifications();

            listBox.ItemsSource = notifications;
        }
        /// <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;
                }
            }
        }
 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);
     }
 }
예제 #6
0
        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);
            }
        }
        /// <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);
            }
        }
예제 #8
0
 public void ClearAllNotifications()
 {
     if (_notificationManager != null)
     {
         var scheduledNotifications = _notificationManager.GetScheduledToastNotifications();
         foreach (var notification in scheduledNotifications)
         {
             _notificationManager.RemoveFromSchedule(notification);
         }
     }
 }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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);
                }
            }
        }
예제 #11
0
        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 DisableAllBossNotifications()
        {
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
            IReadOnlyList <ScheduledToastNotification> scheduledToasts = notifier.GetScheduledToastNotifications();

            foreach (var toast in scheduledToasts)
            {
                if (BossExists(toast.Group))
                {
                    notifier.RemoveFromSchedule(toast);
                }
            }
        }
예제 #13
0
        /// <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]);
                }
            }
        }
        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);
            }
        }
예제 #15
0
        /// <summary>
        /// returns the <see cref="ScheduledToastNotification"/> whose id matches the passed id and whose <see cref="ScheduledToastNotification.Group"/> matches <see cref="TOAST_GROUP"/>
        /// </summary>
        /// <param name="id"></param>
        /// <returns>the ScheduledToastNotification if one was found, else returns null</returns>
        private static ScheduledToastNotification FindToastNotificationForID(string id)
        {
            IReadOnlyList <ScheduledToastNotification> scheduledToasts = toastNotifier.GetScheduledToastNotifications();

            // find the scheduled toast to cancel
            try
            {
                return(scheduledToasts.First(toast => toast.Id == id && toast.Group == TOAST_GROUP && toast.Tag == id));
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #16
0
        private void PrepareNotificationListView()
        {
            ToastNotifier notifier =
                ToastNotificationManager.CreateToastNotifier();

            List <ScheduledToastNotification> initialList = new List <ScheduledToastNotification>();

            initialList = notifier.GetScheduledToastNotifications().ToList();

            var collection = ParseInitialListToNotificationItemList(initialList);

            NotificationList = new ObservableCollection <NotificationItem>(collection);

            NotificationListView.ItemsSource = NotificationList;
        }
    public void Init(ListBox display)
    {
        display.Items.Clear();
        IReadOnlyList <ScheduledToastNotification> list = _notifier.GetScheduledToastNotifications();

        foreach (ScheduledToastNotification item in list)
        {
            display.Items.Add(new Item
            {
                Id      = item.Id,
                Time    = item.Content.GetElementsByTagName("text")[0].InnerText,
                Content = item.Content.GetElementsByTagName("text")[1].InnerText,
            });
        }
    }
예제 #18
0
        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);
        }
예제 #19
0
        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);
                }
            }
        }
예제 #20
0
        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);
            }
        }
예제 #21
0
        /// <summary>
        /// Searching Notifications for spesific ToDo item unique Id.
        /// </summary>
        /// <param name="uniqueId">ToDo item unique id</param>
        /// <returns>If notification exists return the ScheduledToastNotification</returns>
        private static ScheduledToastNotification GetNotificationForToDo(string uniqueId)
        {
            ToastNotifier updater = ToastNotificationManager.CreateToastNotifier();
            IReadOnlyList <ScheduledToastNotification> scheduled = updater.GetScheduledToastNotifications();

            if (scheduled.Count == 0)
            {
                return(null);
            }
            else
            {
                foreach (var item in scheduled)
                {
                    if (item.Id.Equals(uniqueId))
                    {
                        return(item);
                    }
                }
                return(null);
            }
        }
예제 #22
0
        // 删除指定的 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();
        }
예제 #23
0
        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);
                        }
                    }
                }
            }
        }
예제 #24
0
        // 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();
        }
예제 #25
0
 public Task <bool> IsScheduledAsync(ToastId toastId)
 {
     return(Task.FromResult(notifier.GetScheduledToastNotifications().Where(n => n.Tag == toastId.Tag && n.Group == toastId.Group).Any()));
 }
예제 #26
0
        //Add Timer Function
        async void btn_TimerAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string   AlarmName      = "";
                DateTime BeginAlarmTime = DateTime.Now;

                //Check for empty timer time
                if (String.IsNullOrWhiteSpace(txtbox_TimerMinutes.Text))
                {
                    txtbox_TimerMinutes.Text = "0";
                }
                if (String.IsNullOrWhiteSpace(txtbox_TimerHours.Text))
                {
                    txtbox_TimerHours.Text = "0";
                }
                if (String.IsNullOrWhiteSpace(txtbox_TimerDays.Text))
                {
                    txtbox_TimerDays.Text = "0";
                }

                //Check alarm time for 0
                if (txtbox_TimerMinutes.Text == "0" && txtbox_TimerHours.Text == "0" && txtbox_TimerDays.Text == "0")
                {
                    txtbox_TimerDays.Text    = "";
                    txtbox_TimerHours.Text   = "";
                    txtbox_TimerMinutes.Text = "";
                    txtbox_TimerDays.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm time, and try again.", "TimeMe").ShowAsync();
                    return;
                }

                //Check for other characters
                if (Regex.IsMatch(txtbox_TimerMinutes.Text, "(\\D+)") || Regex.IsMatch(txtbox_TimerHours.Text, "(\\D+)") || Regex.IsMatch(txtbox_TimerDays.Text, "(\\D+)"))
                {
                    txtbox_TimerDays.Text    = "";
                    txtbox_TimerHours.Text   = "";
                    txtbox_TimerMinutes.Text = "";
                    txtbox_TimerDays.Focus(FocusState.Programmatic);
                    await new MessageDialog("The timer alarm time can only contain numbers, please check your entered time.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm time exceeds time limits
                if (Convert.ToInt32(txtbox_TimerDays.Text) > 31)
                {
                    txtbox_TimerDays.Text = "";
                    txtbox_TimerDays.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm time,\n31 days is the maximum.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm time exceeds time limits
                if (Convert.ToInt32(txtbox_TimerHours.Text) > 24)
                {
                    txtbox_TimerHours.Text = "";
                    txtbox_TimerHours.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm time,\n24 hours is the maximum.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm time exceeds time limits
                if (Convert.ToInt32(txtbox_TimerMinutes.Text) > 60)
                {
                    txtbox_TimerMinutes.Text = "";
                    txtbox_TimerMinutes.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm time,\n60 minutes is the maximum.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm times starts with a 0
                if (txtbox_TimerMinutes.Text.Length > 1 && txtbox_TimerMinutes.Text.StartsWith("0"))
                {
                    txtbox_TimerMinutes.Text = "";
                    txtbox_TimerMinutes.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm minutes time.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm times starts with a 0
                if (txtbox_TimerHours.Text.Length > 1 && txtbox_TimerHours.Text.StartsWith("0"))
                {
                    txtbox_TimerHours.Text = "";
                    txtbox_TimerHours.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm hours time.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if alarm times starts with a 0
                if (txtbox_TimerDays.Text.Length > 1 && txtbox_TimerDays.Text.StartsWith("0"))
                {
                    txtbox_TimerDays.Text = "";
                    txtbox_TimerDays.Focus(FocusState.Programmatic);
                    await new MessageDialog("Please enter a valid timer alarm days time.", "TimeMe").ShowAsync();
                    return;
                }

                BeginAlarmTime = DateTime.Now.AddSeconds(-DateTime.Now.Second).AddDays(Convert.ToInt32(txtbox_TimerDays.Text)).AddHours(Convert.ToInt32(txtbox_TimerHours.Text)).AddMinutes(Convert.ToInt32(txtbox_TimerMinutes.Text));
                AlarmName      = "Timer set in " + txtbox_TimerDays.Text + "days " + txtbox_TimerHours.Text + "hours " + txtbox_TimerMinutes.Text + "mins";

                //Check date overlapping with existing alarms
                ToastNotifier CreateToastNotifier = ToastNotificationManager.CreateToastNotifier();
                if (CreateToastNotifier.GetScheduledToastNotifications().Any(x => x.DeliveryTime.LocalDateTime.ToString() == BeginAlarmTime.ToString()))
                {
                    await new MessageDialog("Timer alarm overlaps with an existing alarm please choose another time point.", "TimeMe").ShowAsync();
                    return;
                }

                //Check if date and time is in the future
                if (BeginAlarmTime < DateTime.Now)
                {
                    await new MessageDialog("The alarm timer date and time point needs to be in the future to be added as timer.", "TimeMe").ShowAsync();
                    return;
                }

                XmlDocument ToastAlarmXmlReady = new XmlDocument();
                ToastAlarmXmlReady.LoadXml("<toast duration=\"long\" launch=\"ToastTimer\"><visual><binding template=\"ToastImageAndText02\"><image id=\"1\" src=\"ms-appx:///Assets/Icons/AlarmClock.png\"/><text id=\"1\">TimeMe</text><text id=\"2\">" + AlarmName + "</text></binding></visual><audio src=\"ms-winsoundevent:Notification.Looping.Alarm\" loop=\"true\"/></toast>");
                CreateToastNotifier.AddToSchedule(new ScheduledToastNotification(ToastAlarmXmlReady, BeginAlarmTime)
                {
                    Id = new Random().Next(1, 999999999).ToString()
                });

                txtbox_TimerDays.Text    = "";
                txtbox_TimerHours.Text   = "";
                txtbox_TimerMinutes.Text = "";
                TimersLoad();

                if (lb_TimerListBox.Items.Count == 1)
                {
                    await new MessageDialog("Your TimeMe timer alarm has been successfully set and will alarm as entered, please note that your volume needs to be turned up and the app must have permission to show notifications.", "TimeMe").ShowAsync();
                }
            }
            catch
            {
                TimersLoad();
                await new MessageDialog("Failed to add your new TimeMe timer alarm, please try again.", "TimeMe").ShowAsync();
            }
        }
예제 #27
0
        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;
        }
예제 #28
0
 private static bool IsScheduled(DateTime timeToAppearAt)
 {
     return(_toastNotifier.GetScheduledToastNotifications().Any(i => i.DeliveryTime.Ticks == timeToAppearAt.Ticks));
 }
 /// <summary>
 /// Gets the collection of ScheduledToastNotification objects that this app has scheduled for display.
 /// </summary>
 /// <returns>The collection of scheduled toast notifications that the app bound to this notifier has scheduled for timed display.</returns>
 public IReadOnlyList <ScheduledToastNotification> GetScheduledToastNotifications()
 {
     return(_notifier.GetScheduledToastNotifications());
 }
예제 #30
0
        private async void Add_Click(object sender, RoutedEventArgs e)
        {
            string str;

            description.Document.GetText(Windows.UI.Text.TextGetOptions.None, out str);
            DateTime dt = Convert.ToDateTime(String.Format("{0:dd/MM/yyyy} {1:t}", date.Date.Date, time.Time));
            WorkDB   db = new WorkDB();

            if (stype.SelectedIndex == 0)
            {
                Vaccine vac = new Vaccine();
                vac.cabinet = cabinet_v.Text;
                vac.phone   = telephone_v.Text;
                vac.vaccine = vaccin.Text;
                vac.fio     = fio_v.Text;

                db.InsertReminderVaccine(vac, dt, str);
            }
            if (stype.SelectedIndex == 1)
            {
                Doctor doct = new Doctor();
                doct.cabinet = cabinet_d.Text;
                doct.doctor  = doc.Text;
                doct.fio     = fio_d.Text;
                doct.phone   = telephone_d.Text;

                db.InsertReminderDoctor(doct, dt, str);
            }
            if (stype.SelectedIndex == 2)
            {
                DataModel.Action act = new DataModel.Action();
                act.place = place.Text;


                act.Latitude  = geo.Latitude;
                act.Longitude = geo.Longitude;

                db.InsertReminderAction(act, dt, str);
            }

            // 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((stype.SelectedIndex == 0 ? "Прививка" : stype.SelectedIndex == 1 ? "Прием врача" : "Мероприятие")));
            strings[1].AppendChild(toastXml.CreateTextNode("Время: " + dt.ToString()));

            // Create the toast notification object.
            try
            {
                var           toast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, dt);
                ToastNotifier not   = ToastNotificationManager.CreateToastNotifier();
                var           v     = not.GetScheduledToastNotifications();
                not.AddToSchedule(toast);
            }
            catch (Exception ex)
            {
            }
            var dlg = new MessageDialog("Данные успешно сохранены !");

            dlg.ShowAsync();
            this.Frame.Navigate(typeof(MainPage));
        }