Skip to content

Commit 2e1a1bf

Browse files
authored
Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface (#365)
* Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface * Document param * Add docstring * Fix tests
1 parent 765f36a commit 2e1a1bf

File tree

6 files changed

+73
-25
lines changed

6 files changed

+73
-25
lines changed

src/Microsoft.Performance.SDK.Runtime/ApplicationEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.Performance.SDK.Runtime
1313
{
1414
/// <inheritdoc cref="IApplicationEnvironment"/>
1515
public class ApplicationEnvironment
16-
: IApplicationEnvironment
16+
: IApplicationEnvironmentV2
1717
{
1818
private readonly IMessageBox messageBox;
1919

src/Microsoft.Performance.SDK.Tests/TestClasses/TestApplicationEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Microsoft.Performance.SDK.Tests.TestClasses
1111
{
1212
public class TestApplicationEnvironment
13-
: IApplicationEnvironment
13+
: IApplicationEnvironmentV2
1414
{
1515
public string ApplicationName { get; set; }
1616

src/Microsoft.Performance.SDK/Processing/ApplicationEnvironmentExtensions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Globalization;
6+
using Microsoft.Performance.SDK.Auth;
67

78
namespace Microsoft.Performance.SDK.Processing
89
{
@@ -143,5 +144,40 @@ public static void ShowError(
143144
{
144145
self.DisplayMessage(MessageType.Error, formatProvider, format, args);
145146
}
147+
148+
/// <summary>
149+
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
150+
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
151+
/// </summary>
152+
/// <param name="self">
153+
/// The <see cref="IApplicationEnvironment"/> instance.
154+
/// </param>
155+
/// <param name="provider">
156+
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
157+
/// <typeparamref name="TAuth"/>.
158+
/// </param>
159+
/// <typeparam name="TAuth">
160+
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
161+
/// </typeparam>
162+
/// <typeparam name="TResult">
163+
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
164+
/// </typeparam>
165+
/// <returns>
166+
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
167+
/// <paramref name="provider"/> will be <c>null</c>.
168+
/// </returns>
169+
public static bool TryGetAuthProvider<TAuth, TResult>(
170+
this IApplicationEnvironment self,
171+
out IAuthProvider<TAuth, TResult> provider)
172+
where TAuth : IAuthMethod<TResult>
173+
{
174+
if (self is IApplicationEnvironmentV2 v2)
175+
{
176+
return v2.TryGetAuthProvider(out provider);
177+
}
178+
179+
provider = null;
180+
return false;
181+
}
146182
}
147183
}

src/Microsoft.Performance.SDK/Processing/IApplicationEnvironment.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using Microsoft.Performance.SDK.Auth;
65
using Microsoft.Performance.SDK.Extensibility.DataCooking;
76
using Microsoft.Performance.SDK.Extensibility.SourceParsing;
87

@@ -118,26 +117,5 @@ ButtonResult MessageBox(
118117
string caption,
119118
string format,
120119
params object[] args);
121-
122-
/// <summary>
123-
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
124-
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
125-
/// </summary>
126-
/// <param name="provider">
127-
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
128-
/// <typeparamref name="TAuth"/>.
129-
/// </param>
130-
/// <typeparam name="TAuth">
131-
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
132-
/// </typeparam>
133-
/// <typeparam name="TResult">
134-
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
135-
/// </typeparam>
136-
/// <returns>
137-
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
138-
/// <paramref name="provider"/> will be <c>null</c>.
139-
/// </returns>
140-
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
141-
where TAuth : IAuthMethod<TResult>;
142120
}
143121
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using Microsoft.Performance.SDK.Auth;
3+
4+
namespace Microsoft.Performance.SDK.Processing
5+
{
6+
/// <summary>
7+
/// Extends <see cref="IApplicationEnvironment"/> to provide additional functionality.
8+
/// </summary>
9+
[Obsolete("This interface will be removed in version 2.0 of the SDK. It is OK to use this interface in version 1.x of the SDK.")]
10+
public interface IApplicationEnvironmentV2
11+
: IApplicationEnvironment
12+
{
13+
/// <summary>
14+
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
15+
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
16+
/// </summary>
17+
/// <param name="provider">
18+
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
19+
/// <typeparamref name="TAuth"/>.
20+
/// </param>
21+
/// <typeparam name="TAuth">
22+
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
23+
/// </typeparam>
24+
/// <typeparam name="TResult">
25+
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
26+
/// </typeparam>
27+
/// <returns>
28+
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
29+
/// <paramref name="provider"/> will be <c>null</c>.
30+
/// </returns>
31+
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
32+
where TAuth : IAuthMethod<TResult>;
33+
}
34+
}

src/Microsoft.Performance.Testing.SDK/StubApplicationEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Microsoft.Performance.Testing.SDK
1111
{
1212
public class StubApplicationEnvironment
13-
: IApplicationEnvironment
13+
: IApplicationEnvironmentV2
1414
{
1515
public string ApplicationName { get; set; }
1616

0 commit comments

Comments
 (0)