Inheritance: IScheduledToastNotification
        /// <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;
            }
        }
示例#2
0
        /// <summary>
        /// Создание всплывающего уведомления
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool CreateScheduledToast(int timestamp, int id, string message)
        {
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            var notifications = toastNotifier.GetScheduledToastNotifications();
            foreach (var notification in notifications)
            {
                if (notification.Id == id.ToString())
                    return false;
            }

            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(AppConstants.AppMessages[AppConstants.UsedLanguage]["txtAppName"]));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));

            XmlElement toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
            toastElement.SetAttribute("launch", "note_id=" + id.ToString());

            DateTimeOffset schedule = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan());
            schedule = schedule.AddSeconds(timestamp).ToLocalTime();

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, schedule);
            scheduledToast.Id = id.ToString();

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);

            return true;
        }
        /// <summary>
        /// Creates a reminder at specific time (system reminder on win phone, scheduled notification toast on win 8)
        /// </summary>
        public static void RegisterReminder(string id, string title, string content, DateTime triggerTime)
        {
            if (triggerTime <= DateTime.Now) return; // Trigger time has passed

            // ensure we respect the user's settings for reminders
            if (!AreRemindersEnabled()) return;

#if NETFX_CORE
            var notifier = ToastNotificationManager.CreateToastNotifier();
            var reminders = notifier.GetScheduledToastNotifications();
            var existingReminder = reminders.FirstOrDefault(n => n.Id == id);
            if (existingReminder != null)
            {
                notifier.RemoveFromSchedule(existingReminder);
            }

            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(content));

            XmlNodeList toastImageElements = toastXml.GetElementsByTagName("image");

            ((XmlElement)toastImageElements[0]).SetAttribute("src", "ms-appx:///Assets/Logo.png");

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, triggerTime);
            scheduledToast.Id = id;
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
#endif
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Check if a background toast is already scheduled
            if (ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications().Select(x => x.Id = "Background").Count() > 0)
            {
                return;
            }

            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode("League of Legends"));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode("New Champion data has arrived. Keep up with the Meta now!"));

            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio = toastXml.CreateElement("audio");
            audio.SetAttribute("src", "ms-appx:///Assets/yourturn.mp3");
            toastNode.AppendChild(audio);

            ToastNotification toast = new ToastNotification(toastXml);
            DateTime dueTime = DateTime.Now.AddHours(72);
            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
            scheduledToast.Id = "Background";
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);
        }
示例#5
0
         public static void SetReminder(RecipeDataItem item)
         {


                var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();

                
                if (!IsScheduled(item.UniqueId))
                {
                    Windows.Data.Xml.Dom.XmlDocument doc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                    var textLines = doc.GetElementsByTagName("text");
                    textLines[0].InnerText = item.Title;
                    textLines[1].InnerText = "Have you finished cooking?";
                    ScheduledToastNotification reminder = new ScheduledToastNotification(doc, DateTime.Now.AddSeconds(10));
                    reminder.Id = item.UniqueId;
                    toastNotifier.AddToSchedule(reminder);
                }
                else
                {

                    var schedule = toastNotifier.GetScheduledToastNotifications().FirstOrDefault(x => x.Id == item.UniqueId);
                    if (schedule != null)
                        toastNotifier.RemoveFromSchedule(schedule);
                }

                
            }
 public static string ScheduleNotification(XmlDocument toastXml, DateTimeOffset date)
 {
     ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
     Debug.WriteLine("Date " + date);
     ScheduledToastNotification customAlarmScheduledToast = new ScheduledToastNotification(toastXml, date);
     toastNotifier.AddToSchedule(customAlarmScheduledToast);
     return customAlarmScheduledToast.Id;
 }
示例#7
0
        public static void ScheduleToast(ToastTemplateType toastTemplateType, string[] text, string image, DateTimeOffset deliveryTime)
        {
            var toastXml = CreateToastNotificationXml(toastTemplateType, text, image);

            var notification = new ScheduledToastNotification(toastXml, deliveryTime);

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(notification);
        }
示例#8
0
        public static void ShowScheduledToast(string message, DateTimeOffset on)
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();
            var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            var element = template.GetElementsByTagName("text")[0];
            element.AppendChild(template.CreateTextNode("message"));

            var scheduledToast = new ScheduledToastNotification(template, on);
            notifier.AddToSchedule(scheduledToast);
        }
示例#9
0
        private static void show(XmlDocument content, DateTime deliveryTime, string id)
          
        {
            
             var scheduledToast = new ScheduledToastNotification(content, new DateTimeOffset(deliveryTime));
              scheduledToast.Tag = id;
            scheduledToast.Group = "toastgroup";
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);


        }
示例#10
0
        public static void CreateNotification(TaskModel data)
        {
            // NghiaTT - Add toast notification
            // TODO: test
            const string xmlFormat = "<toast><visual><binding template='ToastText02'><text id='1'>{0}</text><text id='2'>{1}</text></binding></visual></toast>";
            var xmlString = string.Format(xmlFormat, data.Name, data.Description);
            var xmlDom = new XmlDocument();
            xmlDom.LoadXml(xmlString);
            var dueTime = RepositoryUtils.GetDateTimeFromStrings(data.StartDate, data.StartTime).AddSeconds(15); // 15' before the start time

            var endTime = RepositoryUtils.GetDateTimeFromStrings(data.EndDate, data.EndTime);

            var deviation = (endTime.Year * 365 + endTime.Month * 30 + endTime.Day) - (dueTime.Year * 365 + dueTime.Month * 30 + dueTime.Day);

            if (dueTime < DateTime.Now) return;
            //var dueTime = DateTime.Now.AddSeconds(5);
            ScheduledToastNotification toast;

            switch (data.RepeatType)
            {
                    // NghiaTT: Why 1e9?? Snooze a billion times?
                case 1:
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(1), (uint)1e9);
                    break;
                case 2:
                    try
                    {
                        toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(7), (uint)1e9 / 7);
                    }
                    catch (Exception)
                    {
                        
                        throw;
                    }
                    
                    break;
                case 3:
                    // TODO: check for day in month
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(30), (uint)1e9 / 30);
                    break;
                case 4:
                    // TODO: check for leap year
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(365), (uint)1e9 / 365);
                    break;
                default:
                    toast = new ScheduledToastNotification(xmlDom, dueTime);
                    break;
            }
            toast.Id = data.ID.ToString();
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
        }
示例#11
0
        public static void ScheduleTaskReminders(DateTime dueDate, string className, string taskName, long taskId)
        {
            string dueSoonXml =
                $@"
            <toast scenario=""reminder"">
            <visual>
            <binding template = ""ToastGeneric"">
            <text>{
                    "Assignment Due Soon"}</text>
            <text>{className} - {taskName}{Environment.NewLine}Due on {
                    dueDate.ToString("dddd, MM/d # h:mm tt").Replace("#", "at")}</text>
            </binding>
            </visual>
            </toast>";
            string dueNowXml =
                $@"
            <toast scenario=""reminder"">
            <visual>
            <binding template = ""ToastGeneric"">
            <text>{"Assignment Due"
                    }</text>
            <text>{className} - {taskName}</text>
            </binding>
            </visual>
            </toast>";
            XmlDocument dueSoon = new XmlDocument();
            XmlDocument dueNow = new XmlDocument();
            dueSoon.LoadXml(dueSoonXml);
            dueNow.LoadXml(dueNowXml);

            DateTime notificationTime1 = dueDate.Subtract(TimeSpan.FromHours(12));
            if (notificationTime1 < DateTime.Now)
            {
                notificationTime1 = DateTime.Now.AddSeconds(5);
            }
            DateTime notificationTime2 = dueDate;
            ScheduledToastNotification notifyBefore = new ScheduledToastNotification(dueSoon, notificationTime1)
            {
                Id = taskId + "_1"
            };
            ScheduledToastNotification notifyOnTime = new ScheduledToastNotification(dueNow, notificationTime2)
            {
                Id = taskId + "_2"
            };

            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.AddToSchedule(notifyBefore);
            notifier.AddToSchedule(notifyOnTime);
        }
 public void Schedule(DateTime when)
 {
     StringBuilder template = new StringBuilder();
     template.Append("<toast><visual version='2'><binding template='ToastText02'>");
     template.AppendFormat("<text id='2'>Enter Message:</text>");
     template.Append("</binding></visual><actions>");
     template.Append("<input id='message' type='text'/>");
     template.Append("<action activationType='foreground' content='ok' arguments='ok'/>");
     template.Append("</actions></toast>");
     XmlDocument xml = new XmlDocument();
     xml.LoadXml(template.ToString());
     ScheduledToastNotification toast = new ScheduledToastNotification(xml, when);
     toast.Id = random.Next(1, 100000000).ToString();
     ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
 }
