├── .gitignore ├── LICENSE.txt ├── O365-APIs-Start-Windows.sln ├── Office365StarterProject ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── CalendarIcon.png │ ├── ContactsIcon.png │ ├── EmailIcon.png │ ├── Logo.scale-100.png │ ├── Logo310x150.png │ ├── Logo310x310.png │ ├── Logo70x70.png │ ├── MyFilesIcon.png │ ├── SmallLogo.scale-100.png │ ├── SplashScreen.scale-100.png │ ├── Square310x310Logo.scale-100.png │ ├── Square70x70Logo.scale-100.png │ ├── StoreLogo.scale-100.png │ ├── UserDefault.png │ ├── UserDefaultSignedIn.png │ └── Wide310x150Logo.scale-100.png ├── Common │ ├── BooleanToVisibilityConverter.cs │ ├── NavigationHelper.cs │ ├── ObservableDictionary.cs │ ├── RelayCommand.cs │ └── SuspensionManager.cs ├── Helpers │ ├── AuthenticationHelper.cs │ ├── CalendarOperations.cs │ ├── ContactsOperations.cs │ ├── DiscoveryServiceCache.cs │ ├── Extensions.cs │ ├── FileOperations.cs │ ├── MailOperations.cs │ ├── MessageDialogHelper.cs │ └── UserOperations.cs ├── MainPage.xaml ├── MainPage.xaml.cs ├── Office365Starter.csproj ├── Package.appxmanifest ├── Properties │ └── AssemblyInfo.cs ├── ViewModels │ ├── CalendarViewModel.cs │ ├── ContactItemViewModel.cs │ ├── ContactsViewModel.cs │ ├── EventViewModel.cs │ ├── FileSystemItemViewModel.cs │ ├── FilesViewModel.cs │ ├── LoggingViewModel.cs │ ├── MailItemViewModel.cs │ ├── MailViewModel.cs │ ├── UserViewModel.cs │ └── ViewModelBase.cs ├── Views │ ├── Calendar.xaml │ ├── Calendar.xaml.cs │ ├── Contacts.xaml │ ├── Contacts.xaml.cs │ ├── Mail.xaml │ ├── Mail.xaml.cs │ ├── MyFiles.xaml │ └── MyFiles.xaml.cs └── packages.config ├── README.md └── loc └── README-ja-JP.md /.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 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # MSTest test Results 20 | [Tt]est[Rr]esult*/ 21 | [Bb]uild[Ll]og.* 22 | 23 | #NUNIT 24 | *.VisualState.xml 25 | TestResult.xml 26 | 27 | # Build Results of an ATL Project 28 | [Dd]ebugPS/ 29 | [Rr]eleasePS/ 30 | dlldata.c 31 | 32 | *_i.c 33 | *_p.c 34 | *_i.h 35 | *.ilk 36 | *.meta 37 | *.obj 38 | *.pch 39 | *.pdb 40 | *.pgc 41 | *.pgd 42 | *.rsp 43 | *.sbr 44 | *.tlb 45 | *.tli 46 | *.tlh 47 | *.tmp 48 | *.tmp_proj 49 | *.log 50 | *.vspscc 51 | *.vssscc 52 | .builds 53 | *.pidb 54 | *.svclog 55 | *.scc 56 | 57 | # Chutzpah Test files 58 | _Chutzpah* 59 | 60 | # Visual C++ cache files 61 | ipch/ 62 | *.aps 63 | *.ncb 64 | *.opensdf 65 | *.sdf 66 | *.cachefile 67 | 68 | # Visual Studio profiler 69 | *.psess 70 | *.vsp 71 | *.vspx 72 | 73 | # TFS 2012 Local Workspace 74 | $tf/ 75 | 76 | # Guidance Automation Toolkit 77 | *.gpState 78 | 79 | # ReSharper is a .NET coding add-in 80 | _ReSharper*/ 81 | *.[Rr]e[Ss]harper 82 | *.DotSettings.user 83 | 84 | # JustCode is a .NET coding addin-in 85 | .JustCode 86 | 87 | # TeamCity is a build add-in 88 | _TeamCity* 89 | 90 | # DotCover is a Code Coverage Tool 91 | *.dotCover 92 | 93 | # NCrunch 94 | *.ncrunch* 95 | _NCrunch_* 96 | .*crunch*.local.xml 97 | 98 | # MightyMoose 99 | *.mm.* 100 | AutoTest.Net/ 101 | 102 | # Web workbench (sass) 103 | .sass-cache/ 104 | 105 | # Installshield output folder 106 | [Ee]xpress/ 107 | 108 | # DocProject is a documentation generator add-in 109 | DocProject/buildhelp/ 110 | DocProject/Help/*.HxT 111 | DocProject/Help/*.HxC 112 | DocProject/Help/*.hhc 113 | DocProject/Help/*.hhk 114 | DocProject/Help/*.hhp 115 | DocProject/Help/Html2 116 | DocProject/Help/html 117 | 118 | # Click-Once directory 119 | publish/ 120 | 121 | # Publish Web Output 122 | *.[Pp]ublish.xml 123 | *.azurePubxml 124 | 125 | # NuGet Packages Directory 126 | packages/ 127 | ## TODO: If the tool you use requires repositories.config uncomment the next line 128 | #!packages/repositories.config 129 | 130 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 131 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) 132 | !packages/build/ 133 | 134 | # Windows Azure Build Output 135 | csx/ 136 | *.build.csdef 137 | 138 | # Windows Store app package directory 139 | AppPackages/ 140 | 141 | # Others 142 | sql/ 143 | *.Cache 144 | ClientBin/ 145 | [Ss]tyle[Cc]op.* 146 | ~$* 147 | *~ 148 | *.dbmdl 149 | *.dbproj.schemaview 150 | *.pfx 151 | *.publishsettings 152 | node_modules/ 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | *.mdf 166 | *.ldf 167 | 168 | # Business Intelligence projects 169 | *.rdl.data 170 | *.bim.layout 171 | *.bim_*.settings 172 | 173 | # Microsoft Fakes 174 | FakesAssemblies/ 175 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | O365-APIs-Start-Windows, https://github.com/OfficeDev/Office-365-APIs-Starter-Project-for-Windows 2 | 3 | Copyright (c) Microsoft Corporation 4 | All rights reserved. 5 | 6 | MIT License: 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining 9 | a copy of this software and associated documentation files (the 10 | ""Software""), to deal in the Software without restriction, including 11 | without limitation the rights to use, copy, modify, merge, publish, 12 | distribute, sublicense, and/or sell copies of the Software, and to 13 | permit persons to whom the Software is furnished to do so, subject to 14 | the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /O365-APIs-Start-Windows.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Office365Starter", "Office365StarterProject\Office365Starter.csproj", "{52E95C2D-A5EF-468C-8D59-5E5DB61704CC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|ARM = Debug|ARM 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|Any CPU = Release|Any CPU 15 | Release|ARM = Release|ARM 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 23 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|ARM.ActiveCfg = Debug|ARM 24 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|ARM.Build.0 = Debug|ARM 25 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|ARM.Deploy.0 = Debug|ARM 26 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x64.ActiveCfg = Debug|x64 27 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x64.Build.0 = Debug|x64 28 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x64.Deploy.0 = Debug|x64 29 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x86.ActiveCfg = Debug|x86 30 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x86.Build.0 = Debug|x86 31 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Debug|x86.Deploy.0 = Debug|x86 32 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|Any CPU.Deploy.0 = Release|Any CPU 35 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|ARM.ActiveCfg = Release|ARM 36 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|ARM.Build.0 = Release|ARM 37 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|ARM.Deploy.0 = Release|ARM 38 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x64.ActiveCfg = Release|x64 39 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x64.Build.0 = Release|x64 40 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x64.Deploy.0 = Release|x64 41 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x86.ActiveCfg = Release|x86 42 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x86.Build.0 = Release|x86 43 | {52E95C2D-A5EF-468C-8D59-5E5DB61704CC}.Release|x86.Deploy.0 = Release|x86 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Office365StarterProject/App.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 9 | 10 | 11 | 12 | 13 | White 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Office365StarterProject/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Office365StarterProject.ViewModels; 4 | using System; 5 | using Windows.ApplicationModel; 6 | using Windows.ApplicationModel.Activation; 7 | using Windows.UI.Xaml; 8 | using Windows.UI.Xaml.Controls; 9 | using Windows.UI.Xaml.Navigation; 10 | 11 | // The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227 12 | namespace Office365StarterProject 13 | { 14 | /// 15 | /// Provides application-specific behavior to supplement the default Application class. 16 | /// 17 | sealed partial class App : Application 18 | { 19 | /// 20 | /// Represents the current user of the sample. 21 | /// 22 | private static UserViewModel _currentUser; 23 | public static UserViewModel CurrentUser 24 | { 25 | get 26 | { 27 | if (_currentUser == null) 28 | { 29 | _currentUser = new UserViewModel(); 30 | } 31 | return _currentUser; 32 | } 33 | } 34 | /// 35 | /// Initializes the singleton application object. This is the first line of authored code 36 | /// executed, and as such is the logical equivalent of main() or WinMain(). 37 | /// 38 | public App() 39 | { 40 | this.InitializeComponent(); 41 | this.Suspending += OnSuspending; 42 | } 43 | 44 | /// 45 | /// Invoked when the application is launched normally by the end user. Other entry points 46 | /// will be used such as when the application is launched to open a specific file. 47 | /// 48 | /// Details about the launch request and process. 49 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")] 50 | protected override void OnLaunched(LaunchActivatedEventArgs e) 51 | { 52 | 53 | #if DEBUG 54 | if (System.Diagnostics.Debugger.IsAttached) 55 | { 56 | this.DebugSettings.EnableFrameRateCounter = false; 57 | } 58 | #endif 59 | 60 | Frame rootFrame = Window.Current.Content as Frame; 61 | 62 | // Do not repeat app initialization when the Window already has content, 63 | // just ensure that the window is active 64 | if (rootFrame == null) 65 | { 66 | // Create a Frame to act as the navigation context and navigate to the first page 67 | rootFrame = new Frame(); 68 | // Set the default language 69 | rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; 70 | 71 | rootFrame.NavigationFailed += OnNavigationFailed; 72 | 73 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 74 | { 75 | //TODO: Load state from previously suspended application 76 | } 77 | 78 | // Place the frame in the current Window 79 | Window.Current.Content = rootFrame; 80 | } 81 | 82 | if (rootFrame.Content == null) 83 | { 84 | // When the navigation stack isn't restored navigate to the first page, 85 | // configuring the new page by passing required information as a navigation 86 | // parameter 87 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 88 | } 89 | // Ensure the current window is active 90 | Window.Current.Activate(); 91 | } 92 | 93 | /// 94 | /// Invoked when Navigation to a certain page fails 95 | /// 96 | /// The Frame which failed navigation 97 | /// Details about the navigation failure 98 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 99 | { 100 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 101 | } 102 | 103 | /// 104 | /// Invoked when application execution is being suspended. Application state is saved 105 | /// without knowing whether the application will be terminated or resumed with the contents 106 | /// of memory still intact. 107 | /// 108 | /// The source of the suspend request. 109 | /// Details about the suspend request. 110 | private void OnSuspending(object sender, SuspendingEventArgs e) 111 | { 112 | var deferral = e.SuspendingOperation.GetDeferral(); 113 | //TODO: Save application state and stop any background activity 114 | deferral.Complete(); 115 | } 116 | } 117 | } 118 | //********************************************************* 119 | // 120 | // MIT License: 121 | // Permission is hereby granted, free of charge, to any person obtaining 122 | // a copy of this software and associated documentation files (the 123 | // ""Software""), to deal in the Software without restriction, including 124 | // without limitation the rights to use, copy, modify, merge, publish, 125 | // distribute, sublicense, and/or sell copies of the Software, and to 126 | // permit persons to whom the Software is furnished to do so, subject to 127 | // the following conditions: 128 | 129 | // The above copyright notice and this permission notice shall be 130 | // included in all copies or substantial portions of the Software. 131 | 132 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 133 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 134 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 135 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 136 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 137 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 138 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 139 | // 140 | //********************************************************* 141 | -------------------------------------------------------------------------------- /Office365StarterProject/Assets/CalendarIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/CalendarIcon.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/ContactsIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/ContactsIcon.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/EmailIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/EmailIcon.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Logo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Logo310x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Logo310x150.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Logo310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Logo310x310.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Logo70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Logo70x70.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/MyFilesIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/MyFilesIcon.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/SmallLogo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/SmallLogo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/SplashScreen.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/SplashScreen.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Square310x310Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Square310x310Logo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Square70x70Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Square70x70Logo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/StoreLogo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/StoreLogo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/UserDefault.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/UserDefault.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/UserDefaultSignedIn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/UserDefaultSignedIn.png -------------------------------------------------------------------------------- /Office365StarterProject/Assets/Wide310x150Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OfficeDev/O365-Windows-Start/d2ef21ffdedd74cb872f66ce78d4e3b287b2ec40/Office365StarterProject/Assets/Wide310x150Logo.scale-100.png -------------------------------------------------------------------------------- /Office365StarterProject/Common/BooleanToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Windows.UI.Xaml; 3 | using Windows.UI.Xaml.Data; 4 | 5 | namespace Office365StarterProject.Common 6 | { 7 | /// 8 | /// Value converter that translates true to and false to 9 | /// . 10 | /// 11 | public sealed class BooleanToVisibilityConverter : IValueConverter 12 | { 13 | public object Convert(object value, Type targetType, object parameter, string language) 14 | { 15 | return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, string language) 19 | { 20 | return value is Visibility && (Visibility)value == Visibility.Visible; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Office365StarterProject/Common/ObservableDictionary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Windows.Foundation.Collections; 5 | 6 | namespace Office365StarterProject.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 Values 110 | { 111 | get { return this._dictionary.Values; } 112 | } 113 | 114 | public bool Contains(KeyValuePair item) 115 | { 116 | return this._dictionary.Contains(item); 117 | } 118 | 119 | public int Count 120 | { 121 | get { return this._dictionary.Count; } 122 | } 123 | 124 | public bool IsReadOnly 125 | { 126 | get { return false; } 127 | } 128 | 129 | public IEnumerator> GetEnumerator() 130 | { 131 | return this._dictionary.GetEnumerator(); 132 | } 133 | 134 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 135 | { 136 | return this._dictionary.GetEnumerator(); 137 | } 138 | 139 | public void CopyTo(KeyValuePair[] array, int arrayIndex) 140 | { 141 | int arraySize = array.Length; 142 | foreach (var pair in this._dictionary) 143 | { 144 | if (arrayIndex >= arraySize) break; 145 | array[arrayIndex++] = pair; 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /Office365StarterProject/Common/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Input; 3 | 4 | namespace Office365StarterProject.Common 5 | { 6 | /// 7 | /// A command whose sole purpose is to relay its functionality 8 | /// to other objects by invoking delegates. 9 | /// The default return value for the CanExecute method is 'true'. 10 | /// needs to be called whenever 11 | /// is expected to return a different value. 12 | /// 13 | public class RelayCommand : ICommand 14 | { 15 | private readonly Action _execute; 16 | private readonly Func _canExecute; 17 | 18 | /// 19 | /// Raised when RaiseCanExecuteChanged is called. 20 | /// 21 | public event EventHandler CanExecuteChanged; 22 | 23 | /// 24 | /// Creates a new command that can always execute. 25 | /// 26 | /// The execution logic. 27 | public RelayCommand(Action execute) 28 | : this(execute, null) 29 | { 30 | } 31 | 32 | /// 33 | /// Creates a new command. 34 | /// 35 | /// The execution logic. 36 | /// The execution status logic. 37 | public RelayCommand(Action execute, Func canExecute) 38 | { 39 | if (execute == null) 40 | throw new ArgumentNullException("execute"); 41 | _execute = execute; 42 | _canExecute = canExecute; 43 | } 44 | 45 | /// 46 | /// Determines whether this can execute in its current state. 47 | /// 48 | /// 49 | /// Data used by the command. If the command does not require data to be passed, this object can be set to null. 50 | /// 51 | /// true if this command can be executed; otherwise, false. 52 | public bool CanExecute(object parameter) 53 | { 54 | return _canExecute == null ? true : _canExecute(); 55 | } 56 | 57 | /// 58 | /// Executes the on the current command target. 59 | /// 60 | /// 61 | /// Data used by the command. If the command does not require data to be passed, this object can be set to null. 62 | /// 63 | public void Execute(object parameter) 64 | { 65 | _execute(); 66 | } 67 | 68 | /// 69 | /// Method used to raise the event 70 | /// to indicate that the return value of the 71 | /// method has changed. 72 | /// 73 | public void RaiseCanExecuteChanged() 74 | { 75 | var handler = CanExecuteChanged; 76 | if (handler != null) 77 | { 78 | handler(this, EventArgs.Empty); 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/ContactsOperations.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.OData.Core; 4 | using Microsoft.Office365.OutlookServices; 5 | using Office365StarterProject.ViewModels; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | 12 | namespace Office365StarterProject.Helpers 13 | { 14 | /// 15 | /// Contains methods for accessing events in a contact list. 16 | /// 17 | public class ContactsOperations 18 | { 19 | private string _contactsCapability = ServiceCapabilities.Contacts.ToString(); 20 | 21 | /// 22 | /// Gets a collection of contacts. 23 | /// 24 | /// A collection of contact items. 25 | public async Task> GetContactsAsync() 26 | { 27 | // Make sure we have a reference to the Exchange client 28 | var exchangeClient = await AuthenticationHelper.GetOutlookClientAsync(_contactsCapability); 29 | 30 | // Query contacts 31 | var contactsResults = await exchangeClient.Me.Contacts.OrderBy(c => c.DisplayName).ExecuteAsync(); 32 | 33 | // Return the first page of contacts. 34 | return contactsResults.CurrentPage.ToList(); 35 | 36 | } 37 | 38 | /// 39 | /// Adds a new contact. 40 | /// 41 | internal async Task AddContactItemAsync( 42 | string fileAs, 43 | string givenName, 44 | string surname, 45 | string jobTitle, 46 | string email, 47 | string workPhone, 48 | string mobilePhone 49 | ) 50 | { 51 | string newContactId = string.Empty; 52 | 53 | Contact newContact = new Contact 54 | { 55 | FileAs = fileAs, 56 | GivenName = givenName, 57 | Surname = surname, 58 | JobTitle = jobTitle, 59 | MobilePhone1 = mobilePhone 60 | }; 61 | 62 | newContact.BusinessPhones.Add(workPhone); 63 | 64 | // Note: Setting EmailAddress1 to a null or empty string will throw an exception that 65 | // states the email address is invalid and the contact cannot be added. 66 | // Setting EmailAddress1 to a string that does not resemble an email address will not 67 | // cause an exception to be thrown, but the value is not stored in EmailAddress1. 68 | if (!string.IsNullOrEmpty(email)) 69 | newContact.EmailAddresses.Add(new EmailAddress() { Address = email, Name = email }); 70 | 71 | try 72 | { 73 | // Make sure we have a reference to the Exchange client 74 | var exchangeClient = await AuthenticationHelper.GetOutlookClientAsync(_contactsCapability); 75 | 76 | // This results in a call to the service. 77 | await exchangeClient.Me.Contacts.AddContactAsync(newContact); 78 | 79 | } 80 | catch (Exception e) 81 | { 82 | throw new Exception("We could not create your contact: " + e.Message); 83 | } 84 | return newContactId; 85 | } 86 | 87 | /// 88 | /// Updates an existing contact. 89 | /// 90 | internal async Task UpdateContactItemAsync(string selectedContactId, 91 | string fileAs, 92 | string givenName, 93 | string surname, 94 | string jobTitle, 95 | string email, 96 | string workPhone, 97 | string mobilePhone 98 | ) 99 | { 100 | IContact contactToUpdate = null; 101 | 102 | try 103 | { 104 | // Make sure we have a reference to the Exchange client 105 | var exchangeClient = await AuthenticationHelper.GetOutlookClientAsync(_contactsCapability); 106 | 107 | contactToUpdate = await exchangeClient.Me.Contacts[selectedContactId].ExecuteAsync(); 108 | 109 | contactToUpdate.FileAs = fileAs; 110 | contactToUpdate.GivenName = givenName; 111 | contactToUpdate.Surname = surname; 112 | contactToUpdate.JobTitle = jobTitle; 113 | contactToUpdate.BusinessPhones[0] = workPhone; 114 | contactToUpdate.MobilePhone1 = mobilePhone; 115 | 116 | // Note: Setting EmailAddress1 to a null or empty string will throw an exception that 117 | // states the email address is invalid and the contact cannot be added. 118 | // Setting EmailAddress1 to a string that does not resemble an email address will not 119 | // cause an exception to be thrown, but the value is not stored in EmailAddress1. 120 | 121 | if (!string.IsNullOrEmpty(email)) 122 | { 123 | contactToUpdate.EmailAddresses[0].Address = email; 124 | contactToUpdate.EmailAddresses[0].Name = email; 125 | } 126 | 127 | // Update the contact in Exchange 128 | await contactToUpdate.UpdateAsync(); 129 | 130 | // A note about Batch Updating 131 | // You can save multiple updates on the client and save them all at once (batch) by 132 | // implementing the following pattern: 133 | // 1. Call UpdateAsync(true) for each contact you want to update. Setting the parameter dontSave to true 134 | // means that the updates are registered locally on the client, but won't be posted to the server. 135 | // 2. Call exchangeClient.Context.SaveChangesAsync() to post all contact updates you have saved locally 136 | // using the preceding UpdateAsync(true) call to the server, i.e., the user's Office 365 contacts list. 137 | } 138 | catch(ODataErrorException odataEx) 139 | { 140 | // Error with updated image 141 | Debug.WriteLine(odataEx.Message); 142 | } 143 | 144 | return contactToUpdate; 145 | } 146 | 147 | /// 148 | /// Removes a contact. 149 | /// 150 | internal async Task DeleteContactItemAsync(string selectedContactId) 151 | { 152 | bool result = false; 153 | try 154 | { 155 | // Make sure we have a reference to the Exchange client 156 | var exchangeClient = await AuthenticationHelper.GetOutlookClientAsync(_contactsCapability); 157 | 158 | // Get the contact to be removed from the Exchange service. This results in a call to the service. 159 | var contactToDelete = await exchangeClient.Me.Contacts[selectedContactId].ExecuteAsync(); 160 | if (contactToDelete != null) 161 | { 162 | await contactToDelete.DeleteAsync(); 163 | result = true; 164 | } 165 | } 166 | catch (Exception) 167 | { 168 | throw new Exception("Your contact was not deleted on the Exchange service"); 169 | } 170 | 171 | return result; 172 | } 173 | } 174 | } 175 | //********************************************************* 176 | // 177 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 178 | // 179 | //Copyright (c) Microsoft Corporation 180 | //All rights reserved. 181 | // 182 | // MIT License: 183 | // Permission is hereby granted, free of charge, to any person obtaining 184 | // a copy of this software and associated documentation files (the 185 | // ""Software""), to deal in the Software without restriction, including 186 | // without limitation the rights to use, copy, modify, merge, publish, 187 | // distribute, sublicense, and/or sell copies of the Software, and to 188 | // permit persons to whom the Software is furnished to do so, subject to 189 | // the following conditions: 190 | 191 | // The above copyright notice and this permission notice shall be 192 | // included in all copies or substantial portions of the Software. 193 | 194 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 195 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 196 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 197 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 198 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 199 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 200 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 201 | // 202 | //********************************************************* 203 | -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/DiscoveryServiceCache.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Office365.Discovery; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Windows.Storage; 9 | using Windows.Storage.Streams; 10 | 11 | namespace Office365StarterProject.Helpers 12 | { 13 | public enum ServiceCapabilities 14 | { 15 | Mail, 16 | Calendar, 17 | Contacts, 18 | MyFiles 19 | } 20 | public class ServiceCapabilityCache 21 | { 22 | public string UserId { get; set; } 23 | 24 | public CapabilityDiscoveryResult CapabilityResult { get; set; } 25 | } 26 | 27 | public class DiscoveryServiceCache 28 | { 29 | const string FileName = "DiscoveryInfo.txt"; 30 | static ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion); 31 | 32 | public string UserId 33 | { 34 | get; 35 | set; 36 | } 37 | 38 | public IDictionary DiscoveryInfoForServices 39 | { 40 | get; 41 | set; 42 | } 43 | 44 | public static async Task LoadAsync() 45 | { 46 | StorageFolder localFolder = ApplicationData.Current.LocalFolder; 47 | try 48 | { 49 | _lock.EnterReadLock(); 50 | StorageFile textFile = await localFolder.GetFileAsync(FileName); 51 | 52 | using (IRandomAccessStream textStream = await textFile.OpenReadAsync()) 53 | { 54 | using (DataReader textReader = new DataReader(textStream)) 55 | { 56 | uint textLength = (uint)textStream.Size; 57 | 58 | await textReader.LoadAsync(textLength); 59 | return Load(textReader); 60 | } 61 | } 62 | } 63 | catch (Exception ex) 64 | { 65 | 66 | } 67 | finally 68 | { 69 | _lock.ExitReadLock(); 70 | } 71 | 72 | return null; 73 | } 74 | 75 | public static async Task LoadAsync(ServiceCapabilities capability) 76 | { 77 | CapabilityDiscoveryResult capabilityDiscoveryResult = null; 78 | 79 | DiscoveryServiceCache cache = await LoadAsync(); 80 | 81 | cache.DiscoveryInfoForServices.TryGetValue(capability.ToString(), out capabilityDiscoveryResult); 82 | 83 | if (cache == null || capabilityDiscoveryResult == null) 84 | { 85 | return null; 86 | } 87 | 88 | return new ServiceCapabilityCache 89 | { 90 | UserId = cache.UserId, 91 | CapabilityResult = capabilityDiscoveryResult 92 | }; 93 | } 94 | 95 | public static async Task CreateAndSaveAsync(string userId, IDictionary discoveryInfoForServices) 96 | { 97 | var cache = new DiscoveryServiceCache 98 | { 99 | UserId = userId, 100 | DiscoveryInfoForServices = discoveryInfoForServices 101 | }; 102 | 103 | StorageFolder localFolder = ApplicationData.Current.LocalFolder; 104 | 105 | StorageFile textFile = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); 106 | try 107 | { 108 | _lock.EnterWriteLock(); 109 | using (IRandomAccessStream textStream = await textFile.OpenAsync(FileAccessMode.ReadWrite)) 110 | { 111 | using (DataWriter textWriter = new DataWriter(textStream)) 112 | { 113 | cache.Save(textWriter); 114 | await textWriter.StoreAsync(); 115 | } 116 | } 117 | } 118 | finally 119 | { 120 | _lock.ExitWriteLock(); 121 | } 122 | 123 | return cache; 124 | } 125 | 126 | private void Save(DataWriter textWriter) 127 | { 128 | textWriter.WriteStringWithLength(UserId); 129 | 130 | textWriter.WriteInt32(DiscoveryInfoForServices.Count); 131 | 132 | foreach (var i in DiscoveryInfoForServices) 133 | { 134 | textWriter.WriteStringWithLength(i.Key); 135 | textWriter.WriteStringWithLength(i.Value.ServiceResourceId); 136 | textWriter.WriteStringWithLength(i.Value.ServiceEndpointUri.ToString()); 137 | textWriter.WriteStringWithLength(i.Value.ServiceApiVersion); 138 | } 139 | } 140 | 141 | private static DiscoveryServiceCache Load(DataReader textReader) 142 | { 143 | var cache = new DiscoveryServiceCache(); 144 | 145 | cache.UserId = textReader.ReadString(); 146 | var entryCount = textReader.ReadInt32(); 147 | 148 | cache.DiscoveryInfoForServices = new Dictionary(entryCount); 149 | 150 | for (var i = 0; i < entryCount; i++) 151 | { 152 | var key = textReader.ReadString(); 153 | 154 | var serviceResourceId = textReader.ReadString(); 155 | var serviceEndpointUri = new Uri(textReader.ReadString()); 156 | var serviceApiVersion = textReader.ReadString(); 157 | 158 | cache.DiscoveryInfoForServices.Add(key, new CapabilityDiscoveryResult(serviceEndpointUri, serviceResourceId, serviceApiVersion)); 159 | } 160 | 161 | return cache; 162 | } 163 | } 164 | } 165 | 166 | 167 | //********************************************************* 168 | // 169 | // MIT License: 170 | // Permission is hereby granted, free of charge, to any person obtaining 171 | // a copy of this software and associated documentation files (the 172 | // ""Software""), to deal in the Software without restriction, including 173 | // without limitation the rights to use, copy, modify, merge, publish, 174 | // distribute, sublicense, and/or sell copies of the Software, and to 175 | // permit persons to whom the Software is furnished to do so, subject to 176 | // the following conditions: 177 | 178 | // The above copyright notice and this permission notice shall be 179 | // included in all copies or substantial portions of the Software. 180 | 181 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 182 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 183 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 184 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 185 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 186 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 187 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 188 | // 189 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/Extensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | using Windows.Storage.Streams; 3 | 4 | namespace Office365StarterProject.Helpers 5 | { 6 | static class Extensions 7 | { 8 | public static void WriteStringWithLength(this DataWriter w, string s) 9 | { 10 | w.WriteUInt32((uint)s.Length); 11 | w.WriteString(s); 12 | } 13 | 14 | public static string ReadString(this DataReader r) 15 | { 16 | return r.ReadString(r.ReadUInt32()); 17 | } 18 | 19 | 20 | } 21 | } 22 | 23 | //********************************************************* 24 | // 25 | // MIT License: 26 | // Permission is hereby granted, free of charge, to any person obtaining 27 | // a copy of this software and associated documentation files (the 28 | // ""Software""), to deal in the Software without restriction, including 29 | // without limitation the rights to use, copy, modify, merge, publish, 30 | // distribute, sublicense, and/or sell copies of the Software, and to 31 | // permit persons to whom the Software is furnished to do so, subject to 32 | // the following conditions: 33 | 34 | // The above copyright notice and this permission notice shall be 35 | // included in all copies or substantial portions of the Software. 36 | 37 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 38 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 39 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 40 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 41 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 42 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 43 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 44 | // 45 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/FileOperations.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.OData.Client; 4 | using Microsoft.OData.Core; 5 | using Microsoft.Office365.SharePoint.FileServices; 6 | using Office365StarterProject.ViewModels; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | using Windows.Storage; 14 | using Windows.Storage.Pickers; 15 | 16 | namespace Office365StarterProject.Helpers 17 | { 18 | /// 19 | /// Contains methods for accessing the files and folders. 20 | /// 21 | public class FileOperations 22 | { 23 | private string _filesCapability = ServiceCapabilities.MyFiles.ToString(); 24 | 25 | /// 26 | /// Performs a search of the default Documents folder. Displays the first page of results. 27 | /// 28 | /// A collection of information that describes files and folders. 29 | internal async Task> GetMyFilesAsync() 30 | { 31 | try 32 | { 33 | var sharePointClient = await AuthenticationHelper.GetSharePointClientAsync(_filesCapability); 34 | 35 | // Performs a search of the default Documents folder (folder Id is "root") 36 | // You could also specify another folder if you know its Id using the following syntax. 37 | // var filesResults = await sharePointClient.Files.GetById("folderId").ToFolder().Children.ExecuteAsync(); 38 | // This results in a call to the service. 39 | var filesResults = await sharePointClient.Files.ExecuteAsync(); 40 | 41 | // In this example, we'll just return the first page of results 42 | return filesResults.CurrentPage.OrderBy(e => e.Name); 43 | } 44 | catch (ODataErrorException) 45 | { 46 | return null; 47 | } 48 | catch(DataServiceQueryException) 49 | { 50 | return null; 51 | } 52 | } 53 | /// 54 | /// Creates a new file named demo.txt in the default document library. 55 | /// 56 | /// A Boolean value that indicates whether the new text file was successfully created. 57 | internal async Task CreateNewTextFileAsync() 58 | { 59 | bool isSuccess = false; 60 | var sharePointClient = await AuthenticationHelper.GetSharePointClientAsync(_filesCapability); 61 | 62 | try 63 | { 64 | // In this example, we'll create a simple text file and write the current timestamp into it. 65 | string createdTime = "Created at " + DateTime.Now.ToLocalTime().ToString(); 66 | byte[] bytes = Encoding.UTF8.GetBytes(createdTime); 67 | 68 | using (MemoryStream stream = new MemoryStream(bytes)) 69 | { 70 | // File is called demo.txt. If it already exists, we'll get an exception. 71 | File newFile = new File 72 | { 73 | Name = "demo.txt" 74 | }; 75 | 76 | // Create the empty file. 77 | await sharePointClient.Files.AddItemAsync(newFile); 78 | 79 | // Upload the file contents. 80 | await sharePointClient.Files.GetById(newFile.Id).ToFile().UploadAsync(stream); 81 | } 82 | 83 | isSuccess = true; 84 | } 85 | 86 | // ODataErrorException can be thrown when you try to create a file that already exists. 87 | catch (ODataErrorException) 88 | { 89 | isSuccess = false; 90 | } 91 | 92 | return isSuccess; 93 | } 94 | 95 | /// 96 | /// Deletes the selected item or folder from the ListBox. 97 | /// 98 | /// A Boolean value that indicates whether the file or folder was successfully deleted. 99 | internal async Task DeleteFileOrFolderAsync(FileSystemItemViewModel _selectedFileObject) 100 | { 101 | bool? isSuccess = false; 102 | 103 | try 104 | { 105 | // Gets the FileSystemItem that is selected in the bound ListBox control. 106 | IItem fileOrFolderToDelete = _selectedFileObject.FileSystemItem; 107 | 108 | // This results in a call to the service. 109 | await fileOrFolderToDelete.DeleteAsync(); 110 | 111 | isSuccess = true; 112 | } 113 | catch (Microsoft.Data.OData.ODataErrorException) 114 | { 115 | isSuccess = null; 116 | } 117 | catch (NullReferenceException) 118 | { 119 | isSuccess = null; 120 | } 121 | 122 | return isSuccess; 123 | } 124 | 125 | /// 126 | /// Reads the contents of a text file and displays the results in a TextBox. 127 | /// 128 | /// The file selected in the ListBox. 129 | /// A Boolean value that indicates whether the text file was successfully read. 130 | internal async Task ReadTextFileAsync(FileSystemItemViewModel _selectedFileObject) 131 | { 132 | 133 | string fileContents = string.Empty; 134 | object[] results = new object[] { fileContents, false }; 135 | 136 | try 137 | { 138 | // Get a handle on the selected item. 139 | IItem myFile = _selectedFileObject.FileSystemItem; 140 | 141 | // Check that the selected item is a text-based file. 142 | if (!myFile.Name.EndsWith(".txt") && !myFile.Name.EndsWith(".xml")) 143 | { 144 | results[0] = string.Empty; 145 | results[1] = false; 146 | return results; 147 | } 148 | 149 | File file = myFile as File; 150 | 151 | // Download the file contents as a string. This results in a call to the service. 152 | using (Stream stream = await file.DownloadAsync()) 153 | { 154 | using (StreamReader reader = new StreamReader(stream)) 155 | { 156 | results[0] = await reader.ReadToEndAsync(); 157 | results[1] = true; 158 | } 159 | } 160 | } 161 | catch (NullReferenceException) 162 | { 163 | results[1] = false; 164 | } 165 | catch (ArgumentException) 166 | { 167 | results[1] = false; 168 | } 169 | 170 | return results; 171 | } 172 | 173 | /// 174 | /// Update the currently selected item by appending new text. 175 | /// 176 | /// The file selected in the ListBox. 177 | /// The updated text contents of the file. 178 | /// A Boolean value that indicates whether the text file was successfully updated. 179 | internal async Task UpdateTextFileAsync(FileSystemItemViewModel _selectedFileObject, string fileText) 180 | { 181 | File file; 182 | byte[] byteArray; 183 | bool isSuccess = false; 184 | 185 | try 186 | { 187 | // Get a handle on the selected item. 188 | IItem myFile = _selectedFileObject.FileSystemItem; 189 | file = myFile as File; 190 | string updateTime = "\n\r\n\rLast update at " + DateTime.Now.ToLocalTime().ToString(); 191 | byteArray = Encoding.UTF8.GetBytes(fileText + updateTime); 192 | 193 | using (MemoryStream stream = new MemoryStream(byteArray)) 194 | { 195 | // Update the file. This results in a call to the service. 196 | await file.UploadAsync(stream); 197 | isSuccess = true; // We've updated the file. 198 | } 199 | } 200 | catch (ArgumentException) 201 | { 202 | isSuccess = false; 203 | } 204 | 205 | return isSuccess; 206 | } 207 | 208 | /// 209 | /// Downloads a file selected in the ListBox control. 210 | /// 211 | /// The file selected in the ListBox. 212 | /// A Stream of the downloaded file. 213 | internal async Task DownloadFileAsync(FileSystemItemViewModel _selectedFileObject) 214 | { 215 | 216 | File file; 217 | Stream stream = null; 218 | 219 | try 220 | { 221 | // Get a handle on the selected item. 222 | IItem myFile = _selectedFileObject.FileSystemItem; 223 | file = myFile as File; 224 | // Download the file from the service. This results in call to the service. 225 | stream = await file.DownloadAsync(); 226 | } 227 | 228 | catch (NullReferenceException) 229 | { 230 | // Silently fail. A null stream will be handled higher up the stack. 231 | } 232 | 233 | return stream; 234 | } 235 | 236 | 237 | /// 238 | /// Uploads a file to the default document library. 239 | /// 240 | /// A Boolean value that indicates whether the upload was successful. 241 | internal async Task UploadFileAsync() 242 | { 243 | bool isSuccess = false; 244 | try 245 | { 246 | FileOpenPicker picker = new FileOpenPicker(); 247 | picker.FileTypeFilter.Add("*"); 248 | picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; 249 | 250 | StorageFile sFile = await picker.PickSingleFileAsync(); 251 | if (sFile != null) 252 | { 253 | var sharePointClient = await AuthenticationHelper.GetSharePointClientAsync(_filesCapability); 254 | using (var stream = await sFile.OpenStreamForReadAsync()) 255 | { 256 | File newFile = new File 257 | { 258 | Name = sFile.Name 259 | }; 260 | 261 | await sharePointClient.Files.AddItemAsync(newFile); 262 | await sharePointClient.Files.GetById(newFile.Id).ToFile().UploadAsync(stream); 263 | } 264 | isSuccess = true; 265 | } 266 | } 267 | catch (NullReferenceException) 268 | { 269 | isSuccess = false; 270 | } 271 | 272 | return isSuccess; 273 | } 274 | } 275 | } 276 | //********************************************************* 277 | // 278 | // MIT License: 279 | // Permission is hereby granted, free of charge, to any person obtaining 280 | // a copy of this software and associated documentation files (the 281 | // ""Software""), to deal in the Software without restriction, including 282 | // without limitation the rights to use, copy, modify, merge, publish, 283 | // distribute, sublicense, and/or sell copies of the Software, and to 284 | // permit persons to whom the Software is furnished to do so, subject to 285 | // the following conditions: 286 | 287 | // The above copyright notice and this permission notice shall be 288 | // included in all copies or substantial portions of the Software. 289 | 290 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 291 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 292 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 293 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 294 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 295 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 296 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 297 | // 298 | //********************************************************* 299 | -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/MailOperations.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Office365.OutlookServices; 2 | using Office365StarterProject.ViewModels; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Office365StarterProject.Helpers 10 | { 11 | class MailOperations 12 | { 13 | private string _mailCapability = ServiceCapabilities.Mail.ToString(); 14 | 15 | /// 16 | /// Fetches email from user's Inbox. 17 | /// 18 | /// The page of mail results to be fetched. 19 | /// The size of the results page. 20 | internal async Task> GetEmailMessagesAsync(int pageNo, int pageSize) 21 | { 22 | 23 | // Make sure we have a reference to the Outlook Services client 24 | var outlookClient = await AuthenticationHelper.GetOutlookClientAsync(_mailCapability); 25 | 26 | var mailResults = await (from i in outlookClient.Me.Folders.GetById("Inbox").Messages 27 | orderby i.DateTimeReceived descending 28 | select i).Skip((pageNo - 1) * pageSize).Take(pageSize).ExecuteAsync(); 29 | 30 | foreach (var message in mailResults.CurrentPage) 31 | { 32 | System.Diagnostics.Debug.WriteLine("Message '{0}' received at '{1}'.", 33 | message.Subject, 34 | message.DateTimeReceived.ToString()); 35 | } 36 | 37 | 38 | return (List)mailResults.CurrentPage; 39 | 40 | } 41 | 42 | /// 43 | /// Compose and send a new email. 44 | /// 45 | /// The subject line of the email. 46 | /// The body of the email. 47 | /// A semicolon separated list of email addresses. 48 | /// 49 | internal async Task ComposeAndSendMailAsync(string subject, 50 | string bodyContent, 51 | string recipients) 52 | { 53 | // The identifier of the composed and sent message. 54 | string newMessageId = string.Empty; 55 | 56 | // Prepare the recipient list 57 | var toRecipients = new List(); 58 | string[] splitter = { ";" }; 59 | var splitRecipientsString = recipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); 60 | foreach (string recipient in splitRecipientsString) 61 | { 62 | toRecipients.Add(new Recipient 63 | { 64 | EmailAddress = new EmailAddress 65 | { 66 | Address = recipient.Trim(), 67 | Name = recipient.Trim(), 68 | }, 69 | }); 70 | } 71 | 72 | // Prepare the draft message. 73 | var draft = new Message 74 | { 75 | Subject = subject, 76 | Body = new ItemBody 77 | { 78 | ContentType = BodyType.Text, 79 | Content = bodyContent 80 | }, 81 | ToRecipients = toRecipients, 82 | }; 83 | 84 | try 85 | { 86 | // Make sure we have a reference to the Outlook Services client. 87 | var outlookClient = await AuthenticationHelper.GetOutlookClientAsync(_mailCapability); 88 | 89 | //Send the mail. 90 | await outlookClient.Me.SendMailAsync(draft, true); 91 | 92 | return draft.Id; 93 | } 94 | 95 | //Catch any exceptions related to invalid OData. 96 | catch (Microsoft.OData.Core.ODataException ode) 97 | { 98 | 99 | throw new Exception("We could not send the message: " + ode.Message); 100 | } 101 | catch (Exception e) 102 | { 103 | throw new Exception("We could not send the message: " + e.Message); 104 | } 105 | } 106 | 107 | /// 108 | /// Removes a mail item from the user's inbox. 109 | /// 110 | /// string. The unique Id of the mail item to delete. 111 | /// 112 | internal async Task DeleteMailItemAsync(string selectedMailId) 113 | { 114 | IMessage thisMailItem = null; 115 | try 116 | { 117 | // Make sure we have a reference to the Outlook Services client 118 | var outlookClient = await AuthenticationHelper.GetOutlookClientAsync(_mailCapability); 119 | 120 | // Get the mail item to be removed. 121 | thisMailItem = await outlookClient.Me.Folders.GetById("Inbox").Messages.GetById(selectedMailId).ExecuteAsync(); 122 | 123 | // Delete the mail item. 124 | await thisMailItem.DeleteAsync(false); 125 | return true; 126 | } 127 | 128 | //Catch any exceptions related to invalid OData. 129 | catch (Microsoft.OData.Core.ODataException ode) 130 | { 131 | 132 | throw new Exception("The message could not be deleted: " + ode.Message); 133 | } 134 | 135 | catch (Exception e) 136 | { 137 | throw new Exception("The message could not be deleted: " + e.Message); 138 | } 139 | 140 | } 141 | 142 | internal string BuildRecipientList(IList recipientList) 143 | { 144 | StringBuilder recipientListBuilder = new StringBuilder(); 145 | foreach (Recipient recipient in recipientList) 146 | { 147 | if (recipientListBuilder.Length == 0) 148 | { 149 | recipientListBuilder.Append(recipient.EmailAddress.Address); 150 | } 151 | else 152 | { 153 | recipientListBuilder.Append(";" + recipient.EmailAddress.Address); 154 | } 155 | } 156 | 157 | return recipientListBuilder.ToString(); 158 | } 159 | 160 | } 161 | } 162 | 163 | //********************************************************* 164 | // 165 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 166 | // 167 | //Copyright (c) Microsoft Corporation 168 | //All rights reserved. 169 | // 170 | // MIT License: 171 | // Permission is hereby granted, free of charge, to any person obtaining 172 | // a copy of this software and associated documentation files (the 173 | // ""Software""), to deal in the Software without restriction, including 174 | // without limitation the rights to use, copy, modify, merge, publish, 175 | // distribute, sublicense, and/or sell copies of the Software, and to 176 | // permit persons to whom the Software is furnished to do so, subject to 177 | // the following conditions: 178 | 179 | // The above copyright notice and this permission notice shall be 180 | // included in all copies or substantial portions of the Software. 181 | 182 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 183 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 184 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 185 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 186 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 187 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 188 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 189 | // 190 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/MessageDialogHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Office365.OAuth; 4 | using System; 5 | using System.Diagnostics; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using Windows.UI.Popups; 9 | 10 | namespace Office365StarterProject.Helpers 11 | { 12 | internal static class MessageDialogHelper 13 | { 14 | 15 | internal static async Task ShowYesNoDialogAsync(string content, string title) 16 | { 17 | bool result = false; 18 | MessageDialog messageDialog = new MessageDialog(content, title); 19 | 20 | messageDialog.Commands.Add(new UICommand( 21 | "Yes", 22 | new UICommandInvokedHandler((cmd) => result = true) 23 | )); 24 | messageDialog.Commands.Add(new UICommand( 25 | "No", 26 | new UICommandInvokedHandler((cmd) => result = false) 27 | )); 28 | 29 | // Set the command that will be invoked by default 30 | messageDialog.DefaultCommandIndex = 0; 31 | 32 | // Set the command to be invoked when escape is pressed 33 | messageDialog.CancelCommandIndex = 1; 34 | 35 | await messageDialog.ShowAsync(); 36 | 37 | return result; 38 | } 39 | 40 | internal static async void ShowDialogAsync(string content, string title) 41 | { 42 | MessageDialog messageDialog = new MessageDialog(content, title); 43 | messageDialog.Commands.Add(new UICommand( 44 | "OK", 45 | null 46 | )); 47 | 48 | await messageDialog.ShowAsync(); 49 | } 50 | 51 | #region Exception display helpers 52 | // Display details of the exception in a message dialog. 53 | // We are doing this here to help you, as a developer, understand exactly 54 | // what exception was received. In a real app, you would 55 | // handle exceptions within your code and give a more user-friendly behavior. 56 | internal static void DisplayException(AuthenticationFailedException exception) 57 | { 58 | var title = "Authentication failed"; 59 | StringBuilder content = new StringBuilder(); 60 | content.AppendLine("We were unable to connect to Office 365. Here's the exception we received:"); 61 | content.AppendFormat("Exception: {0}\n", exception.ErrorCode); 62 | content.AppendFormat("Description: {0}\n\n", exception.ErrorDescription); 63 | content.AppendLine("Suggestion: Make sure you have added the Connected Services to this project as outlined in the Readme file"); 64 | MessageDialogHelper.ShowDialogAsync(content.ToString(), title); 65 | Debug.WriteLine(content.ToString()); 66 | } 67 | 68 | // Display details of the exception. 69 | // We are doing this here to help you, as a developer, understand exactly 70 | // what exception was received. In a real app, you would 71 | // handle exceptions within your code and give a more user-friendly behavior. 72 | internal static void DisplayException(MissingConfigurationValueException exception) 73 | { 74 | var title = "Connected Services configuration failure"; 75 | StringBuilder content = new StringBuilder(); 76 | content.AppendLine("We were unable to connect to Office 365. Here's the exception we received:"); 77 | content.AppendFormat("Exception: {0}\n\n", exception.Message); 78 | content.AppendLine("Suggestion: Make sure you have added the Connected Services to this project as outlined in the Readme file."); 79 | MessageDialogHelper.ShowDialogAsync(content.ToString(), title); 80 | } 81 | 82 | // Display details of the exception. 83 | // We are doing this here to help you, as a developer, understand exactly 84 | // what exception was received. In a real app, you would 85 | // handle exceptions within your code and give a more user-friendly behavior. 86 | internal static void DisplayException(Exception exception) 87 | { 88 | var title = "Connected Services configuration failure"; 89 | StringBuilder content = new StringBuilder(); 90 | content.AppendLine("We were unable to connect to Office 365. Here's the exception we received:"); 91 | content.AppendFormat("Exception: {0}\n\n", exception.Message); 92 | content.AppendLine("Suggestion: Make sure you have added the Connected Services to this project as outlined in the Readme file."); 93 | MessageDialogHelper.ShowDialogAsync(content.ToString(), title); 94 | } 95 | #endregion 96 | } 97 | } 98 | //********************************************************* 99 | // 100 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 101 | // 102 | //Copyright (c) Microsoft Corporation 103 | //All rights reserved. 104 | // 105 | // MIT License: 106 | // Permission is hereby granted, free of charge, to any person obtaining 107 | // a copy of this software and associated documentation files (the 108 | // ""Software""), to deal in the Software without restriction, including 109 | // without limitation the rights to use, copy, modify, merge, publish, 110 | // distribute, sublicense, and/or sell copies of the Software, and to 111 | // permit persons to whom the Software is furnished to do so, subject to 112 | // the following conditions: 113 | 114 | // The above copyright notice and this permission notice shall be 115 | // included in all copies or substantial portions of the Software. 116 | 117 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 118 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 119 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 120 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 121 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 122 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 123 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 124 | // 125 | //********************************************************* 126 | -------------------------------------------------------------------------------- /Office365StarterProject/Helpers/UserOperations.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Azure.ActiveDirectory.GraphClient; 4 | using Microsoft.Data.OData; 5 | using System; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | using Windows.UI.Xaml.Media.Imaging; 9 | 10 | namespace Office365StarterProject.Helpers 11 | { 12 | /// 13 | /// Contains methods for accessing user information stored in Azure AD. 14 | /// 15 | public class UserOperations 16 | { 17 | private string _userEmail = string.Empty; 18 | 19 | /// 20 | /// Authenticates and signs in the user. 21 | /// 22 | /// 23 | public async Task GetCurrentUserAsync() 24 | { 25 | try 26 | { 27 | IUser currentUser = null; 28 | 29 | // Make sure we have a reference to the Azure Active Directory client 30 | var aadClient = await AuthenticationHelper.GetGraphClientAsync(); 31 | 32 | if (aadClient != null) 33 | { 34 | // This results in a call to the service. 35 | currentUser = await (aadClient.Users 36 | .Where(i => i.ObjectId == AuthenticationHelper.LoggedInUser) 37 | .ExecuteSingleAsync()); 38 | 39 | if (currentUser != null) 40 | _userEmail = currentUser.Mail; 41 | 42 | } 43 | 44 | return currentUser; 45 | } 46 | catch (ODataErrorException ode) 47 | { 48 | MessageDialogHelper.DisplayException(ode); 49 | return null; 50 | } 51 | } 52 | 53 | /// 54 | /// Get the user's photo. 55 | /// 56 | /// The target user. 57 | /// 58 | public async Task GetUserThumbnailPhotoAsync(IUser user) 59 | { 60 | BitmapImage bitmap = null; 61 | try 62 | { 63 | // The using statement ensures that Dispose is called even if an 64 | // exception occurs while you are calling methods on the object. 65 | using (var dssr = await user.ThumbnailPhoto.DownloadAsync()) 66 | using (var stream = dssr.Stream) 67 | using (var memStream = new MemoryStream()) 68 | { 69 | await stream.CopyToAsync(memStream); 70 | memStream.Seek(0, SeekOrigin.Begin); 71 | bitmap = new BitmapImage(); 72 | await bitmap.SetSourceAsync(memStream.AsRandomAccessStream()); 73 | } 74 | 75 | } 76 | catch(ODataException) 77 | { 78 | // Something went wrong retrieving the thumbnail photo, so set the bitmap to a default image 79 | bitmap = new BitmapImage(new Uri("ms-appx:///assets/UserDefaultSignedIn.png", UriKind.RelativeOrAbsolute)); 80 | } 81 | 82 | return bitmap; 83 | } 84 | 85 | /// 86 | /// Sign out of the service. 87 | /// 88 | /// 89 | public async Task SignOutAsync() 90 | { 91 | await AuthenticationHelper.SignOutAsync(); 92 | } 93 | } 94 | } 95 | //********************************************************* 96 | // 97 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 98 | // 99 | //Copyright (c) Microsoft Corporation 100 | //All rights reserved. 101 | // 102 | // MIT License: 103 | // Permission is hereby granted, free of charge, to any person obtaining 104 | // a copy of this software and associated documentation files (the 105 | // ""Software""), to deal in the Software without restriction, including 106 | // without limitation the rights to use, copy, modify, merge, publish, 107 | // distribute, sublicense, and/or sell copies of the Software, and to 108 | // permit persons to whom the Software is furnished to do so, subject to 109 | // the following conditions: 110 | 111 | // The above copyright notice and this permission notice shall be 112 | // included in all copies or substantial portions of the Software. 113 | 114 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 115 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 116 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 117 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 118 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 119 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 120 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 121 | // 122 | //********************************************************* 123 | -------------------------------------------------------------------------------- /Office365StarterProject/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 39 | 40 | 114 | 126 | 138 | 139 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /Office365StarterProject/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Office365StarterProject.Common; 4 | using Office365StarterProject.Helpers; 5 | using Office365StarterProject.ViewModels; 6 | using Office365StarterProject.Views; 7 | using System; 8 | using Windows.UI.Xaml; 9 | using Windows.UI.Xaml.Controls; 10 | using Windows.UI.Xaml.Navigation; 11 | 12 | namespace Office365StarterProject 13 | { 14 | /// 15 | /// The main page that contains sign-in and navigation to Office 365 functionality. 16 | /// 17 | public sealed partial class MainPage : Page 18 | { 19 | private NavigationHelper navigationHelper; 20 | 21 | /// 22 | /// NavigationHelper is used on each page to aid in navigation and 23 | /// process lifetime management 24 | /// 25 | public NavigationHelper NavigationHelper 26 | { 27 | get { return this.navigationHelper; } 28 | } 29 | 30 | 31 | public MainPage() 32 | { 33 | this.InitializeComponent(); 34 | this.navigationHelper = new NavigationHelper(this); 35 | this.navigationHelper.LoadState += navigationHelper_LoadState; 36 | } 37 | 38 | private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) 39 | { 40 | this.DataContext = App.CurrentUser; 41 | } 42 | 43 | private void Calendar_Button_Click(object sender, RoutedEventArgs e) 44 | { 45 | this.Frame.Navigate(typeof(Calendar)); 46 | } 47 | 48 | private void MyFiles_Button_Click(object sender, RoutedEventArgs e) 49 | { 50 | this.Frame.Navigate(typeof(MyFiles)); 51 | } 52 | 53 | private void Contacts_Button_Click(object sender, RoutedEventArgs e) 54 | { 55 | this.Frame.Navigate(typeof(Contacts)); 56 | } 57 | 58 | private void Mail_Button_Click(object sender, RoutedEventArgs e) 59 | { 60 | this.Frame.Navigate(typeof(Mail)); 61 | } 62 | 63 | #region NavigationHelper registration 64 | 65 | /// The methods provided in this section are simply used to allow 66 | /// NavigationHelper to respond to the page's navigation methods. 67 | /// 68 | /// Page specific logic should be placed in event handlers for the 69 | /// 70 | /// and . 71 | /// The navigation parameter is available in the LoadState method 72 | /// in addition to page state preserved during an earlier session. 73 | 74 | protected override void OnNavigatedTo(NavigationEventArgs e) 75 | { 76 | navigationHelper.OnNavigatedTo(e); 77 | 78 | // Developer code - if you haven't registered the app yet, we warn you. 79 | if (!App.Current.Resources.ContainsKey("ida:ClientID")) 80 | { 81 | MessageDialogHelper.ShowDialogAsync("To run this sample, you must register it with Office 365. You can do that through the 'Add | Connected services' dialog in Visual Studio. See Readme for more info", "Oops - App not registered with Office 365"); 82 | } 83 | } 84 | 85 | protected override void OnNavigatedFrom(NavigationEventArgs e) 86 | { 87 | navigationHelper.OnNavigatedFrom(e); 88 | } 89 | 90 | #endregion 91 | 92 | } 93 | } 94 | //********************************************************* 95 | // 96 | // MIT License: 97 | // Permission is hereby granted, free of charge, to any person obtaining 98 | // a copy of this software and associated documentation files (the 99 | // ""Software""), to deal in the Software without restriction, including 100 | // without limitation the rights to use, copy, modify, merge, publish, 101 | // distribute, sublicense, and/or sell copies of the Software, and to 102 | // permit persons to whom the Software is furnished to do so, subject to 103 | // the following conditions: 104 | 105 | // The above copyright notice and this permission notice shall be 106 | // included in all copies or substantial portions of the Software. 107 | 108 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 109 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 110 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 111 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 112 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 113 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 114 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 115 | // 116 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Office365StarterProject 6 | Microsoft 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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Office365StarterProject/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("Office365StarterProject")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Office365StarterProject")] 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)] -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/CalendarViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Office365StarterProject.Common; 4 | using Office365StarterProject.Helpers; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Collections.ObjectModel; 8 | using System.ComponentModel; 9 | using System.Threading.Tasks; 10 | using System.Windows.Input; 11 | 12 | namespace Office365StarterProject.ViewModels 13 | { 14 | /// 15 | /// Contains the calendar view model. 16 | /// 17 | public class CalendarViewModel : ViewModelBase 18 | { 19 | private bool _loadingCalendarEvents = false; 20 | 21 | CalendarOperations _calendarOperations = new CalendarOperations(); 22 | public bool LoadingCalendarEvents 23 | { 24 | get 25 | { 26 | return _loadingCalendarEvents; 27 | } 28 | set 29 | { 30 | SetProperty(ref _loadingCalendarEvents, value); 31 | } 32 | } 33 | 34 | /// 35 | /// The EventModel class object that enapsulates an event. 36 | /// 37 | private EventViewModel _selectedEvent = null; 38 | 39 | /// 40 | /// Sets or gets the selected EventViewModel from the calendar list in a UI 41 | /// Updates event view model fields bound to event field properties exposed in this model 42 | /// 43 | public EventViewModel SelectedEvent 44 | { 45 | get 46 | { 47 | return _selectedEvent; 48 | } 49 | set 50 | { 51 | if (SetProperty(ref _selectedEvent, value)) 52 | { 53 | ((RelayCommand)this.DeleteEventCommand).RaiseCanExecuteChanged(); 54 | ((RelayCommand)this.CancelEventChangesCommand).RaiseCanExecuteChanged(); 55 | if (_selectedEvent != null) 56 | { 57 | _selectedEvent.PropertyChanged += _selectedEvent_PropertyChanged; 58 | } 59 | } 60 | } 61 | } 62 | 63 | 64 | void _selectedEvent_PropertyChanged(object sender, PropertyChangedEventArgs e) 65 | { 66 | if (e.PropertyName == "IsNewOrDirty") 67 | { 68 | ((RelayCommand)this.CancelEventChangesCommand).RaiseCanExecuteChanged(); 69 | } 70 | } 71 | 72 | /// 73 | /// The user calendar events to be shown on a bound UI list 74 | /// 75 | public ObservableCollection Events { get; private set; } 76 | 77 | /// 78 | /// Clears the public selected event properties that are bound to a consuming UI 79 | /// 80 | public ICommand NewEventCommand { protected set; get; } 81 | 82 | /// 83 | /// Get a calendar event from the user's calendar 84 | /// 85 | public ICommand GetCalendarEventsCommand { protected set; get; } 86 | 87 | 88 | /// 89 | /// Remove a calendar event 90 | /// 91 | public ICommand DeleteEventCommand { protected set; get; } 92 | 93 | /// 94 | /// Cancel pending changes to a calendar event 95 | /// 96 | public ICommand CancelEventChangesCommand { protected set; get; } 97 | 98 | /// 99 | /// Takes an ExchangeClient object for an authenticated user 100 | /// 101 | /// ExcangeClient client 102 | public CalendarViewModel() 103 | { 104 | this.Events = new ObservableCollection(); 105 | 106 | //construct relay commands to be bound to controls on a UI 107 | this.NewEventCommand = new RelayCommand(ExecuteNewEventCommandAsync); 108 | this.GetCalendarEventsCommand = new RelayCommand(ExecuteGetCalendarEventsCommandAsync); 109 | this.DeleteEventCommand = new RelayCommand(ExecuteDeleteCommandAsync,CanDeleteEvent); 110 | this.CancelEventChangesCommand = new RelayCommand(ExecuteCancelEventChangesCommand, CanCancelEventChanges); 111 | } 112 | 113 | /// 114 | /// Loads today's calendar event items for the user 115 | /// 116 | /// 117 | public async Task LoadCalendarAsync() 118 | { 119 | LoggingViewModel.Instance.Information = "Getting your calendar events ..."; 120 | try 121 | { 122 | //Clear out any calendar events added in previous calls to LoadCalendarAsync() 123 | if (Events != null) 124 | Events.Clear(); 125 | else 126 | Events = new ObservableCollection(); 127 | 128 | // Get calendar events 129 | List events = await _calendarOperations.GetCalendarEventsAsync(); 130 | 131 | if (events.Count == 0) 132 | { 133 | LoggingViewModel.Instance.Information = "You have no calendar events."; 134 | } 135 | else 136 | { 137 | //Load events into the observable collection that is bound to UI 138 | foreach (EventViewModel calendarEvent in events) 139 | { 140 | Events.Add(calendarEvent); 141 | } 142 | LoggingViewModel.Instance.Information = String.Format("{0} calendar events loaded", Events.Count); 143 | } 144 | } 145 | catch (Exception ex) 146 | { 147 | LoggingViewModel.Instance.Information = "Error loading calendar: " + ex.Message; 148 | return false; 149 | } 150 | return true; 151 | } 152 | 153 | private bool CanDeleteEvent() 154 | { 155 | return (this.SelectedEvent != null); 156 | } 157 | 158 | private bool CanCancelEventChanges() 159 | { 160 | return (this.SelectedEvent != null && this.SelectedEvent.IsNewOrDirty); 161 | } 162 | 163 | /// 164 | /// Cancels any event changes that the user has applied locally. 165 | /// 166 | void ExecuteCancelEventChangesCommand() 167 | { 168 | if (this.SelectedEvent != null) 169 | { 170 | if (this.SelectedEvent.IsNew) 171 | { 172 | this.Events.Remove(this.SelectedEvent); 173 | } 174 | else 175 | { 176 | this.SelectedEvent.Reset(); 177 | } 178 | } 179 | 180 | } 181 | 182 | /// 183 | /// Creates a new event and adds it to the collection. 184 | /// 185 | /// The event is created locally. 186 | async void ExecuteNewEventCommandAsync() 187 | { 188 | var aadClient = await AuthenticationHelper.GetGraphClientAsync(); 189 | 190 | var currentUser = await (aadClient.Users 191 | .Where(i => i.ObjectId == AuthenticationHelper.LoggedInUser) 192 | .ExecuteSingleAsync()); 193 | var newEvent = new EventViewModel(currentUser.Mail); 194 | this.Events.Add(newEvent); 195 | this.SelectedEvent = newEvent; 196 | LoggingViewModel.Instance.Information = "Click the Update Event button and we'll save the new event to your calendar"; 197 | 198 | } 199 | 200 | /// 201 | /// Reloads the user's calendar with the newest calendar events 202 | /// 203 | async void ExecuteGetCalendarEventsCommandAsync() 204 | { 205 | 206 | this.LoadingCalendarEvents = true; 207 | //Reload the user's calendar 208 | await this.LoadCalendarAsync(); 209 | this.LoadingCalendarEvents = false; 210 | } 211 | 212 | 213 | /// 214 | /// Sends event remove request to Exchange service 215 | /// 216 | async void ExecuteDeleteCommandAsync() 217 | { 218 | if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the event '{0}'?", this._selectedEvent.DisplayString), "Confirm Deletion")) 219 | { 220 | if (!String.IsNullOrEmpty(this._selectedEvent.Id)) 221 | { 222 | var success = await _calendarOperations.DeleteCalendarEventAsync(this._selectedEvent.Id); 223 | if (success) 224 | { 225 | //Removes event from bound observable collection 226 | Events.Remove((EventViewModel)_selectedEvent); 227 | } 228 | } 229 | 230 | } 231 | } 232 | 233 | } 234 | } 235 | //********************************************************* 236 | // 237 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 238 | // 239 | //Copyright (c) Microsoft Corporation 240 | //All rights reserved. 241 | // 242 | // MIT License: 243 | // Permission is hereby granted, free of charge, to any person obtaining 244 | // a copy of this software and associated documentation files (the 245 | // ""Software""), to deal in the Software without restriction, including 246 | // without limitation the rights to use, copy, modify, merge, publish, 247 | // distribute, sublicense, and/or sell copies of the Software, and to 248 | // permit persons to whom the Software is furnished to do so, subject to 249 | // the following conditions: 250 | 251 | // The above copyright notice and this permission notice shall be 252 | // included in all copies or substantial portions of the Software. 253 | 254 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 255 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 256 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 257 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 258 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 259 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 260 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 261 | // 262 | //********************************************************* 263 | -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/ContactItemViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Office365.OutlookServices; 4 | using Office365StarterProject.Common; 5 | using Office365StarterProject.Helpers; 6 | using System; 7 | using System.Text.RegularExpressions; 8 | using Windows.UI.Xaml.Media.Imaging; 9 | 10 | namespace Office365StarterProject.ViewModels 11 | { 12 | /// 13 | /// Models a contact item 14 | /// 15 | public class ContactItemViewModel : ViewModelBase 16 | { 17 | private string _id; 18 | private bool _isNewOrDirty; 19 | private string _displayString; 20 | 21 | private string _contactDisplayName; 22 | private string _contactFileAs; 23 | private string _contactFirstName; 24 | private string _contactLastName; 25 | private string _contactJobTitle; 26 | private string _contactEmail; 27 | private string _contactWorkPhone; 28 | private string _contactMobilePhone; 29 | 30 | private IContact _serverContactData; 31 | ContactsOperations _contactsOperations = new ContactsOperations(); 32 | 33 | public bool IsNewOrDirty 34 | { 35 | get 36 | { 37 | return _isNewOrDirty; 38 | } 39 | set 40 | { 41 | if (SetProperty(ref _isNewOrDirty, value) && SaveChangesCommand != null) 42 | { 43 | UpdateDisplayString(); 44 | LoggingViewModel.Instance.Information = "Press the Update Contact button and we'll save the changes to your contacts"; 45 | SaveChangesCommand.RaiseCanExecuteChanged(); 46 | } 47 | } 48 | } 49 | public string ContactFileAs 50 | { 51 | get 52 | { 53 | return _contactFileAs; 54 | } 55 | set 56 | { 57 | if (SetProperty(ref _contactFileAs, value)) 58 | { 59 | IsNewOrDirty = true; 60 | } 61 | } 62 | } 63 | public string ContactDisplayName 64 | { 65 | get 66 | { 67 | return _contactDisplayName; 68 | } 69 | set 70 | { 71 | if (SetProperty(ref _contactDisplayName, value)) 72 | { 73 | IsNewOrDirty = true; 74 | UpdateDisplayString(); 75 | } 76 | } 77 | } 78 | public string ContactFirstName 79 | { 80 | get 81 | { 82 | return _contactFirstName; 83 | } 84 | set 85 | { 86 | if (SetProperty(ref _contactFirstName, value)) 87 | { 88 | UpdateContactDisplayName(); 89 | IsNewOrDirty = true; 90 | } 91 | } 92 | } 93 | public string ContactLastName 94 | { 95 | get 96 | { 97 | return _contactLastName; 98 | } 99 | set 100 | { 101 | if (SetProperty(ref _contactLastName, value)) 102 | { 103 | UpdateContactDisplayName(); 104 | IsNewOrDirty = true; 105 | } 106 | } 107 | } 108 | public string ContactJobTitle 109 | { 110 | get 111 | { 112 | return _contactJobTitle; 113 | } 114 | set 115 | { 116 | if (SetProperty(ref _contactJobTitle, value)) 117 | { 118 | IsNewOrDirty = true; 119 | } 120 | } 121 | } 122 | public string ContactEmail 123 | { 124 | get 125 | { 126 | return _contactEmail; 127 | } 128 | set 129 | { 130 | if (SetProperty(ref _contactEmail, value)) 131 | { 132 | IsNewOrDirty = true; 133 | } 134 | } 135 | } 136 | public string ContactWorkPhone 137 | { 138 | get 139 | { 140 | return _contactWorkPhone; 141 | } 142 | set 143 | { 144 | if (SetProperty(ref _contactWorkPhone, value)) 145 | { 146 | IsNewOrDirty = true; 147 | } 148 | } 149 | } 150 | public string ContactMobilePhone 151 | { 152 | get 153 | { 154 | return _contactMobilePhone; 155 | } 156 | set 157 | { 158 | if (SetProperty(ref _contactMobilePhone, value)) 159 | { 160 | IsNewOrDirty = true; 161 | } 162 | } 163 | } 164 | 165 | public string DisplayString 166 | { 167 | get 168 | { 169 | return _displayString; 170 | } 171 | set 172 | { 173 | SetProperty(ref _displayString, value); 174 | } 175 | } 176 | private void UpdateContactDisplayName() 177 | { 178 | this.ContactDisplayName = String.Format("{0} {1}", this.ContactFirstName, this.ContactLastName); 179 | } 180 | 181 | private void UpdateDisplayString() 182 | { 183 | DisplayString = (this.IsNewOrDirty) ? ContactDisplayName + " *" : ContactDisplayName; 184 | 185 | } 186 | public string Id 187 | { 188 | set 189 | { 190 | _id = value; 191 | } 192 | 193 | get 194 | { 195 | return _id; 196 | } 197 | } 198 | 199 | public bool IsNew 200 | { 201 | get 202 | { 203 | return this._serverContactData == null; 204 | } 205 | } 206 | 207 | public void Reset() 208 | { 209 | if (!this.IsNew) 210 | { 211 | this.initialize(this._serverContactData); 212 | } 213 | } 214 | /// 215 | /// Changes a contact. 216 | /// 217 | public RelayCommand SaveChangesCommand { get; private set; } 218 | private bool CanSaveChanges() 219 | { 220 | return (this.IsNewOrDirty); 221 | } 222 | /// 223 | /// Saves changes to a contact on the Exchange service and 224 | /// updates the local collection of contacts. 225 | /// 226 | public async void ExecuteSaveChangesCommandAsync() 227 | { 228 | string operationType = string.Empty; 229 | try 230 | { 231 | if (!String.IsNullOrEmpty(this.Id)) 232 | { 233 | operationType = "update"; 234 | //Send changes to Exchange 235 | _serverContactData = await _contactsOperations.UpdateContactItemAsync( 236 | this.Id, 237 | this._contactFileAs, 238 | this._contactFirstName, 239 | this._contactLastName, 240 | this._contactJobTitle, 241 | this._contactEmail, 242 | this._contactWorkPhone, 243 | this._contactMobilePhone 244 | ); 245 | this.IsNewOrDirty = false; 246 | } 247 | else 248 | { 249 | operationType = "save"; 250 | //Add the contact 251 | //Send the add request to Exchange service with new contact properties 252 | this.Id = await _contactsOperations.AddContactItemAsync( 253 | this._contactFileAs, 254 | this._contactFirstName, 255 | this._contactLastName, 256 | this._contactJobTitle, 257 | this._contactEmail, 258 | this._contactWorkPhone, 259 | this._contactMobilePhone 260 | ); 261 | this.IsNewOrDirty = false; 262 | } 263 | LoggingViewModel.Instance.Information = "Your contact is updated."; 264 | } 265 | catch (Exception ex) 266 | { 267 | LoggingViewModel.Instance.Information = string.Format("We could not {0} your contact. Error: {1}", operationType, ex.Message); 268 | } 269 | } 270 | public ContactItemViewModel() 271 | { 272 | this.Id = string.Empty; 273 | 274 | this._contactDisplayName = "New Contact"; 275 | this._contactFileAs = string.Empty; 276 | this._contactFirstName = string.Empty; 277 | this._contactLastName = string.Empty; 278 | this._contactJobTitle = string.Empty; 279 | this._contactEmail = string.Empty; 280 | this._contactWorkPhone = string.Empty; 281 | this._contactMobilePhone = string.Empty; 282 | this.SaveChangesCommand = new RelayCommand(ExecuteSaveChangesCommandAsync, CanSaveChanges); 283 | this.IsNewOrDirty = true; 284 | 285 | 286 | } 287 | public ContactItemViewModel(IContact contactData) 288 | { 289 | initialize(contactData); 290 | } 291 | private void initialize(IContact contactData) 292 | { 293 | _serverContactData = contactData; 294 | _id = _serverContactData.Id; 295 | 296 | _contactDisplayName = TidyValue(_serverContactData.DisplayName); 297 | _contactFileAs = TidyValue(_serverContactData.FileAs); 298 | _contactFirstName = TidyValue(_serverContactData.GivenName); 299 | _contactLastName = TidyValue(_serverContactData.Surname); 300 | _contactJobTitle = TidyValue(_serverContactData.JobTitle); 301 | if (_serverContactData.EmailAddresses[0] != null) 302 | _contactEmail = TidyValue(_serverContactData.EmailAddresses[0].Address); 303 | _contactWorkPhone = TidyValue(_serverContactData.BusinessPhones[0]); 304 | _contactMobilePhone = TidyValue(_serverContactData.MobilePhone1); 305 | 306 | this.IsNewOrDirty = false; 307 | 308 | this.SaveChangesCommand = new RelayCommand(ExecuteSaveChangesCommandAsync, CanSaveChanges); 309 | UpdateDisplayString(); 310 | } 311 | 312 | // Ensures that null strings are converted to empty strings. 313 | private string TidyValue(string value) 314 | { 315 | return (value == null) ? string.Empty : value; 316 | } 317 | } 318 | } 319 | //********************************************************* 320 | // 321 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 322 | // 323 | //Copyright (c) Microsoft Corporation 324 | //All rights reserved. 325 | // 326 | // MIT License: 327 | // Permission is hereby granted, free of charge, to any person obtaining 328 | // a copy of this software and associated documentation files (the 329 | // ""Software""), to deal in the Software without restriction, including 330 | // without limitation the rights to use, copy, modify, merge, publish, 331 | // distribute, sublicense, and/or sell copies of the Software, and to 332 | // permit persons to whom the Software is furnished to do so, subject to 333 | // the following conditions: 334 | 335 | // The above copyright notice and this permission notice shall be 336 | // included in all copies or substantial portions of the Software. 337 | 338 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 339 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 340 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 341 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 342 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 343 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 344 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 345 | // 346 | //********************************************************* 347 | -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/ContactsViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Office365StarterProject.Common; 4 | using Office365StarterProject.Helpers; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Collections.ObjectModel; 8 | using System.ComponentModel; 9 | using System.Threading.Tasks; 10 | using System.Windows.Input; 11 | using Windows.Storage; 12 | using Windows.Storage.Pickers; 13 | using Windows.Storage.Streams; 14 | 15 | namespace Office365StarterProject.ViewModels 16 | { 17 | /// 18 | /// Contains the calendar view model. 19 | /// 20 | class ContactsViewModel : ViewModelBase 21 | { 22 | private ContactsOperations _contactsOperations = null; 23 | 24 | public ContactsViewModel() 25 | { 26 | // Instantiate a private instance of the contacts operations object 27 | _contactsOperations = new ContactsOperations(); 28 | 29 | this.Contacts = new ObservableCollection(); 30 | 31 | //construct relay commands to be bound to controls on a UI 32 | this.NewContactCommand = new RelayCommand(ExecuteNewContactCommand); 33 | this.GetContactsCommand = new RelayCommand(ExecuteGetContactsCommandAsync); 34 | this.DeleteContactCommand = new RelayCommand(ExecuteDeleteCommandAsync, CanDeleteContact); 35 | this.CancelContactChangesCommand = new RelayCommand(ExecuteCancelContactChangesCommand, CanCancelContactChanges); 36 | } 37 | 38 | /// 39 | /// The user contacts to be shown on a bound UI list 40 | /// 41 | public ObservableCollection Contacts { get; private set; } 42 | 43 | /// 44 | /// Command to instantiate a new contact locally. 45 | /// 46 | public ICommand NewContactCommand { protected set; get; } 47 | 48 | /// 49 | /// Command to get the user's contacts. 50 | /// 51 | public ICommand GetContactsCommand { protected set; get; } 52 | 53 | 54 | /// 55 | /// Command to delete a contact. 56 | /// 57 | public ICommand DeleteContactCommand { protected set; get; } 58 | 59 | /// 60 | /// Cancel pending changes to a contact 61 | /// 62 | public ICommand CancelContactChangesCommand { protected set; get; } 63 | 64 | private bool _loadingContacts = false; 65 | /// 66 | /// Gets or sets whether we are in the process of loading contact data. 67 | /// 68 | public bool LoadingContacts 69 | { 70 | get 71 | { 72 | return _loadingContacts; 73 | } 74 | private set 75 | { 76 | SetProperty(ref _loadingContacts, value); 77 | } 78 | } 79 | 80 | private ContactItemViewModel _selectedContact = null; 81 | 82 | /// 83 | /// Sets or gets the selected ContactViewModel from the contact list in a UI. 84 | /// Updates contact view model fields bound to contact field properties exposed in this model. 85 | /// 86 | public ContactItemViewModel SelectedContact 87 | { 88 | get 89 | { 90 | return _selectedContact; 91 | } 92 | set 93 | { 94 | if(SetProperty(ref _selectedContact,value)) 95 | { 96 | // Enable and disable commands depending on whether a contact has been selected. 97 | ((RelayCommand)this.DeleteContactCommand).RaiseCanExecuteChanged(); 98 | ((RelayCommand)this.CancelContactChangesCommand).RaiseCanExecuteChanged(); 99 | if(_selectedContact!=null) 100 | { 101 | _selectedContact.PropertyChanged += _selectedContact_PropertyChanged; 102 | } 103 | } 104 | } 105 | } 106 | 107 | void _selectedContact_PropertyChanged(object sender, PropertyChangedEventArgs e) 108 | { 109 | if(e.PropertyName=="IsNewOrDirty") 110 | { 111 | ((RelayCommand)this.CancelContactChangesCommand).RaiseCanExecuteChanged(); 112 | } 113 | } 114 | 115 | private bool CanDeleteContact() 116 | { 117 | return (this.SelectedContact != null); 118 | } 119 | 120 | private bool CanCancelContactChanges() 121 | { 122 | return (this.SelectedContact != null && this.SelectedContact.IsNewOrDirty); 123 | } 124 | 125 | private bool CanUpdateContactImage() 126 | { 127 | return (this.SelectedContact != null); 128 | } 129 | 130 | /// 131 | /// Cancels any contact changes that the user has applied locally. 132 | /// 133 | void ExecuteCancelContactChangesCommand() 134 | { 135 | if (this.SelectedContact != null) 136 | { 137 | if (this.SelectedContact.IsNew) 138 | { 139 | this.Contacts.Remove(this.SelectedContact); 140 | } 141 | else 142 | { 143 | this.SelectedContact.Reset(); 144 | } 145 | } 146 | 147 | } 148 | 149 | /// 150 | /// Creates a new contact and adds it to the collection. 151 | /// 152 | /// The contact is created locally. 153 | void ExecuteNewContactCommand() 154 | { 155 | var newContact = new ContactItemViewModel(); 156 | this.Contacts.Add(newContact); 157 | this.SelectedContact = newContact; 158 | LoggingViewModel.Instance.Information = "Click the Update Contact button and we'll save the new contact."; 159 | } 160 | 161 | /// 162 | /// Gets the user's contacts from the Exchange service. 163 | /// 164 | async void ExecuteGetContactsCommandAsync() 165 | { 166 | this.LoadingContacts = true; 167 | await this.LoadContactsAsync(); 168 | this.LoadingContacts = false; 169 | } 170 | 171 | private async Task LoadContactsAsync() 172 | { 173 | LoggingViewModel.Instance.Information = string.Empty; 174 | try 175 | { 176 | //Clear out any contacts added in previous calls to LoadContactsAsync() 177 | if (Contacts != null) 178 | Contacts.Clear(); 179 | else 180 | Contacts = new ObservableCollection(); 181 | 182 | LoggingViewModel.Instance.Information = "Getting contacts ..."; 183 | 184 | //Get contacts from Exchange service via API. 185 | var contacts = await _contactsOperations.GetContactsAsync(); 186 | 187 | if (contacts.Count == 0) 188 | { 189 | LoggingViewModel.Instance.Information = "You have no contacts."; 190 | } 191 | else 192 | { 193 | // Load contacts into the observable collection that is bound to UI 194 | foreach (var contact in contacts) 195 | { 196 | Contacts.Add(new ContactItemViewModel(contact)); 197 | } 198 | 199 | LoggingViewModel.Instance.Information = String.Format("{0} contacts loaded.", Contacts.Count); 200 | } 201 | } 202 | catch (Exception ex) 203 | { 204 | LoggingViewModel.Instance.Information = "Error loading contacts: " + ex.Message; 205 | return false; 206 | } 207 | return true; 208 | } 209 | 210 | 211 | /// 212 | /// Sends contact remove request to the Exchange service. 213 | /// 214 | async void ExecuteDeleteCommandAsync() 215 | { 216 | try 217 | { 218 | if (await MessageDialogHelper.ShowYesNoDialogAsync(String.Format("Are you sure you want to delete the contact '{0}'?", this._selectedContact.DisplayString), "Confirm Deletion")) 219 | { 220 | if (!String.IsNullOrEmpty(this._selectedContact.Id)) 221 | { 222 | if( await _contactsOperations.DeleteContactItemAsync(this._selectedContact.Id)) 223 | //Removes contact from bound observable collection 224 | Contacts.Remove((ContactItemViewModel)_selectedContact); 225 | 226 | } 227 | 228 | } 229 | } 230 | catch (Exception) 231 | { 232 | LoggingViewModel.Instance.Information = "We could not delete your contact."; 233 | } 234 | } 235 | 236 | } 237 | } 238 | //********************************************************* 239 | // 240 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 241 | // 242 | //Copyright (c) Microsoft Corporation 243 | //All rights reserved. 244 | // 245 | // MIT License: 246 | // Permission is hereby granted, free of charge, to any person obtaining 247 | // a copy of this software and associated documentation files (the 248 | // ""Software""), to deal in the Software without restriction, including 249 | // without limitation the rights to use, copy, modify, merge, publish, 250 | // distribute, sublicense, and/or sell copies of the Software, and to 251 | // permit persons to whom the Software is furnished to do so, subject to 252 | // the following conditions: 253 | 254 | // The above copyright notice and this permission notice shall be 255 | // included in all copies or substantial portions of the Software. 256 | 257 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 258 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 259 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 260 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 261 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 262 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 263 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 264 | // 265 | //********************************************************* 266 | -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/FileSystemItemViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Office365.SharePoint; 4 | using Microsoft.Office365.SharePoint.FileServices; 5 | 6 | namespace Office365StarterProject.ViewModels 7 | { 8 | /// 9 | /// Contains the files that are used in the view model. 10 | /// 11 | public class FileSystemItemViewModel 12 | { 13 | 14 | private IItem _fileSystemItem; 15 | private string _name; 16 | 17 | public FileSystemItemViewModel(IItem fileSystemItem) 18 | { 19 | if (fileSystemItem == null) 20 | { 21 | throw new System.ArgumentNullException("fileSystemItem"); 22 | } 23 | 24 | _fileSystemItem = fileSystemItem; 25 | 26 | _name = fileSystemItem.Name; 27 | } 28 | 29 | public IItem FileSystemItem 30 | { 31 | get 32 | { 33 | return _fileSystemItem; 34 | } 35 | private set 36 | 37 | { _fileSystemItem = value; } 38 | } 39 | 40 | /// 41 | /// The DisplayName property is the property path used in the 42 | /// DisplayMemberPath property in the ListBox control that is 43 | /// bound to the ViewModel. 44 | /// 45 | public string DisplayName 46 | { 47 | get 48 | { 49 | if (_fileSystemItem is Folder) 50 | { 51 | return _name + " (folder)"; 52 | } 53 | else 54 | { 55 | return _name; 56 | } 57 | } 58 | } 59 | 60 | public string Name 61 | { 62 | get 63 | { 64 | return _name; 65 | } 66 | 67 | set 68 | { 69 | _name = value; 70 | } 71 | } 72 | 73 | public override string ToString() 74 | { 75 | return _name; 76 | } 77 | } 78 | } 79 | //********************************************************* 80 | // 81 | // MIT License: 82 | // Permission is hereby granted, free of charge, to any person obtaining 83 | // a copy of this software and associated documentation files (the 84 | // ""Software""), to deal in the Software without restriction, including 85 | // without limitation the rights to use, copy, modify, merge, publish, 86 | // distribute, sublicense, and/or sell copies of the Software, and to 87 | // permit persons to whom the Software is furnished to do so, subject to 88 | // the following conditions: 89 | 90 | // The above copyright notice and this permission notice shall be 91 | // included in all copies or substantial portions of the Software. 92 | 93 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 94 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 95 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 96 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 97 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 98 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 99 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 100 | // 101 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/LoggingViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Office365StarterProject.ViewModels; 4 | 5 | namespace Office365StarterProject.Helpers 6 | { 7 | public class LoggingViewModel : ViewModelBase 8 | { 9 | public static LoggingViewModel Instance { get; private set; } 10 | 11 | static LoggingViewModel() 12 | { 13 | Instance = new LoggingViewModel(); 14 | } 15 | 16 | private string _information; 17 | 18 | public string Information 19 | { 20 | get 21 | { 22 | return _information; 23 | } 24 | set 25 | { 26 | SetProperty(ref _information, value); 27 | } 28 | } 29 | } 30 | } 31 | //********************************************************* 32 | // 33 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 34 | // 35 | //Copyright (c) Microsoft Corporation 36 | //All rights reserved. 37 | // 38 | // MIT License: 39 | // Permission is hereby granted, free of charge, to any person obtaining 40 | // a copy of this software and associated documentation files (the 41 | // ""Software""), to deal in the Software without restriction, including 42 | // without limitation the rights to use, copy, modify, merge, publish, 43 | // distribute, sublicense, and/or sell copies of the Software, and to 44 | // permit persons to whom the Software is furnished to do so, subject to 45 | // the following conditions: 46 | 47 | // The above copyright notice and this permission notice shall be 48 | // included in all copies or substantial portions of the Software. 49 | 50 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 51 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 52 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 53 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 54 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 55 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 56 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 57 | // 58 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/MailItemViewModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Office365.OutlookServices; 2 | using Office365StarterProject.Common; 3 | using Office365StarterProject.Helpers; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Collections.ObjectModel; 7 | using System.ComponentModel; 8 | using System.ComponentModel.DataAnnotations; 9 | using System.Text.RegularExpressions; 10 | using System.Threading.Tasks; 11 | using System.Windows.Input; 12 | using Windows.Data.Html; 13 | 14 | namespace Office365StarterProject.ViewModels 15 | { 16 | class MailItemViewModel : ViewModelBase 17 | { 18 | private string _id; 19 | 20 | //Specfies the mail body as a text block consisting of multiple lines. This prevents body display 21 | //as a single line of text. 22 | [DataType(DataType.MultilineText)] 23 | private string _body; 24 | private string _displayString; 25 | private string _recipients; 26 | private string _subject; 27 | private string _sender; 28 | private DateTimeOffset? _received; 29 | private MailOperations _mailOperations = new MailOperations(); 30 | 31 | public string DisplayString 32 | { 33 | get 34 | { 35 | return _displayString; 36 | } 37 | set 38 | { 39 | SetProperty(ref _displayString, value); 40 | } 41 | } 42 | 43 | public string ID 44 | { 45 | set 46 | { 47 | _id = value; 48 | } 49 | 50 | get 51 | { 52 | return _id; 53 | } 54 | } 55 | 56 | //Specfies the mail body as a text block consisting of multiple lines. This prevents body display 57 | //as a single line of text. 58 | [DataType(DataType.MultilineText)] 59 | public string Body 60 | { 61 | get 62 | { 63 | return _body; 64 | } 65 | 66 | set 67 | { 68 | SetProperty(ref _body, value); 69 | } 70 | } 71 | public string Recipients 72 | { 73 | get 74 | { 75 | return _recipients; 76 | } 77 | 78 | set 79 | { 80 | SetProperty(ref _recipients, value); 81 | } 82 | } 83 | public string Subject 84 | { 85 | get 86 | { 87 | return _subject; 88 | } 89 | 90 | set 91 | { 92 | SetProperty(ref _subject, value); 93 | } 94 | } 95 | public string Sender 96 | { 97 | get 98 | { 99 | return _sender; 100 | } 101 | 102 | set 103 | { 104 | SetProperty(ref _sender, value); 105 | } 106 | } 107 | 108 | //Display format for the date and time of message receipt. The DataFormatString defines the display 109 | //of the DateTimeOffset object when it is bound to a XAML control. 110 | [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM-dd-yyyy HH:mm tt}")] 111 | public DateTimeOffset? Received 112 | { 113 | get 114 | { 115 | return _received; 116 | } 117 | 118 | set 119 | { 120 | SetProperty(ref _received, value); 121 | } 122 | } 123 | 124 | public MailItemViewModel() 125 | { 126 | this._id = string.Empty; 127 | this._body = "New mail"; 128 | this._subject = string.Empty; 129 | this._recipients = string.Empty; 130 | this._sender = string.Empty; 131 | this._received = null; 132 | this._displayString = string.Empty; 133 | 134 | } 135 | 136 | public MailItemViewModel(IMessage serverMailItem) 137 | { 138 | initialize(serverMailItem); 139 | } 140 | 141 | private void initialize(IMessage serverMailItem) 142 | { 143 | 144 | _id = serverMailItem.Id; 145 | 146 | //If HTML, take text. Otherwise, use content as is 147 | string bodyContent = serverMailItem.Body.Content; 148 | if (serverMailItem.Body.ContentType == BodyType.HTML) 149 | { 150 | bodyContent = HtmlUtilities.ConvertToText(bodyContent); 151 | } 152 | _body = bodyContent; 153 | 154 | _subject = serverMailItem.Subject; 155 | 156 | _recipients = _mailOperations.BuildRecipientList(serverMailItem.ToRecipients); 157 | 158 | if (serverMailItem.Sender != null) 159 | { 160 | _sender = serverMailItem.Sender.EmailAddress.Address; 161 | } 162 | else 163 | _sender = string.Empty; // Sometimes, mails exist as draft, and therefore haven't been sent. 164 | 165 | if (serverMailItem.DateTimeReceived != null) 166 | { 167 | _received = serverMailItem.DateTimeReceived; 168 | } 169 | 170 | _displayString = _received + ": " +_sender + ":: " + _subject; 171 | } 172 | 173 | 174 | } 175 | 176 | } 177 | 178 | //********************************************************* 179 | // 180 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 181 | // 182 | //Copyright (c) Microsoft Corporation 183 | //All rights reserved. 184 | // 185 | // MIT License: 186 | // Permission is hereby granted, free of charge, to any person obtaining 187 | // a copy of this software and associated documentation files (the 188 | // ""Software""), to deal in the Software without restriction, including 189 | // without limitation the rights to use, copy, modify, merge, publish, 190 | // distribute, sublicense, and/or sell copies of the Software, and to 191 | // permit persons to whom the Software is furnished to do so, subject to 192 | // the following conditions: 193 | 194 | // The above copyright notice and this permission notice shall be 195 | // included in all copies or substantial portions of the Software. 196 | 197 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 198 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 199 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 200 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 201 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 202 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 203 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 204 | // 205 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/UserViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using Microsoft.Azure.ActiveDirectory.GraphClient; 4 | using Microsoft.Office365.OAuth; 5 | using Office365StarterProject.Common; 6 | using Office365StarterProject.Helpers; 7 | using System; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using Windows.UI.Xaml.Media.Imaging; 11 | 12 | namespace Office365StarterProject.ViewModels 13 | { 14 | /// 15 | /// Respresents the signed-in user. 16 | /// 17 | public class UserViewModel : ViewModelBase 18 | { 19 | 20 | private IUser _currentUser; 21 | private string _mailAddress; 22 | private string _id; 23 | private string _displayName = "(not connected)"; 24 | private string _jobTitle; 25 | private bool _signedIn; 26 | private string _logOnCaption = "Connect to Office 365"; 27 | private static readonly BitmapImage _signedOutImage = new BitmapImage(new Uri("ms-appx:///assets/UserDefault.png", UriKind.RelativeOrAbsolute)); 28 | private BitmapImage _avatar = _signedOutImage; 29 | private RelayCommand _toggleSignInCommand; 30 | private UserOperations _userOperations = new UserOperations(); 31 | 32 | /// 33 | /// Gets the Id of the user. 34 | /// 35 | public string Id 36 | { 37 | get 38 | { 39 | return _id; 40 | } 41 | 42 | private set 43 | { 44 | SetProperty(ref _id, value); 45 | } 46 | } 47 | 48 | /// 49 | /// True if the user is signed in; Otherwise, false. 50 | /// 51 | public bool SignedIn 52 | { 53 | get 54 | { 55 | return _signedIn; 56 | } 57 | 58 | private set 59 | { 60 | SetProperty(ref _signedIn, value); 61 | } 62 | } 63 | 64 | /// 65 | /// The display name of the user. 66 | /// 67 | public string DisplayName 68 | { 69 | get 70 | { 71 | return _displayName; 72 | } 73 | 74 | private set 75 | { 76 | SetProperty(ref _displayName, value); 77 | } 78 | } 79 | 80 | /// 81 | /// The job title of the user. 82 | /// 83 | public string JobTitle 84 | { 85 | get 86 | { 87 | return _jobTitle; 88 | } 89 | 90 | private set 91 | { 92 | SetProperty(ref _jobTitle, value); 93 | } 94 | } 95 | 96 | /// 97 | /// Caption to show depending on the whether the user is signed in or not. 98 | /// 99 | public string LogOnCaption 100 | { 101 | get 102 | { 103 | return _logOnCaption; 104 | } 105 | 106 | set 107 | { 108 | SetProperty(ref _logOnCaption, value); 109 | } 110 | } 111 | 112 | /// 113 | /// The user's avatar. 114 | /// 115 | public BitmapImage Avatar 116 | { 117 | get 118 | { 119 | return _avatar; 120 | } 121 | 122 | set 123 | { 124 | SetProperty(ref _avatar, value); 125 | } 126 | } 127 | 128 | public string MailAddress 129 | { 130 | get 131 | { 132 | return _mailAddress; 133 | } 134 | 135 | } 136 | 137 | private bool _isBusy = false; 138 | 139 | /// 140 | /// True when we are in the process of logging in; Otherwise, false. 141 | /// 142 | public bool IsBusy 143 | { 144 | get 145 | { 146 | return _isBusy; 147 | } 148 | set 149 | { 150 | SetProperty(ref _isBusy, value); 151 | } 152 | 153 | } 154 | 155 | /// 156 | /// Command to sign the user in if he is not already signed in or to sign the user out. 157 | /// 158 | public RelayCommand ToggleSignInCommand 159 | { 160 | get 161 | { 162 | if (_toggleSignInCommand == null) 163 | { 164 | _toggleSignInCommand = new RelayCommand 165 | ( 166 | async () => 167 | { 168 | if (!SignedIn) 169 | { 170 | this.IsBusy = true; 171 | await SignInCurrentUserAsync(); 172 | this.IsBusy = false; 173 | } 174 | else 175 | { 176 | this.IsBusy = true; 177 | await SignOutAsync(); 178 | this.IsBusy = false; 179 | } 180 | }, 181 | null 182 | ); 183 | } 184 | 185 | return _toggleSignInCommand; 186 | } 187 | } 188 | 189 | private async Task SignOutAsync() 190 | { 191 | if (!SignedIn) 192 | return; 193 | 194 | await _userOperations.SignOutAsync(); 195 | 196 | Avatar = _signedOutImage; 197 | 198 | DisplayName = "(not connected)"; 199 | JobTitle = String.Empty; 200 | 201 | SignedIn = false; 202 | this.LogOnCaption = "Connect to Office 365"; 203 | } 204 | 205 | /// 206 | /// Signs in the current user. 207 | /// 208 | /// 209 | public async Task SignInCurrentUserAsync() 210 | { 211 | _currentUser = await _userOperations.GetCurrentUserAsync(); 212 | 213 | if (_currentUser != null) 214 | { 215 | this.DisplayName = _currentUser.DisplayName; 216 | this.JobTitle = _currentUser.JobTitle; 217 | this.Avatar = await _userOperations.GetUserThumbnailPhotoAsync(_currentUser); 218 | this.LogOnCaption = "Disconnect from Office 365"; 219 | this.Id = _currentUser.ObjectId; 220 | this._mailAddress = _currentUser.Mail; 221 | this.SignedIn = true; 222 | } 223 | } 224 | } 225 | } 226 | //********************************************************* 227 | // 228 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 229 | // 230 | //Copyright (c) Microsoft Corporation 231 | //All rights reserved. 232 | // 233 | // MIT License: 234 | // Permission is hereby granted, free of charge, to any person obtaining 235 | // a copy of this software and associated documentation files (the 236 | // ""Software""), to deal in the Software without restriction, including 237 | // without limitation the rights to use, copy, modify, merge, publish, 238 | // distribute, sublicense, and/or sell copies of the Software, and to 239 | // permit persons to whom the Software is furnished to do so, subject to 240 | // the following conditions: 241 | 242 | // The above copyright notice and this permission notice shall be 243 | // included in all copies or substantial portions of the Software. 244 | 245 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 246 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 247 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 248 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 249 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 250 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 251 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 252 | // 253 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace Office365StarterProject.ViewModels 8 | { 9 | /// 10 | /// Base view model for working with Office 365 services. 11 | /// 12 | public class ViewModelBase : INotifyPropertyChanged 13 | { 14 | 15 | protected bool SetProperty(ref T field, T value, [CallerMemberName] string propertyName = "") 16 | { 17 | // If the value is the same as the current value, return false to indicate this was a no-op. 18 | if (Object.Equals(field, value)) 19 | return false; 20 | 21 | // Raise any registered property changed events and indicate to the user that the value was indeed changed. 22 | field = value; 23 | NotifyPropertyChanged(propertyName); 24 | return true; 25 | } 26 | 27 | public event PropertyChangedEventHandler PropertyChanged; 28 | 29 | 30 | protected void NotifyPropertyChanged([CallerMemberName]string propertyName = "") 31 | { 32 | if (PropertyChanged != null) 33 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 34 | } 35 | } 36 | } 37 | 38 | //********************************************************* 39 | // 40 | //O365-APIs-Start-Windows, https://github.com/OfficeDev/O365-APIs-Start-Windows 41 | // 42 | //Copyright (c) Microsoft Corporation 43 | //All rights reserved. 44 | // 45 | // MIT License: 46 | // Permission is hereby granted, free of charge, to any person obtaining 47 | // a copy of this software and associated documentation files (the 48 | // ""Software""), to deal in the Software without restriction, including 49 | // without limitation the rights to use, copy, modify, merge, publish, 50 | // distribute, sublicense, and/or sell copies of the Software, and to 51 | // permit persons to whom the Software is furnished to do so, subject to 52 | // the following conditions: 53 | 54 | // The above copyright notice and this permission notice shall be 55 | // included in all copies or substantial portions of the Software. 56 | 57 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 58 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 59 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 60 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 61 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 62 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 63 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 64 | // 65 | //********************************************************* 66 | -------------------------------------------------------------------------------- /Office365StarterProject/Views/Calendar.xaml.cs: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | 4 | using Office365StarterProject.Common; 5 | using Office365StarterProject.Helpers; 6 | using Office365StarterProject.ViewModels; 7 | using System; 8 | using Windows.UI.Xaml.Controls; 9 | using Windows.UI.Xaml.Navigation; 10 | 11 | namespace Office365StarterProject.Views 12 | { 13 | /// 14 | /// The Calendar page. 15 | /// 16 | public sealed partial class Calendar : Page 17 | { 18 | 19 | private NavigationHelper navigationHelper; 20 | private ObservableDictionary defaultViewModel = new ObservableDictionary(); 21 | 22 | /// 23 | /// This can be changed to a strongly typed view model. 24 | /// 25 | public ObservableDictionary DefaultViewModel 26 | { 27 | get { return this.defaultViewModel; } 28 | } 29 | 30 | /// 31 | /// NavigationHelper is used on each page to aid in navigation and 32 | /// process lifetime management 33 | /// 34 | public NavigationHelper NavigationHelper 35 | { 36 | get { return this.navigationHelper; } 37 | } 38 | 39 | public Calendar() 40 | { 41 | this.InitializeComponent(); 42 | this.navigationHelper = new NavigationHelper(this); 43 | this.navigationHelper.LoadState += navigationHelper_LoadState; 44 | this.navigationHelper.SaveState += navigationHelper_SaveState; 45 | } 46 | 47 | /// 48 | /// Populates the page with content passed during navigation. Any saved state is also 49 | /// provided when recreating a page from a prior session. 50 | /// 51 | /// 52 | /// The source of the event; typically 53 | /// 54 | /// Event data that provides both the navigation parameter passed to 55 | /// when this page was initially requested and 56 | /// a dictionary of state preserved by this page during an earlier 57 | /// session. The state will be null the first time a page is visited. 58 | private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) 59 | { 60 | } 61 | 62 | /// 63 | /// Preserves state associated with this page in case the application is suspended or the 64 | /// page is discarded from the navigation cache. Values must conform to the serialization 65 | /// requirements of . 66 | /// 67 | /// The source of the event; typically 68 | /// Event data that provides an empty dictionary to be populated with 69 | /// serializable state. 70 | private void navigationHelper_SaveState(object sender, SaveStateEventArgs e) 71 | { 72 | } 73 | 74 | #region NavigationHelper registration 75 | 76 | /// The methods provided in this section are simply used to allow 77 | /// NavigationHelper to respond to the page's navigation methods. 78 | /// 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 | defaultViewModel["CalendarViewModel"] = new CalendarViewModel(); 91 | defaultViewModel["LoggingViewModel"] = LoggingViewModel.Instance; 92 | 93 | } 94 | 95 | protected override void OnNavigatedFrom(NavigationEventArgs e) 96 | { 97 | LoggingViewModel.Instance.Information = string.Empty; 98 | navigationHelper.OnNavigatedFrom(e); 99 | } 100 | 101 | #endregion 102 | } 103 | } 104 | //********************************************************* 105 | // 106 | // MIT License: 107 | // Permission is hereby granted, free of charge, to any person obtaining 108 | // a copy of this software and associated documentation files (the 109 | // ""Software""), to deal in the Software without restriction, including 110 | // without limitation the rights to use, copy, modify, merge, publish, 111 | // distribute, sublicense, and/or sell copies of the Software, and to 112 | // permit persons to whom the Software is furnished to do so, subject to 113 | // the following conditions: 114 | 115 | // The above copyright notice and this permission notice shall be 116 | // included in all copies or substantial portions of the Software. 117 | 118 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 119 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 120 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 121 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 122 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 123 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 124 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 125 | // 126 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Views/Contacts.xaml.cs: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | 4 | using Office365StarterProject.Common; 5 | using Office365StarterProject.Helpers; 6 | using Office365StarterProject.ViewModels; 7 | using System; 8 | using Windows.UI.Xaml.Controls; 9 | using Windows.UI.Xaml.Navigation; 10 | 11 | namespace Office365StarterProject.Views 12 | { 13 | /// 14 | /// The Contacts page. 15 | /// 16 | public sealed partial class Contacts : Page 17 | { 18 | 19 | private NavigationHelper navigationHelper; 20 | private ObservableDictionary defaultViewModel = new ObservableDictionary(); 21 | 22 | /// 23 | /// This can be changed to a strongly typed view model. 24 | /// 25 | public ObservableDictionary DefaultViewModel 26 | { 27 | get { return this.defaultViewModel; } 28 | } 29 | 30 | /// 31 | /// NavigationHelper is used on each page to aid in navigation and 32 | /// process lifetime management 33 | /// 34 | public NavigationHelper NavigationHelper 35 | { 36 | get { return this.navigationHelper; } 37 | } 38 | 39 | public Contacts() 40 | { 41 | this.InitializeComponent(); 42 | this.navigationHelper = new NavigationHelper(this); 43 | this.navigationHelper.LoadState += navigationHelper_LoadState; 44 | this.navigationHelper.SaveState += navigationHelper_SaveState; 45 | } 46 | /// 47 | /// Populates the page with content passed during navigation. Any saved state is also 48 | /// provided when recreating a page from a prior session. 49 | /// 50 | /// 51 | /// The source of the event; typically 52 | /// 53 | /// Event data that provides both the navigation parameter passed to 54 | /// when this page was initially requested and 55 | /// a dictionary of state preserved by this page during an earlier 56 | /// session. The state will be null the first time a page is visited. 57 | private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) 58 | { 59 | } 60 | 61 | /// 62 | /// Preserves state associated with this page in case the application is suspended or the 63 | /// page is discarded from the navigation cache. Values must conform to the serialization 64 | /// requirements of . 65 | /// 66 | /// The source of the event; typically 67 | /// Event data that provides an empty dictionary to be populated with 68 | /// serializable state. 69 | private void navigationHelper_SaveState(object sender, SaveStateEventArgs e) 70 | { 71 | } 72 | 73 | #region NavigationHelper registration 74 | 75 | /// The methods provided in this section are simply used to allow 76 | /// NavigationHelper to respond to the page's navigation methods. 77 | /// 78 | /// Page specific logic should be placed in event handlers for the 79 | /// 80 | /// and . 81 | /// The navigation parameter is available in the LoadState method 82 | /// in addition to page state preserved during an earlier session. 83 | 84 | protected override void OnNavigatedTo(NavigationEventArgs e) 85 | { 86 | navigationHelper.OnNavigatedTo(e); 87 | 88 | 89 | defaultViewModel["ContactsViewModel"] = new ContactsViewModel(); 90 | defaultViewModel["LoggingViewModel"] = LoggingViewModel.Instance; 91 | 92 | } 93 | 94 | protected override void OnNavigatedFrom(NavigationEventArgs e) 95 | { 96 | LoggingViewModel.Instance.Information = string.Empty; 97 | navigationHelper.OnNavigatedFrom(e); 98 | } 99 | 100 | #endregion 101 | } 102 | } 103 | //********************************************************* 104 | // 105 | // MIT License: 106 | // Permission is hereby granted, free of charge, to any person obtaining 107 | // a copy of this software and associated documentation files (the 108 | // ""Software""), to deal in the Software without restriction, including 109 | // without limitation the rights to use, copy, modify, merge, publish, 110 | // distribute, sublicense, and/or sell copies of the Software, and to 111 | // permit persons to whom the Software is furnished to do so, subject to 112 | // the following conditions: 113 | 114 | // The above copyright notice and this permission notice shall be 115 | // included in all copies or substantial portions of the Software. 116 | 117 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 118 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 119 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 120 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 121 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 122 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 123 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 124 | // 125 | //********************************************************* -------------------------------------------------------------------------------- /Office365StarterProject/Views/Mail.xaml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |