Пример #1
0
        public async static void UpdateTile(Location location, string method, string asrMethod, string midnightMethod)
        {
            string lang = "en";
            CultureInfo currentCulture = CultureInfo.CurrentCulture;
            if (currentCulture.Name == "fr-FR")
                lang = "fr";

            DateTime date = DateTime.Now;
            int dst = LocationService.GetDSTByRegion(location.Country, location.State, location.City, location.TimeZone, date);
            CultureInfo culture = new CultureInfo("en-US");
            DateTime expires = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59).ToUniversalTime();
            string urlString = string.Format("http://islamine.com/services/prayertimes?date={0}&latitude={1}&longitude={2}&timezone={3}&dst={4}&method={5}&city={6}&timezonename={7}&lang={8}&asr={9}&midnight={10}",
                date.ToString("yyyy-MM-dd HH:mm:ss"),
                location.Latitude.ToString("0.#####", culture),
                location.Longitude.ToString("0.#####", culture),
                location.TimeZone.ToString("0.#", culture),
                dst,
                method,
                location.City,
                location.TimezoneName.Replace('/', '-'),
                lang,
                asrMethod,
                midnightMethod);

            PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;
            DateTime tomorrow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 1).AddDays(1);
            DateTimeOffset startTime = new DateTimeOffset(tomorrow);
            TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(new Uri(urlString), recurrence);
        }
Пример #2
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);
     }
 }
Пример #3
0
 private void UpdateTile(Location location, MethodBase method, string asrMethod, string midnightMethod)
 {
     if (!string.IsNullOrEmpty(location.City) && method != null)
         Notification.UpdateTile(location, method.ToString(), asrMethod, midnightMethod);
 }
Пример #4
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);
        }
Пример #5
0
        public void UpdateNotifications()
        {
            // Cancel previous toast notification planning
            this.CancelPlanningToastNotifications();

            Location homeLocation = new Location();
            homeLocation.Latitude = Convert.ToDouble(localSettings.Values["latitude"]);
            homeLocation.Longitude = Convert.ToDouble(localSettings.Values["longitude"]);
            homeLocation.City = (string)localSettings.Values["city"];
            homeLocation.State = (string)localSettings.Values["state"];
            homeLocation.Country = (string)localSettings.Values["country"];
            homeLocation.TimeZone = Convert.ToDouble(localSettings.Values["timezone"]);
            homeLocation.TimezoneName = (string)localSettings.Values["timezoneName"];

            MethodBase homeMethod = null;
            if (MethodName == "Auto")
                homeMethod = GetMethodByCountry(location.Country, location.City);
            else
                homeMethod = Method;

            this.UpdateTile(homeLocation, homeMethod, AsrMethod, MidnightMethod);
            toastNotificationsTask = this.UpdateToastNotifications(homeLocation, homeMethod, AsrMethod, MidnightMethod);
        }
Пример #6
0
        public async void SearchCity(string city)
        {
            try
            {
                ErrorMessage = "";
                IsSearching = true;
                bool found = false;
                Location = new Location();

                // Try in cache first
                List<Location> cacheList = await LocationService.GetLocationsFromCache();
                foreach (Location item in cacheList)
                {
                    if (item.City.ToLower().Contains(city.ToLower()))
                    {
                        Location = item;
                        found = true;
                        IsCoordsComplete = true;
                        IsSearching = false;
                        break;
                    }
                }

                //if (found && LocationService.IsCachedLocationExpired(Location))
                //{
                //    LocationService.DeleteFile(Filenames.Locations);
                //    found = false;
                //}

                if (!found)
                {
                    Tuple<double, double, string, string, string> position = await LocationService.GetPosition(city);
                    Location.Latitude = position.Item1;
                    Location.Longitude = position.Item2;
                    Location.City = position.Item3;
                    Location.State = position.Item4;
                    Location.Country = position.Item5;

                    Tuple<double, int, string> zoneInfos = await LocationService.GetTimeInfos(Location.Latitude, Location.Longitude);
                    Location.TimeZone = zoneInfos.Item1;
                    Location.TimezoneName = zoneInfos.Item3;
                    Location.Dst = LocationService.GetDSTByRegion(Location.Country, Location.State, Location.City, Location.TimeZone, DateTime.Now);

                    OnPropertyChanged("Location");

                    IsCoordsComplete = true;

                    // Mise en cache
                    await LocationService.CacheLocation(Location.City, Location.State, Location.Country, Location.Latitude, Location.Longitude, Location.TimeZone, Location.Dst, Location.TimezoneName);
                }
                ComputePrayers();

                if (string.IsNullOrEmpty((string)localSettings.Values["city"]))
                {
                    SaveHomeSettings();
                    UpdateNotifications();
                }
            }
            catch (FileNotFoundException)
            {
                ErrorMessage = loader.GetString("ErrorMessagesLocationNotFoundError");
            }
            catch (NotSupportedException e)
            {
                ErrorMessage = e.Message;
            }
            catch (Exception)
            {
                ErrorMessage = loader.GetString("ErrorMessagesInternetConnectionError");
            }
            finally
            {
                IsSearching = false;
            }
        }
Пример #7
0
 public void LoadPrayersByLocation(Location location)
 {
     Location = location;
     ComputePrayers();
 }
Пример #8
0
 public async Task LoadPrayersWithGeolocation()
 {
     IsSearching = true;
     Location = new Location();
     bool success = await GetGeoposition();
     if (success)
     {
         SaveHomeSettings();
         ComputePrayers(TimeZoneInfo.Local);
         UpdateNotifications();
     }
     else
     {
         if (Groups != null && Groups.Count > 0)
             Groups.Clear();
     }
 }
Пример #9
0
        public PrayerViewModel()
        {
            timer.Tick += TimerTick;
            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();

            currentDate = DateTime.Now;

            MethodUsedString = loader.GetString("CurrentMethod");

            DisplayMode = DisplayModes.NextSevenDays;
            MethodName = (string)localSettings.Values["method"];
            if (string.IsNullOrWhiteSpace(MethodName))
                MethodName = MethodsList[0];

            AsrMethod = (string)localSettings.Values["asrMethod"];
            if (string.IsNullOrWhiteSpace(AsrMethod))
                AsrMethod = AsrMethodsList[0];

            MidnightMethod = (string)localSettings.Values["midnightMethod"];
            if (string.IsNullOrWhiteSpace(MidnightMethod))
                MidnightMethod = MidnightMethodsList[0];

            int maghribAdj;
            if (int.TryParse((string)localSettings.Values["maghribAdjustement"], out maghribAdj))
                MaghribAdjustement = maghribAdj;
            else
                MaghribAdjustement = DefaultValues.MaghribAdjustment;

            Location = new Location();

            try
            {
                SearchPane = SearchPane.GetForCurrentView();
                if (SearchPane != null)
                {
                    this.IsSearchEnabled = true;
                }
            }
            catch { }
        }
Пример #10
0
 public FavoritesViewModel(Location location = null)
 {
     this.location = location;
     FavoritesTitle = loader.GetString("FavoritesTitle");
 }
Пример #11
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);
                        }
                    }
                }
            }
        }