示例#13
0
        /// <summary>
        /// Set alarm toast notification
        /// </summary>
        /// <param name="nextAlarm"></param>
        private void setToast(AlarmEvent nextAlarm)
        {
            ToastNotificationManager.History.Clear();

            string alarmName = nextAlarm.AlarmName;
            string alarmTime = nextAlarm.Day.ToString("hh:mm tt");

            string snoozeTime = nextAlarm.SnoozeTime.SnoozeMin;
            string soundPath = nextAlarm.SelectedSound.ToastFilePath;

            string xml = $@"<toast activationType='foreground' scenario='reminder' launch='args'>
                                            <visual>
                                                <binding template='ToastGeneric'>
                                                <image placement='AppLogoOverride' src='Assets/Alarm_Icon.png'/>
                                                <text>Alarm</text>
                                                <text>{alarmName}</text>
                                                <text>{alarmTime}</text>
                                                </binding>
                                            </visual>
                    <actions>
                       <input id='snoozeTime' type='selection' defaultInput='{snoozeTime}'>
                            <selection id='5' content  = '5 minutes'/>
                            <selection id='10' content = '10 minutes'/>
                            <selection id='20' content = '20 minutes'/>
                            <selection id='30' content = '30 minutes'/>
                            <selection id='60' content = '1 hour'/>
                        </input>
                    <action activationType='system' arguments='snooze' hint-inputId='snoozeTime' content='' />
                    <action activationType='system' arguments='dismiss' content='' />
                    </actions>
                <audio src='{soundPath}' loop='true'/>
                                        </toast>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            DateTime sceduleTime = nextAlarm.Day;

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            var toast = new ScheduledToastNotification(doc, sceduleTime);

            toast.Id = nextAlarm.ID;

            toastNotifier.AddToSchedule(toast);
        }
示例#14
0
        private void createToast()
        {
            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.AddToSchedule(toast);
            }
            catch (Exception ex)
            {
            }
        }
        /// <summary>
        /// Handles the Click event of the Button control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();

            //Removing previous schedules
            foreach (var scheduledNotification in notifier.GetScheduledToastNotifications())
                notifier.RemoveFromSchedule(scheduledNotification);

            //Creating xml template for Toast
            ToastTemplateType toastType = ToastTemplateType.ToastText01;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastType);
            XmlNodeList toastTextElement = toastXml.GetElementsByTagName("text");
            toastTextElement[0].AppendChild(toastXml.CreateTextNode("Hi ! This was scheduled"));

            //Creating Scheduled toast and adding it to schedule
            ScheduledToastNotification scheduleToast = new ScheduledToastNotification(toastXml, DateTime.Today.Add(NotificationTime.Time));
            notifier.AddToSchedule(scheduleToast);
        }
    private void ShowToastNotification(LocalNotification notification)
    {
        var tileXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

        var tileTitle = tileXml.GetElementsByTagName("text");
        ((XmlElement)tileTitle[0]).InnerText = notification.Title;
        ((XmlElement)tileTitle[1]).InnerText = notification.Text;

        var correctedTime = notification.NotifyTime <= DateTime.Now
            ? DateTime.Now.AddMilliseconds(100)
            : notification.NotifyTime;

        var scheduledToastNotification = new ScheduledToastNotification(tileXml, correctedTime)
        {
            Id = notification.Id.ToString()
        };

        ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToastNotification);
    }
        public  void schedulenotif(double time, string content)
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            toastTextElements[0].AppendChild(toastXml.CreateTextNode(content + " begins in 15 minutes"));
            double dueTimeInSec = time;

            DateTime dueTime = DateTime.Now.AddSeconds(dueTimeInSec);
            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
            string content1 = content;
            if (content.Length > 16)
                content1 = content.Substring(0, 16);
            scheduledToast.Id = content1;


            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);

        }
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;

            IToastText02 Trying_Toast = ToastContentFactory.CreateToastText02();

            Trying_Toast.TextHeading.Text = "Hey";

            Trying_Toast.TextBodyWrap.Text = "That’s The content of the toast";

            ScheduledToastNotification GiveitTime;
            GiveitTime = new ScheduledToastNotification(Trying_Toast.GetXml(),

            DateTime.Now.AddSeconds(10));

            GiveitTime.Id = "Any ID";

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(GiveitTime);
        }
        void SendToast(FlickrPhotoResult flickrPhotoResult)
        {
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            XmlDocument xmlToastContent = ToastNotificationManager.GetTemplateContent(
              ToastTemplateType.ToastImageAndText01);

            TemplateUtility.CompleteTemplate(
              xmlToastContent,
              new string[] { flickrPhotoResult.Title },
              new string[] { flickrPhotoResult.ImageUrl },
              "ms-winsoundevent:Notification.Mail");

            // TODO: change delivery time
            ScheduledToastNotification toastNotification = new ScheduledToastNotification(xmlToastContent,
              (new DateTimeOffset(DateTime.Now) + TimeSpan.FromSeconds(10)));

            // TODO: change identifier
            toastNotification.Id = "Fred";

            toastNotifier.AddToSchedule(toastNotification);
        }
