This commit is contained in:
Shane Weaver 2021-08-31 10:01:54 -07:00 коммит произвёл GitHub
Родитель 3ca626410a
Коммит 1f20efb7a2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 79 добавлений и 23 удалений

Просмотреть файл

@ -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>

Просмотреть файл

@ -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>

Просмотреть файл

@ -20,6 +20,11 @@ namespace CommunityToolkit.Graph.Extensions
/// <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)
@ -33,6 +38,10 @@ namespace CommunityToolkit.Graph.Extensions
/// <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)
@ -47,12 +56,33 @@ namespace CommunityToolkit.Graph.Extensions
/// <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>

Просмотреть файл

@ -95,10 +95,35 @@ namespace CommunityToolkit.Graph.Helpers.RoamingSettings
}
/// <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()

Просмотреть файл

@ -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>

Просмотреть файл

@ -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
{

Просмотреть файл

@ -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
{

Просмотреть файл

@ -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
{
@ -77,7 +77,8 @@ namespace UnitTests.UWP.Helpers
Assert.AreEqual(fileContents2, readContents2);
// Delete a file
await storageHelper.DeleteItemAsync(filePath);
var itemDeleted = await storageHelper.TryDeleteItemAsync(filePath);
Assert.IsTrue(itemDeleted);
tcs.SetResult(true);
}
@ -111,7 +112,7 @@ namespace UnitTests.UWP.Helpers
// Create a folder
await storageHelper.CreateFolderAsync(folderName);
// Create a subfolder
await storageHelper.CreateFolderAsync(subfolderName, folderName);
@ -132,7 +133,8 @@ namespace UnitTests.UWP.Helpers
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);
}

Просмотреть файл

@ -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
{

Просмотреть файл

@ -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