Ejemplo n.º 1
0
        void ScheduleReEngageToast()
        {
            if (needsSessionToast)
            {
                string   invite  = "Your ammo is piling up. Let's battle!";
                DateTime dueTime = DateTime.Now.AddSeconds(40);

//LAB_ANSWER_BEGIN
#if NETFX_CORE
                var notificationXmlDoc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                var textNodeList       = notificationXmlDoc.GetElementsByTagName("text");
                if (textNodeList.Count > 0)
                {
                    textNodeList[0].AppendChild(notificationXmlDoc.CreateTextNode(invite));
                    var toast = new ScheduledToastNotification(notificationXmlDoc, dueTime);
                    toast.Id = (++toastId).ToString();
                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                }
#endif
//LAB_ANSWER_END


                needsSessionToast = false;
            }
        }
        public async void AddNotification(Note note)
        {
            if (IsNotificationAllowed)
            {
                DateTime time          = DateTime.ParseExact(note.TimeOfNote, @"dd-MM-yyyy HH\:mm", CultureInfo.InvariantCulture);
                var      toastNotifier = ToastNotificationManager.CreateToastNotifier();
                var      toastXml      = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                var      toastText     = toastXml.GetElementsByTagName("text");
                var      toastElement  = ((XmlElement)toastXml.SelectSingleNode("/toast"));
                toastElement.SetAttribute("launch", "toast://" + note.RoomID);
                string nameRoom = note.RoomName.Replace("A", "Aula ")
                                  .Replace("BW", " Łazienka damska")
                                  .Replace("BM", " Łazienka męska")
                                  .Replace("F", " Bufet")
                                  .Replace("S", " Apteczka")
                                  .Replace("CY", "Szatnia żółta")
                                  .Replace("CG", "Szatnia zielona");

                toastText[0].AppendChild(toastXml.CreateTextNode($"{note.TextOfNote} za {App.TimerNotifications} min w {(nameRoom.Contains("Aula") ? "" : "sali")} {nameRoom}"));
                toastText[1].AppendChild(toastXml.CreateTextNode($"Chcesz zobaczyć mapę?"));

                var customAlarmScheduledToast = new ScheduledToastNotification(toastXml, time);
                toastNotifier.AddToSchedule(customAlarmScheduledToast);
            }
            else
            {
                MessageDialog message = new MessageDialog("Powiadomienia w aplikacji są wyłączone, aby je włączyć proszę przejść do ustawień.");
                await message.ShowAsync();
            }
        }
Ejemplo n.º 3
0
        public void ShowNotifications()
        {
            var toastCollection = GetNotificationsFromRss();
            LogManager.Log("2->toastCollection.Count :" + toastCollection.Count());
            var notifi = ToastNotificationManager.CreateToastNotifier(appName);
            for (int i = 0; i < toastCollection.Count(); i++)
            {
                var unicornToast = toastCollection.ElementAt(i);
                XmlDocument doc = new XmlDocument();
                var xmlString = unicornToast.ToastContent.GetContent();
                doc.LoadXml(xmlString);

                if (i == 0)
                {
                    //MessageBox.Show("before toast");
                    var toast = new ToastNotification(doc);
                    //toast.Activated += Toast_Activated;
                    //toast.Failed += Toast_Failed;
                    LogManager.Log("3->notifi.Show :");
                    notifi.Show(toast);
                    LogManager.Log("3->notifi.Show done :");
                    //MessageBox.Show("after toast");
                    AddNotificationToDb(unicornToast.Url);
                }
                else
                {
                    var scheduleDuration = 4; //???????ConfigurationManager.AppSettings.Get("scheduleDurationGap")
                    var scheduledToast = new ScheduledToastNotification(doc, new DateTimeOffset(DateTime.Now.AddMinutes(i * scheduleDuration)));
                    notifi.AddToSchedule(scheduledToast);
                    LogManager.Log("3->notifi.AddToSchedule :");
                    AddNotificationToDb(unicornToast.Url);
                }
            }
        }
