private async void btnDiscoverContacts_Click(object sender, RoutedEventArgs e)
        {
            String discoveryResultText = "Capability: {0} \nEndpoint Uri: {1} \nResource Id: {2}\n\n";

            var capabilityContacts = ServiceCapabilities.Contacts.ToString();

            CapabilityDiscoveryResult discoveryCapabilityResult = await Office365ServiceHelper.GetDiscoveryCapabilityResultAsync(capabilityContacts);

            txtBoxStatus.Text = String.Format(discoveryResultText,
                                              capabilityContacts,
                                              discoveryCapabilityResult.ServiceEndpointUri.ToString(),
                                              discoveryCapabilityResult.ServiceResourceId).Replace("\n", Environment.NewLine);

            OutlookServicesClient outlookContactsClient = new OutlookServicesClient(discoveryCapabilityResult.ServiceEndpointUri,
                                                                                    async() =>
            {
                return(await Office365ServiceHelper.GetAccessTokenForResourceAsync(discoveryCapabilityResult));
            });

            var contactsResults = await outlookContactsClient.Me.Contacts.ExecuteAsync();

            do
            {
                var contacts = contactsResults.CurrentPage;
                foreach (var contact in contacts)
                {
                    txtBoxStatus.Text += String.Format(discoveryResultText,
                                                       capabilityContacts,
                                                       contact.DisplayName,
                                                       contact.JobTitle).Replace("\n", Environment.NewLine);
                }

                contactsResults = await contactsResults.GetNextPageAsync();
            } while (contactsResults != null);
        }
        private async void btnDiscoverMyFiles_Click(object sender, RoutedEventArgs e)
        {
            String discoveryResultText = "Capability: {0} \nEndpoint Uri: {1} \nResource Id: {2}\n\n";

            var capabilityMyFiles = ServiceCapabilities.MyFiles.ToString();

            CapabilityDiscoveryResult discoveryCapabilityResult = await Office365ServiceHelper.GetDiscoveryCapabilityResultAsync(capabilityMyFiles);

            txtBoxStatus.Text = String.Format(discoveryResultText,
                                              capabilityMyFiles,
                                              discoveryCapabilityResult.ServiceEndpointUri.ToString(),
                                              discoveryCapabilityResult.ServiceResourceId).Replace("\n", Environment.NewLine);
        }
        private async void btnGetAllCapabilities_Click(object sender, RoutedEventArgs e)
        {
            txtBoxStatus.Text = "";

            String discoveryResultText = "Capability: {0} \nEndpoint Uri: {1} \nResource Id: {2}\n\n";

            var capabilitiesResult = await Office365ServiceHelper.GetAllCapabilityDiscoveryResultAsync();

            foreach (var capability in capabilitiesResult)
            {
                txtBoxStatus.Text += String.Format(discoveryResultText,
                                                   capability.Key,
                                                   capability.Value.ServiceEndpointUri.ToString(),
                                                   capability.Value.ServiceResourceId).Replace("\n", Environment.NewLine);
            }
        }