//******************************** HELPER FUNCTIONS *******************// private static List <Contact> prepareList(List <Contact> fromSqlList, IUserContactsCollectionPage mscontactslist) { var temp = new List <Contact>(); foreach (Contact c in fromSqlList) { var match = mscontactslist.Where(m => m.FileAs == c.FileAs).FirstOrDefault(); c.Id = match.Id; //set the Id property from SQL to MS Contact Id temp.Add(c); } return(temp); }
private async void GetContactsButton_Click(Object sender, RoutedEventArgs e) { try { //contacts = await graphClient.Me.Contacts.Request().Top(20).GetAsync(); // contacts = await graphClient.Me.Contacts.Request().OrderBy("displayName").GetAsync(); contacts = await graphClient.Me.Contacts.Request().OrderBy("displayName") .Select("displayName,emailAddresses").GetAsync(); //contacts = await graphClient.Me.Contacts.Request() // .Filter("startswith(displayName,'A'") // .Select("displayName,emailAddresses").GetAsync(); MyContacts = new ObservableCollection <Models.Contact>(); while (true) { foreach (var contact in contacts) { if (contact.DisplayName.StartsWith("A")) { MyContacts.Add(new Models.Contact { Id = contact.Id, DisplayName = contact.DisplayName, EmailAddress = (contact.EmailAddresses.Count() > 0) ? $"{contact.EmailAddresses.First().Address}" : "Unknown email", }); } } if (MyContacts.Count() >= 20) { break; } if (contacts.NextPageRequest == null) { break; } contacts = await contacts.NextPageRequest.GetAsync(); } ContactCountTextBlock.Text = $"Here are your first {MyContacts.Count()} contacts that start with A"; ContactsDataGrid.ItemsSource = MyContacts; } catch (ServiceException ex) { ContactCountTextBlock.Text = $"We could not get contacts: {ex.Error.Message}"; } }
public void InitializeDefaultData() { this.Me = new User(); Me.Mail = "*****@*****.**"; Me.DisplayName = "Test Test"; this.MyMessages = new MailFolderMessagesCollectionPage(); this.Users = new GraphServiceUsersCollectionPage(); this.People = new UserPeopleCollectionPage(); this.Contacts = new UserContactsCollectionPage(); }
public async Task GetContactsPaging() { try { IUserContactsCollectionPage page = await graphClient.Me.Contacts.Request().GetAsync(); while (page.NextPageRequest != null) { page = await page.NextPageRequest.GetAsync(); } } catch (Microsoft.Graph.ServiceException e) { Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code); } }
public async Task ContactsExpandExtensionsPaging() { try { IUserContactsCollectionPage page = await graphClient.Me.Contacts.Request().Expand($"extensions($filter=Id eq 'Microsoft.OutlookServices.OpenTypeExtension.Com.Contoso.Mainer')").GetAsync(); // When expanding extensions, a filter must be provided to specify which extensions to expand. For example $expand=Extensions($filter=Id eq 'Com.Insightly.CRMOpportunity'). while (page.NextPageRequest != null) { page = await page.NextPageRequest.GetAsync(); } } catch (Microsoft.Graph.ServiceException e) { Assert.Fail("Something happened, check out a trace. Error code: {0}", e.Error.Code); } }
/// <summary> /// GetContactAsync. /// </summary> /// <param name="name">name.</param> /// <returns>Task contains List of Contacts.</returns> private async Task <List <Contact> > GetMSContactsAsync(string name) { List <Contact> items = new List <Contact>(); var optionList = new List <QueryOption>(); var filterString = $"startswith(displayName, '{name}') or startswith(givenName,'{name}') or startswith(surname,'{name}')"; optionList.Add(new QueryOption("$filter", filterString)); // Get the current user's profile. IUserContactsCollectionPage contacts = null; try { contacts = await this._graphClient.Me.Contacts.Request(optionList).GetAsync(); } catch (ServiceException ex) { throw GraphClient.HandleGraphAPIException(ex); } if (contacts?.Count > 0) { foreach (Contact contact in contacts) { // Filter out conference rooms. string displayName = contact.DisplayName ?? string.Empty; if (!displayName.StartsWith("Conf Room")) { // Get user properties. items.Add(contact); } if (items.Count >= 10) { break; } } } return(items); }
/// <inheritdoc/> internal override async Task <List <CalendarSkillContactModel> > CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { var name = (string)parameters["Name"]; var results = new List <CalendarSkillContactModel>(); var optionList = new List <QueryOption>(); optionList.Add(new QueryOption("$search", $"\"{name}\"")); // Get the current user's profile. IUserContactsCollectionPage contacts = await client.Me.Contacts.Request(optionList).Select("displayName,emailAddresses,imAddresses").GetAsync(cancellationToken).ConfigureAwait(false); var contactsResult = new List <CalendarSkillContactModel>(); if (contacts?.Count > 0) { foreach (var contact in contacts) { var emailAddresses = contact.EmailAddresses.Where(e => this.IsEmail(e.Address)).Select(e => e.Address).ToList(); if (!emailAddresses.Any()) { emailAddresses = contact.ImAddresses.Where(e => this.IsEmail(e)).ToList(); } if (emailAddresses.Any()) { // Get user properties. contactsResult.Add(new CalendarSkillContactModel { Name = contact.DisplayName, EmailAddresses = emailAddresses, Id = contact.Id, }); } } } IUserPeopleCollectionPage people = await client.Me.People.Request(optionList).Select("displayName,emailAddresses").GetAsync(cancellationToken).ConfigureAwait(false); if (people?.Count > 0) { var existingResult = new HashSet <string>(contactsResult.SelectMany(c => c.EmailAddresses), StringComparer.OrdinalIgnoreCase); foreach (var person in people) { var emailAddresses = new List <string>(); foreach (var email in person.EmailAddresses) { // If the email address isn't already included in the contacts list, add it if (!existingResult.Contains(email.Address) && this.IsEmail(email.Address)) { emailAddresses.Add(email.Address); } } // Get user properties. if (emailAddresses.Any()) { results.Add(new CalendarSkillContactModel { Name = person.DisplayName, EmailAddresses = emailAddresses, Id = person.Id, }); } } } results.AddRange(contactsResult); return(results); }