コード例 #1
0
        private void BindDataContext()
        {
            var birthdays = BirthdayUtility.GetBirthdays();

            LocalizeBirthdayText(birthdays);

            birthdays.AlphaGroupAllBirthdays = AlphaKeyGroup <FriendBirthday> .CreateGroups
                                               (
                birthdays.AllBirthdays,
                Thread.CurrentThread.CurrentUICulture,
                f => f.Name, true
                                               );

            BirthdayCardList.SelectedItems.Clear();
            birthdays.BirthdayCards = new ObservableCollection <CardEntity>();
            DataContext             = birthdays;

            foreach (var card in BirthdayUtility.GetBirthdayCards())
            {
                birthdays.BirthdayCards.Add(card);
            }
        }
コード例 #2
0
        /// <summary>
        /// Delete old calendar entries and add new ones
        /// </summary>
        public static void UpdateCalendarEntries()
        {
            try
            {
                ClearOldReminders();

                //add a dummy reminder to test in debug mode
//#if DEBUG

//                if (ScheduledActionService.Find("DummyReminder") != null)
//                {
//                    ScheduledActionService.Remove("DummyReminder");
//                }
//                Reminder dummyReminder = new Reminder("DummyReminder");
//                dummyReminder.BeginTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute + 1, 0);
//                dummyReminder.Title = AppResources.BirthdayLabel;
//                dummyReminder.Content = "Shahzad " + AppResources.BirthdayReminderMessage;
//                ScheduledActionService.Add(dummyReminder);

//#endif



                //create new reminders
                var allBirthdays = BirthdayUtility.GetBirthdays().AllBirthdays;

                if (allBirthdays == null || !allBirthdays.Any())
                {
                    return;
                }

                var orderedBirthdayList = allBirthdays.Where(b => b.DaysAhead.HasValue && b.DaysAhead > 0)
                                          .OrderBy(b => b.DaysAhead)
                                          .ToList();

                foreach (var birthday in orderedBirthdayList)
                {
                    //check to see if the reminder aleady exists and the birthday has a value
                    if (ScheduledActionService.Find(birthday.Id.ToString()) != null || !birthday.Birthday.HasValue)
                    {
                        continue;
                    }

                    //add a reminder
                    var birthdayValue = birthday.Birthday.Value;
                    var reminder      = new Reminder(birthday.Id.ToString())
                    {
                        BeginTime     = GetBeginTime(birthdayValue),
                        Content       = birthday.Name + " " + AppResources.BirthdayReminderMessage,
                        NavigationUri = new Uri("/FriendDetails.xaml?" + UriParameter.FriendId + "=" + birthday.Id, UriKind.Relative),
                        Title         = AppResources.BirthdayLabel
                    };

                    ScheduledActionService.Add(reminder);

                    //update friend details to reflect reminder created
                    var friend = BirthdayUtility.GetFriendDetailsById(birthday.Id);

                    if (friend == null)
                    {
                        continue;
                    }

                    friend.IsReminderCreated = true;
                    BirthdayUtility.UpdateFriendDetails(friend);
                }
            }
            catch (InvalidOperationException ex)
            {
                if (!ex.Message.Contains("The maximum number of ScheduledActions of this type have already been added"))
                {
                    throw;
                }
            }
        }