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 @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Graph;
using Microsoft.Toolkit.Extensions;
using Newtonsoft.Json;

namespace Microsoft.Toolkit.Services.OneDrive
Expand Down Expand Up @@ -69,35 +70,7 @@ public string FormattedFileSize
{
get
{
var size = FileSize.HasValue ? FileSize.Value : 0;
if (size < 1024)
{
return size.ToString("F0") + " bytes";
}
else if ((size >> 10) < 1024)
{
return (size / (float)1024).ToString("F1") + " KB";
}
else if ((size >> 20) < 1024)
{
return ((size >> 10) / (float)1024).ToString("F1") + " MB";
}
else if ((size >> 30) < 1024)
{
return ((size >> 20) / (float)1024).ToString("F1") + " GB";
}
else if ((size >> 40) < 1024)
{
return ((size >> 30) / (float)1024).ToString("F1") + " TB";
}
else if ((size >> 50) < 1024)
{
return ((size >> 40) / (float)1024).ToString("F1") + " PB";
}
else
{
return ((size >> 50) / (float)1024).ToString("F0") + " EB";
}
return FileSize.HasValue ? Converters.ToFileSizeString(FileSize.Value) : Converters.ToFileSizeString(0L);
}
}

Expand Down
8 changes: 8 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"CodeFile": "AadLoginCode.bind",
"XamlCodeFile": "AadLoginXaml.bind",
"Icon": "/SamplePages/AadLogin/AadLogin.png",
"BadgeUpdateVersionRequired": "DEPRECATED",
"DeprecatedWarning": "The AadLogin control has been replaced with the LoginButton control and will be removed in a future update.",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/graph/AadLogin.md"
},
{
Expand All @@ -388,6 +390,8 @@
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.Graph/ProfileCard",
"XamlCodeFile": "ProfileCardXaml.bind",
"Icon": "/SamplePages/ProfileCard/ProfileCard.png",
"BadgeUpdateVersionRequired": "DEPRECATED",
"DeprecatedWarning": "The ProfileCard control has been replaced with the PersonView control and will be removed in a future update.",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/graph/ProfileCard.md"
},
{
Expand All @@ -398,6 +402,8 @@
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.Graph/PeoplePicker",
"XamlCodeFile": "PeoplePickerXaml.bind",
"Icon": "/SamplePages/PeoplePicker/PeoplePicker.png",
"BadgeUpdateVersionRequired": "DEPRECATED",
"DeprecatedWarning": "The PeoplePicker control has been replaced with the new PeoplePicker control in Microsoft.Toolkit.Graph.Controls and will be removed in a future update.",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/graph/PeoplePicker.md"
},
{
Expand Down Expand Up @@ -428,6 +434,8 @@
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.Graph/PlannerTaskList",
"XamlCodeFile": "PlannerTaskListXaml.bind",
"Icon": "/SamplePages/PlannerTaskList/PlannerTaskList.png",
"BadgeUpdateVersionRequired": "DEPRECATED",
"DeprecatedWarning": "The PlannerTaskList control will be replaced with a new Task control and will be removed in a future update.",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/graph/PlannerTaskList.md"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
/// <summary>
/// The AAD Login Control leverages MSAL libraries to support basic AAD sign-in processes for Microsoft Graph and beyond.
/// </summary>
[Obsolete("This control will be removed in a future release of the toolkit. Please use the new Graph controls at https://aka.ms/wgt")]
[TemplatePart(Name = "RootGrid", Type = typeof(Grid))]
[TemplatePart(Name = "ContentPresenter", Type = typeof(ContentPresenter))]
public partial class AadLogin : Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
/// <summary>
/// The PeoplePicker Control is a simple control that allows for selection of one or more users from an organizational AD.
/// </summary>
[Obsolete("This control will be removed in a future release of the toolkit. Please use the new Graph controls at https://aka.ms/wgt")]
[TemplatePart(Name = SearchBoxPartName, Type = typeof(TextBox))]
[TemplatePart(Name = InternalSearchBoxTextBoxPartName, Type = typeof(TextBox))]
[TemplatePart(Name = SearchResultListBoxPartName, Type = typeof(ListBox))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
/// <summary>
/// The PlannerTaskList Control displays a simple list of Planner tasks.
/// </summary>
[Obsolete("This control will be removed in a future release of the toolkit. Please use the new Graph controls at https://aka.ms/wgt")]
[TemplatePart(Name = ControlTasks, Type = typeof(ListView))]
[TemplatePart(Name = ControlInput, Type = typeof(TextBox))]
[TemplatePart(Name = ControlAdd, Type = typeof(Button))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
/// <summary>
/// The Profile Card control is a simple way to display a user in multiple different formats and mixes of name/image/e-mail.
/// </summary>
[Obsolete("This control will be removed in a future release of the toolkit. Please use the new Graph controls at https://aka.ms/wgt")]
public partial class ProfileCard : Control
{
private static readonly BitmapImage PersonPhoto = new BitmapImage(new Uri("ms-appx:///Microsoft.Toolkit.Uwp.UI.Controls.Graph/Assets/person.png"));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls.Graph">
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls.Graph"
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters">

<local:DriveItemIconConverter x:Key="DriveItemIconConverter" />
<local:FileSizeConverter x:Key="FileSizeConverter" />
<converters:FileSizeToFriendlyStringConverter x:Key="FileSizeConverter" />

<Style x:Name="MetaLabel" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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 Windows.UI.Xaml.Data;

namespace Microsoft.Toolkit.Uwp.UI.Converters
{
/// <summary>
/// Converts a file size in bytes to a more human-readable friendly format using <see cref="Toolkit.Converters.ToFileSizeString(long)"/>
/// </summary>
public class FileSizeToFriendlyStringConverter : IValueConverter
{
/// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is long size)
{
return Toolkit.Converters.ToFileSizeString(size);
}

return string.Empty;
}

/// <inheritdoc/>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.Toolkit.Uwp.UI.Controls
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Toolkit
{
/// <summary>
/// All common long extensions should go here
/// Set of helpers to convert between data types and notations.
/// </summary>
internal static class Int64Extensions
public static class Converters
{
/// <summary>
/// Translate numeric file size to string format.
/// Translate numeric file size in bytes to a human-readable shorter string format.
/// </summary>
/// <param name="size">file size in bytes.</param>
/// <returns>Returns file size string.</returns>
public static string ToFileSizeString(this long size)
/// <param name="size">File size in bytes.</param>
/// <returns>Returns file size short string.</returns>
public static string ToFileSizeString(long size)
{
if (size < 1024)
{
Expand Down Expand Up @@ -46,4 +50,4 @@ public static string ToFileSizeString(this long size)
}
}
}
}
}
4 changes: 3 additions & 1 deletion Microsoft.Toolkit/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +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.Globalization;
using System.Net;
using System.Text.RegularExpressions;

namespace Microsoft.Toolkit.Extensions
{
/// <summary>
/// Helpers for working with strings.
/// Helpers for working with strings and string representations.
/// </summary>
public static class StringExtensions
{
Expand Down Expand Up @@ -104,6 +105,7 @@ public static bool IsCharacterString(this string str)
/// </summary>
/// <param name="value">The object to convert.</param>
/// <returns>String representation of the object.</returns>
[Obsolete("Use value?.ToString() instead. This will be removed in the next release of the toolkit.")]
public static string ToSafeString(this object value)
{
return value?.ToString();
Expand Down
140 changes: 140 additions & 0 deletions Microsoft.Toolkit/Helpers/NotifyTaskCompletion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.ComponentModel;
using System.Threading.Tasks;

namespace Microsoft.Toolkit.Helpers
{
/// <summary>
/// Helper class to wrap around a Task to provide more information usable for UI databinding scenarios. As discussed in MSDN Magazine: https://msdn.microsoft.com/magazine/dn605875.
/// </summary>
/// <typeparam name="TResult">Type of result returned by task.</typeparam>
public sealed class NotifyTaskCompletion<TResult> : INotifyPropertyChanged
{
/// <summary>
/// Initializes a new instance of the <see cref="NotifyTaskCompletion{TResult}"/> class.
/// </summary>
/// <param name="task">Task to wait on.</param>
public NotifyTaskCompletion(Task<TResult> task)
{
Task = task;
if (!task.IsCompleted)
{
TaskCompletion = WatchTaskAsync(task);
}
}

private async Task WatchTaskAsync(Task task)
{
try
{
await task;
}
catch
{
}

if (PropertyChanged == null)
{
return;
}

PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(Status)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(IsCompleted)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(IsNotCompleted)));

if (task.IsCanceled)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(IsCanceled)));
}
else if (task.IsFaulted)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(IsFaulted)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(Exception)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(InnerException)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(ErrorMessage)));
}
else
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(IsSuccessfullyCompleted)));
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(Result)));
}
}

