Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

<Title>Windows Community Toolkit .NET Standard Auth Services</Title>
<Description>
This package includes .NET Standard authentication helpers such as:
- MsalProvider:
This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.

Classes:
- MsalProvider: An authentication provider based on MSAL for .NET.
</Description>
<PackageTags>Community Toolkit Provider Authentication Auth Msal</PackageTags>
</PropertyGroup>
Expand All @@ -18,7 +20,4 @@
<ProjectReference Include="..\CommunityToolkit.Authentication\CommunityToolkit.Authentication.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.194" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<TargetFramework>uap10.0.17134</TargetFramework>
<Title>Windows Community Toolkit Graph Uwp Authentication Provider</Title>
<Description>
This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.
This library provides an authentication provider based on the native Windows dialogues.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<Title>Windows Community Toolkit .NET Standard Auth Services</Title>
<Description>
This package includes .NET Standard authentication helpers such as:
- BaseProvider:
- IProvider:
- MockProvider:
- ProviderManager:
- ProviderState:
- ProviderStateChangedEventArgs:

- BaseProvider: A base construct for building Graph Providers on top of.
- IProvider: Authentication provider interface to expose more states around the authentication process for Graph controls and helpers.
- ProviderManager: Shared provider manager used by controls and helpers to authenticate and call the Microsoft Graph.
- ProviderState: Represents the current authentication state of the session for a given IProvider.
</Description>
<PackageTags>Community Toolkit Provider Authentication Auth</PackageTags>
</PropertyGroup>
Expand Down
26 changes: 12 additions & 14 deletions CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
<Description>
This library provides Microsoft Graph UWP XAML controls. It is part of the Windows Community Toolkit.

Classes:
- GraphPresenter:
- LoginButton: The Login Control leverages MSAL libraries to support the sign-in processes for Microsoft Graph and beyond.
Controls:
- GraphPresenter: A specialized ContentPresenter for fetching and displaying data from Microsoft Graph.
- LoginButton: The Login Control leverages the global authentication provider to support the sign-in processes for Microsoft Graph and beyond.
- PersonView: The PersonView control displays a user photo and can display their name and e-mail.
- PeoplePicker: The PeoplePicker Control is a simple control that allows for selection of one or more users.
- PeoplePicker: The PeoplePicker Control is a simple control that allows for selection users.

Extensions:
- FrameworkElement.IsVisibleWhen(ProviderState): Extension on FrameworkElement for toggling visibility in response to changes in the global authentcation provider.

Triggers:
- ProviderStateTrigger: StateTrigger for reacting to changes in the global authentcation provider.
</Description>
<PackageTags>UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login</PackageTags>
<PackageTags>UWP Community Toolkit Windows Controls Microsoft Graph Login Person PeoplePicker Presenter</PackageTags>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

Expand All @@ -22,8 +28,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.Graph" Version="4.0.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.0.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Input" Version="7.0.1" />
</ItemGroup>

Expand All @@ -35,14 +41,6 @@
<None Include="VisualStudioToolsManifest.xml" Pack="true" PackagePath="tools" />
<None Include="$(OutDir)\Design\$(MSBuildProjectName).Design*.dll;$(OutDir)\Design\$(MSBuildProjectName).Design*.pdb" Pack="true" PackagePath="lib\$(TargetFramework)\Design" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Triggers\" />
</ItemGroup>

<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ private async void GraphPresenter_Loaded(object sender, RoutedEventArgs e)
// Note: some interfaces from the Graph SDK don't implement IBaseRequestBuilder properly, see https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/722
if (RequestBuilder != null)
{
var request = new BaseRequest(
RequestBuilder.RequestUrl,
RequestBuilder.Client); // TODO: Do we need separate Options here?
request.Method = HttpMethods.GET;
request.QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List<Microsoft.Graph.QueryOption>();
var request = new BaseRequest(RequestBuilder.RequestUrl, RequestBuilder.Client) // TODO: Do we need separate Options here?
{
Method = HttpMethods.GET,
QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List<Microsoft.Graph.QueryOption>(),
};

// Handle Special QueryOptions
if (!string.IsNullOrWhiteSpace(OrderBy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace CommunityToolkit.Graph.Uwp.Controls
/// </summary>
public partial class PeoplePicker : TokenizingTextBox
{
private DispatcherQueueTimer _typeTimer = null;
private readonly DispatcherQueueTimer _typeTimer = null;

/// <summary>
/// Initializes a new instance of the <see cref="PeoplePicker"/> class.
Expand Down
14 changes: 10 additions & 4 deletions CommunityToolkit.Graph/CommunityToolkit.Graph.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

<Title>Windows Community Toolkit .NET Standard Graph Services</Title>
<Description>
This package includes .NET Standard code helpers such as:
- GraphExtensions: Helpers for common tasks related to the Microsoft Graph used by the Microsoft.Toolkit.Graph.Controls.
- ProviderExtensions: Extension on IProvider for accessing a pre-configured GraphServiceClient instance.
This package includes .NET Standard code helpers such as:

Extensions:
- GraphExtensions: Helpers for common tasks related to the Microsoft Graph in context of the available controls and helpers.
- ProviderExtensions: Extension on IProvider for accessing a pre-configured GraphServiceClient instance.

Helpers:
- OneDriveStorageHelper: A helper for interacting with data stored via files and folders in OneDrive.
- UserExtensionStorageHelper: A helper for interacting with open extensions on the Graph User to store data in key/value pairs.
</Description>
<PackageTags>Windows Community Toolkit Graph Provider Extensions</PackageTags>
<PackageTags>Windows Community Toolkit Microsoft Graph Provider Extensions Helpers Roaming Settings</PackageTags>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,37 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Extensions;
using Microsoft.Graph;
using Microsoft.Toolkit.Helpers;

namespace CommunityToolkit.Graph.Helpers.RoamingSettings
namespace CommunityToolkit.Graph.Extensions
{
/// <summary>
/// Helpers for interacting with files in the special OneDrive AppRoot folder.
/// OneDrive focused extension methods to the Graph SDK used by the controls and helpers.
/// </summary>
internal static class OneDriveDataSource
public static partial class GraphExtensions
{
private static GraphServiceClient Graph => ProviderManager.Instance.GlobalProvider?.GetClient();

/// <summary>
/// Updates or create a new file on the remote with the provided content.
/// </summary>
/// <typeparam name="T">The type of object to save.</typeparam>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task<DriveItem> SetFileAsync<T>(string userId, string itemPath, T fileContents, IObjectSerializer serializer)
public static async Task<DriveItem> SetFileAsync<T>(this GraphServiceClient graph, string userId, string itemPath, T fileContents, IObjectSerializer serializer)
{
var json = serializer.Serialize(fileContents) as string;
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));

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

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

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

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

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

if (path != null)
{
await Graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(path).Children.Request().AddAsync(folderDriveItem);
await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(path).Children.Request().AddAsync(folderDriveItem);
}
else
{
await Graph.Users[userId].Drive.Special.AppRoot.Children.Request().AddAsync(folderDriveItem);
await graph.Users[userId].Drive.Special.AppRoot.Children.Request().AddAsync(folderDriveItem);
}
}

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

var results = new List<(DirectoryItemType, string)>();
foreach (var item in folderContents)
Expand Down
Loading