Ejemplo n.º 4
0
        public static void wyswietlNotyfikacje()
        {
            XmlNodeList toastTextAttributes = toastXml.GetElementsByTagName("text");

            String napis;

            //losowanie
            Random r = new Random();
            int    x = r.Next(0, i);

            try
            {
                napis = dane[x];
            }
            catch (Exception) {
                napis = "Pusty słownik.";
            };


            toastTextAttributes[0].InnerText = napis;

            //okreslenie kiedy ma sie pojawic:
            Int16    odstepSek = 1;
            DateTime dueTime   = DateTime.Now.AddSeconds(odstepSek);

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.AddToSchedule(scheduledToast);
        }
        void ScheduleToast(String updateString, DateTime dueTime, int idNumber)
        {
            // Scheduled toasts use the same toast templates as all other kinds of toasts.
            IToastText02 toastContent = ToastContentFactory.CreateToastText02();

            toastContent.TextHeading.Text  = updateString;
            toastContent.TextBodyWrap.Text = "Received: " + dueTime.ToLocalTime();

            ScheduledToastNotification toast;

            if (RepeatBox.IsChecked != null && (bool)RepeatBox.IsChecked)
            {
                toast = new ScheduledToastNotification(toastContent.GetXml(), dueTime, TimeSpan.FromSeconds(60), 5);

                // You can specify an ID so that you can manage toasts later.
                // Make sure the ID is 15 characters or less.
                toast.Id = "Repeat" + idNumber;
            }
            else
            {
                toast    = new ScheduledToastNotification(toastContent.GetXml(), dueTime);
                toast.Id = "Toast" + idNumber;
            }

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
            rootPage.NotifyUser("Scheduled a toast with ID: " + toast.Id, NotifyType.StatusMessage);
        }
