private async Task ShowContacts(ContactReader reader) { txtContacts.Text = ""; //reset text box var batch = await reader.ReadBatchAsync(); while (batch.Contacts.Count != 0 && batch.Status == ContactBatchStatus.Success) { foreach (Contact c in batch.Contacts) { txtContacts.Text += c.FirstName + " " + c.LastName + "\n"; } batch = await reader.ReadBatchAsync(); } }
/// <summary> /// Update displayed contacts. /// </summary> /// <param name="reader"></param> /// <returns></returns> private async Task DisplayContactsFromReaderAsync(ContactReader reader) { Contacts.Clear(); ContactBatch contactBatch = await reader.ReadBatchAsync(); while (contactBatch.Contacts.Count != 0 && contactBatch.Status == ContactBatchStatus.Success) { foreach (Contact c in contactBatch.Contacts) { Contacts.Add(new ContactViewModel(c)); } contactBatch = await reader.ReadBatchAsync(); } }
public async Task <List <string> > getContacts() { List <string> listResults = new List <string>(); ContactStore store = null; IReadOnlyList <ContactList> list = null; ContactReader reader = null; ContactBatch batch = null; // *** This RequestStoreAsync() call is where the exception is thrown. All the cases below have the same issue. *** //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite); //store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); store = await ContactManager.RequestStoreAsync(); list = await store.FindContactListsAsync(); foreach (ContactList contactList in list) { reader = contactList.GetContactReader(); batch = await reader.ReadBatchAsync(); foreach (Contact contact in batch.Contacts) { string fullname = contact.FullName; //+ ", " + contact.Name;// + ", " + contact.Emails.First().Address; listResults.Add(fullname); DisplayContact dc = new DisplayContact(contact); vDisplayContact.Add(dc); } } return(listResults); }
async Task <ObservableCollection <Contact> > GetContactsAsync() { ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); //find contact list ContactList contactlist = await store.CreateContactListAsync(Windows.ApplicationModel.Package.Current.DisplayName); //problem if it already exists ContactReader contactreader = contactlist.GetContactReader(); ContactBatch contactbatch = await contactreader.ReadBatchAsync(); return(new ObservableCollection <Contact>(contactbatch.Contacts)); // store.FindContactsAsync() }
/// <summary> /// Displays the items from the contact store in the contacts view. /// </summary> /// <param name="reader">Contact store reader</param> /// <param name="isGroup"> /// Boolean to decide if to show the list in a group or a flat list /// Groups is shown by default and search /// Flast list is shown during search /// </param> private async Task DisplayContactsFromReaderAsync(ContactReader reader, bool isGroup) { contactItems.Clear(); ContactBatch contactBatch = await reader.ReadBatchAsync(); if (contactBatch.Contacts.Count == 0) { Debug.WriteLine("Contact store empty"); ContactsStatusText = "We couldn't find any contacts."; ShowContactListStatusText(); return; } while (contactBatch.Contacts.Count != 0) { //should batch add to avoid triggering callbacks foreach (Contact c in contactBatch.Contacts) { ContactItem contactToAdd = new ContactItem(c.Id, c.DisplayName); contactToAdd.SetImageAsync(c.Thumbnail); contactItems.Add(contactToAdd); } contactBatch = await reader.ReadBatchAsync(); } if (isGroup) { GroupsOfContacts = alphaGroupSorting(contactItems); ShowContactGroup(); } else { ListOfContacts = contactItems; ShowContactList(); } return; }
private async Task DisplayContactsFromReaderAsync(ContactReader reader, bool isGroup) { contactItems.Clear(); ContactBatch contactBatch = await reader.ReadBatchAsync(); if (contactBatch.Contacts.Count == 0) { return; } while (contactBatch.Contacts.Count != 0) { foreach (Contact c in contactBatch.Contacts) { if (c.Phones.Count > 0 || c.Emails.Count > 0) { ContactItem contactToAdd = new ContactItem(c.Id, c.DisplayName); contactToAdd.ContactEmails = c.Emails; contactToAdd.ContactPhones = c.Phones; contactToAdd.SetImageAsync(c.Thumbnail); contactItems.Add(contactToAdd); } } contactBatch = await reader.ReadBatchAsync(); } if (isGroup) { groupsOfContacts = alphaGroupSorting(contactItems); } else { _contactsList = contactItems; } return; }
private async Task <IReadOnlyList <Contact> > ListContactsAsync() { ContactStore store = await Store(); if (store != null) { ContactList list = await GetAsync(); if (list != null) { ContactReader reader = list.GetContactReader(); if (reader != null) { ContactBatch batch = await reader.ReadBatchAsync(); if (batch != null) { return(batch.Contacts); } } } } return(null); }
/// <summary> /// Displays the items from the contact store in the contacts view. /// </summary> /// <param name="reader">Contact store reader</param> /// <param name="isGroup"> /// Boolean to decide if to show the list in a group or a flat list /// Groups is shown by default and search /// Flast list is shown during search /// </param> private async Task DisplayContactsFromReaderAsync(ContactReader reader, bool isGroup) { contactItems.Clear(); ContactBatch contactBatch = await reader.ReadBatchAsync(); if (contactBatch.Contacts.Count == 0) { Debug.WriteLine("Contact store empty"); ContactsStatusText = "We couldn't find any contacts."; ShowContactListStatusText(); return; } while (contactBatch.Contacts.Count != 0) { //should batch add to avoid triggering callbacks foreach (Contact c in contactBatch.Contacts) { ContactItem contactToAdd = new ContactItem(c.Id, c.DisplayName); contactToAdd.SetImageAsync(c.Thumbnail); contactItems.Add(contactToAdd); } contactBatch = await reader.ReadBatchAsync(); } if (isGroup) { GroupsOfContacts = alphaGroupSorting(contactItems); ShowContactGroup(); } else { ListOfContacts = contactItems; ShowContactList(); } return; }