Пример #1
0
        void _phoneContacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            ContactsList.Clear();
            try
            {
                if (e.Results.Any())
                {
                    var items = (from r in e.Results
                                 where r.Birthdays.Any()
                                 select r);
                    ContactsList.AddRange(items);
                    if (GetEntriesCompleted != null)
                    {
                        GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                        {
                            Contacts = GetBirthdayContacts().AsQueryable()
                        });
                    }
                }
                else
                {
                    if (GetEntriesCompleted != null)
                    {
                        GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                        {
                            Contacts = new List <BirthdayContact>().AsQueryable()
                        });
                    }
                }
            }
#if DEBUG
            catch (InvalidOperationException iex)
            {
                DebugUtility.SaveDiagnosticException(iex);
#else
            catch
            {
#endif
                if (GetEntriesCompleted != null)
                {
                    GetEntriesCompleted(this, new GetEntriesCompletedEventArgs()
                    {
                        Contacts = new List <BirthdayContact>().AsQueryable()
                    });
                }
            }
        }
Пример #2
0
        public Task <IQueryable <BirthdayContact> > GetAllEntriesAsync(bool forceRefresh = false)
        {
            TaskCompletionSource <IQueryable <BirthdayContact> > tcs = new TaskCompletionSource <IQueryable <BirthdayContact> >();

            if (ContactsList.Count == 0 || forceRefresh)
            {
                Contacts contacts = new Contacts();
                contacts.SearchCompleted += (s, e) =>
                {
                    try
                    {
                        ContactsList.Clear();
                        if (e.Results.Any())
                        {
                            var items = (from r in e.Results
                                         where r.Birthdays.Any()
                                         select r);
                            ContactsList.AddRange(items);
                            tcs.TrySetResult(GetBirthdayContacts().AsQueryable());
                        }
                        else
                        {
                            tcs.TrySetResult(new List <BirthdayContact>().AsQueryable());
                        }
                    }
                    catch (InvalidOperationException iex)
                    {
                        tcs.TrySetException(iex);
                    }
                };
                contacts.SearchAsync(String.Empty, FilterKind.None, "Load Contacts");
                return(tcs.Task);
            }
            else
            {
                tcs.SetResult(GetBirthdayContacts().AsQueryable());
                return(tcs.Task);
            }
        }