From 2c5871072e1c1ffbe79cc55f333acb964e1666a8 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 17 Aug 2021 15:20:17 -0700 Subject: [PATCH] Update nuget icon (#146) * Updated targets and props files to include nuget package icon * Fixed GraphPresenter after props and targets update * Updated Graph version in UnitTests app * Fixed issue with xaml type reflection * Commented out TreatWarningAsErrors --- ...ommunityToolkit.Authentication.Msal.csproj | 1 + .../CommunityToolkit.Graph.Uwp.csproj | 13 +-- .../Controls/GraphPresenter/GraphPresenter.cs | 76 ++++++++------- .../CommunityToolkit.Graph.csproj | 2 +- Directory.Build.props | 95 +++++++------------ Directory.Build.targets | 38 ++++---- SampleTest/SampleTest.csproj | 2 +- UnitTests/UnitTests.UWP/UnitTests.UWP.csproj | 2 +- Windows-Toolkit-Graph-Controls.sln | 4 + build/Windows.Toolkit.Common.props | 45 +++++++++ build/Windows.Toolkit.Common.targets | 24 +++++ build/Windows.Toolkit.UWP.Build.targets | 19 ++++ .../Windows.Toolkit.Workarounds.Xaml.targets | 12 +++ 13 files changed, 207 insertions(+), 126 deletions(-) create mode 100644 build/Windows.Toolkit.Common.props create mode 100644 build/Windows.Toolkit.Common.targets create mode 100644 build/Windows.Toolkit.UWP.Build.targets create mode 100644 build/Windows.Toolkit.Workarounds.Xaml.targets diff --git a/CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj b/CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj index 78acb3f..050e3e8 100644 --- a/CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj +++ b/CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj @@ -1,4 +1,5 @@  + netstandard2.0 diff --git a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj index 931ba3c..f7a121f 100644 --- a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj +++ b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj @@ -21,17 +21,17 @@ UWP Community Toolkit Windows Controls Microsoft Graph Login Person PeoplePicker Presenter 9.0 + + + + + + - - - - - - @@ -50,4 +50,5 @@ + diff --git a/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs b/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs index ed8edb7..abc710b 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs +++ b/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/GraphPresenter.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Threading; using Microsoft.Graph; using Microsoft.Toolkit.Uwp; -using Newtonsoft.Json.Linq; using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -20,14 +20,6 @@ namespace CommunityToolkit.Graph.Uwp.Controls /// public class GraphPresenter : ContentPresenter { - /// - /// Gets or sets a to be used to make a request to the graph. The results will be automatically populated to the property. Use a to change the presentation of the data. - /// - public IBaseRequestBuilder RequestBuilder - { - get { return (IBaseRequestBuilder)GetValue(RequestBuilderProperty); } - set { SetValue(RequestBuilderProperty, value); } - } /// /// Identifies the dependency property. @@ -38,6 +30,23 @@ namespace CommunityToolkit.Graph.Uwp.Controls public static readonly DependencyProperty RequestBuilderProperty = DependencyProperty.Register(nameof(RequestBuilder), typeof(IBaseRequestBuilder), typeof(GraphPresenter), new PropertyMetadata(null)); + /// + /// Initializes a new instance of the class. + /// + public GraphPresenter() + { + this.Loaded += this.GraphPresenter_Loaded; + } + + /// + /// Gets or sets a to be used to make a request to the graph. The results will be automatically populated to the property. Use a to change the presentation of the data. + /// + public IBaseRequestBuilder RequestBuilder + { + get { return (IBaseRequestBuilder)this.GetValue(RequestBuilderProperty); } + set { this.SetValue(RequestBuilderProperty, value); } + } + /// /// Gets or sets the of item returned by the . /// Set to the base item type and use the property to indicate if a collection is expected back. @@ -59,52 +68,47 @@ namespace CommunityToolkit.Graph.Uwp.Controls /// public string OrderBy { get; set; } - /// - /// Initializes a new instance of the class. - /// - public GraphPresenter() - { - Loaded += GraphPresenter_Loaded; - } - private async void GraphPresenter_Loaded(object sender, RoutedEventArgs e) { var dispatcherQueue = DispatcherQueue.GetForCurrentThread(); // 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) + if (this.RequestBuilder != null) { - var request = new BaseRequest(RequestBuilder.RequestUrl, RequestBuilder.Client) // TODO: Do we need separate Options here? + var request = new BaseRequest(this.RequestBuilder.RequestUrl, this.RequestBuilder.Client) // TODO: Do we need separate Options here? { Method = HttpMethods.GET, - QueryOptions = QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List(), + QueryOptions = this.QueryOptions?.Select(option => (Microsoft.Graph.QueryOption)option)?.ToList() ?? new List(), }; // Handle Special QueryOptions - if (!string.IsNullOrWhiteSpace(OrderBy)) + if (!string.IsNullOrWhiteSpace(this.OrderBy)) { - request.QueryOptions.Add(new Microsoft.Graph.QueryOption("$orderby", OrderBy)); + request.QueryOptions.Add(new Microsoft.Graph.QueryOption("$orderby", this.OrderBy)); } try { - var response = await request.SendAsync(null, CancellationToken.None).ConfigureAwait(false) as JObject; + var responseObj = await request.SendAsync(null, CancellationToken.None).ConfigureAwait(false); - //// TODO: Deal with paging? - - var values = response["value"]; - object data = null; - - if (IsCollection) + if (responseObj is JsonElement responseElement) { - data = values.ToObject(Array.CreateInstance(ResponseType, 0).GetType()); - } - else - { - data = values.ToObject(ResponseType); - } + //// TODO: Deal with paging? - _ = dispatcherQueue.EnqueueAsync(() => Content = data); + var value = responseElement.GetProperty("value"); + object data = null; + + if (this.IsCollection) + { + data = value.EnumerateArray().ToList().Select(elem => System.Text.Json.JsonSerializer.Deserialize(elem.GetRawText(), this.ResponseType)); + } + else + { + data = System.Text.Json.JsonSerializer.Deserialize(value.GetRawText(), this.ResponseType); + } + + _ = dispatcherQueue.EnqueueAsync(() => this.Content = data); + } } catch { diff --git a/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj b/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj index 0611f52..18f7b16 100644 --- a/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj +++ b/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj @@ -20,7 +20,7 @@ - + diff --git a/Directory.Build.props b/Directory.Build.props index 7e3e158..08755e5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,94 +1,63 @@ - Microsoft.Toolkit - true - true - https://raw.githubusercontent.com/CommunityToolkit/CommunityToolkit/master/build/nuget.png - https://github.com/CommunityToolkit/WindowsCommunityToolkit - https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/master/License.md - https://github.com/CommunityToolkit/WindowsCommunityToolkit/releases - (c) .NET Foundation and Contributors. All rights reserved. - $(MSBuildThisFileDirectory)Toolkit.ruleset - en-US - $(MSBuildProjectName.Contains('.Design')) - $(MSBuildProjectName.Contains('Test')) - $(MSBuildProjectName.Contains('Uwp')) - $(MSBuildProjectName.Contains('Sample')) - $(MSBuildProjectName.Contains('Wpf')) - 19041 - 17763 - $(MSBuildThisFileDirectory)bin\nupkg + $(MSBuildThisFileDirectory) + $(RepositoryDirectory)build\ - - true - $(MSBuildThisFileDirectory)toolkit.snk - + - + true + $(RepositoryDirectory)bin\nupkg + true + + + + false + false + $(NoWarn);CS8002;SA0001 + + - + - true + + $(NoWarn);CS8002 + + true + + + + + + + + - + - + true - + true - + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - + - - - - - - - - - - - - true - - - - - - - - - $(NoWarn);8002 - - - - - - - - - stylecop.json - - \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index cf384f9..9f10e09 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,30 +1,32 @@ - - - - - 10.0.$(DefaultTargetPlatformVersion).0 - 10.0.$(DefaultTargetPlatformMinVersion).0 - Full - - - - Windows Desktop Extensions for the UWP - - - Windows Mobile Extensions for the UWP - - + + + + true + false + + + + + + true + $(MSBuildThisFileDirectory)toolkit.snk + + + + + - + <_Parameter1>CommitHash <_Parameter2>$(SourceRevisionId) - + + \ No newline at end of file diff --git a/SampleTest/SampleTest.csproj b/SampleTest/SampleTest.csproj index 31b313c..e93c327 100644 --- a/SampleTest/SampleTest.csproj +++ b/SampleTest/SampleTest.csproj @@ -160,7 +160,7 @@ - 4.0.0 + 4.2.0 6.2.12 diff --git a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj index 0ab1474..9bbac3f 100644 --- a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj +++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj @@ -160,7 +160,7 @@ 5.10.3 - 4.0.0 + 4.2.0 6.2.12 diff --git a/Windows-Toolkit-Graph-Controls.sln b/Windows-Toolkit-Graph-Controls.sln index 12933bc..5b6fffd 100644 --- a/Windows-Toolkit-Graph-Controls.sln +++ b/Windows-Toolkit-Graph-Controls.sln @@ -21,6 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Config", "Build Confi settings.xamlstyler = settings.xamlstyler stylecop.json = stylecop.json version.json = version.json + build\Windows.Toolkit.Common.props = build\Windows.Toolkit.Common.props + build\Windows.Toolkit.Common.targets = build\Windows.Toolkit.Common.targets + build\Windows.Toolkit.UWP.Build.targets = build\Windows.Toolkit.UWP.Build.targets + build\Windows.Toolkit.Workarounds.Xaml.targets = build\Windows.Toolkit.Workarounds.Xaml.targets EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTest", "SampleTest\SampleTest.csproj", "{26F5807A-25B5-4E09-8C72-1749C4C59591}" diff --git a/build/Windows.Toolkit.Common.props b/build/Windows.Toolkit.Common.props new file mode 100644 index 0000000..70a111d --- /dev/null +++ b/build/Windows.Toolkit.Common.props @@ -0,0 +1,45 @@ + + + + .NET Foundation + Microsoft.Toolkit + Windows Community Toolkit + Windows;Community;Toolkit;WCT;Graph;Authentication; + MIT + true + (c) .NET Foundation and Contributors. All rights reserved. + https://github.com/CommunityToolkit/Graph-Controls + https://github.com/CommunityToolkit/Graph-Controls/releases + Icon.png + https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/main/build/nuget.png + + + + Strict + Disable + Latest + en-US + true + + + + 10.0 + 19041 + 17763 + + + + $(MSBuildProjectName.Contains('.Sample')) + $(MSBuildProjectName.Contains('Test')) + $(MSBuildProjectName.Contains('.Uwp')) + True + False + + + + true + true + $(TF_BUILD) + + + \ No newline at end of file diff --git a/build/Windows.Toolkit.Common.targets b/build/Windows.Toolkit.Common.targets new file mode 100644 index 0000000..b73fa48 --- /dev/null +++ b/build/Windows.Toolkit.Common.targets @@ -0,0 +1,24 @@ + + + + + $(Product) Asset + + + + $(CommonTags);.NET + $(CommonTags);UWP + $(CommonTags);$(PackageTags) + $(CommonTags) + + + + + + + + + + + + \ No newline at end of file diff --git a/build/Windows.Toolkit.UWP.Build.targets b/build/Windows.Toolkit.UWP.Build.targets new file mode 100644 index 0000000..96eb9df --- /dev/null +++ b/build/Windows.Toolkit.UWP.Build.targets @@ -0,0 +1,19 @@ + + + + + $(TargetPlatformBaseVersion).$(TargetPlatformRevision).0 + $(TargetPlatformBaseVersion).$(TargetPlatformMinRevision).0 + Portable + + + + + Windows Desktop Extensions for the UWP + + + Windows Mobile Extensions for the UWP + + + + \ No newline at end of file diff --git a/build/Windows.Toolkit.Workarounds.Xaml.targets b/build/Windows.Toolkit.Workarounds.Xaml.targets new file mode 100644 index 0000000..ae7dc1a --- /dev/null +++ b/build/Windows.Toolkit.Workarounds.Xaml.targets @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file