Ejemplo n.º 6
0
        private async void Period_pickerFlyout_TimePicked(TimePickerFlyout sender, TimePickedEventArgs args)
        {
            if (Convert.ToInt32(sender.Time.TotalMinutes) != 0)
            {
                Period_picker_tamp.TIME_PERIOD = Convert.ToInt32(sender.Time.TotalMinutes);
                Period_picker_tamp.TIMESTART   = DateTime.Now.ToString("s");
                Period_picker_tamp.TIMEEND     = DateTime.Now.AddMinutes(Period_picker_tamp.TIME_PERIOD).ToString("s");
                DB_Controller db = new DB_Controller();
                await db.update_TimePeriodList(Period_picker_tamp);

                foreach (ScheduledToastNotification s in ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications())
                {
                    if (s.Id == "Period" + Period_picker_tamp.ID.ToString())
                    {
                        ScheduledToastNotification recurringToast = new ScheduledToastNotification(s.Content, DateTime.Parse(Period_picker_tamp.TIMEEND));
                        ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(s);
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast);
                        break;
                    }
                }

                foreach (DB_TimePeriodList s in timePeriodListData)
                {
                    if (s.ID == Period_picker_tamp.ID)
                    {
                        s.TIME_PERIOD      = Period_picker_tamp.TIME_PERIOD;
                        s.TIMESTART        = Period_picker_tamp.TIMESTART;
                        s.TIMEEND          = Period_picker_tamp.TIMEEND;
                        Period_picker_tamp = null;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 通知栏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Clock_OnClick(object sender, RoutedEventArgs e)
        {
            var type    = ToastTemplateType.ToastText02;
            var content = ToastNotificationManager.GetTemplateContent(type);

            if (TodoListView.SelectedItem != null)
            {
                var todoItem = TodoListView.SelectedItem as TodoItem;

                //生成XML
                XmlNodeList toastxml = content.GetElementsByTagName("text");
                toastxml[0].AppendChild(content.CreateTextNode(todoItem.Content));
                toastxml[1].AppendChild(content.CreateTextNode(todoItem.DateCreated.ToString()));

                //设置时间、次数等参数

                string   setDateTime             = ConvertToDateTime(MyDatePicker, MyTimePicker);
                DateTime due                     = DateTime.Parse(setDateTime);
                TimeSpan span                    = TimeSpan.FromMinutes(1);
                UInt32   time                    = 3;
                ScheduledToastNotification toast = new ScheduledToastNotification(content, due, span, time);
                //设置Toast的id
                toast.Id = "toast1";

                var node  = content.SelectSingleNode("/toast");
                var audio = content.CreateElement("audio");
                audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
                audio.SetAttribute("loop", "false");
                node.AppendChild(audio);
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
            }
        }
Ejemplo n.º 8
0
        // 添加指定的 ScheduledToastNotification 到计划列表中
        private void btnAddScheduledToast_Click(object sender, RoutedEventArgs e)
        {
            string toastXml = $@"
                <toast activationType='foreground' launch='Notification-Toast-Schedule-Arguments'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content {DateTime.Now.ToString("mm:ss")}</text>
                        </binding>
                    </visual>
                </toast>";

            // 将 xml 字符串转换为 Windows.Data.Xml.Dom.XmlDocument 对象
            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            // 实例化 ScheduledToastNotification 对象(15 秒后显示此 Toast 通知,然后每隔 60 秒再显示一次 Toast,循环显示 5 次)
            // 但是经测试,只会显示一次,无法循环显示,不知道为什么
            // ScheduledToastNotification toastNotification = new ScheduledToastNotification(toastDoc, DateTime.Now.AddSeconds(15), TimeSpan.FromSeconds(60), 5);

            // 实例化 ScheduledToastNotification 对象(15 秒后显示此 Toast 通知)
            ScheduledToastNotification toastNotification = new ScheduledToastNotification(toastDoc, DateTime.Now.AddSeconds(15));

            toastNotification.Id  = new Random().Next(100000, 1000000).ToString();
            toastNotification.Tag = toastDoc.GetElementsByTagName("text")[1].InnerText;

            // 将指定的 ScheduledToastNotification 添加进计划列表
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.AddToSchedule(toastNotification);

            ShowScheduledToasts();
        }
Ejemplo n.º 9
0
        public static void CreateDefferedToast()
        {
            // Construct the visuals of the toast (using Notifications library)
            ToastContent toastContent = new ToastContent()
            {
                // Arguments when the user taps body of toast
                Launch = "action=viewConversation&conversationId=5",

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "Hello world!"
                            }
                        }
                    }
                }
            };

            // Create the XML document (BE SURE TO REFERENCE WINDOWS.DATA.XML.DOM)
            var doc = new XmlDocument();

            doc.LoadXml(toastContent.GetContent());

            // And create the toast notification
            var toast = new ScheduledToastNotification(toastContent.GetXml(), DateTime.Now.AddSeconds(10));

            // And then show it
            DesktopNotificationManagerCompat.CreateToastNotifier().AddToSchedule(toast);
        }
