Skip to content

Commit 1daaf4e

Browse files
Updated Graph usage pattern in RoamingSettings helpers and updated descriptions to csproj files. (#139)
1 parent 6fdcc7d commit 1daaf4e

File tree

13 files changed

+161
-173
lines changed

13 files changed

+161
-173
lines changed

CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
<Title>Windows Community Toolkit .NET Standard Auth Services</Title>
66
<Description>
7-
This package includes .NET Standard authentication helpers such as:
8-
- MsalProvider:
7+
This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.
8+
9+
Classes:
10+
- MsalProvider: An authentication provider based on MSAL for .NET.
911
</Description>
1012
<PackageTags>Community Toolkit Provider Authentication Auth Msal</PackageTags>
1113
</PropertyGroup>
@@ -18,7 +20,4 @@
1820
<ProjectReference Include="..\CommunityToolkit.Authentication\CommunityToolkit.Authentication.csproj" />
1921
</ItemGroup>
2022

21-
<ItemGroup>
22-
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.194" />
23-
</ItemGroup>
2423
</Project>

CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<TargetFramework>uap10.0.17134</TargetFramework>
55
<Title>Windows Community Toolkit Graph Uwp Authentication Provider</Title>
66
<Description>
7-
This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.
7+
This library provides an authentication provider based on the native Windows dialogues.
88

99
Classes:
10-
- WindowsProvider:
10+
- WindowsProvider: An authentication provider based on the native AccountsSettingsPane in Windows.
1111
</Description>
12-
<PackageTags>UWP Toolkit Windows Microsoft Graph AadLogin Authentication Login</PackageTags>
12+
<PackageTags>UWP Community Toolkit Provider Authentication Auth Windows</PackageTags>
1313
<LangVersion>9.0</LangVersion>
1414
</PropertyGroup>
1515

CommunityToolkit.Authentication/CommunityToolkit.Authentication.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
<Title>Windows Community Toolkit .NET Standard Auth Services</Title>
66
<Description>
77
This package includes .NET Standard authentication helpers such as:
8-
- BaseProvider:
9-
- IProvider:
10-
- MockProvider:
11-
- ProviderManager:
12-
- ProviderState:
13-
- ProviderStateChangedEventArgs:
8+
9+
- BaseProvider: A base construct for building Graph Providers on top of.
10+
- IProvider: Authentication provider interface to expose more states around the authentication process for Graph controls and helpers.
11+
- ProviderManager: Shared provider manager used by controls and helpers to authenticate and call the Microsoft Graph.
12+
- ProviderState: Represents the current authentication state of the session for a given IProvider.
1413
</Description>
1514
<PackageTags>Community Toolkit Provider Authentication Auth</PackageTags>
1615
</PropertyGroup>

CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
<Description>
77
This library provides Microsoft Graph UWP XAML controls. It is part of the Windows Community Toolkit.
88

9-
Classes:
10-
- GraphPresenter:
11-
- LoginButton: The Login Control leverages MSAL libraries to support the sign-in processes for Microsoft Graph and beyond.
9+
Controls:
10+
- GraphPresenter: A specialized ContentPresenter for fetching and displaying data from Microsoft Graph.
11+
- LoginButton: The Login Control leverages the global authentication provider to support the sign-in processes for Microsoft Graph and beyond.
1212
- PersonView: The PersonView control displays a user photo and can display their name and e-mail.
13-
- PeoplePicker: The PeoplePicker Control is a simple control that allows for selection of one or more users.
13+
- PeoplePicker: The PeoplePicker Control is a simple control that allows for selection users.
14+
15+
Extensions:
16+
- FrameworkElement.IsVisibleWhen(ProviderState): Extension on FrameworkElement for toggling visibility in response to changes in the global authentcation provider.
17+
18+
Triggers:
19+
- ProviderStateTrigger: StateTrigger for reacting to changes in the global authentcation provider.
1420
</Description>
15-
<PackageTags>UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login</PackageTags>
21+
<PackageTags>UWP Community Toolkit Windows Controls Microsoft Graph Login Person PeoplePicker Presenter</PackageTags>
1622
<LangVersion>9.0</LangVersion>
1723
</PropertyGroup>
1824

@@ -22,8 +28,8 @@
2228
</ItemGroup>
2329

2430
<ItemGroup>
31+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
2532
<PackageReference Include="Microsoft.Graph" Version="4.0.0" />
26-
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.0.1" />
2733
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Input" Version="7.0.1" />
2834
</ItemGroup>
2935

@@ -35,14 +41,6 @@
3541
<None Include="VisualStudioToolsManifest.xml" Pack="true" PackagePath="tools" />
3642
<None Include="$(OutDir)\Design\$(MSBuildProjectName).Design*.dll;$(OutDir)\Design\$(MSBuildProjectName).Design*.pdb" Pack="true" PackagePath="lib\$(TargetFramework)\Design" />
3743
</ItemGroup>
38-
39-
<ItemGroup>
40-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
41-
</ItemGroup>
42-
43-
<ItemGroup>
44-
<Folder Include="Triggers\" />
45-
</ItemGroup>
4644

4745
<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
4846
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">

CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ private async void GraphPresenter_Loaded(object sender, RoutedEventArgs e)
7474
// Note: some interfaces from the Graph SDK don't implement IBaseRequestBuilder properly, see https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/722
7575
if (RequestBuilder != null)
7676
{
77-
var request = new BaseRequest(
78-
RequestBuilder.RequestUrl,
79-
RequestBuilder.Client); // TODO: Do we need separate Options here?
80-
request.Method = HttpMethods.GET;
81-
request.QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List<Microsoft.Graph.QueryOption>();
77+
var request = new BaseRequest(RequestBuilder.RequestUrl, RequestBuilder.Client) // TODO: Do we need separate Options here?
78+
{
79+
Method = HttpMethods.GET,
80+
QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List<Microsoft.Graph.QueryOption>(),
81+
};
8282

8383
// Handle Special QueryOptions
8484
if (!string.IsNullOrWhiteSpace(OrderBy))

CommunityToolkit.Graph.Uwp/Controls/PeoplePicker/PeoplePicker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace CommunityToolkit.Graph.Uwp.Controls
2222
/// </summary>
2323
public partial class PeoplePicker : TokenizingTextBox
2424
{
25-
private DispatcherQueueTimer _typeTimer = null;
25+
private readonly DispatcherQueueTimer _typeTimer = null;
2626

2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="PeoplePicker"/> class.

CommunityToolkit.Graph/CommunityToolkit.Graph.csproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55

66
<Title>Windows Community Toolkit .NET Standard Graph Services</Title>
77
<Description>
8-
This package includes .NET Standard code helpers such as:
9-
- GraphExtensions: Helpers for common tasks related to the Microsoft Graph used by the Microsoft.Toolkit.Graph.Controls.
10-
- ProviderExtensions: Extension on IProvider for accessing a pre-configured GraphServiceClient instance.
8+
This package includes .NET Standard code helpers such as:
9+
10+
Extensions:
11+
- GraphExtensions: Helpers for common tasks related to the Microsoft Graph in context of the available controls and helpers.
12+
- ProviderExtensions: Extension on IProvider for accessing a pre-configured GraphServiceClient instance.
13+
14+
Helpers:
15+
- OneDriveStorageHelper: A helper for interacting with data stored via files and folders in OneDrive.
16+
- UserExtensionStorageHelper: A helper for interacting with open extensions on the Graph User to store data in key/value pairs.
1117
</Description>
12-
<PackageTags>Windows Community Toolkit Graph Provider Extensions</PackageTags>
18+
<PackageTags>Windows Community Toolkit Microsoft Graph Provider Extensions Helpers Roaming Settings</PackageTags>
1319
<LangVersion>9.0</LangVersion>
1420
</PropertyGroup>
1521

CommunityToolkit.Graph/Helpers/RoamingSettings/OneDriveDataSource.cs renamed to CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,37 @@
77
using System.IO;
88
using System.Text;
99
using System.Threading.Tasks;
10-
using CommunityToolkit.Authentication;
11-
using CommunityToolkit.Graph.Extensions;
1210
using Microsoft.Graph;
1311
using Microsoft.Toolkit.Helpers;
1412

15-
namespace CommunityToolkit.Graph.Helpers.RoamingSettings
13+
namespace CommunityToolkit.Graph.Extensions
1614
{
1715
/// <summary>
18-
/// Helpers for interacting with files in the special OneDrive AppRoot folder.
16+
/// OneDrive focused extension methods to the Graph SDK used by the controls and helpers.
1917
/// </summary>
20-
internal static class OneDriveDataSource
18+
public static partial class GraphExtensions
2119
{
22-
private static GraphServiceClient Graph => ProviderManager.Instance.GlobalProvider?.GetClient();
23-
2420
/// <summary>
2521
/// Updates or create a new file on the remote with the provided content.
2622
/// </summary>
2723
/// <typeparam name="T">The type of object to save.</typeparam>
2824
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
29-
public static async Task<DriveItem> SetFileAsync<T>(string userId, string itemPath, T fileContents, IObjectSerializer serializer)
25+
public static async Task<DriveItem> SetFileAsync<T>(this GraphServiceClient graph, string userId, string itemPath, T fileContents, IObjectSerializer serializer)
3026
{
3127
var json = serializer.Serialize(fileContents) as string;
3228
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
3329

34-
return await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Content.Request().PutAsync<DriveItem>(stream);
30+
return await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Content.Request().PutAsync<DriveItem>(stream);
3531
}
3632

3733
/// <summary>
3834
/// Get a file from the remote.
3935
/// </summary>
4036
/// <typeparam name="T">The type of object to return.</typeparam>
4137
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
42-
public static async Task<T> GetFileAsync<T>(string userId, string itemPath, IObjectSerializer serializer)
38+
public static async Task<T> GetFileAsync<T>(this GraphServiceClient graph, string userId, string itemPath, IObjectSerializer serializer)
4339
{
44-
Stream stream = await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Content.Request().GetAsync();
40+
Stream stream = await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Content.Request().GetAsync();
4541

4642
string streamContents = new StreamReader(stream).ReadToEnd();
4743

@@ -52,12 +48,20 @@ public static async Task<T> GetFileAsync<T>(string userId, string itemPath, IObj
5248
/// Delete the file from the remote.
5349
/// </summary>
5450
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
55-
public static async Task DeleteItemAsync(string userId, string itemPath)
51+
public static async Task DeleteItemAsync(this GraphServiceClient graph, string userId, string itemPath)
5652
{
57-
await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().DeleteAsync();
53+
await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().DeleteAsync();
5854
}
5955

60-
public static async Task CreateFolderAsync(string userId, string folderName, string path = null)
56+
/// <summary>
57+
/// Ensure a folder exists by name.
58+
/// </summary>
59+
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
60+
/// <param name="userId">The id of the target Graph user.</param>
61+
/// <param name="folderName">The name of the new folder.</param>
62+
/// <param name="path">The path to create the new folder in.</param>
63+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
64+
public static async Task CreateFolderAsync(this GraphServiceClient graph, string userId, string folderName, string path = null)
6165
{
6266
var folderDriveItem = new DriveItem()
6367
{
@@ -67,17 +71,24 @@ public static async Task CreateFolderAsync(string userId, string folderName, str
6771

6872
if (path != null)
6973
{
70-
await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(path).Children.Request().AddAsync(folderDriveItem);
74+
await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(path).Children.Request().AddAsync(folderDriveItem);
7175
}
7276
else
7377
{
74-
await Graph.Users[userId].Drive.Special.AppRoot.Children.Request().AddAsync(folderDriveItem);
78+
await graph.Users[userId].Drive.Special.AppRoot.Children.Request().AddAsync(folderDriveItem);
7579
}
7680
}
7781

78-
public static async Task<IEnumerable<(DirectoryItemType, string)>> ReadFolderAsync(string userId, string folderPath)
82+
/// <summary>
83+
/// Retrieve a list of directory items with names and types.
84+
/// </summary>
85+
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
86+
/// <param name="userId">The id of the target Graph user.</param>
87+
/// <param name="folderPath">The path to create the new folder in.</param>
88+
/// <returns>A <see cref="Task"/> with the directory listings.</returns>
89+
public static async Task<IEnumerable<(DirectoryItemType, string)>> ReadFolderAsync(this GraphServiceClient graph, string userId, string folderPath)
7990
{
80-
IDriveItemChildrenCollectionPage folderContents = await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(folderPath).Children.Request().GetAsync();
91+
IDriveItemChildrenCollectionPage folderContents = await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(folderPath).Children.Request().GetAsync();
8192

8293
var results = new List<(DirectoryItemType, string)>();
8394
foreach (var item in folderContents)

0 commit comments

Comments
 (0)