From d32f228157a3e195702d47241e64bb5d7502cf04 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 22 Jun 2021 13:42:33 -0700 Subject: [PATCH 1/3] Updated tests after provider event name change. Adjusted uwp project files to match WCT. --- ...CommunityToolkit.Authentication.Uwp.csproj | 20 +---------- .../CommunityToolkit.Graph.Uwp.csproj | 35 ++++++------------- .../ManualGraphRequestSample/MainPage.xaml | 1 - .../RoamingSettings/Test_OneDriveDataStore.cs | 2 +- .../Test_UserExtensionDataStore.cs | 2 +- 5 files changed, 13 insertions(+), 47 deletions(-) diff --git a/CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj b/CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj index d6d0735..01d1e55 100644 --- a/CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj +++ b/CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj @@ -3,7 +3,6 @@ uap10.0.17134 Windows Community Toolkit Graph Uwp Authentication Provider - CommunityToolkit.Authentication.Uwp This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit. @@ -11,28 +10,11 @@ - WindowsProvider: UWP Toolkit Windows Microsoft Graph AadLogin Authentication Login - false - true - 8.0 - Debug;Release;CI - AnyCPU;ARM;ARM64;x64;x86 + 9.0 - - $(DefineConstants);WINRT - - - - - - - - - - - diff --git a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj index 5b061cc..2104762 100644 --- a/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj +++ b/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj @@ -3,7 +3,6 @@ uap10.0.17763 Windows Community Toolkit Graph Uwp Controls and Helpers - CommunityToolkit.Graph.Uwp This library provides Microsoft Graph UWP XAML controls. It is part of the Windows Community Toolkit. @@ -14,51 +13,37 @@ - PeoplePicker: The PeoplePicker Control is a simple control that allows for selection of one or more users. UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login - false - true 9.0 - Debug;Release;CI - AnyCPU;ARM;ARM64;x64;x86 - - - + + + + - + + + + + + - - - - - - - - MSBuild:Compile - - - - - $(DefineConstants);WINRT - - - diff --git a/Samples/ManualGraphRequestSample/MainPage.xaml b/Samples/ManualGraphRequestSample/MainPage.xaml index 0d73d05..7214f9c 100644 --- a/Samples/ManualGraphRequestSample/MainPage.xaml +++ b/Samples/ManualGraphRequestSample/MainPage.xaml @@ -33,7 +33,6 @@ IsActive="False" /> - ProviderManager.Instance.ProviderStateChanged += (s, e) => { var providerManager = s as ProviderManager; - if (e.Reason == ProviderManagerChangedState.ProviderStateChanged && providerManager.GlobalProvider.State == ProviderState.SignedIn) + if (providerManager.GlobalProvider.State == ProviderState.SignedIn) { test.Invoke(); } diff --git a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs index 9f01297..9ab65cc 100644 --- a/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs +++ b/UnitTests/UnitTests.UWP/RoamingSettings/Test_UserExtensionDataStore.cs @@ -139,7 +139,7 @@ await App.DispatcherQueue.EnqueueAsync(async () => ProviderManager.Instance.ProviderStateChanged += (s, e) => { var providerManager = s as ProviderManager; - if (e.Reason == ProviderManagerChangedState.ProviderStateChanged && providerManager.GlobalProvider.State == ProviderState.SignedIn) + if (providerManager.GlobalProvider.State == ProviderState.SignedIn) { test.Invoke(); } From 7cebb25958e992bfdf6036e4c6208f39b82d5f19 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 22 Jun 2021 14:41:53 -0700 Subject: [PATCH 2/3] Adjusted logic in login button to fix loading hang --- .../Controls/LoginButton/LoginButton.cs | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs index 05b01c8..89a0466 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs +++ b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs @@ -42,7 +42,6 @@ protected override void OnApplyTemplate() { base.OnApplyTemplate(); - IsLoading = true; LoadData(); if (_loginButton != null) @@ -99,41 +98,37 @@ private async void SignOutButton_Click(object sender, RoutedEventArgs e) private async void LoadData() { var provider = ProviderManager.Instance.GlobalProvider; - - if (provider == null) + switch (provider?.State) { - return; - } + case ProviderState.Loading: + IsLoading = true; + break; - if (provider.State == ProviderState.Loading) - { - IsLoading = true; - } - else if (provider.State == ProviderState.SignedIn) - { - try - { - // https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/master/src/components/mgt-login/mgt-login.ts#L139 - // TODO: Batch with photo request later? https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/29 - UserDetails = await provider.GetClient().GetMeAsync(); - } - catch (Exception e) - { - LoginFailed?.Invoke(this, new LoginFailedEventArgs(e)); - } + case ProviderState.SignedIn: + try + { + IsLoading = true; - IsLoading = false; - } - else if (provider.State == ProviderState.SignedOut) - { - UserDetails = null; // What if this was user provided? Should we not hook into these events then? + // https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/master/src/components/mgt-login/mgt-login.ts#L139 + // TODO: Batch with photo request later? https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/29 + UserDetails = await provider.GetClient().GetMeAsync(); + } + catch (Exception e) + { + LoginFailed?.Invoke(this, new LoginFailedEventArgs(e)); + } + finally + { + IsLoading = false; + } - IsLoading = false; - } - else - { - // Provider in Loading state - Debug.Fail("unsupported state"); + break; + + case ProviderState.SignedOut: + default: + UserDetails = null; // What if this was user provided? Should we not hook into these events then? + IsLoading = false; + break; } } From cf0598673ecc97e8d93173d834f938b586c20b7b Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Wed, 23 Jun 2021 10:04:45 -0700 Subject: [PATCH 3/3] Updated LoginButton loading logic --- .../LoginButton/LoginButton.Properties.cs | 18 ----------- .../Controls/LoginButton/LoginButton.cs | 31 +++++++++++++++++-- .../Controls/LoginButton/LoginButton.xaml | 3 +- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Properties.cs b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Properties.cs index addd2f8..82374bc 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Properties.cs +++ b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Properties.cs @@ -29,23 +29,5 @@ public User UserDetails /// public static readonly DependencyProperty UserDetailsProperty = DependencyProperty.Register(nameof(UserDetails), typeof(User), typeof(LoginButton), new PropertyMetadata(null)); - - /// - /// Gets or sets a value indicating whether the control is loading and has not established a sign-in state. - /// - public bool IsLoading - { - get { return (bool)GetValue(IsLoadingProperty); } - protected set { SetValue(IsLoadingProperty, value); } - } - - /// - /// Identifies the dependency property. - /// - /// - /// The identifier for the dependency property. - /// - public static readonly DependencyProperty IsLoadingProperty = - DependencyProperty.Register(nameof(IsLoading), typeof(bool), typeof(LoginButton), new PropertyMetadata(true)); } } diff --git a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs index 89a0466..b69b3d6 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs +++ b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs @@ -4,7 +4,6 @@ using System; using System.ComponentModel; -using System.Diagnostics; using System.Threading.Tasks; using CommunityToolkit.Authentication; using CommunityToolkit.Graph.Extensions; @@ -27,6 +26,21 @@ public partial class LoginButton : Control private Button _loginButton; private ButtonBase _signOutButton; + private bool _isLoading; + + /// + /// Gets or sets a value indicating whether the control is loading and has not established a sign-in state. + /// + protected bool IsLoading + { + get => _isLoading; + set + { + _isLoading = value; + UpdateButtonEnablement(); + } + } + /// /// Initializes a new instance of the class. /// @@ -37,13 +51,22 @@ public LoginButton() ProviderManager.Instance.ProviderStateChanged += (sender, args) => LoadData(); } + /// + /// Update the enablement state of the button in relation to the _isLoading property. + /// + protected void UpdateButtonEnablement() + { + if (_loginButton != null) + { + _loginButton.IsEnabled = !_isLoading; + } + } + /// protected override void OnApplyTemplate() { base.OnApplyTemplate(); - LoadData(); - if (_loginButton != null) { _loginButton.Click -= LoginButton_Click; @@ -67,6 +90,8 @@ protected override void OnApplyTemplate() { _signOutButton.Click += SignOutButton_Click; } + + LoadData(); } private async void LoginButton_Click(object sender, RoutedEventArgs e) diff --git a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.xaml b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.xaml index c15d51a..acbae71 100644 --- a/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.xaml +++ b/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.xaml @@ -22,8 +22,7 @@