Ejemplo n.º 10
0
        public static void ScheduleToast(DateTime timeToAppearAt)
        {
            // If in the past or within 5 seconds, don't schedule
            if (timeToAppearAt <= DateTime.Now.AddSeconds(5))
            {
                throw new ArgumentException("timeToAppearAt must be at least 5 seconds in the future.");
            }

            // Generate a RemoteId for the specified time
            string remoteId = GetRemoteId(timeToAppearAt);

            // If this notification is already scheduled
            if (IsScheduled(timeToAppearAt))
            {
                // Do nothing
                return;
            }

            // Create the notification's content
            XmlDocument toastContent = CreateToastContent(timeToAppearAt, remoteId);

            ScheduledToastNotification notif = new ScheduledToastNotification(toastContent, timeToAppearAt)
            {
                RemoteId = remoteId
            };

            // And schedule the toast
            _toastNotifier.AddToSchedule(notif);
        }
        private async void OnReminderButtonClicked(object sender, RoutedEventArgs e)
        {
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            if (notifier.Setting != NotificationSetting.Enabled)
            {
                var dialog = new MessageDialog("Notifications are currently disabled");
                await dialog.ShowAsync();

                return;
            }

            ToastTemplateType toastTemplate     = ToastTemplateType.ToastText01;
            XmlDocument       toastXml          = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList       toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode("Reminder! Check Friends With Paws"));
            var date = DateTimeOffset.Now.AddSeconds(15);
            var stnA = new ScheduledToastNotification(toastXml, date);

            notifier.AddToSchedule(stnA);

            ToastTemplateType toastTemplateB     = ToastTemplateType.ToastText01;
            XmlDocument       toastXmlB          = ToastNotificationManager.GetTemplateContent(toastTemplateB);
            XmlNodeList       toastTextElementsB = toastXmlB.GetElementsByTagName("text");

            toastTextElementsB[0].AppendChild(toastXmlB.CreateTextNode("Please check what's new with Friends With Paws"));
            var      dateB      = DateTimeOffset.Now.AddSeconds(60);
            IXmlNode toastNodeB = toastXmlB.SelectSingleNode("/toast");

            ((XmlElement)toastNodeB).SetAttribute("duration", "long");
            var stnB = new ScheduledToastNotification(toastXmlB, dateB);

            notifier.AddToSchedule(stnB);
        }
Ejemplo n.º 12
0
        public void Init()
        {
            if (Items == null)
            {
                Items = new List <PomodoroItem>
                {
                    new PomodoroItem(PomodoroType.TaskTimer,
                                     Color.FromArgb(255, 240, 58, 23),
                                     Color.FromArgb(255, 239, 105, 80)),
                    new PomodoroItem(PomodoroType.ShortBreak,
                                     Color.FromArgb(255, 131, 190, 236),
                                     Color.FromArgb(255, 179, 219, 212)),
                    new PomodoroItem(PomodoroType.LongBreak,
                                     Color.FromArgb(255, 186, 216, 10),
                                     Color.FromArgb(255, 228, 245, 119)),
                };
            }
            ScheduledToastNotification toast = GetToast();
            PomodoroItem item = Items[0];

            if (toast != null)
            {
                item    = Items.FirstOrDefault(f => f.Id == toast.Id);
                _start  = toast.DeliveryTime.UtcDateTime - item.TimeSpan;
                _finish = toast.DeliveryTime.UtcDateTime;
                Start();
            }
            Select(item);
        }
Ejemplo n.º 13
0
        public static void SendToast(
            string head,
            string text,
            DateTimeOffset dueTime,
            string launch)
        {
            ToastTemplateType toastTemplate     = ToastTemplateType.ToastText02;
            XmlDocument       toastXml          = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList       toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(head));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(text));

            IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio     = toastXml.CreateElement("audio");

            audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");

            toastNode.AppendChild(audio);

            if (launch != null)
            {
                ((XmlElement)toastNode).SetAttribute("launch", launch);
            }

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);

            scheduledToast.Id = "Future_Toast";
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// トースト通知スケジュール発信
        /// </summary>
        /// <returns></returns>
        private bool CreateScheduleToast()
        {
            try
            {
                var tmpl = ToastTemplateType.ToastImageAndText02;
                var xml  = ToastNotificationManager.GetTemplateContent(tmpl);
                Debug.WriteLine(xml.GetXml());

                var images = xml.GetElementsByTagName("image");
                var src    = images[0].Attributes.GetNamedItem("src");
                src.InnerText = AppConst.TOAST_ICON_FILE_DIR;
                Debug.WriteLine(src.InnerText);

                var texts = xml.GetElementsByTagName("text");
                texts[0].AppendChild(xml.CreateTextNode("使用確認"));
                texts[1].AppendChild(xml.CreateTextNode("家計簿アプリを使用しましたか?"));

                DateTimeOffset dateTimeOffset =
                    new DateTimeOffset(DTPickerToast.Value.Year, DTPickerToast.Value.Month, DTPickerToast.Value.Day,
                                       DateTime.Now.Hour + int.Parse(TbAddHour.Text),
                                       DateTime.Now.Minute + int.Parse(TbAddMinute.Text),
                                       DateTime.Now.Second, TimeSpan.Zero);
                var scheduled = new ScheduledToastNotification(xml, dateTimeOffset);

                var toastNotifier = ToastNotificationManager.CreateToastNotifier(TOAST_TITLE);
                toastNotifier.AddToSchedule(scheduled);
                toastNotifier.ScheduledToastNotificationShowing += ToastNotifier_ScheduledToastNotificationShowing;
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(false);
            }
            return(true);
        }
        private async void OnReminderButtonClicked(object sender, RoutedEventArgs e)
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();

            if (notifier.Setting != NotificationSetting.Enabled)
            {
                var dialog = new MessageDialog("Notifications are currently disabled");
                await dialog.ShowAsync();

                return;
            }

            //Creating and setting the first toast notification
            var templateFirstToast = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
            var elementFirstToast  = templateFirstToast.GetElementsByTagName("text")[0];

            elementFirstToast.AppendChild(templateFirstToast.CreateTextNode("Reminder! Check Friends With Paws"));
            var dateFirstToast = DateTimeOffset.Now.AddSeconds(5);
            var stnFirstToast  = new ScheduledToastNotification(templateFirstToast, dateFirstToast);

            notifier.AddToSchedule(stnFirstToast);

            //Creating and setting the second toast notification
            var templateSecondToast = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
            var elementSecondToast  = templateSecondToast.GetElementsByTagName("text")[0];

            elementSecondToast.AppendChild(templateSecondToast.CreateTextNode("Please check what's new with Friends With Paws"));
            var dateSecondToast = DateTimeOffset.Now.AddSeconds(8);
            var stnSecondToast  = new ScheduledToastNotification(templateSecondToast, dateSecondToast);

            notifier.AddToSchedule(stnSecondToast);
        }
Ejemplo n.º 16
0
        public void CreateNotificationTask(TimeSpan timeToLeave, string message)
        {
            DateTime alarmTime      = DateTime.Now + timeToLeave;
            var      scheduledNotif = new ScheduledToastNotification(CreateStructuredMessage(message), alarmTime);

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledNotif);
        }
Ejemplo n.º 17
0
        private async void reminder_button_Click(object sender, RoutedEventArgs e)
        {
            MessageDialog showDialog = new MessageDialog("wenst u een reminder een half uur voor de afspraak ?");

            showDialog.Commands.Add(new UICommand("Ok")
            {
                Id = 0
            });
            showDialog.Commands.Add(new UICommand("Cancel")
            {
                Id = 1
            });
            showDialog.DefaultCommandIndex = 1;
            var result = await showDialog.ShowAsync();

            if ((int)result.Id == 1)
            {
                Frame.Navigate(typeof(Newsfeed));
            }
            if ((int)result.Id == 0)
            {
                String[] datumFormat       = datum.Text.Split('/');
                String[] tijdformat        = tijd.Text.Split(':');
                DateTime datumNotification = new DateTime(Int32.Parse(datumFormat[2]), Int32.Parse(datumFormat[0]), Int32.Parse(datumFormat[1]), Int32.Parse(tijdformat[0]), Int32.Parse(tijdformat[1]), Int32.Parse(tijdformat[2]));
                datumNotification.AddMinutes(-30);
                IToastText02 toast = ToastContentFactory.CreateToastText02();
                toast.TextHeading.Text  = newsitem.Titel;;
                toast.TextBodyWrap.Text = newsitem.Inhoud;
                ScheduledToastNotification toastNotification = new ScheduledToastNotification(toast.GetXml(), datumNotification);
                toastNotification.Id = "id";
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(toastNotification);
                Frame.Navigate(typeof(Newsfeed));
            }
        }
Ejemplo n.º 18
0
        private async void Ture_Click(object sender, RoutedEventArgs e)
        {
            //隐藏确认按钮,避免多次点击
            Ture_Button.Visibility = Visibility.Collapsed;

            int Hours = 0;

            //点击设置推送按钮的统计
            JYAnalytics.TrackEvent("Push");

            if (on_off == "开")
            {
                try
                {
                    for (int i = 1; i <= 7; i++)

                    {
                        Hours = Hours + 24;
                        XmlDocument xdoc     = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                        var         txtnodes = xdoc.GetElementsByTagName("text");
                        txtnodes[0].InnerText = "快来看看账号有没有更新吧!";
                        ScheduledToastNotification toast3 = new ScheduledToastNotification(xdoc, DateTimeOffset.Now.AddHours(Hours));
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast3);
                    }
                }
                catch (Exception ex)
                {
                    Windows.UI.Popups.MessageDialog messageDialog = new Windows.UI.Popups.MessageDialog("设置成功!");
                    await messageDialog.ShowAsync();
                }
            }
        }
Ejemplo n.º 19
0
        public static void scheduleToast(string state, string title, string imageURL, DateTime date)
        {
            ToastVisual visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = state
                        },
                        new AdaptiveText()
                        {
                            Text = title
                        }
                    },
                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source   = imageURL,
                        HintCrop = ToastGenericAppLogoCrop.Circle
                    }
                }
            };
            ToastContent content = new ToastContent()
            {
                Visual = visual
            };
            var toast = new ScheduledToastNotification(content.GetXml(), date);

            toast.Tag = title;
            var notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.AddToSchedule(toast);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Schedule a notification of the specified date and type.
        /// </summary>
        /// <param name="noticeText"></param>
        /// <param name="dueTime"></param>
        /// <param name="notificationType"></param>
        public static void ScheduleNotification(string noticeText, DateTime dueTime, NotificationType notificationType)
        {
            switch (notificationType)
            {
            case NotificationType.Toast:
                string toast = string.Format("<toast>"
                                             + "<visual>"
                                             + "<binding template = \"ToastGeneric\" >"
                                             + "<image placement=\"appLogoOverride\" src=\"Assets\\CompanionAppIcon44x44.png\" />"
                                             + "<text>{0}</text>"
                                             + "</binding>"
                                             + "</visual>"
                                             + "</toast>", noticeText);

                XmlDocument toastDOM = new XmlDocument();
                toastDOM.LoadXml(toast);
                ScheduledToastNotification toastNotification = new ScheduledToastNotification(toastDOM, dueTime)
                {
                    Id = "Note_Reminder"
                };
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(toastNotification);
                break;

            case NotificationType.Tile:
                //TODO: Tile updates
                throw new NotImplementedException();

            default:
                break;
            }
        }
Ejemplo n.º 21
0
        private async void btnReminderTimer_Click(object sender, RoutedEventArgs e)
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();

            // Make sure notifications are enabled
            if (notifier.Setting != NotificationSetting.Enabled)
            {
                var dialog = new MessageDialog("Notifications are currently disabled");
                await dialog.ShowAsync();

                return;
            }

            // Get a toast template and insert a text node containing a message
            var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
            var element  = template.GetElementsByTagName("text")[0];

            element.AppendChild(template.CreateTextNode("Reminder!"));

            // Schedule the toast to appear 30 seconds from now
            var date = DateTimeOffset.Now.AddSeconds(30);
            var stn  = new ScheduledToastNotification(template, date);

            notifier.AddToSchedule(stn);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates the task toast.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <param name="timePrior">The time prior.</param>
        public static void CreateTaskToast(Model.Task task, int timePrior)
        {
            if (task?.DueDate == null)
            {
                return;
            }
            var date = task.DueDate.Value;
            var time = task.DueTime;

            var displayTime = new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, 0);

            if (displayTime < DateTime.Now)
            {
                return;
            }
            displayTime = displayTime.AddMinutes(-timePrior);
            var toastXml = CreateXmlDocument(task, date, time);

            var toastNotification = new ScheduledToastNotification(toastXml, displayTime)
            {
                Id = $"{task.TaskId}"
            };

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toastNotification);
        }
