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
5 changes: 2 additions & 3 deletions CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Microsoft.Graph" Version="4.2.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Input" Version="7.0.2" />
<PackageReference Include="Microsoft.Graph" Version="4.3.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Input" Version="7.1.0-rc1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CommunityToolkit.Graph/CommunityToolkit.Graph.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Graph" Version="4.2.0" />
<PackageReference Include="Microsoft.Toolkit" Version="7.1.0-preview1" />
<PackageReference Include="Microsoft.Graph" Version="4.3.0" />
<PackageReference Include="Microsoft.Toolkit" Version="7.1.0-rc1" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions CommunityToolkit.Graph/Extensions/GraphExtensions.OneDrive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static partial class GraphExtensions
/// <summary>
/// Updates or create a new file on the remote with the provided content.
/// </summary>
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
/// <param name="userId">The id of the target Graph user.</param>
/// <param name="itemPath">The path of the target item.</param>
/// <param name="fileContents">The contents to put in the file.</param>
/// <param name="serializer">A serializer for converting stored values.</param>
/// <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>(this GraphServiceClient graph, string userId, string itemPath, T fileContents, IObjectSerializer serializer)
Expand All @@ -33,6 +38,10 @@ public static async Task<DriveItem> SetFileAsync<T>(this GraphServiceClient grap
/// <summary>
/// Get a file from the remote.
/// </summary>
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
/// <param name="userId">The id of the target Graph user.</param>
/// <param name="itemPath">The path of the target item.</param>
/// <param name="serializer">A serializer for converting stored values.</param>
/// <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>(this GraphServiceClient graph, string userId, string itemPath, IObjectSerializer serializer)
Expand All @@ -47,12 +56,33 @@ public static async Task<T> GetFileAsync<T>(this GraphServiceClient graph, strin
/// <summary>
/// Delete the file from the remote.
/// </summary>
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
/// <param name="userId">The id of the target Graph user.</param>
/// <param name="itemPath">The path of the target item.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task DeleteItemAsync(this GraphServiceClient graph, string userId, string itemPath)
{
await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().DeleteAsync();
}

/// <summary>
/// Rename an item.
/// </summary>
/// <param name="graph">Instance of the <see cref="GraphServiceClient"/>.</param>
/// <param name="userId">The id of the target Graph user.</param>
/// <param name="itemPath">The path of the target item.</param>
/// <param name="newName">The new name for the item.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task RenameItemAsync(this GraphServiceClient graph, string userId, string itemPath, string newName)
{
var driveItem = new DriveItem
{
Name = newName,
};

await graph.Users[userId].Drive.Special.AppRoot.ItemWithPath(itemPath).Request().UpdateAsync(driveItem);
}

/// <summary>
/// Ensure a folder exists by name.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,35 @@ public Task CreateFolderAsync(string folderName, string folderPath)
}

/// <inheritdoc />
public Task DeleteItemAsync(string itemPath)
public async Task<bool> TryDeleteItemAsync(string itemPath)
{
var graph = GetGraphClient();
return graph.DeleteItemAsync(UserId, itemPath);
try
{
var graph = GetGraphClient();
await graph.DeleteItemAsync(UserId, itemPath);

return true;
}
catch
{
return false;
}
}

/// <inheritdoc />
public async Task<bool> TryRenameItemAsync(string itemPath, string newName)
{
try
{
var graph = GetGraphClient();
await graph.RenameItemAsync(UserId, itemPath, newName);

return true;
}
catch
{
return false;
}
}

private static GraphServiceClient GetGraphClient()
Expand Down
2 changes: 1 addition & 1 deletion SampleTest/SampleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Graph">
<Version>4.2.0</Version>
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.12</Version>
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/UnitTests.UWP/Providers/Test_MockProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Authentication;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTests.UWP.Authentication
{
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/UnitTests.UWP/Providers/Test_WindowsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using Microsoft.Toolkit.Uwp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;

namespace UnitTests.UWP.Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Helpers.RoamingSettings;
using Microsoft.Toolkit.Helpers;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace UnitTests.UWP.Helpers
{
Expand Down Expand Up @@ -77,7 +77,8 @@ async void test()
Assert.AreEqual(fileContents2, readContents2);

// Delete a file
await storageHelper.DeleteItemAsync(filePath);
var itemDeleted = await storageHelper.TryDeleteItemAsync(filePath);
Assert.IsTrue(itemDeleted);

tcs.SetResult(true);
}
Expand Down Expand Up @@ -111,7 +112,7 @@ async void test()

// Create a folder
await storageHelper.CreateFolderAsync(folderName);

// Create a subfolder
await storageHelper.CreateFolderAsync(subfolderName, folderName);

Expand All @@ -132,7 +133,8 @@ async void test()
Assert.AreEqual(DirectoryItemType.File, folderItemsList[1].ItemType);

// Delete a folder
await storageHelper.DeleteItemAsync(folderName);
var itemDeleted = await storageHelper.TryDeleteItemAsync(folderName);
Assert.IsTrue(itemDeleted);

tcs.SetResult(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Helpers.RoamingSettings;
using Microsoft.Toolkit.Extensions;
using Microsoft.Toolkit.Helpers;
using Microsoft.Toolkit.Uwp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;

namespace UnitTests.UWP.Helpers
{
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/UnitTests.UWP/VisualUITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.UI.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace UnitTests.UWP
Expand Down