Esempio n. 1
0
 public async static Task PlanToastNotifications(CancellationToken token, PrayerTimeCalculation prayerCalculation, Location location)
 {
     if (!token.IsCancellationRequested)
     {
         await Task.Factory.StartNew(() =>
         {
             DoToastNotificationPlanning(ref token, prayerCalculation, location);
         }, token);
     }
 }
Esempio n. 2
0
        private async Task UpdateToastNotifications(Location location, MethodBase method, string asrMethod, string midnightMethod)
        {

            this.source = new CancellationTokenSource();
            PrayerTimeCalculation prayerCalculation = new PrayerTimeCalculation(
                method,
                ConvertStringToAsrMethod(asrMethod),
                ConvertStringToMidnightMethod(midnightMethod),
                this.MaghribAdjustement);

            await Notification.PlanToastNotifications(source.Token, prayerCalculation, location);
        }
Esempio n. 3
0
        private void ComputePrayers(TimeZoneInfo timeZoneInfo = null)
        {
            prayerCalculation = new PrayerTimeCalculation(
                GetMethod(),
                ConvertStringToAsrMethod(this.asrMethod),
                ConvertStringToMidnightMethod(this.midnightMethod),
                this.MaghribAdjustement);

            Groups = new ObservableCollection<Group>();
            int length = 0;
            DateTime dateUsed = currentDate, date;
            switch (displayMode)
            {
                case DisplayModes.Today:
                    length = 1;
                    break;
                case DisplayModes.NextSevenDays:
                    length = 7;
                    break;
                case DisplayModes.CurrentMonth:
                    length = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
                    dateUsed = new DateTime(currentDate.Year, currentDate.Month, 1);
                    break;
            }

            for (int i = 0; i < length; i++)
            {
                date = dateUsed.AddDays(i);
                string day = date.ToString("ddd d MMM");

                TimeFormat format = TimeFormat.Format24h;
                if (timeZoneInfo != null)
                    Location.Dst = LocationService.GetTimezoneDST(timeZoneInfo, date);
                else
                    Location.Dst = LocationService.GetDSTByRegion(Location.Country, Location.State, Location.City, Location.TimeZone, date);

                ObservableCollection<Prayer> prayers = DictionaryPrayersToCollection(prayerCalculation.GetTimes(date, Location.Latitude, Location.Longitude, Location.TimeZone, Location.Dst, format), date, i - 1);
                Group group = new Group();
                group.Items = prayers;
                group.Title = day;
                Groups.Add(group);
            }

            // Assign the next prayer for each prayer...
            for (int i = 0; i < Groups.Count; i++)
            {
                for (int j = 0; j < Groups[i].Items.Count; j++)
                {
                    if (j + 1 < Groups[i].Items.Count)
                        Groups[i].Items[j].NextPrayer = Groups[i].Items[j + 1];
                    else if (i + 1 < Groups.Count)
                        Groups[i].Items[j].NextPrayer = Groups[i + 1].Items[0];
                    else
                        Groups[i].Items[j].NextPrayer = null;
                }
            }

            OnPropertyChanged("Groups");
        }
Esempio n. 4
0
        private static void DoToastNotificationPlanning(ref CancellationToken token, PrayerTimeCalculation prayerCalculation, Location location)
        {
            // Plan notifications for 680 days
            int days = 680;
            DateTime now = DateTime.Now;
            DateTime currentDate = new DateTime(now.Year, now.Month, now.Day);
            DateTime date;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            // Remove all scheduled notifications
            IEnumerable<ScheduledToastNotification> scheduledNotifications = notifier.GetScheduledToastNotifications();
            foreach (ScheduledToastNotification scheduledNotification in scheduledNotifications)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                notifier.RemoveFromSchedule(scheduledNotification);
            }

            for (int i = 0; i < days; i++)
            {
                date = currentDate.AddDays(i);
                string day = date.ToString("ddd d MMM");

                TimeFormat format = TimeFormat.Format24h;
                int dst = LocationService.GetDSTByRegion(location.Country, location.State, location.City, location.TimeZone, date);
                IDictionary prayers = prayerCalculation.GetTimes(date, location.Latitude, location.Longitude, location.TimeZone, dst, format);

                foreach (DictionaryEntry prayer in prayers)
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    if (prayer.Key != "Imsak" && prayer.Key != "Sunset" && prayer.Key != "Midnight")
                    {
                        string prayerName = prayer.Key.ToString();
                        if (prayer.Key == "Sunrise")
                        {
                            prayerName = "Shuruq";
                        }

                        XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
                        string label = prayerName == "Shuruq" ? loader.GetString("ToastNotificationShuruqText") : loader.GetString("ToastNotificationText");
                        if (!stringElements.Item(0).HasChildNodes())
                        {
                            stringElements.Item(0).AppendChild(toastXml.CreateTextNode(label));
                        }
                        else
                        {
                            stringElements.Item(0).ReplaceChild(toastXml.CreateTextNode(label), stringElements.Item(0).FirstChild);
                        }

                        string prayerText = prayerName + " " + prayer.Value.ToString();
                        if (!stringElements.Item(1).HasChildNodes())
                        {
                            stringElements.Item(1).AppendChild(toastXml.CreateTextNode(prayerText));
                        }
                        else
                        {
                            stringElements.Item(1).ReplaceChild(toastXml.CreateTextNode(prayerText), stringElements.Item(1).FirstChild);
                        }

                        string[] split = prayer.Value.ToString().Split(':');
                        DateTime prayerTime = date.AddHours(Convert.ToDouble(split[0])).AddMinutes(Convert.ToDouble(split[1]));

                        if (prayerTime > DateTime.Now)
                        {
                            DateTimeOffset displayTime = new DateTimeOffset(prayerTime);
                            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, displayTime);
                            scheduledToast.Id = prayerName + " " + i;
                            notifier.AddToSchedule(scheduledToast);
                        }
                    }
                }
            }
        }