Ejemplo n.º 23
0
        public ScheduledToastNotification AddBreakFinishedToastNotificationSchedule(DateTime time, string audioUri, bool isRemoveOthers = true)
        {
            if (isRemoveOthers)
            {
                RemoveBreakFinishedToastNotificationSchedule();
            }

            var toastContent = GetBreakToastContent();

            if (string.IsNullOrWhiteSpace(audioUri) == false)
            {
                toastContent.Audio = new ToastAudio()
                {
                    Src = new Uri(audioUri)
                };
                //("ms-appx:///Assets/Audio/CustomToastAudio.m4a")
            }

            var notifier = ToastNotificationManager.CreateToastNotifier();

            var toast = new ScheduledToastNotification(toastContent.GetXml(), time)
            {
                Tag            = ToastTag,
                ExpirationTime = time.AddHours(1),
                Id             = _id++.ToString()
            };

            notifier.AddToSchedule(toast);
            Debug.WriteLine("add break:" + toast.Id);
            return(toast);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Define Toast notification for ToDo item under ToDo Note
        /// </summary>
        /// <param name="Notetitle">ToDo Note Title</param>
        /// <param name="tdItem">ToDo Item</param>
        public static void SetScheduledToast(string Notetitle, ToDo tdItem)
        {
            if (tdItem.DueDate < DateTime.Now)
            {
                tdItem.HasReminder = false;
                return;
            }

            var notifier = ToastNotificationManager.CreateToastNotifier();

            // Make sure notifications are enabled
            if (notifier.Setting != NotificationSetting.Enabled)
            {
                Helpers.ShowMessageAsync("Notifications are currently disabled", "Set Reminder");
                return;
            }

            var         toastXml          = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(Notetitle));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(tdItem.Title));

            var d = new DateTimeOffset(tdItem.DueDate);

            ScheduledToastNotification toast = new ScheduledToastNotification(toastXml, d);// GetNotificationForToDo(tdItem.UniqueId);

            toast              = new ScheduledToastNotification(toastXml, d);
            toast.Id           = tdItem.UniqueId;
            tdItem.HasReminder = true;
            notifier.AddToSchedule(toast);
        }
Ejemplo n.º 25
0
        /// <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);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Permet d'enregistrer un toast à afficher à une date précise
        /// </summary>
        /// <param name="titre">le titre du Toast</param>
        /// <param name="phrase">La phrase du toast</param>
        /// <param name="activationTime">la date d'activation</param>
        /// <param name="idNotif">l'id du toast</param>
        /// <param name="minute">le nombre de minutes avant une répétition (0 pour aucun)</param>
        /// <param name="repeat">le nombre de répétition (0 pour aucun)</param>
        public static void LancerToast(string titre, string phrase, DateTime activationTime, int idNotif, int minute, uint repeat)
        {
            //création du toast
            var toastContent = ToastContentFactory.CreateToastText02();

            toastContent.TextHeading.Text  = titre;
            toastContent.TextBodyWrap.Text = phrase;
            ScheduledToastNotification toast;

            if (minute > 0 && repeat > 0)
            {
                toast = new ScheduledToastNotification(toastContent.GetXml(), activationTime, TimeSpan.FromMinutes(minute), repeat)
                {
                    Id = idNotif.ToString()
                };
            }
            else
            {
                toast = new ScheduledToastNotification(toastContent.GetXml(), activationTime)
                {
                    Id = idNotif.ToString()
                };
            }
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
        }
