private async Task SaveFriends() { try { var friendListTask = await DownloadFriends(App.AccessToken); friendListTask = App.IsTrial ? friendListTask.Take(100).ToList() : friendListTask; _savedFriendList = BirthdayUtility.GetFriendList(); if (!App.UserPreferences.ContactSync.FacebookSyncEnabled.HasValue || App.UserPreferences.ContactSync.FacebookSyncEnabled.Value) { //display status message StatusText.Text = AppResources.RetrievingFbFriend; foreach (var user in friendListTask) { //check if the friend exists already if (_savedFriendList != null && _savedFriendList.Count > 0 && _savedFriendList.Exists(f => !String.IsNullOrEmpty(f.FacebookId) && f.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase))) { UpdateExistingFriendToList(user, _savedFriendList.Find(x => !String.IsNullOrEmpty(x.FacebookId) && x.FacebookId.Equals(user.FacebookId, StringComparison.InvariantCultureIgnoreCase))); } else { BirthdayUtility.AddNewFriend(user); } } } //Save friend list to file StatusText.Text = AppResources.SaveBdays; //update the reminder list StatusText.Text = AppResources.CreateBdayReminder; ReminderUtility.UpdateCalendarEntries(); //BirthdayUtility.downloadProfileImages(isSync); //update last sync time in settings and app user preferences App.UserPreferences.ContactSync.LastSync = DateTime.Now; if (App.UserPreferences != null) { SettingsUtility.UpdateUserSettings(App.UserPreferences); } await BirthdayUtility.SyncCards(App.UserPreferences.UserDetails.FacebookId); //update card sync status App.UserPreferences.ContactSync.CardsSynced = true; if (App.UserPreferences != null) { SettingsUtility.UpdateUserSettings(App.UserPreferences); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppResources.ErrBuildBdayList, MessageBoxButton.OK); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } }
/// <summary> /// Retrieves list of recent birthdays /// </summary> /// <returns>List of friend</returns> private void GetRecentBirthdays() { try { var friendList = BirthdayUtility.GetFriendList(); var recentBirthdays = new List <FriendEntity>(); var todayBirthday = new List <FriendEntity>(); var weekBirthday = new List <FriendEntity>(); Settings = SettingsUtility.GetUserPreferences(); LoadLocalizedRes(); var notificationCount = 0; var isReminderExpired = false; foreach (var friend in friendList) { if (!friend.Birthday.HasValue || (friend.IsHidden.HasValue && friend.IsHidden.Value)) { continue; } var daysAhead = DateTimeUtility.GetTimeToEvent(friend.Birthday.Value); //if the birthday is today, add recent birthdays to list if (daysAhead == 0) { //if the birthday is today, raise a toast notification recentBirthdays.Add(friend); todayBirthday.Add(friend); notificationCount++; if (friend.LastToastRaisedYear < DateTime.Now.Year) { if (!Settings.ReminderNotification.LocalNotifications.HasValue || Settings.ReminderNotification.LocalNotifications.Value) { RaiseToast(friend.Name + " " + Resources.BdayTodayMsg, Resources.BdayTileLabel, new Uri("/FriendDetails.xaml?" + UriParameter.FriendId + "=" + friend.UniqueId, UriKind.Relative)); } //update the last notification raised year friend.LastToastRaisedYear = DateTime.Now.Year; BirthdayUtility.UpdateFriendDetails(friend); } } //if birthday is tomorrow if (daysAhead == 1) { recentBirthdays.Add(friend); notificationCount++; } //check if reminder for upcoming birthdays exist if (daysAhead > 0 && daysAhead < 7) { if (!friend.IsReminderCreated) { isReminderExpired = true; notificationCount++; } weekBirthday.Add(friend); } } //raise a toast notification if reminders have to be created if (isReminderExpired) { RaiseToast(Resources.UpdateBdayReminder, Resources.BdayTileLabel, new Uri("/StartChecks.xaml?" + UriParameter.Action + "=Toast", UriKind.Relative)); } //update shell tile UpdateTile(notificationCount, weekBirthday); BirthdayUtility.DownloadProfileImages("No"); //send an email - [[to be implemented later]] //if (settings.ReminderNotification.SendEmailReminders && !string.IsNullOrEmpty(settings.UserDetails.Email)) //{ // String emailText = getReminderEmailContent(todayBirthday); // sendEmail(settings.UserDetails.Email,emailText); //} ////wish via email //if (todayBirthday!=null && todayBirthday.Count>0) //{ // wishViaEmail(todayBirthday); //} } catch (Exception ex) { AppLog.WriteToLog(DateTime.Now, ex.Message + ". " + ex.StackTrace, LogLevel.Error); throw; } }