From edd407d60b604f19535d72e2e616b42a841ad922 Mon Sep 17 00:00:00 2001 From: michael-hawker Date: Mon, 21 Oct 2019 00:47:27 -0700 Subject: [PATCH 1/7] Move needed graph Dependencies to Microsoft.Toolkit and Microsoft.Toolkit.Uwp.UI FileSize String Extension and Converter Centralize Usage in other places from OneDrive and SharePoint --- .../Services/OneDrive/OneDriveStorageItem.cs | 31 +--- .../SharePointFileList/FileSizeConverter.cs | 24 --- .../SharePointFileList/Int64Extensions.cs | 49 ----- .../SharePointFileList.xaml | 5 +- .../FileSizeToFriendlyStringConverter.cs | 33 ++++ .../Extensions/StringExtensions.cs | 39 +++- .../Helpers/NotifyTaskCompletion.cs | 174 ++++++++++++++++++ 7 files changed, 250 insertions(+), 105 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/FileSizeConverter.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/Int64Extensions.cs create mode 100644 Microsoft.Toolkit.Uwp.UI/Converters/FileSizeToFriendlyStringConverter.cs create mode 100644 Microsoft.Toolkit/Helpers/NotifyTaskCompletion.cs diff --git a/Microsoft.Toolkit.Services/Services/OneDrive/OneDriveStorageItem.cs b/Microsoft.Toolkit.Services/Services/OneDrive/OneDriveStorageItem.cs index 1c4ce9760c9..f8a70aabead 100644 --- a/Microsoft.Toolkit.Services/Services/OneDrive/OneDriveStorageItem.cs +++ b/Microsoft.Toolkit.Services/Services/OneDrive/OneDriveStorageItem.cs @@ -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 @@ -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 ? FileSize.Value.ToFileSizeString() : 0L.ToFileSizeString(); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/FileSizeConverter.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/FileSizeConverter.cs deleted file mode 100644 index 35f040ccd49..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/FileSizeConverter.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 Microsoft.Toolkit.Extensions; -using Windows.UI.Xaml.Data; - -namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph -{ - internal class FileSizeConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, string language) - { - long size = (long)value; - return size.ToFileSizeString(); - } - - public object ConvertBack(object value, Type targetType, object parameter, string language) - { - throw new NotImplementedException(); - } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/Int64Extensions.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/Int64Extensions.cs deleted file mode 100644 index e18c3388a4a..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/Int64Extensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -// 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. - -namespace Microsoft.Toolkit.Uwp.UI.Controls -{ - /// - /// All common long extensions should go here - /// - internal static class Int64Extensions - { - /// - /// Translate numeric file size to string format. - /// - /// file size in bytes. - /// Returns file size string. - public static string ToFileSizeString(this long size) - { - 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"; - } - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/SharePointFileList.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/SharePointFileList.xaml index 2d03f48896e..5a829c0ba79 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/SharePointFileList.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Graph/SharePointFileList/SharePointFileList.xaml @@ -1,10 +1,11 @@  + xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls.Graph" + xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"> - +