├── README.md ├── GraphSDKDemo ├── Assets │ ├── StoreLogo.png │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Wide310x150Logo.scale-200.png │ ├── Square150x150Logo.scale-200.png │ └── Square44x44Logo.targetsize-24_altform-unplated.png ├── Models │ ├── GroupInfoList.cs │ ├── File.cs │ ├── Folder.cs │ ├── Event.cs │ ├── Message.cs │ └── Contact.cs ├── Views │ ├── HomePage.xaml.cs │ ├── HomePage.xaml │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── ContactsPage.xaml.cs │ ├── ContactsPage.xaml │ ├── EventsPage.xaml │ ├── MessagesPage.xaml │ ├── EventsPage.xaml.cs │ ├── DriveItemsPage.xaml.cs │ ├── MessagesPage.xaml.cs │ └── DriveItemsPage.xaml ├── Properties │ ├── AssemblyInfo.cs │ └── Default.rd.xml ├── GraphDateTimeTimeZoneConverter.cs ├── Package.appxmanifest ├── App.xaml.cs ├── OAuth.resw ├── GraphSDKDemo.csproj └── App.xaml ├── LICENSE ├── GraphSDKDemo.sln └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # GraphSDK 2 | Code from my Building Apps with Microsoft Graph and Visual Studio talk 3 | -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/StoreLogo.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /GraphSDKDemo/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogreen/GraphSDK/HEAD/GraphSDKDemo/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /GraphSDKDemo/Models/GroupInfoList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace GraphSDKDemo.Models 4 | { 5 | public class GroupInfoList : List 6 | { 7 | public object Key { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /GraphSDKDemo/Models/File.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GraphSDKDemo.Models 4 | { 5 | public class File 6 | { 7 | public string Id { get; set; } 8 | public string Name { get; set; } 9 | public long Size { get; set; } 10 | public DateTime Created { get; set; } 11 | public DateTime LastModified { get; set; } 12 | public bool Shared { get; set; } 13 | public string Url { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GraphSDKDemo/Models/Folder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GraphSDKDemo.Models 4 | { 5 | public class Folder 6 | { 7 | public string Id { get; set; } 8 | public string Name { get; set; } 9 | public int FileCount { get; set; } 10 | public DateTime Created { get; set; } 11 | public DateTime LastModified { get; set; } 12 | public bool Shared { get; set; } 13 | public string Url { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GraphSDKDemo/Models/Event.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GraphSDKDemo.Models 4 | { 5 | public class Event 6 | { 7 | public string Id { get; set; } 8 | public string Subject { get; set; } 9 | public string Location { get; set; } 10 | public string Organizer { get; set; } 11 | public DateTime Start { get; set; } 12 | public DateTime End { get; set; } 13 | public bool IsAllDay { get; set; } 14 | public string Categories { get; set; } 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /GraphSDKDemo/Models/Message.cs: -------------------------------------------------------------------------------- 1 | namespace GraphSDKDemo.Models 2 | { 3 | public class Message 4 | { 5 | public string Id { get; set; } 6 | public string From { get; set; } 7 | public string Sender { get; set; } 8 | public string Subject { get; set; } 9 | public string Body { get; set; } 10 | public string ReceivedDateTime { get; set; } 11 | public string Importance { get; set; } 12 | public bool IsRead { get; set; } 13 | public bool HasAttachments { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GraphSDKDemo/Models/Contact.cs: -------------------------------------------------------------------------------- 1 | namespace GraphSDKDemo.Models 2 | { 3 | public class Contact 4 | { 5 | public string Id { get; set; } 6 | public string DisplayName { get; set; } 7 | public string EmailAddress { get; set; } 8 | public string CompanyName { get; set; } 9 | public string JobTitle { get; set; } 10 | public string HomePhone { get; set; } 11 | public string BusinessPhone { get; set; } 12 | public string MobilePhone { get; set; } 13 | public string PersonalNotes { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/HomePage.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Services.MicrosoftGraph; 2 | using Windows.UI.Xaml.Controls; 3 | 4 | namespace GraphSDKDemo 5 | { 6 | public sealed partial class HomePage : Page 7 | { 8 | public HomePage() 9 | { 10 | this.InitializeComponent(); 11 | 12 | if ((App.Current as App).IsAuthenticated) 13 | { 14 | // Get the Graph client from the service 15 | (App.Current as App).GraphClient = MicrosoftGraphService.Instance.GraphProvider; 16 | 17 | HomePageMessage.Text = "Welcome! Please use the menu to the left to select a view."; 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/HomePage.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | Microsoft Graph SDK Demo 13 | Please sign in to continue. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Robert Green 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /GraphSDKDemo/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("GraphSDKDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("GraphSDKDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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)] -------------------------------------------------------------------------------- /GraphSDKDemo/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /GraphSDKDemo/GraphDateTimeTimeZoneConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Graph; 3 | 4 | namespace GraphSDKDemo 5 | { 6 | class GraphDateTimeTimeZoneConverter : Windows.UI.Xaml.Data.IValueConverter 7 | { 8 | public object Convert(object value, Type targetType, object parameter, string language) 9 | { 10 | DateTimeTimeZone date = value as DateTimeTimeZone; 11 | 12 | if (date != null) 13 | { 14 | // Resolve the time zone 15 | var timezone = TimeZoneInfo.FindSystemTimeZoneById(date.TimeZone); 16 | // Parse method assumes local time, which may not be the case 17 | var parsedDateAsLocal = DateTimeOffset.Parse(date.DateTime); 18 | // Determine the offset from UTC time for the specific date 19 | // Making this call adjusts for DST as appropriate 20 | var tzOffset = timezone.GetUtcOffset(parsedDateAsLocal.DateTime); 21 | // Create a new DateTimeOffset with the specific offset from UTC 22 | var correctedDate = new DateTimeOffset(parsedDateAsLocal.DateTime, tzOffset); 23 | // Return the local date time string 24 | return correctedDate.LocalDateTime.ToString(); 25 | } 26 | 27 | return string.Empty; 28 | } 29 | 30 | public object ConvertBack(object value, Type targetType, object parameter, string language) 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /GraphSDKDemo/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | GraphSDKDemo 7 | rogreen 8 | Assets\StoreLogo.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /GraphSDKDemo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphSDKDemo", "GraphSDKDemo\GraphSDKDemo.csproj", "{CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | Release|ARM = Release|ARM 14 | Release|x64 = Release|x64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|ARM.ActiveCfg = Debug|ARM 19 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|ARM.Build.0 = Debug|ARM 20 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|ARM.Deploy.0 = Debug|ARM 21 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x64.ActiveCfg = Debug|x64 22 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x64.Build.0 = Debug|x64 23 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x64.Deploy.0 = Debug|x64 24 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x86.ActiveCfg = Debug|x86 25 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x86.Build.0 = Debug|x86 26 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Debug|x86.Deploy.0 = Debug|x86 27 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|ARM.ActiveCfg = Release|ARM 28 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|ARM.Build.0 = Release|ARM 29 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|ARM.Deploy.0 = Release|ARM 30 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x64.ActiveCfg = Release|x64 31 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x64.Build.0 = Release|x64 32 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x64.Deploy.0 = Release|x64 33 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x86.ActiveCfg = Release|x86 34 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x86.Build.0 = Release|x86 35 | {CB71BB5E-DD6F-4F23-90CB-9AAD2744C16A}.Release|x86.Deploy.0 = Release|x86 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Toolkit.Services.MicrosoftGraph; 2 | using System; 3 | using Windows.UI.Xaml.Controls; 4 | 5 | namespace GraphSDKDemo 6 | { 7 | public sealed partial class MainPage : Page 8 | { 9 | public MainPage() 10 | { 11 | this.InitializeComponent(); 12 | 13 | // Initialize auth state to false 14 | SetAuthState(false); 15 | 16 | // Load OAuth settings 17 | var oauthSettings = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView("OAuth"); 18 | var appId = oauthSettings.GetString("AppId"); 19 | var scopes = oauthSettings.GetString("Scopes"); 20 | 21 | if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(scopes)) 22 | { 23 | Notification.Show("Could not load OAuth Settings from resource file."); 24 | } 25 | else 26 | { 27 | // Initialize Graph 28 | MicrosoftGraphService.Instance.AuthenticationModel = MicrosoftGraphEnums.AuthenticationModel.V2; 29 | MicrosoftGraphService.Instance.Initialize(appId, 30 | MicrosoftGraphEnums.ServicesToInitialize.UserProfile, 31 | scopes.Split(' ')); 32 | 33 | // Navigate to HomePage.xaml 34 | RootFrame.Navigate(typeof(HomePage)); 35 | } 36 | } 37 | 38 | private void SetAuthState(bool isAuthenticated) 39 | { 40 | (App.Current as App).IsAuthenticated = isAuthenticated; 41 | } 42 | 43 | private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) 44 | { 45 | var invokedItem = args.InvokedItem as string; 46 | 47 | switch (invokedItem.ToLower()) 48 | { 49 | case "messages": 50 | RootFrame.Navigate(typeof(MessagesPage)); 51 | break; 52 | case "contacts": 53 | RootFrame.Navigate(typeof(ContactsPage)); 54 | break; 55 | case "events": 56 | RootFrame.Navigate(typeof(EventsPage)); 57 | break; 58 | case "driveitems": 59 | RootFrame.Navigate(typeof(DriveItemsPage)); 60 | break; 61 | case "home": 62 | default: 63 | RootFrame.Navigate(typeof(HomePage)); 64 | break; 65 | } 66 | } 67 | 68 | private void Login_SignInCompleted(object sender, Microsoft.Toolkit.Uwp.UI.Controls.Graph.SignInEventArgs e) 69 | { 70 | // Set the auth state 71 | SetAuthState(true); 72 | // Reload the home page 73 | RootFrame.Navigate(typeof(HomePage)); 74 | } 75 | 76 | private void Login_SignOutCompleted(object sender, EventArgs e) 77 | { 78 | // Set the auth state 79 | SetAuthState(false); 80 | // Reload the home page 81 | RootFrame.Navigate(typeof(HomePage)); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /GraphSDKDemo/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Windows.ApplicationModel; 3 | using Windows.ApplicationModel.Activation; 4 | using Windows.UI.Xaml; 5 | using Windows.UI.Xaml.Controls; 6 | using Windows.UI.Xaml.Navigation; 7 | 8 | namespace GraphSDKDemo 9 | { 10 | /// 11 | /// Provides application-specific behavior to supplement the default Application class. 12 | /// 13 | sealed partial class App : Application 14 | { 15 | public bool IsAuthenticated { get; set; } 16 | public Microsoft.Graph.GraphServiceClient GraphClient { get; set; } 17 | 18 | /// 19 | /// Initializes the singleton application object. This is the first line of authored code 20 | /// executed, and as such is the logical equivalent of main() or WinMain(). 21 | /// 22 | /// 23 | public App() 24 | { 25 | this.InitializeComponent(); 26 | this.Suspending += OnSuspending; 27 | } 28 | 29 | /// 30 | /// Invoked when the application is launched normally by the end user. Other entry points 31 | /// will be used such as when the application is launched to open a specific file. 32 | /// 33 | /// Details about the launch request and process. 34 | protected override void OnLaunched(LaunchActivatedEventArgs e) 35 | { 36 | Frame rootFrame = Window.Current.Content as Frame; 37 | 38 | // Do not repeat app initialization when the Window already has content, 39 | // just ensure that the window is active 40 | if (rootFrame == null) 41 | { 42 | // Create a Frame to act as the navigation context and navigate to the first page 43 | rootFrame = new Frame(); 44 | 45 | rootFrame.NavigationFailed += OnNavigationFailed; 46 | 47 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 48 | { 49 | //TODO: Load state from previously suspended application 50 | } 51 | 52 | // Place the frame in the current Window 53 | Window.Current.Content = rootFrame; 54 | } 55 | 56 | if (e.PrelaunchActivated == false) 57 | { 58 | if (rootFrame.Content == null) 59 | { 60 | // When the navigation stack isn't restored navigate to the first page, 61 | // configuring the new page by passing required information as a navigation 62 | // parameter 63 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 64 | } 65 | // Ensure the current window is active 66 | Window.Current.Activate(); 67 | } 68 | } 69 | 70 | /// 71 | /// Invoked when Navigation to a certain page fails 72 | /// 73 | /// The Frame which failed navigation 74 | /// Details about the navigation failure 75 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 76 | { 77 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 78 | } 79 | 80 | /// 81 | /// Invoked when application execution is being suspended. Application state is saved 82 | /// without knowing whether the application will be terminated or resumed with the contents 83 | /// of memory still intact. 84 | /// 85 | /// The source of the suspend request. 86 | /// Details about the suspend request. 87 | private void OnSuspending(object sender, SuspendingEventArgs e) 88 | { 89 | var deferral = e.SuspendingOperation.GetDeferral(); 90 | //TODO: Save application state and stop any background activity 91 | deferral.Complete(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /GraphSDKDemo/OAuth.resw: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 73984e7d-7bd1-42dd-9415-300c9c88e8bd 122 | 123 | 124 | User.Read Mail.ReadWrite Mail.Send Contacts.Read Contacts.ReadWrite Calendars.ReadWrite Directory.AccessAsUser.All Files.ReadWrite 125 | 126 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/ContactsPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Graph; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.Linq; 6 | using Windows.UI.Xaml; 7 | using Windows.UI.Xaml.Controls; 8 | 9 | namespace GraphSDKDemo 10 | { 11 | public sealed partial class ContactsPage : Page 12 | { 13 | GraphServiceClient graphClient = null; 14 | 15 | IUserContactsCollectionPage contacts = null; 16 | ObservableCollection MyContacts = null; 17 | 18 | Contact myContact = null; 19 | Models.Contact selectedContact = null; 20 | 21 | public ContactsPage() 22 | { 23 | this.InitializeComponent(); 24 | 25 | graphClient = (App.Current as App).GraphClient; 26 | } 27 | 28 | private async void GetContactsButton_Click(Object sender, RoutedEventArgs e) 29 | { 30 | try 31 | { 32 | //contacts = await graphClient.Me.Contacts.Request().Top(20).GetAsync(); 33 | // contacts = await graphClient.Me.Contacts.Request().OrderBy("displayName").GetAsync(); 34 | contacts = await graphClient.Me.Contacts.Request().OrderBy("displayName") 35 | .Select("displayName,emailAddresses").GetAsync(); 36 | //contacts = await graphClient.Me.Contacts.Request() 37 | // .Filter("startswith(displayName,'A'") 38 | // .Select("displayName,emailAddresses").GetAsync(); 39 | 40 | MyContacts = new ObservableCollection(); 41 | 42 | while (true) 43 | { 44 | foreach (var contact in contacts) 45 | { 46 | if (contact.DisplayName.StartsWith("A")) 47 | { 48 | MyContacts.Add(new Models.Contact 49 | { 50 | Id = contact.Id, 51 | DisplayName = contact.DisplayName, 52 | EmailAddress = (contact.EmailAddresses.Count() > 0) ? 53 | $"{contact.EmailAddresses.First().Address}" : 54 | "Unknown email", 55 | }); 56 | } 57 | } 58 | 59 | if (MyContacts.Count() >= 20) { break; } 60 | 61 | if (contacts.NextPageRequest == null) { break; } 62 | 63 | contacts = await contacts.NextPageRequest.GetAsync(); 64 | } 65 | 66 | ContactCountTextBlock.Text = $"Here are your first {MyContacts.Count()} contacts that start with A"; 67 | ContactsDataGrid.ItemsSource = MyContacts; 68 | 69 | } 70 | catch (ServiceException ex) 71 | { 72 | ContactCountTextBlock.Text = $"We could not get contacts: {ex.Error.Message}"; 73 | } 74 | } 75 | 76 | private async void ContactsDataGrid_SelectionChanged(Object sender, SelectionChangedEventArgs e) 77 | { 78 | if (ContactsDataGrid.SelectedItem != null) 79 | { 80 | selectedContact = ((Models.Contact)ContactsDataGrid.SelectedItem); 81 | 82 | // Note: This api does not support using a filter, 83 | // so you can only get a particular contact via the Id 84 | 85 | myContact = await graphClient.Me.Contacts[selectedContact.Id] 86 | .Request().GetAsync(); 87 | 88 | DisplayNameTextBlock.Text = (!string.IsNullOrEmpty(myContact.DisplayName)) ? 89 | myContact.DisplayName : 90 | "Unknown name"; 91 | EmailAddressTextBlock.Text = (myContact.EmailAddresses.Count() > 0) ? 92 | $"{myContact.EmailAddresses.First().Address}" : 93 | "Unknown email"; 94 | CompanyTextBlock.Text = myContact.CompanyName ?? ""; 95 | JobTitleTextBlock.Text = myContact.JobTitle ?? ""; 96 | BusinessPhoneTextBlock.Text = (myContact.BusinessPhones.Count() > 0) ? 97 | myContact.BusinessPhones.First() : ""; 98 | HomePhoneTextBlock.Text = (myContact.HomePhones.Count() > 0) ? 99 | myContact.HomePhones.First() : ""; 100 | MobilePhoneTextBlock.Text = myContact.MobilePhone ?? ""; 101 | NotesTextBlock.Text = myContact.PersonalNotes ?? ""; 102 | } 103 | } 104 | 105 | private async void UpdateContactButton_Click(Object sender, RoutedEventArgs e) 106 | { 107 | var contactToUpdate = new Contact(); 108 | contactToUpdate.PersonalNotes = "My best friend ever!"; 109 | 110 | try 111 | { 112 | var updatedContact = await graphClient.Me.Contacts[selectedContact.Id] 113 | .Request() 114 | .UpdateAsync(contactToUpdate); 115 | } 116 | catch (ServiceException ex) 117 | { 118 | ContactCountTextBlock.Text = $"We could not get update this contact: {ex.Error.Message}"; 119 | } 120 | } 121 | 122 | 123 | private async void AddContactButton_Click(Object sender, RoutedEventArgs e) 124 | { 125 | var contactToAdd = new Contact() 126 | { 127 | GivenName = "A Goode Frendomine", 128 | DisplayName = "A Goode Frendomine" 129 | }; 130 | var emailAddresses = new List(); 131 | var emailAddress = new EmailAddress() 132 | { 133 | Address = "ceo@northwind.com" 134 | }; 135 | emailAddresses.Add(emailAddress); 136 | contactToAdd.EmailAddresses = emailAddresses; 137 | 138 | contactToAdd.CompanyName = "Northwind Traders"; 139 | contactToAdd.JobTitle = "CEO"; 140 | contactToAdd.HomePhones = null; 141 | 142 | var businessPhones = new List 143 | { 144 | "555-555-1212" 145 | }; 146 | contactToAdd.BusinessPhones = businessPhones; 147 | 148 | contactToAdd.MobilePhone = "555-555-1213"; 149 | contactToAdd.PersonalNotes = ""; 150 | 151 | try 152 | { 153 | var updatedContact = await graphClient.Me.Contacts.Request() 154 | .AddAsync(contactToAdd); 155 | } 156 | catch (ServiceException ex) 157 | { 158 | ContactCountTextBlock.Text = $"We could not get add this contact: {ex.Error.Message}"; 159 | } 160 | } 161 | 162 | private async void DeleteContactButton_Click(Object sender, RoutedEventArgs e) 163 | { 164 | try 165 | { 166 | await graphClient.Me.Contacts[selectedContact.Id].Request().DeleteAsync(); 167 | } 168 | catch (ServiceException ex) 169 | { 170 | ContactCountTextBlock.Text = $"We could not get delete this contact: {ex.Error.Message}"; 171 | } 172 | } 173 | 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /GraphSDKDemo/Views/ContactsPage.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 26 | 27 | 28 | 31 | 32 |