/// <summary>
/// Gets the task that is being waited on.
/// </summary>
public Task<TResult> Task { get; private set; }

/// <summary>
/// Gets the task wrapper task.
/// </summary>
public Task TaskCompletion { get; private set; }

/// <summary>
/// Gets the result of the given task.
/// </summary>
public TResult Result
{
get
{
return (Task.Status == TaskStatus.RanToCompletion) ?
Task.Result :
default(TResult);
}
}

/// <summary>
/// Gets the status of the task.
/// </summary>
public TaskStatus Status => Task.Status;

/// <summary>
/// Gets a value indicating whether the task is completed.
/// </summary>
public bool IsCompleted => Task.IsCompleted;

/// <summary>
/// Gets a value indicating whether the task is not completed.
/// </summary>
public bool IsNotCompleted => !Task.IsCompleted;

/// <summary>
/// Gets a value indicating whether the task was successfully completed.
/// </summary>
public bool IsSuccessfullyCompleted => Task.Status == TaskStatus.RanToCompletion;

/// <summary>
/// Gets a value indicating whether the task was cancelled.
/// </summary>
public bool IsCanceled => Task.IsCanceled;

/// <summary>
/// Gets a value indicating whether there was an error with the task.
/// </summary>
public bool IsFaulted => Task.IsFaulted;

/// <summary>
/// Gets the exception which occured on the task (if one occurred).
/// </summary>
public AggregateException Exception => Task.Exception;

/// <summary>
/// Gets the inner exception of the task.
/// </summary>
public Exception InnerException => Exception?.InnerException;

/// <summary>
/// Gets the error message of the task.
/// </summary>
public string ErrorMessage => InnerException?.Message ?? Exception.Message;

/// <summary>
/// PropertyChanged event.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
}