Ejemplo n.º 27
0
        public override object scheduleLocalNotification(double timestampUTC, int notificationId, string callbackArgs, string title, string text, bool playsound, bool pinNotification)
        {
            // Load the content into an XML document
            // ToastText02 is a built-in template with a single line header (id=1)
            // and a chunck of text that can wrap onto a second line (id=2).
            // Colors and small icon are picked up from the package manifest.
            var         xmlString = $@"
				<toast launch='{notificationId}'>
					<visual>
						<binding template='ToastText02'>
							<text id='1'>{title}</text>
							<text id='2'>{text}</text>
						</binding>
					</visual>
					{(playsound? "<audio src='ms-winsoundevent:Notification.Default' />": "")}
				</toast>"                ;
            XmlDocument document  = new XmlDocument();

            document.LoadXml(xmlString);

            // Create a toast notification and send it
            DateTime dueTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);

            dueTime = dueTime.AddMilliseconds(timestampUTC).ToLocalTime();

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(document, dueTime);

            scheduledToast.Id = notificationId.ToString();
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);

            return(null);
        }
Ejemplo n.º 28
0
        private void AddReminder(ITask task)
        {
            if (!task.Alarm.HasValue || task.Alarm.Value <= DateTime.Now)
            {
                LogService.Log("AlarmManager", "Cannot add reminder because alarm date is already past");
                return;
            }

            var notification = NotificationContentBuilder.CreateTaskToastNotification(task);

            if (notification != null)
            {
                ScheduledToastNotification toast = new ScheduledToastNotification(notification, task.Alarm.Value)
                {
                    Id = task.Id.ToString()
                };

                var toastNotifier = this.CreateToastNotifier();
                if (toastNotifier != null)
                {
                    // check if a schedule notification does not already exist for this task
                    var scheduledToastNotifications = toastNotifier.GetScheduledToastNotifications();
                    var existingNotification        = scheduledToastNotifications.FirstOrDefault(n => n.Id == toast.Id);
                    if (existingNotification != null)
                    {
                        toastNotifier.RemoveFromSchedule(existingNotification);
                    }

                    toastNotifier.AddToSchedule(toast);
                }
            }

            LogService.Log("AlarmManager", string.Format("Reminder of task {0} added for {1}", task.Title, task.Alarm.Value));
        }
Ejemplo n.º 29
0
        public override string Send(Notification notification)
        {
            var id = Guid.NewGuid().ToString();

            var soundXml = notification.Sound == null
                ? String.Empty
                : String.Format("<audio src=\"ms-appx:///Assets/{0}.wav\"/>", notification.Sound);

            var xmlData = String.Format(TOAST_TEMPLATE, soundXml, notification.Title, notification.Message);
            var xml     = new XmlDocument();

            xml.LoadXml(xmlData);

            if (notification.Date == null && notification.When == null)
            {
                var toast = new ToastNotification(xml);
                this.toastNotifier.Show(toast);
            }
            else
            {
                var schedule = new ScheduledToastNotification(xml, notification.SendTime)
                {
                    Id = id
                };
                this.toastNotifier.AddToSchedule(schedule);
            }
            return(id);
        }
Ejemplo n.º 30
0
 public static void Last_Notification()
 {
     for (int i = 0; i < 7; i++)
     {
         if (DateTime.Now.AddDays(i).DayOfWeek == DayOfWeek.Thursday)
         {
             try
             {
                 DateTime dt = Data.VakatTime(DateTime.Now.AddDays(i), 5);
                 if (DateTime.Now >= dt.AddMinutes(-25))
                 {
                     dt = Data.VakatTime(DateTime.Now.AddDays(i + 7), 5);
                 }
                 Obrisi_Obavijest("lastnotif");
                 ScheduledToastNotification scheduledToast = new ScheduledToastNotification(Last_Notification_XML(), dt.AddMinutes(-25));
                 scheduledToast.Id            = "lastnotif";
                 scheduledToast.SuppressPopup = true;
                 ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
                 System.Diagnostics.Debug.WriteLine("Alert obavijest postavljena...");
             }
             catch (Exception ex)
             {
                 System.Diagnostics.Debug.WriteLine("Greška pri registraciji Alert obavijesti " + "(" + ex.Message + ")");
             }
         }
     }
 }