示例#20
0
        private void toastf()
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();

            // Make sure notifications are enabled
            if (notifier.Setting != NotificationSetting.Enabled)
            {
                var dialog = new MessageDialog("Notifications are currently disabled");
                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(10);
            var stn = new ScheduledToastNotification(template, date);
            notifier.AddToSchedule(stn);
        }
        public void QueueEventNotifications(EventEntry entity)
        {
            DequeueEventNotifications(entity);

            var notifyXMinutesAhead = new Action<int>(notifyMinutesAhead =>
            {
                try
                {
                    var deliveryDate =
                        GetSanitizedDeliveryDate(entity.EventDateTimeUtc.AddMinutes(0 - notifyMinutesAhead));
                    if (!deliveryDate.HasValue) return;

                    var parts = SplitGuid(entity.Id);

                    var toast = new ScheduledToastNotification(
                        CreateToast($"{entity.Title} {entity.SubTitle}",
                            $"Event starts in {notifyMinutesAhead} minutes",
                            $"toast:eventDetail:{entity.Id}"),
                        deliveryDate.Value)
                    {
                        Id = parts.Item1,
                        Tag = parts.Item2,
                        Group = $"e:{notifyMinutesAhead}min",
                    };

                    _toastNotificationManager.AddToSchedule(toast);
                }
                catch (Exception)
                {

                }
            });

            notifyXMinutesAhead(60);
            notifyXMinutesAhead(30);
            notifyXMinutesAhead(15);
        }
示例#22
0
        static void MakeToastNotifications(Opomnik opomnik)
        {
            foreach (var x in opomnik.Intervali)
            {
                foreach (var y in x.SeznamTerminovZaAlarm)
                {
                    Windows.Data.Xml.Dom.XmlDocument toastXml = new Windows.Data.Xml.Dom.XmlDocument();
                    string toastXmlTemplate = "<toast scenario=\'alarm\' launch=\'app-defined-string\'>" +
                                              "<visual>" +
                                              "<binding template =\'ToastGeneric\'>" +
                                              "<text>" + opomnik.Zdravilo1.Naziv + "</text>" +
                                              "<text>" +
                                              "Vzeti je potrebno: " + x.Doza + " " + opomnik.Zdravilo1.Enota +
                                              "</text>" +
                                              "</binding>" +
                                              "</visual>" +
                                              "<audio src=\'" + opomnik.Melodija + "\'" + "/>" +
                                              "<actions>" +
                                              "<action activationType=\'foreground\' content =\'yes\' arguments=\'" + y.Id + "\'" +
                                              "/>" +
                                              "</actions>" +
                                              "</toast>";

                    toastXml.LoadXml(toastXmlTemplate);
                    //y.TerminZazvonenje = DateTime.Now.AddSeconds(10);
                    var    toast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, y.TerminZazvonenje);
                    Random rnd   = new Random();
                    toast.Id = rnd.Next(10000).ToString();
                    if (Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().Setting ==
                        NotificationSetting.Enabled)
                    {
                        Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                    }
                }
            }
        }
        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);
        }
        void ScheduleToastWithStringManipulation(String updateString, DateTime dueTime, int idNumber)
        {
            // Scheduled toasts use the same toast templates as all other kinds of toasts.
            string toastXmlString = "<toast>"
            + "<visual version='2'>"
            + "<binding template='ToastText02'>"
            + "<text id='2'>" + updateString + "</text>"
            + "<text id='1'>" + "Received: " + dueTime.ToLocalTime() + "</text>"
            + "</binding>"
            + "</visual>"
            + "</toast>";

            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
            try
            {
                toastDOM.LoadXml(toastXmlString);

                ScheduledToastNotification toast;
                if (RepeatBox.IsChecked != null && (bool)RepeatBox.IsChecked)
                {
                    toast = new ScheduledToastNotification(toastDOM, 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(toastDOM, dueTime);
                    toast.Id = "Toast" + idNumber;
                }

                ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                rootPage.NotifyUser("Scheduled a toast with ID: " + toast.Id, NotifyType.StatusMessage);
            }
            catch (Exception)
            {
                rootPage.NotifyUser("Error loading the xml, check for invalid characters in the input", NotifyType.ErrorMessage);
            }
        }
示例#25
0
        private async void Image_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (tbxTitle.Text == "")
            {
                MessageDialog ms = new MessageDialog("Vui lòng nhập tiêu đề!");
                await ms.ShowAsync();
                return;
            }
            if (tbxContent.Text == "")
            {
                MessageDialog ms = new MessageDialog("Vui lòng nhập nội dung!");
                await ms.ShowAsync();
                return;
            }
            var t = time.Time;
            var d = String.Format("{0:d}", date.Date);
            var k = DateTime.ParseExact(d + " " + t, "M/d/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);
            if (k <= DateTime.Now && cbComplete.IsChecked == false)
            {
                MessageDialog ms = new MessageDialog("Hạn chót phải sau thời điểm hiện tại!");
                await ms.ShowAsync();
                return;
            }
            IReadOnlyList<ScheduledToastNotification> scheduled = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();

            foreach (ScheduledToastNotification notify in scheduled)
            {
                if (notify.Id == ("T.note" + ((GhiChu)this.DataContext).Id))
                {
                    ToastNotificationManager.CreateToastNotifier().RemoveFromSchedule(notify);
                }
            }
            GhiChu u = new GhiChu();
            u.Id = ((GhiChu)this.DataContext).Id;
            u.Title = tbxTitle.Text;
            u.Content = tbxContent.Text;
            u.Complete = (bool)cbComplete.IsChecked;
            u.Remind = (bool)cbNhacNho.IsChecked;
            u.Time = k.ToString();
            DatabaseHelper help = new DatabaseHelper();
            help.UpdateContact(u);
            if ((bool)cbNhacNho.IsChecked)
            {
                ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
                XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
                ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "/Assets/noteicon.png");
                ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "alt text");
                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                if ((bool)cbComplete.IsChecked)
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(u.Title + " Hoàn thành!"));
                else
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(u.Title));
                var dueTime = new DateTimeOffset(k);
                var toast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, dueTime);
                toast.Id = "T.note" + u.Id.ToString();
                Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
            }
            if (Frame.CanGoBack)
            {
                Frame.GoBack();
            }
        }
示例#26
0
        private void E_Button_ToastTest_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);


            var dueTime = DateTime.Now.AddSeconds(5);
                
            var strings = toastXml.GetElementsByTagName("text");
            strings[0].AppendChild(toastXml.CreateTextNode("This is a scheduled toast notification"));
            strings[1].AppendChild(toastXml.CreateTextNode("Received: " + dueTime.ToString()));

            // Create the toast notification object.

            var toast = new ScheduledToastNotification(toastXml, dueTime)
            {
                Id = Math.Floor(new Random().NextDouble()*1000000).ToString()
            };



            // Add to the schedule.
            var foo = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();

            if (foo.Count > 0)
            {
                
            }

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);

            var foo2 = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications();
        }
示例#27
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));
        }
        private async void ReminderRegister()
        {

            const string title = "Are you there?";
            const string content = "Click the button below if you are alright!";

            var visual = new ToastVisual
            {
                TitleText = new ToastText
                {
                    Text = title
                },

                BodyTextLine1 = new ToastText
                {
                    Text = content
                }

            };

            var actions = new ToastActionsCustom
            {
                Buttons =
                {
                    new ToastButton("Dismiss", new QueryString
                    {
                        {"action", "dismiss"}
                    }.ToString())
                    {
                        ActivationType = ToastActivationType.Background
                    }
                }

            };

            const int conversationId = 177777;

            var toastContent = new ToastContent
            {
                Visual = visual,
                Actions = actions,
                Scenario = ToastScenario.Reminder,
                Launch = new QueryString
                {
                    {"action","viewConversation" },
                    {"conversationId", conversationId.ToString()}
                }.ToString()
            };

            if (Time > DateTime.Now.TimeOfDay)
            {
                try
                {
                    var scheduled = new ScheduledToastNotification(toastContent.GetXml(),
                        new DateTimeOffset(DateTime.Today + Time)) {Id = "scheduledtoast"};

                    var timeDifference = Time - DateTime.Now.TimeOfDay;
                    timeDifference = timeDifference.Add(new TimeSpan(0, 0, 15, 0));
                    const string taskName = "Reminder";
                    var taskBuilder = new BackgroundTaskBuilder();
                    taskBuilder.Name = taskName;
                    taskBuilder.TaskEntryPoint = typeof (Reminder).FullName;
                    taskBuilder.SetTrigger(new TimeTrigger(Convert.ToUInt32(timeDifference.Minutes.ToString()), true));

                    var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

                    foreach (var task in BackgroundTaskRegistration.AllTasks.Where(task => task.Value.Name == taskName))
                    {
                        task.Value.Unregister(true);
                    }
                    taskBuilder.Register();
                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduled);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
            else
            {
                try
                {
                    var scheduled = new ScheduledToastNotification(toastContent.GetXml(),
                        new DateTimeOffset(DateTime.Today.AddDays(1) + Time))
                    {Id = "scheduledtoast"};
                    
                    var timeDifference = Time.Add(new TimeSpan(1,0,0,0)) ;
                    timeDifference = timeDifference.Add(new TimeSpan(0, 0, 15, 0));
                    const string taskName = "Reminder";
                    var taskBuilder = new BackgroundTaskBuilder();
                    taskBuilder.Name = taskName;
                    taskBuilder.TaskEntryPoint = typeof (Reminder).FullName;
                    taskBuilder.SetTrigger(new TimeTrigger(Convert.ToUInt32(timeDifference.Minutes.ToString()), true));

                    var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

                    foreach (var task in BackgroundTaskRegistration.AllTasks.Where(task => task.Value.Name == taskName))
                    {
                        task.Value.Unregister(true);
                    }

                    ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduled);
                    taskBuilder.Register();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
            
        }
        private async void FeedBtn_Click(object sender, RoutedEventArgs e)
        {
            FeedData feedItem = new FeedData();
                SyndicationClient client = new SyndicationClient();
                Uri RssUri = new Uri("http://dvd.netflix.com/Top100RSS");
                var feeds = await client.RetrieveFeedAsync(RssUri);
            try
            {

                foreach(SyndicationItem feed in feeds.Items)
                {
                    //FeedData feedItem = new FeedData();

                    feedItem.Title = feed.Title.Text;
                    feedItem.PubDate = feed.PublishedDate.DateTime;
                    //feedItem.Image = feed.Summary.Text.Split('<')[5].Replace("img src='", "").Replace("' border='0' />", "");

                    //feedItem.Image = new Regex(@"<img.*?src=""(.*?)""", RegexOptions.IgnoreCase).ToString();

                    //feedItem.Image = Regex.Match(feed.Summary.Text, @"<img\s+src='(.+)'\s+border='0'\s+/>").Groups[1].Value;
                    listTitles.Items.Add(feedItem);

                  

                }
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message).ShowAsync();
            }
            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.ToastImageAndText02);
            var element = template.GetElementsByTagName("text")[1];
            element.AppendChild(template.CreateTextNode("Today's Quote: " + (feedItem.Title.ToString())));
            var eelement = template.GetElementsByTagName("text")[0];
            eelement.AppendChild(template.CreateTextNode("Quote App"));
            XmlNodeList toastImageAttributes = template.GetElementsByTagName("image");

            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///Assets/StoreLogo.scale-100.png");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "red graphic");


            // Schedule the toast to appear 2 seconds from now
            var date = DateTimeOffset.Now.AddSeconds(2);
            var stn = new ScheduledToastNotification(template, date);
            notifier.AddToSchedule(stn);
            //try
            //{
            //    SyndicationClient client = new SyndicationClient();
            //    Uri feedUri = new Uri("http://dvd.netflix.com/Top100RSS");
            //    var feed = await client.RetrieveFeedAsync(feedUri);

            //    foreach(SyndicationItem item in feed.Items)
            //    {
            //        string data = string.Empty;
            //        if(feed.SourceFormat == SyndicationFormat.Atom10)
            //        {
            //            data = item.Content.Text;
            //        }
            //        else if(feed.SourceFormat == SyndicationFormat.Rss20)
            //        {
            //            data = item.Summary.Text;
            //        }

            //        Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?.(?:jpg|bmp|gif|png)", RegexOptions.IgnoreCase);
            //        string filePath = regx.Match(data).Value;

            //        FeedData group = new FeedData(item.Id,
            //                                                    item.Title.Text,
            //                                                    filePath.Replace("small", "large"));
            //        listTitles.Items.Add(group);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    await new MessageDialog(ex.Message).ShowAsync();
            //}




            //HttpClient rssclient = new HttpClient();
            //var RSScontent = await rssclient.GetStringAsync(new Uri("http://teknoseyir.com/feed"));

            //var RssData = from rss in XElement.Parse(RSScontent).Descendants("item")
            //              select new
            //              {
            //                  Title = rss.Element("title").Value,
            //                  pubDate = rss.Element("pubDate").Value,
            //                  Description = rss.Element("description").Value,
            //                  Link = rss.Element("link").Value,
            //                  image = rss.Element("image").Value
            //              };
            //listTitles.Items.Add(RssData);

        }
示例#30
0
        /// <summary>
        /// Display a push notification
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        private void DisplayNotification(string title, string description)
        {

            //<toast>
            //    <visual>
            //        <binding template="ToastText02">
            //            <text id="1">title</text>
            //            <text id="2">description</text>
            //        </binding>
            //    </visual>
            //</toast>

            var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var headlineElement = template.GetElementsByTagName("text")[0];
            var bodyElement = template.GetElementsByTagName("text")[1];

            headlineElement.AppendChild(template.CreateTextNode(title));
            bodyElement.AppendChild(template.CreateTextNode(description));

            var scheduledNotification = new ScheduledToastNotification(template, DateTimeOffset.Now.AddSeconds(1));
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.AddToSchedule(scheduledNotification);
        }
示例#31
0
        private async void themNhacNhoButton_Click(object sender, RoutedEventArgs e)
        {
            // kiem tra ngay gio bao
            if (ngayDatePicker.Date == null || ngayDatePicker.Date < DateTime.Today || (ngayDatePicker.Date == DateTime.Today && gioTimePicker.Time < DateTime.Now.TimeOfDay))
            {
                MessageDialog msDialog1 = new MessageDialog("Ngày báo phải ở tương lai");
                await msDialog1.ShowAsync();
                return;
            }
            // lay thoi gian 
            int day = ngayDatePicker.Date.Value.Day;
            int month = ngayDatePicker.Date.Value.Month;
            int year = ngayDatePicker.Date.Value.Year;
            int hour = gioTimePicker.Time.Hours;
            int minute = gioTimePicker.Time.Minutes;
            DateTime thoigianbao = new DateTime(year, month, day, hour, minute, 0);
            string content = noidungTextBox.Text;
            //int snooze = Convert.ToInt32(((ComboBoxItem)baolaiComboBox.SelectedItem).Tag) * 60;
            //Debug.WriteLine(snooze);
            var xmlString = @"
<toast launch='args' scenario='alarm'>
    <visual>
        <binding template='ToastGeneric'>
            <text>Giảm cân 360</text>
            <text>" + content + @"</text>
        </binding>
    </visual>
    <actions>
        <input id='snoozeTime' type='selection' defaultInput='5'>
            <selection id = '1' content = '1 minutes' />
            <selection id = '5' content = '5 minutes' />
            <selection id = '10' content = '10 minutes' />
            <selection id = '20' content = '20 minutes' />
            <selection id = '30' content = '30 minutes' />
        </input >
        <action activationType='system' arguments = 'snooze' hint-inputId='snoozeTime'
                content = 'Báo lại' />
        <action activationType='system' arguments = 'dismiss'
                content = 'Bỏ qua' />
    </actions>
    <audio loop='true' src='ms-winsoundevent:Notification.Looping.Alarm2' />
</toast>";
            var doc = new Windows.Data.Xml.Dom.XmlDocument();
            doc.LoadXml(xmlString);
            //var toast = new ToastNotification(doc);
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            //thoi gian bao lai
            //TimeSpan snoozeInterval = TimeSpan.FromSeconds(snooze);
            // bao vao thoi gian 
            //var scheduledToast = new ScheduledToastNotification(doc, thoigianbao, snoozeInterval, 0);
            var scheduledToast = new ScheduledToastNotification(doc, thoigianbao);
            toastNotifier.AddToSchedule(scheduledToast);

            MessageDialog msDialog = new MessageDialog("Thêm nhắc nhở thành công");
            await msDialog.ShowAsync();
            Frame.Navigate(typeof(TrangChu), nguoidung);
        }
示例#32
0
        private void CreateNotification(string content)
        {
            var notifier = ToastNotificationManager.CreateToastNotifier();

            // Make sure notifications are enabled
            if (notifier.Setting != NotificationSetting.Enabled)
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Notifications are currently disabled");
                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(content));

            // Schedule the toast to appear 5 seconds from now
            var stn = new ScheduledToastNotification(template, DateTime.Now.AddMilliseconds(100));

            notifier.AddToSchedule(stn);
            notifier.GetScheduledToastNotifications();

        }
        public void AddNotification(LaunchData launchData, NotificationType type)
        {
            if (launchData?.Launch == null)
                return;

            var deliverytime = TimeConverter.DetermineTimeSettings(launchData.Launch.Net, true)
                .AddMinutes(-LaunchPal.App.Settings.NotifyBeforeLaunch.ToIntValue());

            if (deliverytime < DateTime.Now)
            {
                return;
            }

            switch (type)
            {
                case NotificationType.NextLaunch:
                    if (!LaunchPal.App.Settings.LaunchInProgressNotifications)
                        return;
                    break;
                case NotificationType.TrackedLaunch:
                    if (!LaunchPal.App.Settings.TrackedLaunchNotifications)
                        return;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            var groupName = GetGroupNameFromNotificationType(type);

            ToastVisual visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = "Launch Alert!"
                        },
 
                        new AdaptiveText()
                        {
                            Text = $"{launchData?.Launch?.Name} is about to launch."
                        },

                        new AdaptiveText()
                        {
                            Text = $"Time: {TimeConverter.SetStringTimeFormat(launchData.Launch.Net, LaunchPal.App.Settings.UseLocalTime).Replace(" Local", "")}"
                        }
                    },
 
                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source = "Assets/BadgeLogo.scale-200.png",
                        HintCrop = ToastGenericAppLogoCrop.Default
                    }
                }
            };
 

            // Now we can construct the final toast content
            ToastContent toastContent = new ToastContent()
            {
                Visual = visual,
 
                // Arguments when the user taps body of toast
                Launch = new QueryString()
                {
                    { "action", "viewLaunch" },
                    { "LaunchId", launchData?.Launch?.Id.ToString() }
 
                }.ToString(),

                Actions = new ToastActionsCustom()
                {
                    Inputs =
                    {
                        new ToastSelectionBox("snoozeTime")
                        {
                            DefaultSelectionBoxItemId = "15",
                            Items =
                            {
                                new ToastSelectionBoxItem("5", "5 minutes"),
                                new ToastSelectionBoxItem("15", "15 minutes"),
                                new ToastSelectionBoxItem("30", "30 minutes"),
                                new ToastSelectionBoxItem("45", "45 minutes"),
                                new ToastSelectionBoxItem("60", "1 hour")
                            }
                        }
                    },
                    Buttons =
                    {
                        new ToastButtonSnooze()
                        {
                            SelectionBoxId = "snoozeTime"
                        },
                        new ToastButtonDismiss()
                    }
                }
            };

            // And create the toast notification
            var scheduleToast = new ScheduledToastNotification(toastContent.GetXml(), deliverytime)
            {
                Id = launchData?.Launch?.Id.ToString() ?? "0",
                Tag = launchData?.Launch?.Id.ToString() ?? "0",
                Group = groupName,
                NotificationMirroring = NotificationMirroring.Allowed,
            };
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduleToast);
        }
示例#34
0
 public Windows.UI.Notifications.ScheduledToastNotification GetAlarm()
 {
     Windows.UI.Notifications.ScheduledToastNotification toast = new Windows.UI.Notifications.ScheduledToastNotification(toastDOM, BeginTime);
     toast.Tag = _name;
     return(toast);
 }