-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathMockProviderBehavior.cs
More file actions
69 lines (63 loc) · 2.17 KB
/
MockProviderBehavior.cs
File metadata and controls
69 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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.
#if DOTNET
using System;
using System.Linq;
using System.Windows;
using Microsoft.Toolkit.Graph.Providers;
#else
using System.Linq;
using Microsoft.UI.Xaml;
#endif
#if DOTNET
namespace Microsoft.Toolkit.Wpf.Graph.Providers
#else
namespace Microsoft.Toolkit.Graph.Providers
#endif
{
/// <summary>
/// Put in a xaml page with ClientId
/// https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively.
/// </summary>
/// <example>
/// <code>
/// <Interactivity:Interaction.Behaviors>
/// <providers:InteractiveProviderBehavior ClientId = "MyClientIdGuid"/>
/// </Interactivity:Interaction.Behaviors>
/// </code>
/// </example>
public class MockProviderBehavior : CommonProviderBehaviorBase
{
private object lock_sync = new object();
private bool initialized = false;
/// <summary>
/// Gets or sets a value indicating whether the mock provider is signed-in upon initialization.
/// </summary>
public bool SignedIn
{
get { return (bool)GetValue(SignedInProperty); }
set { SetValue(SignedInProperty, value); }
}
/// <summary>
/// Identifies the <see cref="SignedIn"/> dependency property.
/// </summary>
/// <returns>
/// The identifier for the <see cref="SignedIn"/> dependency property.
/// </returns>
public static readonly DependencyProperty SignedInProperty =
DependencyProperty.Register(nameof(SignedIn), typeof(bool), typeof(MockProviderBehavior), new PropertyMetadata(true));
/// <inheritdoc/>
protected override bool Initialize()
{
lock (lock_sync)
{
if (!initialized)
{
ProviderManager.Instance.GlobalProvider = new MockProvider(SignedIn);
}
}
return base.Initialize();
}
}
}