├── .nuget
├── NuGet.exe
├── NuGet.Config
└── NuGet.targets
├── OneNoteServiceSamplesWinUniversal.Shared
├── Assets
│ ├── Logo.jpg
│ ├── BizCard.png
│ ├── DarkGray.png
│ ├── LightGray.png
│ ├── MediumGray.png
│ └── attachment.pdf
├── App.xaml
├── SharedBasePage.xaml
├── Common
│ ├── AppSettings.cs
│ ├── RelayCommand.cs
│ └── ObservableDictionary.cs
├── OneNoteServiceSamplesWinUniversal.Shared.shproj
├── OneNoteApi
│ ├── Pages
│ │ ├── PageResponse.cs
│ │ ├── DeletePageExample.cs
│ │ └── PatchPagesExample.cs
│ ├── HttpUtils.cs
│ ├── GenericEntityResponse.cs
│ ├── Auth.cs
│ ├── ApiBaseResponse.cs
│ ├── Notebooks
│ │ └── PostNotebooksExample.cs
│ ├── Sections
│ │ └── PostSectionsExample.cs
│ ├── SectionGroups
│ │ └── PostSectionGroupsExample.cs
│ ├── LiveIdAuth.cs
│ └── O365Auth.cs
├── OneNoteServiceSamplesWinUniversal.Shared.projitems
├── SharedBasePage.xaml.cs
├── Strings
│ └── en-US
│ │ └── Resources.resw
├── App.xaml.cs
└── DataModel
│ └── ItemPageModel.cs
├── OneNoteServiceSamplesWinUniversal.Windows
├── Assets
│ ├── Logo.scale-100.png
│ ├── SmallLogo.scale-100.png
│ ├── StoreLogo.scale-100.png
│ ├── WideLogo.scale-100.png
│ └── SplashScreen.scale-100.png
├── packages.config
├── Properties
│ └── AssemblyInfo.cs
├── Package.appxmanifest
├── SectionPage.xaml.cs
├── SectionPage.xaml
├── HubPage.xaml.cs
├── HubPage.xaml
├── ItemPage.xaml.cs
└── OneNoteServiceSamplesWinUniversal.Windows.csproj
├── OneNoteServiceSamplesWinUniversal.WindowsPhone
├── Assets
│ ├── Logo.scale-240.png
│ ├── SmallLogo.scale-240.png
│ ├── StoreLogo.scale-240.png
│ ├── WideLogo.scale-240.png
│ ├── SplashScreen.scale-240.png
│ ├── HubBackground.theme-dark.png
│ ├── HubBackground.theme-light.png
│ └── Square71x71Logo.scale-240.png
├── packages.config
├── Properties
│ └── AssemblyInfo.cs
├── Package.appxmanifest
├── SectionPage.xaml
├── SectionPage.xaml.cs
├── ContinuationManager.cs
├── HubPage.xaml.cs
├── ItemPage.xaml
├── OneNoteServiceSamplesWinUniversal.WindowsPhone.csproj
└── HubPage.xaml
├── .gitattributes
├── .gitignore
└── OneNoteServiceSamplesWinUniversal.sln
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/Logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/Logo.jpg
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/BizCard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/BizCard.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/DarkGray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/DarkGray.png
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/LightGray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/LightGray.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/MediumGray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/MediumGray.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Assets/attachment.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Shared/Assets/attachment.pdf
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Assets/Logo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Windows/Assets/Logo.scale-100.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Assets/SmallLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Windows/Assets/SmallLogo.scale-100.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Assets/StoreLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Windows/Assets/StoreLogo.scale-100.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Assets/WideLogo.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Windows/Assets/WideLogo.scale-100.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/Logo.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/Logo.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Assets/SplashScreen.scale-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.Windows/Assets/SplashScreen.scale-100.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/SmallLogo.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/SmallLogo.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/StoreLogo.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/StoreLogo.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/WideLogo.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/WideLogo.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/SplashScreen.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/SplashScreen.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/HubBackground.theme-dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/HubBackground.theme-dark.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/HubBackground.theme-light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/HubBackground.theme-light.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/Square71x71Logo.scale-240.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneNoteDev/OneNoteAPISampleWinUniversal/master/OneNoteServiceSamplesWinUniversal.WindowsPhone/Assets/Square71x71Logo.scale-240.png
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/SharedBasePage.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Common/AppSettings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Windows.Storage;
5 |
6 | namespace OneNoteServiceSamplesWinUniversal.Common
7 | {
8 | public static class AppSettings
9 | {
10 | public static bool GetProviderO365()
11 | {
12 | object result = false;
13 | ApplicationData.Current.LocalSettings.Values.TryGetValue("ProviderO365", out result);
14 | return (bool)(result ?? false);
15 | }
16 | public static void SetProviderO365(bool isO365)
17 | {
18 | ApplicationData.Current.LocalSettings.Values["ProviderO365"] = isO365;
19 | }
20 |
21 | public static bool GetUseBeta()
22 | {
23 | object result = false;
24 | ApplicationData.Current.LocalSettings.Values.TryGetValue("UseBeta", out result);
25 | return (bool)(result ?? false); // default to true
26 | }
27 | public static void SetUseBeta(bool useBeta)
28 | {
29 | ApplicationData.Current.LocalSettings.Values["UseBeta"] = useBeta;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteServiceSamplesWinUniversal.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 556a67f3-bd06-49be-ae69-e638d2d6a790
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("OneNoteServiceSamplesWinUniversal.Windows")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("OneNoteServiceSamplesWinUniversal.Windows")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("OneNoteServiceSamplesWinUniversal.WindowsPhone")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("OneNoteServiceSamplesWinUniversal.WindowsPhone")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | OneNoteAPISamplesUniversal
6 | OneNoteSamples_MSFT
7 | Assets\StoreLogo.png
8 |
9 |
10 | 6.3.0
11 | 6.3.0
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/Pages/PageResponse.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 |
20 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi.Pages
21 | {
22 | ///
23 | /// This class represents the OneNote API Pages response
24 | /// Any response from the Pages API (POST/GET etc) can be translated into this object for ease of use.
25 | ///
26 | ///
27 | /// This is not meant to be a comprehensive SDK or data model.
28 | /// This is ONLY a light-weight representation of a OneNote API's page response.
29 | /// The API's HTTP json response is deserialized into this object
30 | ///
31 | public class PageResponse : ApiBaseResponse
32 | {
33 | ///
34 | /// Title of the page
35 | ///
36 | public string Title;
37 |
38 | public override string ToString()
39 | {
40 | return "Title: " + Title + ", Id: " + Id;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | OneNoteAPISamplesUniversal
7 | OneNoteSamples_MSFT
8 | Assets\StoreLogo.png
9 |
10 |
11 | 6.3.1
12 | 6.3.1
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/HttpUtils.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Net;
4 | using System.Net.Http;
5 | using System.Threading.Tasks;
6 | using Newtonsoft.Json;
7 |
8 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi
9 | {
10 | public static class HttpUtils
11 | {
12 | #region Helper methods used in the examples
13 |
14 | ///
15 | /// Convert the HTTP response message into a simple structure suitable for apps to process
16 | ///
17 | /// The response to convert
18 | ///
19 | /// A simple response
20 | public static async Task TranslateResponse(HttpResponseMessage response, HttpStatusCode expectedStatusCode = HttpStatusCode.Created)
21 | {
22 | ApiBaseResponse apiBaseResponse;
23 | string body = await response.Content.ReadAsStringAsync();
24 | if (response.StatusCode == expectedStatusCode
25 | /* POST calls always return 201-Created upon success */)
26 | {
27 | apiBaseResponse = JsonConvert.DeserializeObject(body);
28 | }
29 | else
30 | {
31 | apiBaseResponse = new ApiBaseResponse();
32 | }
33 |
34 | // Extract the correlation id. Apps should log this if they want to collect the data to diagnose failures with Microsoft support
35 | IEnumerable correlationValues;
36 | if (response.Headers.TryGetValues("X-CorrelationId", out correlationValues))
37 | {
38 | apiBaseResponse.CorrelationId = correlationValues.FirstOrDefault();
39 | }
40 | apiBaseResponse.StatusCode = response.StatusCode;
41 | apiBaseResponse.Body = body;
42 | return apiBaseResponse;
43 | }
44 |
45 | #endregion
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/GenericEntityResponse.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 |
20 | using System.Collections.Generic;
21 |
22 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi
23 | {
24 | ///
25 | /// This class represents a generic the OneNote API entity response
26 | /// Any response from the Notebooks/Sections/SectionGroups API (POST/GET etc) can be translated into this object for ease of use.
27 | ///
28 | ///
29 | /// This is not meant to be a comprehensive SDK or data model.
30 | /// This is ONLY a light-weight representation of a OneNote API's entities (Notebooks, Sections, SectionGroups)
31 | /// The API's HTTP json response is deserialized into this object
32 | ///
33 | public class GenericEntityResponse : ApiBaseResponse
34 | {
35 | ///
36 | /// Name of the entity
37 | ///
38 | public string Name;
39 |
40 | ///
41 | /// Self link to the given entity
42 | ///
43 | public string Self { get; set; }
44 |
45 | public List Sections { get; set; }
46 |
47 | public List SectionGroups { get; set; }
48 |
49 | public override string ToString()
50 | {
51 | return "Name: " + Name + ", Id: " + Id;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/Auth.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 |
20 | using System.Threading.Tasks;
21 |
22 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi
23 | {
24 | public enum AuthProvider
25 | {
26 | MicrosoftAccount,
27 | MicrosoftOffice365
28 | }
29 |
30 | ///
31 | /// This class contains all Authentication related code for interacting with the OneNote APIs
32 | ///
33 | ///
34 | /// Based on the context, we either will authenticate user for O365 or for Live ID
35 | ///
36 | internal static class Auth
37 | {
38 | ///
39 | /// Gets a valid authentication token for the selected Authentication provider
40 | ///
41 | ///
42 | /// Used by the API request generators before making calls to the OneNote APIs.
43 | ///
44 | /// valid authentication token
45 | internal static async Task GetAuthToken(AuthProvider provider)
46 | {
47 | if (provider == AuthProvider.MicrosoftAccount)
48 | {
49 | return await LiveIdAuth.GetAuthToken();
50 | }
51 | else
52 | {
53 | return await O365Auth.GetAuthToken();
54 | }
55 | }
56 |
57 | internal static async Task SignOut(AuthProvider provider)
58 | {
59 | if (provider == AuthProvider.MicrosoftAccount)
60 | {
61 | await LiveIdAuth.SignOut();
62 | }
63 | else
64 | {
65 | await O365Auth.SignOut();
66 | }
67 | }
68 |
69 | internal static bool IsSignedIn(AuthProvider provider)
70 | {
71 | if (provider == AuthProvider.MicrosoftAccount)
72 | {
73 | return LiveIdAuth.IsSignedIn;
74 | }
75 | else
76 | {
77 | return O365Auth.IsSignedIn;
78 | }
79 | }
80 |
81 | internal static async Task GetUserName(AuthProvider provider)
82 | {
83 | if (provider == AuthProvider.MicrosoftAccount)
84 | {
85 | return await LiveIdAuth.GetUserName();
86 | }
87 | else
88 | {
89 | return await O365Auth.GetUserName();
90 | }
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/ApiBaseResponse.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 |
20 | using System.Net;
21 |
22 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi
23 | {
24 | ///
25 | /// Base class representing a simplified response from ALL OneNote APIs
26 | ///
27 | public class ApiBaseResponse
28 | {
29 | ///
30 | /// All OneNote API reponses return a meaningful Http status code
31 | /// Typical pattern for Http status codes are used:
32 | /// 1 1xx Informational
33 | /// 2 2xx Success. e.g. 200-OK for GETs, 201 -Created for POSTs
34 | /// 3 3xx Redirection
35 | /// 4 4xx Client Error e.g. 400-Bad Request
36 | /// 5 5xx Server Error e.g. 500-Internal Server Error
37 | ///
38 | public HttpStatusCode StatusCode { get; set; }
39 |
40 | ///
41 | /// Per call identifier that can be logged to diagnose issues with Microsoft support
42 | /// CorrelationId is included in all Response Headers
43 | ///
44 | public string CorrelationId { get; set; }
45 |
46 | ///
47 | /// Body of the OneNote API response represented as a string.
48 | /// For error cases, this will typically include an error json intended for developers, not for end users.
49 | /// For success cases, depending on the type API call/HTTP verb this may or may not include a json value
50 | ///
51 | public string Body { get; set; }
52 |
53 | ///
54 | /// URLs to launch OneNote rich client/web app
55 | ///
56 | public Links Links { get; set; }
57 |
58 | ///
59 | /// Unique identifier of the object
60 | ///
61 | public string Id { get; set; }
62 |
63 | }
64 |
65 | public class Links
66 | {
67 | ///
68 | /// URL to launch OneNote rich client
69 | ///
70 | public HrefUrl OneNoteClientUrl { get; set; }
71 |
72 | ///
73 | /// URL to launch OneNote web experience
74 | ///
75 | public HrefUrl OneNoteWebUrl { get; set; }
76 | }
77 |
78 | public class HrefUrl
79 | {
80 | public string Href { get; set; }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 |
98 | # NuGet Packages Directory
99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100 | #packages/
101 |
102 | # Windows Azure Build Output
103 | csx
104 | *.build.csdef
105 |
106 | # Windows Store app package directory
107 | AppPackages/
108 |
109 | # Others
110 | sql/
111 | *.Cache
112 | ClientBin/
113 | [Ss]tyle[Cc]op.*
114 | ~$*
115 | *~
116 | *.dbmdl
117 | *.[Pp]ublish.xml
118 | *.pfx
119 | *.publishsettings
120 |
121 | # RIA/Silverlight projects
122 | Generated_Code/
123 |
124 | # Backup & report files from converting an old project file to a newer
125 | # Visual Studio version. Backup files are not needed, because we have git ;-)
126 | _UpgradeReport_Files/
127 | Backup*/
128 | UpgradeLog*.XML
129 | UpgradeLog*.htm
130 |
131 | # SQL Server files
132 | App_Data/*.mdf
133 | App_Data/*.ldf
134 |
135 |
136 | #LightSwitch generated files
137 | GeneratedArtifacts/
138 | _Pvt_Extensions/
139 | ModelManifest.xml
140 |
141 | # =========================
142 | # Windows detritus
143 | # =========================
144 |
145 | # Windows image file caches
146 | Thumbs.db
147 | ehthumbs.db
148 |
149 | # Folder config file
150 | Desktop.ini
151 |
152 | # Recycle Bin used on file shares
153 | $RECYCLE.BIN/
154 |
155 | # Mac desktop service store files
156 | .DS_Store
157 | /packages
158 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Common/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Input;
7 |
8 | namespace OneNoteServiceSamplesWinUniversal.Common
9 | {
10 | ///
11 | /// A command whose sole purpose is to relay its functionality
12 | /// to other objects by invoking delegates.
13 | /// The default return value for the CanExecute method is 'true'.
14 | /// needs to be called whenever
15 | /// is expected to return a different value.
16 | ///
17 | public class RelayCommand : ICommand
18 | {
19 | private readonly Action _execute;
20 | private readonly Func _canExecute;
21 |
22 | ///
23 | /// Raised when RaiseCanExecuteChanged is called.
24 | ///
25 | public event EventHandler CanExecuteChanged;
26 |
27 | ///
28 | /// Creates a new command that can always execute.
29 | ///
30 | /// The execution logic.
31 | public RelayCommand(Action execute)
32 | : this(execute, null)
33 | {
34 | }
35 |
36 | ///
37 | /// Creates a new command.
38 | ///
39 | /// The execution logic.
40 | /// The execution status logic.
41 | public RelayCommand(Action execute, Func canExecute)
42 | {
43 | if (execute == null)
44 | throw new ArgumentNullException("execute");
45 | _execute = execute;
46 | _canExecute = canExecute;
47 | }
48 |
49 | ///
50 | /// Determines whether this can execute in its current state.
51 | ///
52 | ///
53 | /// Data used by the command. If the command does not require data to be passed, this object can be set to null.
54 | ///
55 | /// true if this command can be executed; otherwise, false.
56 | public bool CanExecute(object parameter)
57 | {
58 | return _canExecute == null ? true : _canExecute();
59 | }
60 |
61 | ///
62 | /// Executes the on the current command target.
63 | ///
64 | ///
65 | /// Data used by the command. If the command does not require data to be passed, this object can be set to null.
66 | ///
67 | public void Execute(object parameter)
68 | {
69 | _execute();
70 | }
71 |
72 | ///
73 | /// Method used to raise the event
74 | /// to indicate that the return value of the
75 | /// method has changed.
76 | ///
77 | public void RaiseCanExecuteChanged()
78 | {
79 | var handler = CanExecuteChanged;
80 | if (handler != null)
81 | {
82 | handler(this, EventArgs.Empty);
83 | }
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/Pages/DeletePageExample.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 |
20 | using System.Diagnostics;
21 | using System.Net.Http;
22 | using System.Net.Http.Headers;
23 | using System.Threading.Tasks;
24 |
25 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi.Pages
26 | {
27 | ///
28 | /// Class to show a selection of examples deleting pages via HTTP DELETE to the OneNote API
29 | /// - Delete a new page is represented via the DELETE HTTP verb.
30 | /// For more info, see http://dev.onenote.com/docs#/reference/delete-pages.
31 | ///
32 | ///
33 | /// NOTE: It is not the goal of this code sample to produce well re-factored, elegant code.
34 | /// You may notice code blocks being duplicated in various places in this project.
35 | /// We have deliberately added these code blocks to allow anyone browsing the sample
36 | /// to easily view all related functionality in near proximity.
37 | ///
38 | ///
39 | /// var client = new HttpClient();
40 | /// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await Auth.GetAuthToken());
41 | ///
42 | /// var deleteMessage = new HttpRequestMessage(HttpMethod.Delete, "https://www.onenote.com/api/v1.0/pages");
43 | /// HttpResponseMessage response = await client.SendAsync(deleteMessage);
44 | ///
45 | public static class DeletePagesExample
46 | {
47 | #region Examples of DELETE https://www.onenote.com/api/v1.0/pages
48 |
49 | ///
50 | /// Delete a page.
51 | ///
52 | /// Run the code under the debugger
53 | ///
54 | ///
55 | ///
56 | /// Delete a specified page by ID.
57 | /// The converted HTTP response message
58 | public static async Task DeletePage(bool debug, string pageId, AuthProvider provider, string apiRoute)
59 | {
60 | if (debug)
61 | {
62 | Debugger.Launch();
63 | Debugger.Break();
64 | }
65 |
66 | var client = new HttpClient();
67 |
68 | // Note: API only supports JSON response.
69 | client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
70 |
71 | // Not adding the Authentication header would produce an unauthorized call and the API will return a 401
72 | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
73 | await Auth.GetAuthToken(provider));
74 |
75 | // Prepare an HTTP DELETE request to the Pages endpoint
76 | // The request body content type is text/html
77 | var deleteMessage = new HttpRequestMessage(HttpMethod.Delete, apiRoute + "pages/" + pageId);
78 | var response = await client.SendAsync(deleteMessage);
79 |
80 | return await HttpUtils.TranslateResponse(response);
81 | }
82 |
83 | #endregion
84 | }
85 | }
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Windows/SectionPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Windows.UI.Xaml.Controls;
3 | using Windows.UI.Xaml.Navigation;
4 | using OneNoteServiceSamplesWinUniversal.Common;
5 | using OneNoteServiceSamplesWinUniversal.Data;
6 |
7 | namespace OneNoteServiceSamplesWinUniversal
8 | {
9 | ///
10 | /// A page that displays an overview of a single group, including a preview of the items
11 | /// within the group.
12 | ///
13 | public sealed partial class SectionPage : SharedBasePage
14 | {
15 | private NavigationHelper navigationHelper;
16 | private ObservableDictionary defaultViewModel = new ObservableDictionary();
17 |
18 | public SectionPage()
19 | {
20 | InitializeComponent();
21 | navigationHelper = new NavigationHelper(this);
22 | navigationHelper.LoadState += NavigationHelper_LoadState;
23 | }
24 |
25 | ///
26 | /// Gets the NavigationHelper used to aid in navigation and process lifetime management.
27 | ///
28 | public NavigationHelper NavigationHelper
29 | {
30 | get { return navigationHelper; }
31 | }
32 |
33 | ///
34 | /// Gets the DefaultViewModel. This can be changed to a strongly typed view model.
35 | ///
36 | public ObservableDictionary DefaultViewModel
37 | {
38 | get { return defaultViewModel; }
39 | }
40 |
41 | ///
42 | /// Populates the page with content passed during navigation. Any saved state is also
43 | /// provided when recreating a page from a prior session.
44 | ///
45 | ///
46 | /// The source of the event; typically
47 | ///
48 | /// Event data that provides both the navigation parameter passed to
49 | /// when this page was initially requested and
50 | /// a dictionary of state preserved by this page during an earlier
51 | /// session. The state will be null the first time a page is visited.
52 | private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
53 | {
54 | // TODO: Create an appropriate data model for your problem domain to replace the sample data
55 | var group = await SampleDataSource.GetGroupAsync((string)e.NavigationParameter);
56 | DefaultViewModel["Group"] = group;
57 | DefaultViewModel["Items"] = group.Items;
58 | pageTitle.Text = group.Title;
59 | }
60 |
61 | ///
62 | /// Invoked when an item is clicked.
63 | ///
64 | /// The GridView displaying the item clicked.
65 | /// Event data that describes the item clicked.
66 | private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
67 | {
68 | // Navigate to the appropriate destination page, configuring the new page
69 | // by passing required information as a navigation parameter
70 | var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;
71 | Frame.Navigate(typeof(ItemPage), itemId);
72 | }
73 |
74 | #region NavigationHelper registration
75 |
76 | ///
77 | /// The methods provided in this section are simply used to allow
78 | /// NavigationHelper to respond to the page's navigation methods.
79 | /// Page specific logic should be placed in event handlers for the
80 | ///
81 | /// and .
82 | /// The navigation parameter is available in the LoadState method
83 | /// in addition to page state preserved during an earlier session.
84 | ///
85 | protected override void OnNavigatedTo(NavigationEventArgs e)
86 | {
87 | navigationHelper.OnNavigatedTo(e);
88 | }
89 |
90 | protected override void OnNavigatedFrom(NavigationEventArgs e)
91 | {
92 | navigationHelper.OnNavigatedFrom(e);
93 | }
94 |
95 | #endregion
96 | }
97 | }
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteServiceSamplesWinUniversal.Shared.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 556a67f3-bd06-49be-ae69-e638d2d6a790
7 |
8 |
9 | OneNoteServiceSamplesWinUniversal
10 |
11 |
12 |
13 | Designer
14 |
15 |
16 | App.xaml
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | SharedBasePage.xaml
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | Designer
56 | MSBuild:Compile
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.WindowsPhone/SectionPage.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/Notebooks/PostNotebooksExample.cs:
--------------------------------------------------------------------------------
1 | //*********************************************************
2 | // Copyright (c) Microsoft Corporation
3 | // All rights reserved.
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the ""License"");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT
11 | // WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS
12 | // OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
13 | // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
14 | // PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
15 | //
16 | // See the Apache Version 2.0 License for specific language
17 | // governing permissions and limitations under the License.
18 | //*********************************************************
19 | using System.Diagnostics;
20 | using System.Linq;
21 | using System.Net;
22 | using System.Net.Http;
23 | using System.Net.Http.Headers;
24 | using System.Text;
25 | using System.Threading.Tasks;
26 |
27 | namespace OneNoteServiceSamplesWinUniversal.OneNoteApi.Notebooks
28 | {
29 | ///
30 | /// Class to show a selection of examples creating notebooks via HTTP POST to the OneNote API
31 | /// - Creating a new notebook is represented via the POST HTTP verb.
32 | /// - Creating a new notebook represented by the Uri: https://www.onenote.com/api/v1.0/notebooks
33 | /// For more info, see http://dev.onenote.com/docs
34 | ///
35 | ///
36 | /// NOTE: All notebooks get created under the 'Documents' folder of the user's OneDrive account.
37 | /// The notebook name is specified in the request body
38 | /// NOTE: It is not the goal of this code sample to produce well re-factored, elegant code.
39 | /// You may notice code blocks being duplicated in various places in this project.
40 | /// We have deliberately added these code blocks to allow anyone browsing the sample
41 | /// to easily view all related functionality in near proximity.
42 | ///
43 | ///
44 | /// var client = new HttpClient();
45 | /// client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
46 | /// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await Auth.GetAuthToken());
47 | /// var createMessage = new HttpRequestMessage(HttpMethod.Post, "https://www.onenote.com/api/v1.0/notebooks")
48 | /// {
49 | /// Content = new StringContent("{name: NewNotebookName }", System.Text.Encoding.UTF8, "application/json")
50 | /// };
51 | /// HttpResponseMessage response = await client.SendAsync(createMessage);
52 | ///
53 | public static class PostNotebooksExample
54 | {
55 | #region Examples of POST https://www.onenote.com/api/v1.0/notebooks
56 |
57 | ///
58 | /// Create a notebook with a given name
59 | ///
60 | /// Run the code under the debugger
61 | ///
62 | ///
63 | ///
64 | /// Create notebook using a application/json content type
65 | /// The converted HTTP response message
66 | public static async Task CreateSimpleNotebook(bool debug, string notebookName, AuthProvider provider, string apiRoute)
67 | {
68 | if (debug)
69 | {
70 | Debugger.Launch();
71 | Debugger.Break();
72 | }
73 |
74 | var client = new HttpClient();
75 |
76 | // Note: API only supports JSON response.
77 | client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
78 |
79 | // Not adding the Authentication header would produce an unauthorized call and the API will return a 401
80 | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",
81 | await Auth.GetAuthToken(provider));
82 |
83 | // Prepare an HTTP POST request to the Notebooks endpoint
84 | // The request body content type is application/json and require a name property
85 | var createMessage = new HttpRequestMessage(HttpMethod.Post, apiRoute + "notebooks")
86 | {
87 | Content = new StringContent("{ name : '" + WebUtility.UrlEncode(notebookName) + "' }", Encoding.UTF8, "application/json")
88 | };
89 |
90 | HttpResponseMessage response = await client.SendAsync(createMessage);
91 |
92 | return await HttpUtils.TranslateResponse(response);
93 | }
94 |
95 | #endregion
96 |
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/OneNoteServiceSamplesWinUniversal.Shared/Common/ObservableDictionary.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Windows.Foundation.Collections;
5 |
6 | namespace OneNoteServiceSamplesWinUniversal.Common
7 | {
8 | ///
9 | /// Implementation of IObservableMap that supports reentrancy for use as a default view
10 | /// model.
11 | ///
12 | public class ObservableDictionary : IObservableMap
13 | {
14 | private class ObservableDictionaryChangedEventArgs : IMapChangedEventArgs
15 | {
16 | public ObservableDictionaryChangedEventArgs(CollectionChange change, string key)
17 | {
18 | this.CollectionChange = change;
19 | this.Key = key;
20 | }
21 |
22 | public CollectionChange CollectionChange { get; private set; }
23 | public string Key { get; private set; }
24 | }
25 |
26 | private Dictionary _dictionary = new Dictionary();
27 | public event MapChangedEventHandler MapChanged;
28 |
29 | private void InvokeMapChanged(CollectionChange change, string key)
30 | {
31 | var eventHandler = MapChanged;
32 | if (eventHandler != null)
33 | {
34 | eventHandler(this, new ObservableDictionaryChangedEventArgs(change, key));
35 | }
36 | }
37 |
38 | public void Add(string key, object value)
39 | {
40 | this._dictionary.Add(key, value);
41 | this.InvokeMapChanged(CollectionChange.ItemInserted, key);
42 | }
43 |
44 | public void Add(KeyValuePair item)
45 | {
46 | this.Add(item.Key, item.Value);
47 | }
48 |
49 | public bool Remove(string key)
50 | {
51 | if (this._dictionary.Remove(key))
52 | {
53 | this.InvokeMapChanged(CollectionChange.ItemRemoved, key);
54 | return true;
55 | }
56 | return false;
57 | }
58 |
59 | public bool Remove(KeyValuePair item)
60 | {
61 | object currentValue;
62 | if (this._dictionary.TryGetValue(item.Key, out currentValue) &&
63 | Object.Equals(item.Value, currentValue) && this._dictionary.Remove(item.Key))
64 | {
65 | this.InvokeMapChanged(CollectionChange.ItemRemoved, item.Key);
66 | return true;
67 | }
68 | return false;
69 | }
70 |
71 | public object this[string key]
72 | {
73 | get
74 | {
75 | return this._dictionary[key];
76 | }
77 | set
78 | {
79 | this._dictionary[key] = value;
80 | this.InvokeMapChanged(CollectionChange.ItemChanged, key);
81 | }
82 | }
83 |
84 | public void Clear()
85 | {
86 | var priorKeys = this._dictionary.Keys.ToArray();
87 | this._dictionary.Clear();
88 | foreach (var key in priorKeys)
89 | {
90 | this.InvokeMapChanged(CollectionChange.ItemRemoved, key);
91 | }
92 | }
93 |
94 | public ICollection Keys
95 | {
96 | get { return this._dictionary.Keys; }
97 | }
98 |
99 | public bool ContainsKey(string key)
100 | {
101 | return this._dictionary.ContainsKey(key);
102 | }
103 |
104 | public bool TryGetValue(string key, out object value)
105 | {
106 | return this._dictionary.TryGetValue(key, out value);
107 | }
108 |
109 | public ICollection