Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface (#365)
* Move TryGetAuthProvider to new IApplicationEnvironmentV2 interface * Document param * Add docstring * Fix tests
This commit is contained in:
Родитель
765f36a9a9
Коммит
2e1a1bf926
|
@ -13,7 +13,7 @@ namespace Microsoft.Performance.SDK.Runtime
|
|||
{
|
||||
/// <inheritdoc cref="IApplicationEnvironment"/>
|
||||
public class ApplicationEnvironment
|
||||
: IApplicationEnvironment
|
||||
: IApplicationEnvironmentV2
|
||||
{
|
||||
private readonly IMessageBox messageBox;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ using Microsoft.Performance.SDK.Processing;
|
|||
namespace Microsoft.Performance.SDK.Tests.TestClasses
|
||||
{
|
||||
public class TestApplicationEnvironment
|
||||
: IApplicationEnvironment
|
||||
: IApplicationEnvironmentV2
|
||||
{
|
||||
public string ApplicationName { get; set; }
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.Performance.SDK.Auth;
|
||||
|
||||
namespace Microsoft.Performance.SDK.Processing
|
||||
{
|
||||
|
@ -143,5 +144,40 @@ namespace Microsoft.Performance.SDK.Processing
|
|||
{
|
||||
self.DisplayMessage(MessageType.Error, formatProvider, format, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
|
||||
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
|
||||
/// </summary>
|
||||
/// <param name="self">
|
||||
/// The <see cref="IApplicationEnvironment"/> instance.
|
||||
/// </param>
|
||||
/// <param name="provider">
|
||||
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
|
||||
/// <typeparamref name="TAuth"/>.
|
||||
/// </param>
|
||||
/// <typeparam name="TAuth">
|
||||
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
|
||||
/// </typeparam>
|
||||
/// <typeparam name="TResult">
|
||||
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
|
||||
/// </typeparam>
|
||||
/// <returns>
|
||||
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
|
||||
/// <paramref name="provider"/> will be <c>null</c>.
|
||||
/// </returns>
|
||||
public static bool TryGetAuthProvider<TAuth, TResult>(
|
||||
this IApplicationEnvironment self,
|
||||
out IAuthProvider<TAuth, TResult> provider)
|
||||
where TAuth : IAuthMethod<TResult>
|
||||
{
|
||||
if (self is IApplicationEnvironmentV2 v2)
|
||||
{
|
||||
return v2.TryGetAuthProvider(out provider);
|
||||
}
|
||||
|
||||
provider = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
using Microsoft.Performance.SDK.Auth;
|
||||
using Microsoft.Performance.SDK.Extensibility.DataCooking;
|
||||
using Microsoft.Performance.SDK.Extensibility.SourceParsing;
|
||||
|
||||
|
@ -118,26 +117,5 @@ namespace Microsoft.Performance.SDK.Processing
|
|||
string caption,
|
||||
string format,
|
||||
params object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
|
||||
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
|
||||
/// </summary>
|
||||
/// <param name="provider">
|
||||
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
|
||||
/// <typeparamref name="TAuth"/>.
|
||||
/// </param>
|
||||
/// <typeparam name="TAuth">
|
||||
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
|
||||
/// </typeparam>
|
||||
/// <typeparam name="TResult">
|
||||
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
|
||||
/// </typeparam>
|
||||
/// <returns>
|
||||
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
|
||||
/// <paramref name="provider"/> will be <c>null</c>.
|
||||
/// </returns>
|
||||
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
|
||||
where TAuth : IAuthMethod<TResult>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using Microsoft.Performance.SDK.Auth;
|
||||
|
||||
namespace Microsoft.Performance.SDK.Processing
|
||||
{
|
||||
/// <summary>
|
||||
/// Extends <see cref="IApplicationEnvironment"/> to provide additional functionality.
|
||||
/// </summary>
|
||||
[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.")]
|
||||
public interface IApplicationEnvironmentV2
|
||||
: IApplicationEnvironment
|
||||
{
|
||||
/// <summary>
|
||||
/// Attempts to get an <see cref="IAuthProvider{TAuth, TResult}"/> that can provide authentication
|
||||
/// for <see cref="IAuthMethod{TResult}"/> of type <typeparamref name="TAuth"/>.
|
||||
/// </summary>
|
||||
/// <param name="provider">
|
||||
/// The found provider, or <c>null</c> if no registered provider can provide authentication for
|
||||
/// <typeparamref name="TAuth"/>.
|
||||
/// </param>
|
||||
/// <typeparam name="TAuth">
|
||||
/// The type of the <see cref="IAuthMethod{TResult}"/> for which to attempt to get a provider.
|
||||
/// </typeparam>
|
||||
/// <typeparam name="TResult">
|
||||
/// The type of the result of a successful authentication for <typeparamref name="TAuth"/>.
|
||||
/// </typeparam>
|
||||
/// <returns>
|
||||
/// <c>true</c> if a provider was found; <c>false</c> otherwise. If <c>false</c> is returned,
|
||||
/// <paramref name="provider"/> will be <c>null</c>.
|
||||
/// </returns>
|
||||
bool TryGetAuthProvider<TAuth, TResult>(out IAuthProvider<TAuth, TResult> provider)
|
||||
where TAuth : IAuthMethod<TResult>;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ using System;
|
|||
namespace Microsoft.Performance.Testing.SDK
|
||||
{
|
||||
public class StubApplicationEnvironment
|
||||
: IApplicationEnvironment
|
||||
: IApplicationEnvironmentV2
|
||||
{
|
||||
public string ApplicationName { get; set; }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче