Example #1
0
        public OneNoteTests() : base()
        {
            // Get a page of OneNote sections.
            IOnenoteSectionsCollectionPage sectionPage = graphClient.Me
                                                         .Onenote
                                                         .Sections
                                                         .Request()
                                                         .GetAsync()
                                                         .Result;

            // Get a handle to the first section.
            firstSectionID = sectionPage[0].Id;
        }
Example #2
0
        public static void GetTestSectionId(TestContext c)
        {
            // Get a page of OneNote sections.
            IOnenoteSectionsCollectionPage sectionPage = graphClient.Me
                                                         .Onenote
                                                         .Sections
                                                         .Request()
                                                         .GetAsync()
                                                         .Result;

            // Get a handle to the first section.
            firstSectionID = sectionPage[0].Id;
        }
Example #3
0
        public static async Task SaveToOneNoteAsync(string NoteText)
        {
            GraphServiceClient graphClient = MicrosoftGraphService.Instance.GraphProvider;

            try
            {
                IOnenoteSectionsCollectionPage oneNoteSections = await graphClient.Me.Onenote.Sections.Request()
                                                                 .Filter("displayName eq 'Quick Notes'")
                                                                 .GetAsync();

                string oneNoteSectionId = oneNoteSections[0].Id;

                string oneNoteAddPageRequestUrl = graphClient.Me.Onenote.Sections[oneNoteSectionId].Pages.Request().RequestUrl;

                string oneNotePageBodyHtml = String.Concat(
                    @"<!DOCTYPE html><html><head><title>",
                    NoteText,
                    @"</title></head><body>Generated by QuickNotes</body></html> "
                    );

                HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, oneNoteAddPageRequestUrl);
                httpRequestMessage.Content = new StringContent(oneNotePageBodyHtml, System.Text.Encoding.UTF8, "text/html");
                await graphClient.AuthenticationProvider.AuthenticateRequestAsync(httpRequestMessage);

                HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(httpRequestMessage);

                if (!response.IsSuccessStatusCode)
                {
                    throw new ServiceException(
                              new Error
                    {
                        Code    = response.StatusCode.ToString(),
                        Message = await response.Content.ReadAsStringAsync()
                    });
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
Example #4
0
        public async Async.Task OneNoteListSections()
        {
            try
            {
                IOnenoteSectionsCollectionPage sectionsCollection = await graphClient.Me
                                                                    .Onenote
                                                                    .Sections
                                                                    .Request()
                                                                    .GetAsync();

                Assert.IsTrue(sectionsCollection.Count > 0, $"Expected at least one Section; Actual {sectionsCollection.Count}");
                Assert.IsNotNull(sectionsCollection[0].Id, "Expected an ID value; ID value is missing.");
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.Fail("Error code: {0}", e.Error.Code);
            }

            catch (Exception e)
            {
                Assert.Fail("Error code: {0}", e.Message);
            }
        }
Example #5
0
        private async Task <IActionResult> QueryData(string agrs)
        {
            // Build a client application.
            IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
                                                               .Create("INSERT-CLIENT-APP-ID")
                                                               .Build();
            // Create an authentication provider by passing in a client application and graph scopes.
            DeviceCodeProvider authProvider = new DeviceCodeProvider(publicClientApplication);
            // Create a new instance of GraphServiceClient with the authentication provider.
            GraphServiceClient             graphClient      = new GraphServiceClient(authProvider);
            IOnenoteSectionsCollectionPage myOneNoteResults = await graphClient.Me.Onenote.Sections.Request()
                                                              .Select(u => new
            {
                u.DisplayName,
                u.CreatedBy,
                u.PagesUrl
            }).Filter("<filter condition>")
                                                              .OrderBy("receivedDateTime")
                                                              .GetAsync();


            return(View());
        }
Example #6
0
        public async Task OneNoteListSections()
        {
            try
            {
                IOnenoteSectionsCollectionPage sectionsCollection = await graphClient.Me
                                                                    .Onenote
                                                                    .Sections
                                                                    .Request()
                                                                    .GetAsync();

                Assert.True(sectionsCollection.Count > 0);
                Assert.NotNull(sectionsCollection[0].Id);
            }
            catch (Microsoft.Graph.ServiceException e)
            {
                Assert.True(false, $"Error code: {e.Error.Code}");
            }

            catch (Exception e)
            {
                Assert.True(false, $"Error code: {e.Message}");
            }
        }
        /// <summary>
        /// Gets the OneNote sections of the user authenticated with GraphServiceClient.
        /// </summary>
        /// <param name="client">An authenticated GraphServiceClient containing the user's access token.</param>
        /// <returns>The list of sections owned by the user.</returns>
        public static async Task <List <OnenoteSection> > GetMySections(GraphServiceClient client)
        {
            IOnenoteSectionsCollectionPage results = await client.Me.Onenote.Sections.Request().GetAsync();

            return(results.ToList());
        }