From 2d09ba8f7be48070046a856b8448457b554c6655 Mon Sep 17 00:00:00 2001 From: "Hongyang Du (hond)" Date: Thu, 7 Sep 2023 00:33:37 +0800 Subject: [PATCH 01/13] Drop ADAL to unblock pipeline (#6687) * init * update * revert one test * revert one test * add compatbaseline --- ApiCompatBaseline.txt | 9 +- .../Authentication/AdalAuthenticator.cs | 337 ------------------ .../Authentication/AppCredentials.cs | 18 +- .../CertificateAppCredentials.cs | 54 --- .../ConstantHttpClientFactory.cs | 4 +- .../IJwtTokenProviderFactory.cs | 24 -- .../Authentication/JwtTokenProviderFactory.cs | 30 -- .../ManagedIdentityAppCredentials.cs | 23 -- .../ManagedIdentityAuthenticator.cs | 14 - ...IdentityServiceClientCredentialsFactory.cs | 13 - .../Authentication/MicrosoftAppCredentials.cs | 18 - .../Authentication/MsalAppCredentials.cs | 7 - .../Microsoft.Bot.Connector.csproj | 2 +- ...redentials.cs => MockAppCredentials.cs.cs} | 7 +- .../Authentication/AppCredentialsTests.cs | 75 ---- .../JwtTokenProviderFactoryTests.cs | 47 --- .../ManagedIdentityAppCredentialsTests.cs | 76 ---- .../ManagedIdentityAuthenticatorTests.cs | 37 -- ...ityServiceClientCredentialsFactoryTests.cs | 99 ----- .../Mocks/MockAppCredentials.cs | 7 +- 20 files changed, 18 insertions(+), 883 deletions(-) delete mode 100644 libraries/Microsoft.Bot.Connector/Authentication/AdalAuthenticator.cs delete mode 100644 libraries/Microsoft.Bot.Connector/Authentication/IJwtTokenProviderFactory.cs delete mode 100644 libraries/Microsoft.Bot.Connector/Authentication/JwtTokenProviderFactory.cs rename tests/Microsoft.Bot.Builder.Tests/{MockAppCredentials.cs => MockAppCredentials.cs.cs} (71%) delete mode 100644 tests/Microsoft.Bot.Connector.Tests/Authentication/AppCredentialsTests.cs delete mode 100644 tests/Microsoft.Bot.Connector.Tests/Authentication/JwtTokenProviderFactoryTests.cs delete mode 100644 tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAppCredentialsTests.cs delete mode 100644 tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityServiceClientCredentialsFactoryTests.cs diff --git a/ApiCompatBaseline.txt b/ApiCompatBaseline.txt index 0895775d4c..dd119bc045 100644 --- a/ApiCompatBaseline.txt +++ b/ApiCompatBaseline.txt @@ -1,4 +1,11 @@ # These types are no longer supported in Microsoft.Bot.Builder.Azure: TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbCustomClientOptions' does not exist in the implementation but it does exist in the contract. TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorage' does not exist in the implementation but it does exist in the contract. -TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions' does not exist in the implementation but it does exist in the contract. \ No newline at end of file +TypesMustExist : Type 'Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions' does not exist in the implementation but it does exist in the contract. + +TypesMustExist : Type 'Microsoft.Bot.Connector.Authentication.AdalAuthenticator' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract. +CannotAddAbstractMembers : Member 'Microsoft.Bot.Connector.Authentication.AppCredentials.BuildIAuthenticator()' is abstract in the implementation but is missing in the contract. +MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials..ctor(Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate, System.String, System.Net.Http.HttpClient, Microsoft.Extensions.Logging.ILogger)' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.CertificateAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.BuildAuthenticator()' does not exist in the implementation but it does exist in the contract. \ No newline at end of file diff --git a/libraries/Microsoft.Bot.Connector/Authentication/AdalAuthenticator.cs b/libraries/Microsoft.Bot.Connector/Authentication/AdalAuthenticator.cs deleted file mode 100644 index 1c8b4cd0a1..0000000000 --- a/libraries/Microsoft.Bot.Connector/Authentication/AdalAuthenticator.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Diagnostics; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Clients.ActiveDirectory; - -namespace Microsoft.Bot.Connector.Authentication -{ - /// - /// An authentication class that implements , used to authenticate requests against Azure. - /// - public class AdalAuthenticator : IAuthenticator - { - private const string MsalTemporarilyUnavailable = "temporarily_unavailable"; - - // When TargetFramework moves to netstandard2.1, use HttpStatusCode.TooManyRequests - // https://docs.microsoft.com/en-us/dotnet/api/system.net.httpstatuscode?view=netstandard-2.1#System_Net_HttpStatusCode_TooManyRequests - private const int HttpTooManyRequests = 429; - - // Semaphore to control concurrency while refreshing tokens from ADAL. - // Whenever a token expires, we want only one request to retrieve a token. - // Cached requests take less than 0.1 millisecond to resolve, so the semaphore doesn't hurt performance under load tests - // unless we have more than 10,000 requests per second, but in that case other things would break first. - private static SemaphoreSlim tokenRefreshSemaphore = new SemaphoreSlim(1, 1); - private static readonly TimeSpan SemaphoreTimeout = TimeSpan.FromSeconds(10); - - // Depending on the responses we get from the service, we update a shared retry policy with the RetryAfter header - // from the HTTP 429 we receive. - // When everything seems to be OK, this retry policy will be empty. - // The reason for this is that if a request gets throttled, even if we wait to retry that, another thread will try again right away. - // With the shared retry policy, if a request gets throttled, we know that other threads have to wait as well. - // This variable is guarded by the authContextSemaphore semaphore. Don't modify it outside of the semaphore scope. - private static volatile RetryParams currentRetryPolicy; - - // Our ADAL context. Acquires tokens and manages token caching for us. - private AuthenticationContext authContext; - - private readonly ClientCredential clientCredential; - private readonly ClientAssertionCertificate clientCertificate; - private readonly bool clientCertSendX5c; - private readonly OAuthConfiguration authConfig; - private readonly ILogger logger; - - /// - /// Initializes a new instance of the class. - /// - /// The client credential to use for token acquisition. - /// A configuration object for OAuth client credential authentication. - /// A customized instance of the HttpClient class. - public AdalAuthenticator(ClientCredential clientCredential, OAuthConfiguration configurationOAuth, HttpClient customHttpClient = null) - : this(clientCredential, configurationOAuth, customHttpClient, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The client credential to use for token acquisition. - /// A configuration object for OAuth client credential authentication. - /// A customized instance of the HttpClient class. - /// The type used to perform logging. - public AdalAuthenticator(ClientCredential clientCredential, OAuthConfiguration configurationOAuth, HttpClient customHttpClient = null, ILogger logger = null) - { - this.authConfig = configurationOAuth ?? throw new ArgumentNullException(nameof(configurationOAuth)); - this.clientCredential = clientCredential ?? throw new ArgumentNullException(nameof(clientCredential)); - this.logger = logger; - - Initialize(configurationOAuth, customHttpClient); - } - - /// - /// Initializes a new instance of the class. - /// - /// A client credential that includes a X509Certificate. - /// A configuration object for OAuth client credential authentication. - /// A customized instance of the HttpClient class. - /// The type used to perform logging. - public AdalAuthenticator(ClientAssertionCertificate clientCertificate, OAuthConfiguration configurationOAuth, HttpClient customHttpClient = null, ILogger logger = null) - : this(clientCertificate, false, configurationOAuth, customHttpClient, logger) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// A client credential that includes a X509Certificate. - /// Enables easy certificates roll-over in Azure AD. Setting it to true sends the public certficate to Azure AD along with token requests. - /// A configuration object for OAuth client credential authentication. - /// A customized instance of the HttpClient class. - /// The type used to perform logging. - public AdalAuthenticator(ClientAssertionCertificate clientCertificate, bool sendX5c, OAuthConfiguration configurationOAuth, HttpClient customHttpClient = null, ILogger logger = null) - { - this.authConfig = configurationOAuth ?? throw new ArgumentNullException(nameof(configurationOAuth)); - this.clientCertificate = clientCertificate ?? throw new ArgumentNullException(nameof(clientCertificate)); - this.logger = logger; - this.clientCertSendX5c = sendX5c; - - Initialize(configurationOAuth, customHttpClient); - } - - /// - /// Performs the call to acquire a security token. - /// - /// Forces a token refresh by clearing the token cache and acquiring it again. - /// A object. - public async Task GetTokenAsync(bool forceRefresh = false) - { - var watch = Stopwatch.StartNew(); - - var result = await Retry.Run( - task: () => AcquireTokenAsync(forceRefresh), - retryExceptionHandler: (ex, ct) => HandleAdalException(ex, ct)).ConfigureAwait(false); - - watch.Stop(); - logger?.LogInformation($"GetTokenAsync: Acquired token using ADAL in {watch.ElapsedMilliseconds}."); - - return result; - } - - async Task IAuthenticator.GetTokenAsync(bool forceRefresh) - { - var result = await GetTokenAsync(forceRefresh).ConfigureAwait(false); - return new AuthenticatorResult() - { - AccessToken = result.AccessToken, - ExpiresOn = result.ExpiresOn - }; - } - - private static RetryParams HandleAdalException(Exception ex, int currentRetryCount) - { - if (IsAdalServiceUnavailable(ex)) - { - return ComputeAdalRetry(ex); - } - else if (ex is ThrottleException) - { - // This is an exception that we threw, with knowledge that - // one of our threads is trying to acquire a token from the server - // Use the retry parameters recommended in the exception - ThrottleException throttlException = (ThrottleException)ex; - return throttlException.RetryParams ?? RetryParams.DefaultBackOff(currentRetryCount); - } - else if (IsAdalServiceInvalidRequest(ex)) - { - return RetryParams.StopRetrying; - } - else - { - // We end up here is the exception is not an ADAL exception. An example, is under high traffic - // where we could have a timeout waiting to acquire a token, waiting on the semaphore. - // If we hit a timeout, we want to retry a reasonable number of times. - return RetryParams.DefaultBackOff(currentRetryCount); - } - } - - private static bool IsAdalServiceUnavailable(Exception ex) - { - AdalServiceException adalServiceException = ex as AdalServiceException; - if (adalServiceException == null) - { - return false; - } - - // When the Service Token Server (STS) is too busy because of “too many requests”, - // it returns an HTTP error 429 - return adalServiceException.ErrorCode == MsalTemporarilyUnavailable || adalServiceException.StatusCode == HttpTooManyRequests; - } - - /// - /// Determine whether exception represents an invalid request from AAD. - /// - /// Exception. - /// True if the exception represents an invalid request. - private static bool IsAdalServiceInvalidRequest(Exception ex) - { - if (ex is AdalServiceException adal) - { - // ErrorCode is "invalid_request" - // but HTTP StatusCode covers more non-retryable conditions - if (adal.StatusCode == (int)HttpStatusCode.BadRequest) - { - return true; - } - } - - return false; - } - - private static RetryParams ComputeAdalRetry(Exception ex) - { - if (ex is AdalServiceException) - { - AdalServiceException adalServiceException = (AdalServiceException)ex; - - // When the Service Token Server (STS) is too busy because of “too many requests”, - // it returns an HTTP error 429 with a hint about when you can try again (Retry-After response field) as a delay in seconds - if (adalServiceException.ErrorCode == MsalTemporarilyUnavailable || adalServiceException.StatusCode == HttpTooManyRequests) - { - RetryConditionHeaderValue retryAfter = adalServiceException.Headers.RetryAfter; - - // Depending on the service, the recommended retry time may be in retryAfter.Delta or retryAfter.Date. Check both. - if (retryAfter != null && retryAfter.Delta.HasValue) - { - return new RetryParams(retryAfter.Delta.Value); - } - else if (retryAfter != null && retryAfter.Date.HasValue) - { - return new RetryParams(retryAfter.Date.Value.Offset); - } - - // We got a 429 but didn't get a specific back-off time. Use the default - return RetryParams.DefaultBackOff(0); - } - } - - return RetryParams.DefaultBackOff(0); - } - - private void ReleaseSemaphore() - { - try - { - tokenRefreshSemaphore.Release(); - } - catch (SemaphoreFullException) - { - // We should not be hitting this after switching to SemaphoreSlim, but if we do hit it everything will keep working. - // Logging to have clear knowledge of whether this is happening. - logger?.LogWarning("Attempted to release a full semaphore."); - } - - // Any exception other than SemaphoreFullException should be thrown right away - } - - private void Initialize(OAuthConfiguration configurationOAuth, HttpClient customHttpClient) - { - if (customHttpClient != null) - { - var httpClientFactory = new ConstantHttpClientFactory(customHttpClient); - this.authContext = new AuthenticationContext(configurationOAuth.Authority, configurationOAuth.ValidateAuthority, new TokenCache(), httpClientFactory); - } - else - { - this.authContext = new AuthenticationContext(configurationOAuth.Authority, configurationOAuth.ValidateAuthority); - } - } - - private async Task AcquireTokenAsync(bool forceRefresh = false) - { - bool acquired = false; - - if (forceRefresh) - { - authContext.TokenCache.Clear(); - } - - try - { - // The ADAL client team recommends limiting concurrency of calls. When the Token is in cache there is never - // contention on this semaphore, but when tokens expire there is some. However, after measuring performance - // with and without the semaphore (and different configs for the semaphore), not limiting concurrency actually - // results in higher response times overall. Without the use of this semaphore calls to AcquireTokenAsync can take up - // to 5 seconds under high concurrency scenarios. -#pragma warning disable VSTHRD103 // Call async methods when in an async method - acquired = tokenRefreshSemaphore.Wait(SemaphoreTimeout); -#pragma warning restore VSTHRD103 // Call async methods when in an async method - - // If we are allowed to enter the semaphore, acquire the token. - if (acquired) - { - // Acquire token async using MSAL.NET - // https://github.com/AzureAD/azure-activedirectory-library-for-dotnet - // Given that this is a ClientCredential scenario, it will use the cache without the - // need to call AcquireTokenSilentAsync (which is only for user credentials). - // Scenario details: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Client-credential-flows#it-uses-the-application-token-cache - AuthenticationResult authResult = null; - - // Password based auth - if (clientCredential != null) - { - authResult = await authContext.AcquireTokenAsync(authConfig.Scope, this.clientCredential).ConfigureAwait(false); - } - - // Certificate based auth - else if (clientCertificate != null) - { - authResult = await authContext.AcquireTokenAsync(authConfig.Scope, clientCertificate, sendX5c: this.clientCertSendX5c).ConfigureAwait(false); - } - - // This means we acquired a valid token successfully. We can make our retry policy null. - // Note that the retry policy is set under the semaphore so no additional synchronization is needed. - if (currentRetryPolicy != null) - { - currentRetryPolicy = null; - } - - return authResult; - } - else - { - // If the token is taken, it means that one thread is trying to acquire a token from the server. - // If we already received information about how much to throttle, it will be in the currentRetryPolicy. - // Use that to inform our next delay before trying. - throw new ThrottleException() { RetryParams = currentRetryPolicy }; - } - } - catch (Exception ex) - { - // If we are getting throttled, we set the retry policy according to the RetryAfter headers - // that we receive from the auth server. - // Note that the retry policy is set under the semaphore so no additional synchronization is needed. - if (IsAdalServiceUnavailable(ex)) - { - currentRetryPolicy = ComputeAdalRetry(ex); - } - - throw; - } - finally - { - // Always release the semaphore if we acquired it. - if (acquired) - { - ReleaseSemaphore(); - } - } - } - } -} diff --git a/libraries/Microsoft.Bot.Connector/Authentication/AppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/AppCredentials.cs index 012bb644d6..bc2e335099 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/AppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/AppCredentials.cs @@ -213,27 +213,11 @@ public async Task GetTokenAsync(bool forceRefresh = false) return token.AccessToken; } - /// - /// Builds the lazy to be used for token acquisition. - /// - /// A lazy . - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected abstract Lazy BuildAuthenticator(); - /// /// Builds the lazy to be used for token acquisition. /// /// A lazy . - protected virtual Lazy BuildIAuthenticator() - { - return new Lazy( - () => - { - var lazyAuthenticator = BuildAuthenticator(); - return lazyAuthenticator.Value; - }, - LazyThreadSafetyMode.ExecutionAndPublication); - } + protected abstract Lazy BuildIAuthenticator(); private bool ShouldSetToken() { diff --git a/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs index e46938e10d..c6b6c86295 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/CertificateAppCredentials.cs @@ -6,7 +6,6 @@ using System.Security.Cryptography.X509Certificates; using System.Threading; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Clients.ActiveDirectory; namespace Microsoft.Bot.Connector.Authentication { @@ -15,7 +14,6 @@ namespace Microsoft.Bot.Connector.Authentication /// public class CertificateAppCredentials : AppCredentials { - private readonly ClientAssertionCertificate adalClientCertificate; private readonly X509Certificate2 clientCertificate; private readonly bool sendX5c; @@ -81,58 +79,6 @@ public CertificateAppCredentials(X509Certificate2 clientCertificate, bool sendX5 MicrosoftAppId = appId; } - /// - /// Initializes a new instance of the class. - /// - /// Client certificate to be presented for authentication. - /// Optional. The oauth token tenant. - /// Optional to be used when acquiring tokens. - /// Optional to gather telemetry data while acquiring and managing credentials. - public CertificateAppCredentials(ClientAssertionCertificate clientCertificate, string channelAuthTenant = null, HttpClient customHttpClient = null, ILogger logger = null) - : this(clientCertificate, false, channelAuthTenant, customHttpClient, logger) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Client certificate to be presented for authentication. - /// This parameter, if true, enables application developers to achieve easy certificates roll-over in Azure AD: setting this parameter to true will send the public certificate to Azure AD along with the token request, so that Azure AD can use it to validate the subject name based on a trusted issuer policy. - /// Optional. The oauth token tenant. - /// Optional to be used when acquiring tokens. - /// Optional to gather telemetry data while acquiring and managing credentials. - public CertificateAppCredentials(ClientAssertionCertificate clientCertificate, bool sendX5c, string channelAuthTenant = null, HttpClient customHttpClient = null, ILogger logger = null) - : base(channelAuthTenant, customHttpClient, logger) - { - if (clientCertificate == null) - { - throw new ArgumentNullException(nameof(clientCertificate)); - } - - this.sendX5c = sendX5c; - this.clientCertificate = clientCertificate.Certificate; - MicrosoftAppId = clientCertificate.ClientId; - adalClientCertificate = clientCertificate; - } - - /// - /// Builds the lazy to be used for token acquisition. - /// - /// A lazy . - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() - { - return new Lazy( - () => - new AdalAuthenticator( - adalClientCertificate, - sendX5c, - new OAuthConfiguration() { Authority = OAuthEndpoint, ValidateAuthority = ValidateAuthority, Scope = OAuthScope }, - CustomHttpClient, - Logger), - LazyThreadSafetyMode.ExecutionAndPublication); - } - /// protected override Lazy BuildIAuthenticator() { diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ConstantHttpClientFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/ConstantHttpClientFactory.cs index e9d9e8d64f..b13880adc5 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ConstantHttpClientFactory.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ConstantHttpClientFactory.cs @@ -8,9 +8,9 @@ namespace Microsoft.Bot.Connector.Authentication { /// - /// HttpClientFactory that always returns the same HttpClient instance for ADAL AcquireTokenAsync calls. + /// HttpClientFactory that always returns the same HttpClient instance for AcquireTokenAsync calls. /// - internal class ConstantHttpClientFactory : IdentityModel.Clients.ActiveDirectory.IHttpClientFactory, IMsalHttpClientFactory + internal class ConstantHttpClientFactory : IMsalHttpClientFactory { private readonly HttpClient httpClient; diff --git a/libraries/Microsoft.Bot.Connector/Authentication/IJwtTokenProviderFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/IJwtTokenProviderFactory.cs deleted file mode 100644 index cebc8ee3bc..0000000000 --- a/libraries/Microsoft.Bot.Connector/Authentication/IJwtTokenProviderFactory.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using Microsoft.Azure.Services.AppAuthentication; - -namespace Microsoft.Bot.Connector.Authentication -{ - /// - /// A factory that can create OAuth token providers for generating JWT auth tokens. - /// - [Obsolete("This class is deprecated.", false)] - public interface IJwtTokenProviderFactory - { - /// - /// Creates a new instance of the class. - /// - /// Client id for the managed identity to be used for acquiring tokens. - /// A customized instance of the HttpClient class. - /// A new instance of the class. - AzureServiceTokenProvider CreateAzureServiceTokenProvider(string appId, HttpClient customHttpClient = null); - } -} diff --git a/libraries/Microsoft.Bot.Connector/Authentication/JwtTokenProviderFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/JwtTokenProviderFactory.cs deleted file mode 100644 index 42172ea7a1..0000000000 --- a/libraries/Microsoft.Bot.Connector/Authentication/JwtTokenProviderFactory.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using Microsoft.Azure.Services.AppAuthentication; - -namespace Microsoft.Bot.Connector.Authentication -{ - /// - [Obsolete("This class is deprecated.", false)] - public class JwtTokenProviderFactory : IJwtTokenProviderFactory - { - /// - public AzureServiceTokenProvider CreateAzureServiceTokenProvider(string appId, HttpClient customHttpClient = null) - { - if (string.IsNullOrWhiteSpace(appId)) - { - throw new ArgumentNullException(nameof(appId)); - } - - // https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=dotnet - // "RunAs=App;AppId=" for user-assigned managed identities - var connectionString = $"RunAs=App;AppId={appId}"; - return customHttpClient == null - ? new AzureServiceTokenProvider(connectionString) - : new AzureServiceTokenProvider(connectionString, httpClientFactory: new ConstantHttpClientFactory(customHttpClient)); - } - } -} diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAppCredentials.cs index 7a6fccbb74..c624766732 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAppCredentials.cs @@ -13,21 +13,6 @@ namespace Microsoft.Bot.Connector.Authentication /// public class ManagedIdentityAppCredentials : AppCredentials { - /// - /// Initializes a new instance of the class. - /// Managed Identity for AAD credentials auth and caching. - /// - /// Client ID for the managed identity assigned to the bot. - /// The scope for the token. - /// The JWT token provider factory to use. - /// Optional to be used when acquiring tokens. - /// Optional to gather telemetry data while acquiring and managing credentials. - [Obsolete("This method is deprecated, the IJwtTokenProviderFactory argument is now redundant. Use the overload without this argument.", false)] - public ManagedIdentityAppCredentials(string appId, string oAuthScope, IJwtTokenProviderFactory tokenProviderFactory, HttpClient customHttpClient = null, ILogger logger = null) - : this(appId, oAuthScope, customHttpClient, logger) - { - } - /// /// Initializes a new instance of the class. /// Managed Identity for AAD credentials auth and caching. @@ -47,14 +32,6 @@ public ManagedIdentityAppCredentials(string appId, string oAuthScope, HttpClient MicrosoftAppId = appId; } - /// - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() - { - // Should not be called, legacy - throw new NotImplementedException(); - } - /// protected override Lazy BuildIAuthenticator() { diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs index b16078809a..14ced8afba 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs @@ -21,20 +21,6 @@ public class ManagedIdentityAuthenticator : IAuthenticator private readonly ILogger _logger; private readonly IConfidentialClientApplication _clientApplication; - /// - /// Initializes a new instance of the class. - /// - /// Client id for the managed identity to be used for acquiring tokens. - /// Resource for which to acquire the token. - /// The JWT token provider factory to use. - /// A customized instance of the HttpClient class. - /// The type used to perform logging. - [Obsolete("This method is deprecated, the IJwtTokenProviderFactory argument is now redundant. Use the overload without this argument.", false)] - public ManagedIdentityAuthenticator(string appId, string resource, IJwtTokenProviderFactory tokenProviderFactory, HttpClient customHttpClient = null, ILogger logger = null) - : this(appId, resource, customHttpClient, logger) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityServiceClientCredentialsFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityServiceClientCredentialsFactory.cs index 5c6e40b416..70bcc21caa 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityServiceClientCredentialsFactory.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityServiceClientCredentialsFactory.cs @@ -19,19 +19,6 @@ public class ManagedIdentityServiceClientCredentialsFactory : ServiceClientCrede private readonly HttpClient _httpClient; private readonly ILogger _logger; - /// - /// Initializes a new instance of the class. - /// - /// Client ID for the managed identity assigned to the bot. - /// The JWT token provider factory to use. - /// A custom httpClient to use. - /// A logger instance to use. - [Obsolete("This method is deprecated, the IJwtTokenProviderFactory argument is now redundant. Use the overload without this argument.", false)] - public ManagedIdentityServiceClientCredentialsFactory(string appId, IJwtTokenProviderFactory tokenProviderFactory, HttpClient httpClient = null, ILogger logger = null) - : this(appId, httpClient, logger) - { - } - /// /// Initializes a new instance of the class. /// diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs index eb6b712212..add80a0471 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MicrosoftAppCredentials.cs @@ -5,7 +5,6 @@ using System.Net.Http; using System.Threading; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Clients.ActiveDirectory; namespace Microsoft.Bot.Connector.Authentication { @@ -134,23 +133,6 @@ public MicrosoftAppCredentials(string appId, string password, string channelAuth /// public string MicrosoftAppPassword { get; set; } - /// - /// Builds the lazy to be used for token acquisition. - /// - /// A lazy . - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() - { - return new Lazy( - () => - new AdalAuthenticator( - new ClientCredential(MicrosoftAppId, MicrosoftAppPassword), - new OAuthConfiguration() { Authority = OAuthEndpoint, ValidateAuthority = ValidateAuthority, Scope = OAuthScope }, - this.CustomHttpClient, - this.Logger), - LazyThreadSafetyMode.ExecutionAndPublication); - } - /// protected override Lazy BuildIAuthenticator() { diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs index 0bdb1bc47f..63524e8194 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs @@ -120,13 +120,6 @@ async Task IAuthenticator.GetTokenAsync(bool forceRefresh) return result; } - /// - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() - { - throw new NotImplementedException(); - } - /// protected override Lazy BuildIAuthenticator() { diff --git a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj index 244dea2297..5fc5f2f36b 100644 --- a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj +++ b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj @@ -26,7 +26,7 @@ - + diff --git a/tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs b/tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs.cs similarity index 71% rename from tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs rename to tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs.cs index 2b84860c38..82980905b2 100644 --- a/tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs +++ b/tests/Microsoft.Bot.Builder.Tests/MockAppCredentials.cs.cs @@ -14,11 +14,10 @@ public MockAppCredentials(string channelAuthTenant = null, HttpClient customHttp : base(channelAuthTenant, customHttpClient, logger) { } - - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() + + protected override Lazy BuildIAuthenticator() { - return new Lazy(); + throw new NotImplementedException(); } } } diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/AppCredentialsTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/AppCredentialsTests.cs deleted file mode 100644 index 159f992dc5..0000000000 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/AppCredentialsTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Bot.Connector.Authentication; -using Microsoft.Extensions.Logging; -using Moq; -using Xunit; - -namespace Microsoft.Bot.Connector.Tests.Authentication -{ - public class AppCredentialsTests - { - [Fact] - public void ConstructorTests() - { - var shouldDefaultToChannelScope = new TestAppCredentials("irrelevant", null, null); - Assert.Equal(AuthenticationConstants.ToChannelFromBotOAuthScope, shouldDefaultToChannelScope.OAuthScope); - - var shouldDefaultToCustomScope = new TestAppCredentials("irrelevant", null, null, "customScope"); - Assert.Equal("customScope", shouldDefaultToCustomScope.OAuthScope); - } - - [Fact] - public async Task ProcessHttpRequestShouldNotSendTokenForAnonymous() - { - var sut = new TestAppCredentials("irrelevant", null, null) - { - MicrosoftAppId = null - }; - - // AppId is null. - await sut.ProcessHttpRequestAsync(new HttpRequestMessage(), CancellationToken.None); - Assert.Null(sut.Request.Headers.Authorization); - - // AppId is anonymous skill. - sut.MicrosoftAppId = AuthenticationConstants.AnonymousSkillAppId; - Assert.Null(sut.Request.Headers.Authorization); - } - - private class TestAppCredentials : AppCredentials - { - public TestAppCredentials(string channelAuthTenant = null, HttpClient customHttpClient = null, ILogger logger = null) - : base(channelAuthTenant, customHttpClient, logger) - { - } - - public TestAppCredentials(string channelAuthTenant = null, HttpClient customHttpClient = null, ILogger logger = null, string oAuthScope = null) - : base(channelAuthTenant, customHttpClient, logger, oAuthScope) - { - } - - /// - /// Gets the request sent to . - /// - public HttpRequestMessage Request { get; private set; } - - public override async Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - // This override calls the base and captures the modified request so we can assert the Auth header. - await base.ProcessHttpRequestAsync(request, cancellationToken); - Request = request; - } - - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() - { - return new Mock>().Object; - } - } - } -} diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/JwtTokenProviderFactoryTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/JwtTokenProviderFactoryTests.cs deleted file mode 100644 index b59ce06275..0000000000 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/JwtTokenProviderFactoryTests.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using Microsoft.Bot.Connector.Authentication; -using Xunit; - -namespace Microsoft.Bot.Connector.Tests.Authentication -{ - public class JwtTokenProviderFactoryTests - { - private const string TestAppId = "foo"; - - [Fact] - public void CanCreateAzureServiceTokenProvider() - { - var sut = new JwtTokenProviderFactory(); - var tokenProvider = sut.CreateAzureServiceTokenProvider(TestAppId); - Assert.NotNull(tokenProvider); - } - - [Fact] - public void CanCreateAzureServiceTokenProviderWithCustomHttpClient() - { - using (var customHttpClient = new HttpClient()) - { - var sut = new JwtTokenProviderFactory(); - var tokenProvider = sut.CreateAzureServiceTokenProvider(TestAppId, customHttpClient); - Assert.NotNull(tokenProvider); - } - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public void CannotCreateAzureServiceTokenProviderWithoutAppId(string appId) - { - Assert.Throws(() => - { - var sut = new JwtTokenProviderFactory(); - _ = sut.CreateAzureServiceTokenProvider(appId); - }); - } - } -} diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAppCredentialsTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAppCredentialsTests.cs deleted file mode 100644 index f0fa8e1c00..0000000000 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAppCredentialsTests.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using Microsoft.Bot.Connector.Authentication; -using Microsoft.Extensions.Logging; -using Moq; -using Xunit; - -namespace Microsoft.Bot.Connector.Tests.Authentication -{ - public class ManagedIdentityAppCredentialsTests - { - private const string TestAppId = "foo"; - private const string TestAudience = "bar"; - - [Fact] - public void ConstructorTests() - { - var tokenProviderFactory = new Mock(); - - var sut1 = new ManagedIdentityAppCredentials(TestAppId, TestAudience, tokenProviderFactory.Object); - Assert.Equal(TestAppId, sut1.MicrosoftAppId); - Assert.Equal(TestAudience, sut1.OAuthScope); - - using (var customHttpClient = new HttpClient()) - { - var sut2 = new ManagedIdentityAppCredentials(TestAppId, TestAudience, tokenProviderFactory.Object, customHttpClient); - Assert.Equal(TestAppId, sut2.MicrosoftAppId); - Assert.Equal(TestAudience, sut2.OAuthScope); - - var logger = new Mock().Object; - var sut3 = new ManagedIdentityAppCredentials(TestAppId, TestAudience, tokenProviderFactory.Object, null, logger); - Assert.Equal(TestAppId, sut3.MicrosoftAppId); - Assert.Equal(TestAudience, sut3.OAuthScope); - - var sut4 = new ManagedIdentityAppCredentials(TestAppId, TestAudience, tokenProviderFactory.Object, customHttpClient, logger); - Assert.Equal(TestAppId, sut4.MicrosoftAppId); - Assert.Equal(TestAudience, sut4.OAuthScope); - } - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public void CanCreateCredentialsWithoutAudience(string audience) - { - var tokenProviderFactory = new Mock(); - - var sut = new ManagedIdentityAppCredentials(TestAppId, audience, tokenProviderFactory.Object); - Assert.Equal(TestAppId, sut.MicrosoftAppId); - Assert.Equal(AuthenticationConstants.ToChannelFromBotOAuthScope, sut.OAuthScope); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public void CannotCreateCredentialsWithoutAppId(string appId) - { - Assert.Throws(() => - { - var tokenProviderFactory = new Mock(); - _ = new ManagedIdentityAppCredentials(appId, TestAudience, tokenProviderFactory.Object); - }); - } - - [Fact] - public void CanCreateCredentialsWithoutTokenProviderFactory() - { - _ = new ManagedIdentityAppCredentials(TestAppId, TestAudience, tokenProviderFactory: null); - } - } -} diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs index 4ae1dd6238..7ccab5f4e6 100644 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs +++ b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs @@ -6,9 +6,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using Microsoft.Azure.Services.AppAuthentication; using Microsoft.Bot.Connector.Authentication; -using Microsoft.Extensions.Logging; using Moq; using Moq.Protected; using Newtonsoft.Json.Linq; @@ -20,41 +18,6 @@ public class ManagedIdentityAuthenticatorTests { private const string TestAppId = "foo"; private const string TestAudience = "bar"; - private const string TestConnectionString = "RunAs=App;AppId=foo"; - private const string TestAzureAdInstance = "https://login.microsoftonline.com/"; - - [Fact] - public void ConstructorTests() - { - var callsToCreateTokenProvider = 0; - - var tokenProvider = new Mock(TestConnectionString, TestAzureAdInstance); - - var tokenProviderFactory = new Mock(); - tokenProviderFactory - .Setup(f => f.CreateAzureServiceTokenProvider(It.IsAny(), It.IsAny())) - .Returns((appId, customHttpClient) => - { - callsToCreateTokenProvider++; - Assert.Equal(TestAppId, appId); - - return tokenProvider.Object; - }); - - _ = new ManagedIdentityAuthenticator(TestAppId, TestAudience, tokenProviderFactory.Object); - - using (var customHttpClient = new HttpClient()) - { - _ = new ManagedIdentityAuthenticator(TestAppId, TestAudience, tokenProviderFactory.Object, customHttpClient); - - var logger = new Mock(); - _ = new ManagedIdentityAuthenticator(TestAppId, TestAudience, tokenProviderFactory.Object, null, logger.Object); - - _ = new ManagedIdentityAuthenticator(TestAppId, TestAudience, tokenProviderFactory.Object, customHttpClient, logger.Object); - } - - Assert.Equal(0, callsToCreateTokenProvider); - } [Fact] public void CanGetJwtToken() diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityServiceClientCredentialsFactoryTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityServiceClientCredentialsFactoryTests.cs deleted file mode 100644 index 1dde2e930e..0000000000 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityServiceClientCredentialsFactoryTests.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Net.Http; -using System.Threading; -using Microsoft.Bot.Connector.Authentication; -using Microsoft.Extensions.Logging; -using Moq; -using Xunit; - -namespace Microsoft.Bot.Connector.Tests.Authentication -{ - public class ManagedIdentityServiceClientCredentialsFactoryTests - { - private const string TestAppId = "foo"; - private const string TestAudience = "bar"; - - [Fact] - public void ConstructorTests() - { - var tokenProviderFactory = new Mock(); - - _ = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object); - - using (var customHttpClient = new HttpClient()) - { - _ = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object, customHttpClient); - - var logger = new Mock(); - _ = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object, null, logger.Object); - - _ = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object, customHttpClient, logger.Object); - } - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public void CannotCreateCredentialsFactoryWithoutAppId(string appId) - { - Assert.Throws(() => - { - var tokenProviderFactory = new Mock(); - _ = new ManagedIdentityServiceClientCredentialsFactory(appId, tokenProviderFactory.Object); - }); - } - - [Fact] - public void CanCreateCredentialsFactoryWithoutTokenProviderFactory() - { - _ = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory: null); - } - - [Fact] - public void IsValidAppIdTest() - { - var tokenProviderFactory = new Mock(); - var sut = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object); - - Assert.True(sut.IsValidAppIdAsync(TestAppId, CancellationToken.None).GetAwaiter().GetResult()); - Assert.False(sut.IsValidAppIdAsync("InvalidAppId", CancellationToken.None).GetAwaiter().GetResult()); - } - - [Fact] - public void IsAuthenticationDisabledTest() - { - var tokenProviderFactory = new Mock(); - var sut = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object); - - Assert.False(sut.IsAuthenticationDisabledAsync(CancellationToken.None).GetAwaiter().GetResult()); - } - - [Fact] - public void CanCreateCredentials() - { - var tokenProviderFactory = new Mock(); - var sut = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object); - - var credentials = sut.CreateCredentialsAsync( - TestAppId, TestAudience, "https://login.microsoftonline.com", true, CancellationToken.None); - Assert.NotNull(credentials); - } - - [Fact] - public void CannotCreateCredentialsWithInvalidAppId() - { - var tokenProviderFactory = new Mock(); - var sut = new ManagedIdentityServiceClientCredentialsFactory(TestAppId, tokenProviderFactory.Object); - - Assert.Throws(() => - { - _ = sut.CreateCredentialsAsync( - "InvalidAppId", TestAudience, "https://login.microsoftonline.com", true, CancellationToken.None); - }); - } - } -} diff --git a/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/Mocks/MockAppCredentials.cs b/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/Mocks/MockAppCredentials.cs index ad3749743e..0933c66094 100644 --- a/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/Mocks/MockAppCredentials.cs +++ b/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/Mocks/MockAppCredentials.cs @@ -14,11 +14,10 @@ public MockAppCredentials(string channelAuthTenant = null, HttpClient customHttp : base(channelAuthTenant, customHttpClient, logger) { } - - [Obsolete("This method is deprecated. Use BuildIAuthenticator instead.", false)] - protected override Lazy BuildAuthenticator() + + protected override Lazy BuildIAuthenticator() { - return new Lazy(); + throw new NotImplementedException(); } } } From 946f9d4acf62d7406b3738b08204b5dbd899b1c1 Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:00:31 -0300 Subject: [PATCH 02/13] replace TestFramework package usage (#6690) Co-authored-by: JhontSouth --- .../Microsoft.Bot.Connector.Tests/BaseTest.cs | 1 - .../Microsoft.Bot.Connector.Tests.csproj | 3 +- .../MockContext.cs | 103 ++++++++++++++++++ .../ResourceGroupCleaner.cs | 61 +++++++++++ 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 tests/Microsoft.Bot.Connector.Tests/MockContext.cs create mode 100644 tests/Microsoft.Bot.Connector.Tests/ResourceGroupCleaner.cs diff --git a/tests/Microsoft.Bot.Connector.Tests/BaseTest.cs b/tests/Microsoft.Bot.Connector.Tests/BaseTest.cs index 0a4c6dcb9b..2fc885adc5 100644 --- a/tests/Microsoft.Bot.Connector.Tests/BaseTest.cs +++ b/tests/Microsoft.Bot.Connector.Tests/BaseTest.cs @@ -11,7 +11,6 @@ using Microsoft.Bot.Connector.Authentication; using Microsoft.Bot.Schema; using Microsoft.Rest; -using Microsoft.Rest.ClientRuntime.Azure.TestFramework; using Moq; namespace Microsoft.Bot.Connector.Tests diff --git a/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj b/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj index 68f54caefb..c076ed7830 100644 --- a/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj +++ b/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj @@ -12,10 +12,9 @@ - + - diff --git a/tests/Microsoft.Bot.Connector.Tests/MockContext.cs b/tests/Microsoft.Bot.Connector.Tests/MockContext.cs new file mode 100644 index 0000000000..15c4ea509c --- /dev/null +++ b/tests/Microsoft.Bot.Connector.Tests/MockContext.cs @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using Microsoft.Azure.Test.HttpRecorder; +using Microsoft.Azure.Test.HttpRecorder.ProcessRecordings; + +namespace Microsoft.Bot.Connector.Tests +{ + /// + /// A coordinator for tracking and undoing WAML operations. Usage pattern is + /// using(MockContext.Create()) + /// { + /// maml stuff + /// } + /// You can also manually call the Dispose() or UndoAll() methods to undo all 'undoable' operations since the + /// UndoContext was created. + /// Call: MockContext.Commit() to remove all undo information. + /// + public class MockContext : IDisposable + { + //prevent multiple dispose events + private bool disposed = false; + private List undoHandlers = new List(); + + internal bool OptimizeTestRecordingFile { get; set; } = false; + + /// + /// Initialize a new MockContext. + /// + /// The class name to identify the mock server. + /// Returns a new MockContext. + /// The name method used for the test. + public static MockContext Start( + string className, + [System.Runtime.CompilerServices.CallerMemberName] + string methodName = "testframework_failed") + { + var context = new MockContext(); + if (HttpMockServer.FileSystemUtilsObject == null) + { + HttpMockServer.FileSystemUtilsObject = new FileSystemUtils(); + } + + HttpMockServer.Initialize(className, methodName); + if (HttpMockServer.Mode != HttpRecorderMode.Playback) + { + context.disposed = false; + } + + return context; + } + + /// + /// Dispose the object. + /// + public void Dispose() + { + this.Dispose(true); + } + + /// + /// Stop recording and Discard all undo information. + /// + public void Stop() + { + if (HttpMockServer.Mode != HttpRecorderMode.Playback) + { + foreach (var undoHandler in undoHandlers) + { + undoHandler.DeleteResourceGroups().ConfigureAwait(false).GetAwaiter().GetResult(); + } + } + + string recordedFilePath = HttpMockServer.Flush(); + + if (HttpMockServer.Mode == HttpRecorderMode.Record) + { + // this check should be removed once we make the optimizatoin default + if (OptimizeTestRecordingFile) + { + ProcessRecordedFiles procRecFile = new ProcessRecordedFiles(recordedFilePath); + procRecFile.CompactLroPolling(); + procRecFile.SerializeCompactData(); + } + } + } + + /// + /// Dispose only if we have not previously been disposed. + /// + /// true if we should dispose, otherwise false. + protected virtual void Dispose(bool disposing) + { + if (disposing && !this.disposed) + { + this.Stop(); + this.disposed = true; + } + } + } +} diff --git a/tests/Microsoft.Bot.Connector.Tests/ResourceGroupCleaner.cs b/tests/Microsoft.Bot.Connector.Tests/ResourceGroupCleaner.cs new file mode 100644 index 0000000000..6939b08671 --- /dev/null +++ b/tests/Microsoft.Bot.Connector.Tests/ResourceGroupCleaner.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Net.Http; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Rest; + +namespace Microsoft.Bot.Connector.Tests +{ + public class ResourceGroupCleaner : DelegatingHandler + { + private Regex _resourceGroupPattern = new Regex(@"/subscriptions/[^/]+/resourcegroups/([^?]+)\?api-version"); + private HashSet _resourceGroupsCreated = new HashSet(); + private TokenCredentials _tokenCredentials; + + public ResourceGroupCleaner(TokenCredentials tokenCredentials) + { + _tokenCredentials = tokenCredentials; + } + + public async Task DeleteResourceGroups() + { + HttpClient httpClient = new HttpClient(); + foreach (var resourceGroupUri in _resourceGroupsCreated) + { + HttpRequestMessage httpRequest = new HttpRequestMessage(); + httpRequest.Method = new HttpMethod("DELETE"); + httpRequest.RequestUri = new Uri(resourceGroupUri); + + _tokenCredentials.ProcessHttpRequestAsync(httpRequest, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); + + HttpResponseMessage httpResponse = await httpClient.SendAsync(httpRequest).ConfigureAwait(false); + string groupName = _resourceGroupPattern.Match(resourceGroupUri).Groups[1].Value; + string message = string.Format( + CultureInfo.InvariantCulture, + "Started deletion of resource group '{0}'. Server responded with status code {1}.", + groupName, + httpResponse.StatusCode); + Console.WriteLine(message); + Debug.WriteLine(message); + } + } + + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + if (_resourceGroupPattern.IsMatch(request.RequestUri.AbsoluteUri) && + request.Method == HttpMethod.Put) + { + _resourceGroupsCreated.Add(request.RequestUri.AbsoluteUri); + } + + return base.SendAsync(request, cancellationToken); + } + } +} From c2f3aea4a4c0b5492fc2da629bf42f6d3dd52afb Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:12:35 +0200 Subject: [PATCH 03/13] [#6643] WithManagedIdentity is experimental and not exist in Microsoft.Identity.Client 4.51.0 (#6686) * Update MSI implementation * Fix unit tests --- .../ManagedIdentityAuthenticator.cs | 14 +++++--------- .../Microsoft.Bot.Connector.csproj | 2 +- .../ManagedIdentityAuthenticatorTests.cs | 18 +++++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs index 14ced8afba..1982ac2e4c 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Identity.Client; +using Microsoft.Identity.Client.AppConfig; namespace Microsoft.Bot.Connector.Authentication { @@ -16,10 +17,9 @@ namespace Microsoft.Bot.Connector.Authentication /// public class ManagedIdentityAuthenticator : IAuthenticator { - private readonly string _appId; private readonly string _resource; private readonly ILogger _logger; - private readonly IConfidentialClientApplication _clientApplication; + private readonly IManagedIdentityApplication _clientApplication; /// /// Initializes a new instance of the class. @@ -40,7 +40,6 @@ public ManagedIdentityAuthenticator(string appId, string resource, HttpClient cu throw new ArgumentNullException(nameof(resource)); } - _appId = appId; _resource = resource; _logger = logger ?? NullLogger.Instance; _clientApplication = CreateClientApplication(appId, customHttpClient); @@ -63,10 +62,8 @@ public async Task GetTokenAsync(bool forceRefresh = false) private async Task AcquireTokenAsync(bool forceRefresh) { - var scopes = new string[] { $"{_resource}/.default" }; var authResult = await _clientApplication - .AcquireTokenForClient(scopes) - .WithManagedIdentity(_appId) + .AcquireTokenForManagedIdentity(_resource) .WithForceRefresh(forceRefresh) .ExecuteAsync() .ConfigureAwait(false); @@ -86,10 +83,9 @@ private RetryParams HandleTokenProviderException(Exception e, int retryCount) : RetryParams.DefaultBackOff(retryCount); } - private IConfidentialClientApplication CreateClientApplication(string appId, HttpClient customHttpClient = null) + private IManagedIdentityApplication CreateClientApplication(string appId, HttpClient customHttpClient = null) { - var clientBuilder = ConfidentialClientApplicationBuilder.Create(appId) - .WithExperimentalFeatures(); + var clientBuilder = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId(appId)); if (customHttpClient != null) { diff --git a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj index 5fc5f2f36b..74e4ca28a7 100644 --- a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj +++ b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj @@ -29,7 +29,7 @@ - + diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs index 7ccab5f4e6..9915504cfe 100644 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs +++ b/tests/Microsoft.Bot.Connector.Tests/Authentication/ManagedIdentityAuthenticatorTests.cs @@ -16,8 +16,8 @@ namespace Microsoft.Bot.Connector.Tests.Authentication { public class ManagedIdentityAuthenticatorTests { - private const string TestAppId = "foo"; - private const string TestAudience = "bar"; + private readonly Func appId = (id) => $"id {id} "; + private readonly Func audience = (id) => $"audience {id} "; [Fact] public void CanGetJwtToken() @@ -37,7 +37,7 @@ public void CanGetJwtToken() .ReturnsAsync(response); var httpClient = new HttpClient(mockHttpMessageHandler.Object); - var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient); + var sut = new ManagedIdentityAuthenticator(appId(nameof(CanGetJwtToken)), audience(nameof(CanGetJwtToken)), httpClient); var token = sut.GetTokenAsync().GetAwaiter().GetResult(); Assert.Equal("at_secret", token.AccessToken); @@ -45,9 +45,9 @@ public void CanGetJwtToken() } [Theory] - [InlineData(false)] - [InlineData(true)] - public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput) + [InlineData(false, 1)] + [InlineData(true, 2)] + public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput, int index) { var response = new HttpResponseMessage(HttpStatusCode.OK); var expiresOn = DateTimeOffset.Now.ToUnixTimeSeconds() + 10000; @@ -64,7 +64,7 @@ public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput) .ReturnsAsync(response); var httpClient = new HttpClient(mockHttpMessageHandler.Object); - var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient); + var sut = new ManagedIdentityAuthenticator(appId(nameof(CanGetJwtTokenWithForceRefresh)) + index, audience(nameof(CanGetJwtTokenWithForceRefresh)) + index, httpClient); var token = sut.GetTokenAsync(forceRefreshInput).GetAwaiter().GetResult(); Assert.Equal("at_secret", token.AccessToken); @@ -86,7 +86,7 @@ public void DefaultRetryOnException() }); var httpClient = new HttpClient(mockHttpMessageHandler.Object); - var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient); + var sut = new ManagedIdentityAuthenticator(appId(nameof(DefaultRetryOnException)), audience(nameof(DefaultRetryOnException)), httpClient); try { @@ -130,7 +130,7 @@ public void CanRetryAndAcquireToken() }); var httpClient = new HttpClient(mockHttpMessageHandler.Object); - var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient); + var sut = new ManagedIdentityAuthenticator(appId(nameof(CanRetryAndAcquireToken)), audience(nameof(CanRetryAndAcquireToken)), httpClient); var token = sut.GetTokenAsync().GetAwaiter().GetResult(); Assert.Equal("at_secret", token.AccessToken); From 046725ad84ef7b522cf66b5be963002ccedfb51c Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:56:51 +0200 Subject: [PATCH 04/13] fix: [#6683] Timeout issue when using DLASE (#6696) * Add Http 202 (Accepted) for DLASE * Fix unit tests --- .../Session/StreamingSession.cs | 10 +++++++++- libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs b/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs index 6d0027e414..c691b19183 100644 --- a/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs +++ b/libraries/Microsoft.Bot.Connector.Streaming/Session/StreamingSession.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Runtime.InteropServices; using System.Text.Json; using System.Threading; @@ -91,7 +92,7 @@ public async Task SendRequestAsync(StreamingRequest request, Ca } } - return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false); + return await responseCompletionSource.Task.DefaultTimeOutAsync().ConfigureAwait(false); } public async Task SendResponseAsync(Header header, StreamingResponse response, CancellationToken cancellationToken) @@ -194,6 +195,11 @@ public virtual void ReceiveResponse(Header header, ReceiveResponse response) Log.PayloadReceived(_logger, header); + if (response.StatusCode == (int)HttpStatusCode.Accepted) + { + return; + } + lock (_receiveSync) { if (!response.Streams.Any()) @@ -358,6 +364,8 @@ private void ProcessRequest(Guid id, ReceiveRequest request) { _ = Task.Run(async () => { + // Send an HTTP 202 (Accepted) response right away, otherwise, while under high streaming load, the conversation times out due to not having a response in the request/response time frame. + await SendResponseAsync(new Header { Id = id, Type = PayloadTypes.Response }, new StreamingResponse { StatusCode = (int)HttpStatusCode.Accepted }, _connectionCancellationToken).ConfigureAwait(false); var streamingResponse = await _receiver.ProcessRequestAsync(request, null).ConfigureAwait(false); await SendResponseAsync(new Header() { Id = id, Type = PayloadTypes.Response }, streamingResponse, _connectionCancellationToken).ConfigureAwait(false); diff --git a/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs b/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs index 8ec11383b6..d18e01b511 100644 --- a/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs +++ b/libraries/Microsoft.Bot.Streaming/ProtocolAdapter.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Net; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -75,6 +76,11 @@ private async Task OnReceiveRequestAsync(Guid id, ReceiveRequest request) private async Task OnReceiveResponseAsync(Guid id, ReceiveResponse response) { + if (response.StatusCode == (int)HttpStatusCode.Accepted) + { + return; + } + // we received the response to something, signal it await _requestManager.SignalResponseAsync(id, response).ConfigureAwait(false); } From 8cc12b8b5945786e64ed768a2c557139619d473f Mon Sep 17 00:00:00 2001 From: Michal Hanzlik Date: Thu, 12 Oct 2023 15:57:34 +0200 Subject: [PATCH 05/13] Support SN+I authentication with AAD for CertificateServiceClientCredentialsFactory (#6694) Co-authored-by: Michal Hanzlik --- ...tificateServiceClientCredentialsFactory.cs | 32 ++++++++++++------- ...ateServiceClientCredentialsFactoryTests.cs | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/CertificateServiceClientCredentialsFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/CertificateServiceClientCredentialsFactory.cs index 0b52de3b27..5243ec00df 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/CertificateServiceClientCredentialsFactory.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/CertificateServiceClientCredentialsFactory.cs @@ -16,11 +16,8 @@ namespace Microsoft.Bot.Connector.Authentication /// public class CertificateServiceClientCredentialsFactory : ServiceClientCredentialsFactory { - private readonly X509Certificate2 _certificate; + private readonly CertificateAppCredentials _certificateAppCredentials; private readonly string _appId; - private readonly string _tenantId; - private readonly HttpClient _httpClient; - private readonly ILogger _logger; /// /// Initializes a new instance of the class. @@ -30,7 +27,16 @@ public class CertificateServiceClientCredentialsFactory : ServiceClientCredentia /// The oauth token tenant. /// A custom httpClient to use. /// A logger instance to use. - public CertificateServiceClientCredentialsFactory(X509Certificate2 certificate, string appId, string tenantId = null, HttpClient httpClient = null, ILogger logger = null) + /// A flag if CertificateAppCredentials should send certificate chains in the request. + /// It enables authentication with AAD using certificate subject name (not CNAME) and issuer instead of a thumbprint. + /// + public CertificateServiceClientCredentialsFactory( + X509Certificate2 certificate, + string appId, + string tenantId = null, + HttpClient httpClient = null, + ILogger logger = null, + bool sendX5c = false) : base() { if (string.IsNullOrWhiteSpace(appId)) @@ -38,11 +44,16 @@ public CertificateServiceClientCredentialsFactory(X509Certificate2 certificate, throw new ArgumentNullException(nameof(appId)); } - _certificate = certificate ?? throw new ArgumentNullException(nameof(certificate)); _appId = appId; - _tenantId = tenantId; - _httpClient = httpClient; - _logger = logger; + + // Instance must be reused otherwise it will cause throttling on AAD. + _certificateAppCredentials = new CertificateAppCredentials( + certificate ?? throw new ArgumentNullException(nameof(certificate)), + sendX5c, + appId, + tenantId, + httpClient, + logger); } /// @@ -67,8 +78,7 @@ public override Task CreateCredentialsAsync( throw new InvalidOperationException("Invalid Managed ID."); } - return Task.FromResult( - new CertificateAppCredentials(_certificate, _appId, _tenantId, _httpClient, _logger)); + return Task.FromResult(_certificateAppCredentials); } } } diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/CertificateServiceClientCredentialsFactoryTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/CertificateServiceClientCredentialsFactoryTests.cs index e1bf5ed6bc..d76a54bd3b 100644 --- a/tests/Microsoft.Bot.Connector.Tests/Authentication/CertificateServiceClientCredentialsFactoryTests.cs +++ b/tests/Microsoft.Bot.Connector.Tests/Authentication/CertificateServiceClientCredentialsFactoryTests.cs @@ -27,6 +27,7 @@ public void ConstructorTests() _ = new CertificateServiceClientCredentialsFactory(certificate.Object, TestAppId, tenantId: TestTenantId); _ = new CertificateServiceClientCredentialsFactory(certificate.Object, TestAppId, logger: logger.Object); _ = new CertificateServiceClientCredentialsFactory(certificate.Object, TestAppId, httpClient: new HttpClient()); + _ = new CertificateServiceClientCredentialsFactory(certificate.Object, TestAppId, httpClient: new HttpClient(), sendX5c: true); } [Fact] From 617394d6ff834b0804cceabff2ed9d6e06342cd4 Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:04:05 -0300 Subject: [PATCH 06/13] Add sendx5c parameter to Certificate factory class (#6699) * Add sendX5c parameter in certificate auth factory * Add unit tests * Remove commented property. * Revert changes in CertificateServiceClientCredentialsFactory --- .../Authentication/MsalAppCredentials.cs | 27 +++++ ...salServiceClientCredentialsFactoryTests.cs | 98 +++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 tests/Microsoft.Bot.Connector.Tests/Authentication/MsalServiceClientCredentialsFactoryTests.cs diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs index 63524e8194..aaa048d5f6 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs @@ -106,6 +106,33 @@ public MsalAppCredentials(string appId, X509Certificate2 certificate, string aut .Build(); } + /// + /// Initializes a new instance of the class. + /// + /// The Microsoft application id. + /// The certificate to use for authentication. + /// If true will send the public certificate to Azure AD along with the token request, so that + /// Azure AD can use it to validate the subject name based on a trusted issuer policy. + /// Optional switch for whether to validate the authority. + /// Optional authority. + /// Optional custom scope. + /// Optional . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2234:Pass system uri objects instead of strings", Justification = "Using string overload for legacy compatibility.")] + public MsalAppCredentials(string appId, X509Certificate2 certificate, bool sendX5c, string authority = null, string scope = null, bool validateAuthority = true, ILogger logger = null) + : this( + clientApplication: null, + appId: appId, + authority: authority, + scope: scope, + validateAuthority: validateAuthority, + logger: logger) + { + _clientApplication = ConfidentialClientApplicationBuilder.Create(appId) + .WithAuthority(authority ?? OAuthEndpoint, validateAuthority) + .WithCertificate(certificate, sendX5c) + .Build(); + } + async Task IAuthenticator.GetTokenAsync(bool forceRefresh) { var watch = Stopwatch.StartNew(); diff --git a/tests/Microsoft.Bot.Connector.Tests/Authentication/MsalServiceClientCredentialsFactoryTests.cs b/tests/Microsoft.Bot.Connector.Tests/Authentication/MsalServiceClientCredentialsFactoryTests.cs new file mode 100644 index 0000000000..bd89bffb04 --- /dev/null +++ b/tests/Microsoft.Bot.Connector.Tests/Authentication/MsalServiceClientCredentialsFactoryTests.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Bot.Connector.Authentication; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Microsoft.Identity.Client; +using Moq; +using Xunit; + +namespace Microsoft.Bot.Connector.Tests.Authentication +{ + public class MsalServiceClientCredentialsFactoryTests + { + private const string TestAppId = nameof(TestAppId); + private const string TestTenantId = nameof(TestTenantId); + private const string TestAudience = nameof(TestAudience); + private const string LoginEndpoint = "https://login.microsoftonline.com"; + private const string LoginEndpointGov = "https://login.microsoftonline.us/MicrosoftServices.onmicrosoft.us"; + private readonly Mock logger = new Mock(); + private readonly Mock configuration = new Mock(); + private readonly Mock clientApplication = new Mock(); + + [Fact] + public void ConstructorTests() + { + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + + Assert.NotNull(factory); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + public async Task ShouldReturnEmptyCredentialsWithoutAppId(string appId) + { + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + var credentials = await factory.CreateCredentialsAsync(appId, TestAudience, LoginEndpoint, true, CancellationToken.None); + + Assert.Equal(MsalAppCredentials.Empty, credentials); + } + + [Fact] + public void ShouldThrowIfAppIdDoesNotMatch() + { + configuration.Setup(x => x.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey).Value).Returns(TestAppId); + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + + Assert.ThrowsAsync(() => factory.CreateCredentialsAsync( + "InvalidAppId", TestAudience, LoginEndpoint, true, CancellationToken.None)); + } + + [Fact] + public void ShouldCreateCredentials() + { + configuration.Setup(x => x.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey).Value).Returns(TestAppId); + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + var credentials = factory.CreateCredentialsAsync(TestAppId, TestAudience, LoginEndpoint, true, CancellationToken.None).GetAwaiter().GetResult(); + + Assert.NotNull(credentials); + Assert.IsType(credentials); + } + + [Fact] + public void ShouldCreateCredentialsForGoverment() + { + configuration.Setup(x => x.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey).Value).Returns(TestAppId); + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + var credentials = factory.CreateCredentialsAsync(TestAppId, TestAudience, LoginEndpointGov, true, CancellationToken.None).GetAwaiter().GetResult(); + + Assert.NotNull(credentials); + Assert.IsType(credentials); + } + + [Fact] + public void IsValidAppIdTest() + { + configuration.Setup(x => x.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey).Value).Returns(TestAppId); + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + + Assert.True(factory.IsValidAppIdAsync(TestAppId, CancellationToken.None).GetAwaiter().GetResult()); + Assert.False(factory.IsValidAppIdAsync("InvalidAppId", CancellationToken.None).GetAwaiter().GetResult()); + } + + [Fact] + public void IsAuthenticationDisabledTest() + { + configuration.Setup(x => x.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey).Value).Returns(string.Empty); + var factory = new MsalServiceClientCredentialsFactory(configuration.Object, clientApplication.Object, logger.Object); + + Assert.True(factory.IsAuthenticationDisabledAsync(CancellationToken.None).GetAwaiter().GetResult()); + } + } +} From 4d64c208a6d9e58ffbd0fa43a5bb4a6a83bd50cf Mon Sep 17 00:00:00 2001 From: Alex Terentiev Date: Wed, 1 Nov 2023 12:06:55 -0400 Subject: [PATCH 07/13] SharePoint ACE Activity Handler (#6695) * SharePoint ACE Activity Handler * adding schema - wip * all components * CardViewParameters * Helper methods for card view parameters * Handle action and tests * sync with the changes from local copy * extra comment * properties instead of customProperties, sign in card view * latest changes * correct working implementation * remove SharePoint channel * updated API and comments * move action type to base class * updated comments * comment update * getting tests schema back --------- Co-authored-by: Alex Terentiev --- .../SharePoint/SharePointActivityHandler.cs | 166 ++++++++ .../Microsoft.Bot.Schema.csproj | 1 + .../SharePoint/AceData.cs | 95 +++++ .../SharePoint/AceRequest.cs | 48 +++ .../SharePoint/Actions/BaseAction.cs | 28 ++ .../SharePoint/Actions/ConfirmationDialog.cs | 39 ++ .../SharePoint/Actions/ExecuteAction.cs | 40 ++ .../SharePoint/Actions/ExternalLinkAction.cs | 35 ++ .../Actions/ExternalLinkActionParameters.cs | 38 ++ .../SharePoint/Actions/FocusParameters.cs | 66 +++ .../SharePoint/Actions/GetLocationAction.cs | 35 ++ .../Actions/GetLocationActionParameters.cs | 31 ++ .../SharePoint/Actions/IAction.cs | 19 + .../Actions/ICardActionParameters.cs | 19 + .../Actions/IOnCardSelectionAction.cs | 19 + .../SharePoint/Actions/Location.cs | 54 +++ .../SharePoint/Actions/QuickViewAction.cs | 35 ++ .../Actions/QuickViewActionParameters.cs | 31 ++ .../SharePoint/Actions/SelectMediaAction.cs | 35 ++ .../Actions/SelectMediaActionParameters.cs | 73 ++++ .../SharePoint/Actions/ShowLocationAction.cs | 35 ++ .../Actions/ShowLocationActionParameters.cs | 31 ++ .../SharePoint/Actions/SubmitAction.cs | 40 ++ .../SharePoint/BaseHandleActionResponse.cs | 53 +++ .../SharePoint/CardView/BaseCardComponent.cs | 39 ++ .../SharePoint/CardView/CardBarComponent.cs | 39 ++ .../CardView/CardButtonComponent.cs | 63 +++ .../SharePoint/CardView/CardComponentName.cs | 48 +++ .../SharePoint/CardView/CardImage.cs | 30 ++ .../CardView/CardSearchBoxButton.cs | 30 ++ .../CardView/CardSearchBoxComponent.cs | 46 ++ .../CardView/CardSearchFooterComponent.cs | 61 +++ .../SharePoint/CardView/CardTextComponent.cs | 32 ++ .../CardView/CardTextInputBaseButton.cs | 30 ++ .../CardView/CardTextInputComponent.cs | 60 +++ .../CardView/CardTextInputIconButton.cs | 23 + .../CardView/CardTextInputTitleButton.cs | 23 + .../SharePoint/CardView/CardViewParameters.cs | 392 ++++++++++++++++++ .../SharePoint/CardView/ICardButtonBase.cs | 30 ++ .../CardViewHandleActionResponse.cs | 30 ++ .../SharePoint/CardViewResponse.cs | 53 +++ .../GetPropertyPaneConfigurationResponse.cs | 57 +++ .../IPropertyPaneFieldProperties.cs | 23 + .../IPropertyPaneGroupOrConditionalGroup.cs | 23 + .../SharePoint/NoOpHandleActionResponse.cs | 34 ++ .../PropertyPaneCheckboxProperties.cs | 48 +++ .../PropertyPaneChoiceGroupIconProperties.cs | 34 ++ .../PropertyPaneChoiceGroupImageSize.cs | 41 ++ .../PropertyPaneChoiceGroupOption.cs | 84 ++++ .../PropertyPaneChoiceGroupProperties.cs | 41 ++ .../SharePoint/PropertyPaneDropDownOption.cs | 76 ++++ .../PropertyPaneDropDownProperties.cs | 83 ++++ .../SharePoint/PropertyPaneGroup.cs | 55 +++ .../SharePoint/PropertyPaneGroupField.cs | 106 +++++ .../SharePoint/PropertyPaneLabelProperties.cs | 41 ++ .../PropertyPaneLinkPopupWindowProperties.cs | 87 ++++ .../SharePoint/PropertyPaneLinkProperties.cs | 69 +++ .../SharePoint/PropertyPanePage.cs | 48 +++ .../SharePoint/PropertyPanePageHeader.cs | 34 ++ .../PropertyPaneSliderProperties.cs | 83 ++++ .../PropertyPaneTextFieldProperties.cs | 118 ++++++ .../PropertyPaneToggleProperties.cs | 90 ++++ .../SharePoint/QuickViewData.cs | 41 ++ .../QuickViewHandleActionResponse.cs | 30 ++ .../SharePoint/QuickViewResponse.cs | 71 ++++ .../SharePointActivityHandlerTests.cs | 224 ++++++++++ 66 files changed, 3736 insertions(+) create mode 100644 libraries/Microsoft.Bot.Builder/SharePoint/SharePointActivityHandler.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/AceData.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/AceRequest.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/BaseAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ConfirmationDialog.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExecuteAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/FocusParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/IAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ICardActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/IOnCardSelectionAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/Location.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationActionParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/Actions/SubmitAction.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/BaseCardComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardBarComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardButtonComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardComponentName.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardImage.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxButton.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchFooterComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputBaseButton.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputComponent.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputIconButton.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputTitleButton.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardViewParameters.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardView/ICardButtonBase.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/CardViewResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/GetPropertyPaneConfigurationResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneFieldProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneGroupOrConditionalGroup.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneCheckboxProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupIconProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupImageSize.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupOption.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownOption.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroup.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroupField.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLabelProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkPopupWindowProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePage.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePageHeader.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneSliderProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneTextFieldProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneToggleProperties.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/QuickViewData.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs create mode 100644 libraries/Microsoft.Bot.Schema/SharePoint/QuickViewResponse.cs create mode 100644 tests/Microsoft.Bot.Builder.Tests/SharePoint/SharePointActivityHandlerTests.cs diff --git a/libraries/Microsoft.Bot.Builder/SharePoint/SharePointActivityHandler.cs b/libraries/Microsoft.Bot.Builder/SharePoint/SharePointActivityHandler.cs new file mode 100644 index 0000000000..e3e9b98a21 --- /dev/null +++ b/libraries/Microsoft.Bot.Builder/SharePoint/SharePointActivityHandler.cs @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Bot.Connector; +using Microsoft.Bot.Schema; +using Microsoft.Bot.Schema.SharePoint; +using Microsoft.Bot.Schema.Teams; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Builder.SharePoint +{ + /// + /// The SharePointActivityHandler is derived from ActivityHandler. It adds support for + /// the SharePoint specific events and interactions. + /// + public class SharePointActivityHandler : ActivityHandler + { + /// + /// Invoked when an invoke activity is received from the connector. + /// Invoke activities can be used to communicate many different things. + /// + /// A strongly-typed context object for this turn. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// A task that represents the work queued to execute. + /// + /// Invoke activities communicate programmatic commands from a client or channel to a bot. + /// The meaning of an invoke activity is defined by the property, + /// which is meaningful within the scope of a channel. + /// + protected override async Task OnInvokeActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) + { + try + { + if (turnContext.Activity.Name == null) + { + throw new NotSupportedException(); + } + else + { + switch (turnContext.Activity.Name) + { + case "cardExtension/getCardView": + return CreateInvokeResponse(await OnSharePointTaskGetCardViewAsync(turnContext, SafeCast(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false)); + + case "cardExtension/getQuickView": + return CreateInvokeResponse(await OnSharePointTaskGetQuickViewAsync(turnContext, SafeCast(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false)); + + case "cardExtension/getPropertyPaneConfiguration": + return CreateInvokeResponse(await OnSharePointTaskGetPropertyPaneConfigurationAsync(turnContext, SafeCast(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false)); + + case "cardExtension/setPropertyPaneConfiguration": + BaseHandleActionResponse setPropPaneConfigResponse = await OnSharePointTaskSetPropertyPaneConfigurationAsync(turnContext, SafeCast(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false); + ValidateSetPropertyPaneConfigurationResponse(setPropPaneConfigResponse); + return CreateInvokeResponse(setPropPaneConfigResponse); + + case "cardExtension/handleAction": + return CreateInvokeResponse(await OnSharePointTaskHandleActionAsync(turnContext, SafeCast(turnContext.Activity.Value), cancellationToken).ConfigureAwait(false)); + } + } + } + catch (InvokeResponseException e) + { + return e.CreateInvokeResponse(); + } + + return await base.OnInvokeActivityAsync(turnContext, cancellationToken).ConfigureAwait(false); + } + + /// + /// Override this in a derived class to provide logic for when a card view is fetched. + /// + /// A strongly-typed context object for this turn. + /// The ACE invoke request value payload. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// A Card View Response for the request. + protected virtual Task OnSharePointTaskGetCardViewAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + throw new InvokeResponseException(HttpStatusCode.NotImplemented); + } + + /// + /// Override this in a derived class to provide logic for when a quick view is fetched. + /// + /// A strongly-typed context object for this turn. + /// The ACE invoke request value payload. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// A Quick View Response for the request. + protected virtual Task OnSharePointTaskGetQuickViewAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + throw new InvokeResponseException(HttpStatusCode.NotImplemented); + } + + /// + /// Override this in a derived class to provide logic for getting configuration pane properties. + /// + /// A strongly-typed context object for this turn. + /// The ACE invoke request value payload. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// A Property Pane Configuration Response for the request. + protected virtual Task OnSharePointTaskGetPropertyPaneConfigurationAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + throw new InvokeResponseException(HttpStatusCode.NotImplemented); + } + + /// + /// Override this in a derived class to provide logic for setting configuration pane properties. + /// + /// A strongly-typed context object for this turn. + /// The ACE invoke request value payload. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// Card view or no-op action response. + /// The handler will fail with 500 status code if the response is of type . + protected virtual Task OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + throw new InvokeResponseException(HttpStatusCode.NotImplemented); + } + + /// + /// Override this in a derived class to provide logic for handling ACE actions. + /// + /// A strongly-typed context object for this turn. + /// The ACE invoke request value payload. + /// A cancellation token that can be used by other objects + /// or threads to receive notice of cancellation. + /// A handle action response. + protected virtual Task OnSharePointTaskHandleActionAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + throw new InvokeResponseException(HttpStatusCode.NotImplemented); + } + + /// + /// Safely casts an object to an object of type . + /// + /// The object to be casted. + /// The object casted in the new type. + private static T SafeCast(object value) + { + var obj = value as JObject; + if (obj == null) + { + throw new InvokeResponseException(HttpStatusCode.BadRequest, $"expected type '{value.GetType().Name}'"); + } + + return obj.ToObject(); + } + + private void ValidateSetPropertyPaneConfigurationResponse(BaseHandleActionResponse response) + { + if (response is QuickViewHandleActionResponse) + { + throw new InvokeResponseException(HttpStatusCode.InternalServerError, "Response for SetPropertyPaneConfiguration action can't be of QuickView type."); + } + } + } +} diff --git a/libraries/Microsoft.Bot.Schema/Microsoft.Bot.Schema.csproj b/libraries/Microsoft.Bot.Schema/Microsoft.Bot.Schema.csproj index 391948ee07..4ef13581dc 100644 --- a/libraries/Microsoft.Bot.Schema/Microsoft.Bot.Schema.csproj +++ b/libraries/Microsoft.Bot.Schema/Microsoft.Bot.Schema.csproj @@ -25,6 +25,7 @@ + diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/AceData.cs b/libraries/Microsoft.Bot.Schema/SharePoint/AceData.cs new file mode 100644 index 0000000000..b5640c8951 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/AceData.cs @@ -0,0 +1,95 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint Ace Data object. + /// + public class AceData + { + /// + /// Initializes a new instance of the class. + /// + public AceData() + { + // Do nothing + } + + /// + /// This enum contains the different types of card templates available in the SPFx framework. + /// + public enum AceCardSize + { + /// + /// Medium + /// + Medium, + + /// + /// Large + /// + Large + } + + /// + /// Gets or Sets the card size of the adaptive card extension of type enum. + /// + /// This value is the size of the adaptive card extension. + [JsonProperty(PropertyName = "cardSize")] + [JsonConverter(typeof(StringEnumConverter))] + public AceCardSize CardSize { get; set; } + + /// + /// Gets or Sets the version of the data of type . + /// + /// This value is the version of the adaptive card extension. + /// Although there is no restriction on the format of this property, it is recommended to use semantic versioning. + [JsonProperty(PropertyName = "dataVersion")] + public string DataVersion { get; set; } + + /// + /// Gets or Sets the unique id (Guid) of type . + /// + /// This value is the ID of the adaptive card extension. + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + + /// + /// Gets or Sets the title of type . + /// + /// This value is the title of the adaptive card extension. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or Sets the description of type . + /// + /// This value is the description of the adaptive card extension. + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + + /// + /// Gets or Sets the icon property of type . + /// + /// This value is the icon of the adaptive card extension. + [JsonProperty(PropertyName = "iconProperty")] + public string IconProperty { get; set; } + + /// + /// Gets or Sets the property bag of type . + /// + /// This value is the property bag of the adaptive card extension. + [JsonProperty(PropertyName = "properties")] +#pragma warning disable CA2227 + public JObject Properties { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/AceRequest.cs b/libraries/Microsoft.Bot.Schema/SharePoint/AceRequest.cs new file mode 100644 index 0000000000..75230f5c90 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/AceRequest.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// ACE invoke request payload. + /// + public class AceRequest + { + /// + /// Initializes a new instance of the class. + /// + public AceRequest() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// ACE request data. + /// ACE properties data. + public AceRequest(object data = default, object properties = default) + { + Data = data; + Properties = properties; + } + + /// + /// Gets or sets user ACE request data. + /// + /// The ACE request data. + [JsonProperty(PropertyName = "data")] + public object Data { get; set; } + + /// + /// Gets or sets ACE properties data. Free payload with key-value pairs. + /// + /// ACE Properties object. + [JsonProperty(PropertyName = "properties")] + public object Properties { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/BaseAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/BaseAction.cs new file mode 100644 index 0000000000..eff1ad9b19 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/BaseAction.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Base Action. + /// + public class BaseAction + { + [JsonProperty(PropertyName = "type")] + private readonly string type; + + /// + /// Initializes a new instance of the class. + /// + /// Type of the action. + protected BaseAction(string actionType) + { + this.type = actionType; + } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ConfirmationDialog.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ConfirmationDialog.cs new file mode 100644 index 0000000000..ed311ffcae --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ConfirmationDialog.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint Confirmation Dialog object. + /// + public class ConfirmationDialog + { + /// + /// Initializes a new instance of the class. + /// + public ConfirmationDialog() + { + // Do nothing + } + + /// + /// Gets or Sets the title of type . + /// + /// This value is the title to display. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or Sets the message of type . + /// + /// This value is the message to display. + [JsonProperty(PropertyName = "message")] + public string Message { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExecuteAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExecuteAction.cs new file mode 100644 index 0000000000..664f53b4a9 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExecuteAction.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Action.Execute. + /// + public class ExecuteAction : BaseAction, IAction + { + /// + /// Initializes a new instance of the class. + /// + public ExecuteAction() + : base("Execute") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + #pragma warning disable CA2227 + public Dictionary Parameters { get; set; } + + /// + /// Gets or Sets the verb associated with this action of type . + /// + /// This value is the verb associated with the action. + [JsonProperty(PropertyName = "verb")] + public string Verb { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkAction.cs new file mode 100644 index 0000000000..85feea0325 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint external link action. + /// + public class ExternalLinkAction : BaseAction, IAction, IOnCardSelectionAction + { + /// + /// Initializes a new instance of the class. + /// + public ExternalLinkAction() + : base("ExternalLink") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + public ExternalLinkActionParameters Parameters { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkActionParameters.cs new file mode 100644 index 0000000000..a0b0851aa8 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ExternalLinkActionParameters.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint parameters for an External Link action. + /// + public class ExternalLinkActionParameters + { + /// + /// Initializes a new instance of the class. + /// + public ExternalLinkActionParameters() + { + // Do nothing + } + + /// + /// Gets or Sets a value indicating whether this is a teams deep link property of type . + /// + /// This value indicates whether this is a Teams Deep Link. + [JsonProperty(PropertyName = "isTeamsDeepLink")] + public bool IsTeamsDeepLink { get; set; } + + /// + /// Gets or Sets the target of type . + /// + /// This value is external link to navigate to. + [JsonProperty(PropertyName = "target")] + public string Target { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/FocusParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/FocusParameters.cs new file mode 100644 index 0000000000..847c14ddeb --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/FocusParameters.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint focus parameters. + /// + public class FocusParameters + { + /// + /// Initializes a new instance of the class. + /// + public FocusParameters() + { + // Do nothing + } + + /// + /// This enum contains the different types of aria live options available in the SPFx framework. + /// + public enum AriaLiveOption + { + /// + /// Polite + /// + [EnumMember(Value = "polite")] + Polite, + + /// + /// Assertive + /// + [EnumMember(Value = "assertive")] + Assertive, + + /// + /// Off + /// + [EnumMember(Value = "off")] + Off + } + + /// + /// Gets or Sets the focus target of type . + /// + /// This value is the focus target. + [JsonProperty(PropertyName = "focusTarget")] + public string FocusTarget { get; set; } + + /// + /// Gets or Sets the aria live property of type . + /// + /// This value sets the accessibility reading of the contents within the focus target. + [JsonProperty(PropertyName = "ariaLive")] + [JsonConverter(typeof(StringEnumConverter))] + public AriaLiveOption AriaLive { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationAction.cs new file mode 100644 index 0000000000..5eb12f2d35 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint get location action. + /// + public class GetLocationAction : BaseAction, IAction, IOnCardSelectionAction + { + /// + /// Initializes a new instance of the class. + /// + public GetLocationAction() + : base("VivaAction.GetLocation") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + public GetLocationActionParameters Parameters { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationActionParameters.cs new file mode 100644 index 0000000000..76193688c5 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/GetLocationActionParameters.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint parameters for a Get Location action. + /// + public class GetLocationActionParameters + { + /// + /// Initializes a new instance of the class. + /// + public GetLocationActionParameters() + { + // Do nothing + } + + /// + /// Gets or Sets a value indicating whether the location on the map can be chosen of type . + /// + /// This value indicates whether a location on the map can be chosen. + [JsonProperty(PropertyName = "chooseLocationOnMap")] + public bool ChooseLocationOnMap { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IAction.cs new file mode 100644 index 0000000000..c0bec1ae34 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IAction.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Interface for actions. + /// +#pragma warning disable CA1040 // Avoid empty interfaces + public interface IAction +#pragma warning restore CA1040 // Avoid empty interfaces + { + // This interface has no common methods. + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ICardActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ICardActionParameters.cs new file mode 100644 index 0000000000..d19327323f --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ICardActionParameters.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Interface for card action parameters. + /// +#pragma warning disable CA1040 // Avoid empty interfaces + public interface ICardActionParameters +#pragma warning restore CA1040 // Avoid empty interfaces + { + // This interface has no common methods. + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IOnCardSelectionAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IOnCardSelectionAction.cs new file mode 100644 index 0000000000..4ff488cee3 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/IOnCardSelectionAction.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Interface for action upon card selection. + /// +#pragma warning disable CA1040 // Avoid empty interfaces + public interface IOnCardSelectionAction +#pragma warning restore CA1040 // Avoid empty interfaces + { + // This interface has no common methods. + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/Location.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/Location.cs new file mode 100644 index 0000000000..2f84cbd654 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/Location.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Sharepoint Location object. + /// + public class Location + { + /// + /// Initializes a new instance of the class. + /// + public Location() + { + // Do nothing + } + + /// + /// Gets or Sets latitutde of the location of type . + /// + /// This value is the latitude of the location. + [JsonProperty(PropertyName = "latitude")] + public int Latitude { get; set; } + + /// + /// Gets or Sets longitude of the location of type . + /// + /// This value is the longitude of the location. + [JsonProperty(PropertyName = "longitude")] + public int Longitude { get; set; } + + /// + /// Gets or Sets timestamp of the location of type . + /// + /// This value is the timestamp of the location. + [JsonProperty(PropertyName = "timestamp")] + public int Timestamp { get; set; } + + /// + /// Gets or Sets accuracy of the location of type . + /// + /// This value is the accuracy of the location. + [JsonProperty(PropertyName = "accuracy")] + public int Accuracy { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewAction.cs new file mode 100644 index 0000000000..38a4b4f5c5 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint Quick View action. + /// + public class QuickViewAction : BaseAction, IAction, IOnCardSelectionAction + { + /// + /// Initializes a new instance of the class. + /// + public QuickViewAction() + : base("QuickView") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + public QuickViewActionParameters Parameters { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewActionParameters.cs new file mode 100644 index 0000000000..507685e31a --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/QuickViewActionParameters.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint parameters for an quick view action. + /// + public class QuickViewActionParameters + { + /// + /// Initializes a new instance of the class. + /// + public QuickViewActionParameters() + { + // Do nothing + } + + /// + /// Gets or Sets the quick view id to be opened as part of the action of type . + /// + /// This value is quick view id to open. + [JsonProperty(PropertyName = "view")] + public string View { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaAction.cs new file mode 100644 index 0000000000..dc45e971ec --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint select media action. + /// + public class SelectMediaAction : BaseAction, IAction, IOnCardSelectionAction + { + /// + /// Initializes a new instance of the class. + /// + public SelectMediaAction() + : base("VivaAction.SelectMedia") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + public SelectMediaActionParameters Parameters { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaActionParameters.cs new file mode 100644 index 0000000000..cb62ec013c --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SelectMediaActionParameters.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint parameters for a select media action. + /// + public class SelectMediaActionParameters + { + /// + /// Initializes a new instance of the class. + /// + public SelectMediaActionParameters() + { + // Do nothing + } + + /// + /// This enum contains the different types of media that can be selected. + /// + public enum MediaTypeOption + { + /// + /// Image + /// + Image = 1, + + /// + /// Audio + /// + Audio = 4, + + /// + /// Document + /// + Document = 8 + } + + /// + /// Gets or Sets type of media to be selected of type . + /// + /// This value is the type of media to be selected. + [JsonProperty(PropertyName = "mediaType")] + public MediaTypeOption MediaType { get; set; } + + /// + /// Gets or sets a value indicating whether the allow multiple capture property is enabled of type . + /// + /// This value indicates whether multiple files can be selected. + [JsonProperty(PropertyName = "allowMultipleCapture")] + public bool AllowMultipleCapture { get; set; } + + /// + /// Gets or Sets the max size per file selected of type . + /// + /// This value is the max size per file selected. + [JsonProperty(PropertyName = "maxSizePerFile")] + public int MaxSizePerFile { get; set; } + + /// + /// Gets or Sets the supported file formats of select media action of type . + /// + /// This value is the supported file formats of select media action. + [JsonProperty(PropertyName = "supportedFileFormats")] + public IEnumerable SupportedFileFormats { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationAction.cs new file mode 100644 index 0000000000..72b6d9afc6 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationAction.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint show location action. + /// + public class ShowLocationAction : BaseAction, IAction, IOnCardSelectionAction + { + /// + /// Initializes a new instance of the class. + /// + public ShowLocationAction() + : base("VivaAction.ShowLocation") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + public ShowLocationActionParameters Parameters { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationActionParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationActionParameters.cs new file mode 100644 index 0000000000..cf695d43e0 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/ShowLocationActionParameters.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint parameters for a show location action. + /// + public class ShowLocationActionParameters + { + /// + /// Initializes a new instance of the class. + /// + public ShowLocationActionParameters() + { + // Do nothing + } + + /// + /// Gets or Sets the location coordinates of type . + /// + /// This value is the location to be shown. + [JsonProperty(PropertyName = "locationCoordinates")] + public Location LocationCoordinates { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SubmitAction.cs b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SubmitAction.cs new file mode 100644 index 0000000000..bbd34cc78d --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/Actions/SubmitAction.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Action.Submit. + /// + public class SubmitAction : BaseAction, IAction + { + /// + /// Initializes a new instance of the class. + /// + public SubmitAction() + : base("Submit") + { + // Do nothing + } + + /// + /// Gets or Sets the action parameters of type . + /// + /// This value is the parameters of the action. + [JsonProperty(PropertyName = "parameters")] + #pragma warning disable CA2227 + public Dictionary Parameters { get; set; } + + /// + /// Gets or Sets confirmation dialog associated with this action of type . + /// + /// This value is the confirmation dialog associated with this action. + [JsonProperty(PropertyName = "confirmationDialog")] + public ConfirmationDialog ConfirmationDialog { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs new file mode 100644 index 0000000000..1be7543313 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension View response type. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum ViewResponseType + { + /// + /// Render card view. + /// + Card, + + /// + /// Render quick view. + /// + QuickView, + + /// + /// No operation. + /// + NoOp + } + + /// + /// Response returned when handling a client-side action on an Adaptive Card Extension. + /// + public abstract class BaseHandleActionResponse + { + /// + /// Gets the response type. + /// + /// Response type. + [JsonProperty(PropertyName = "responseType")] + public abstract ViewResponseType ResponseType { get; } + + /// + /// Gets or sets render arguments. + /// + /// Render arguments. + [JsonProperty(PropertyName = "renderArguments")] + public object RenderArguments { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/BaseCardComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/BaseCardComponent.cs new file mode 100644 index 0000000000..2f71901d2a --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/BaseCardComponent.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Base class for Adaptive Card Extensions card view components. + /// + public class BaseCardComponent + { + /// + /// Component name. + /// + [JsonProperty(PropertyName = "componentName")] + private readonly CardComponentName cardComponentName; + + /// + /// Initializes a new instance of the class. + /// + /// Component name. + protected BaseCardComponent(CardComponentName cardComponentName) + { + this.cardComponentName = cardComponentName; + } + + /// + /// Gets or sets optional unique identifier of the component's instance. + /// + /// The value is a unique string identifier of the component. + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardBarComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardBarComponent.cs new file mode 100644 index 0000000000..4cc5d2254b --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardBarComponent.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension card bar component. + /// + public class CardBarComponent : BaseCardComponent + { + /// + /// Initializes a new instance of the class. + /// + public CardBarComponent() + : base(CardComponentName.CardBar) + { + } + + /// + /// Gets or sets the title to display. + /// + /// Title value to display in the card bar. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or sets the icon to display. + /// + /// Icon to display in the card bar. + [JsonProperty(PropertyName = "icon")] + public CardImage Icon { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardButtonComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardButtonComponent.cs new file mode 100644 index 0000000000..c4f4e78311 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardButtonComponent.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Names of the supported Adaptive Card Extension Card View button styles. + /// + [JsonConverter(typeof(StringEnumConverter), /*camelCase*/ true)] + public enum CardButtonStyle + { + /// + /// Default style. + /// + Default, + + /// + /// Positive (primary) style. + /// + Positive + } + + /// + /// Adaptive Card Extension card button component. + /// + public class CardButtonComponent : BaseCardComponent, ICardButtonBase + { + /// + /// Initializes a new instance of the class. + /// + public CardButtonComponent() + : base(CardComponentName.CardButton) + { + } + + /// + /// Gets or sets the button's action. + /// + /// Button's action. + [JsonProperty(PropertyName = "action")] + public IAction Action { get; set; } + + /// + /// Gets or sets the text to display. + /// + /// Text value to display in the card button. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or sets the style of the button. + /// + /// Style of the button. + [JsonProperty(PropertyName = "style")] + public CardButtonStyle Style { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardComponentName.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardComponentName.cs new file mode 100644 index 0000000000..0b3b399e02 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardComponentName.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Names of the supported Adaptive Card Extension Card View Components. + /// + [JsonConverter(typeof(StringEnumConverter), /*camelCase*/ true)] + public enum CardComponentName + { + /// + /// Text component. + /// + Text, + + /// + /// Card button component. + /// + CardButton, + + /// + /// Card bar component. + /// + CardBar, + + /// + /// Text input component. + /// + TextInput, + + /// + /// Search box component. + /// + SearchBox, + + /// + /// Search footer component. + /// + SearchFooter + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardImage.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardImage.cs new file mode 100644 index 0000000000..d1d43832a7 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardImage.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Properties for the image rendered in a card view. + /// + public class CardImage + { + /// + /// Gets or sets the URL to display as image or icon name. + /// + /// image URL or icon name. + [JsonProperty(PropertyName = "url")] + public string Image { get; set; } + + /// + /// Gets or sets the alt text for the image. + /// + /// Alt text for the image. + [JsonProperty(PropertyName = "altText")] + public string AltText { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxButton.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxButton.cs new file mode 100644 index 0000000000..1fa53a5a1e --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxButton.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Card Search box button. + /// + public class CardSearchBoxButton : ICardButtonBase + { + /// + /// Gets or sets the button's action. + /// + /// Button's action. + [JsonProperty(PropertyName = "action")] + public IAction Action { get; set; } + + /// + /// Gets or sets unique Id of the button. + /// + /// Unique Id of the button. + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxComponent.cs new file mode 100644 index 0000000000..c8963b4685 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchBoxComponent.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension search box component. + /// + public class CardSearchBoxComponent : BaseCardComponent + { + /// + /// Initializes a new instance of the class. + /// + public CardSearchBoxComponent() + : base(CardComponentName.SearchBox) + { + } + + /// + /// Gets or sets the placeholder text to display in the sarch box. + /// + /// Placeholder text to display. + [JsonProperty(PropertyName = "placeholder")] + public string Placeholder { get; set; } + + /// + /// Gets or sets the default text value of the search box. + /// + /// Default value to display in the search box. + [JsonProperty(PropertyName = "defaultValue")] + public string DefaultValue { get; set; } + + /// + /// Gets or sets the search box's button configuration. + /// + /// Searh box's button configuration. + [JsonProperty(PropertyName = "button")] + public CardSearchBoxButton Button { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchFooterComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchFooterComponent.cs new file mode 100644 index 0000000000..04b673b560 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardSearchFooterComponent.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension search footer component. + /// + public class CardSearchFooterComponent : BaseCardComponent + { + /// + /// Initializes a new instance of the class. + /// + public CardSearchFooterComponent() + : base(CardComponentName.SearchFooter) + { + // this.ComponentName = CardComponentName.SearchFooter; + } + + /// + /// Gets or sets the title to display. + /// + /// Title value to display in the search footer. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or sets url to the image to use, should be a square aspect ratio and big enough to fit in the image area. + /// + /// Image Url to display in the footer. + [JsonProperty(PropertyName = "imageUrl")] + public Uri ImageUrl { get; set; } + + /// + /// Gets or sets the initials to display in the image area when there is no image. + /// + /// Initials to display in the image area when there is no image. + [JsonProperty(PropertyName = "imageInitials")] + public string ImageInitials { get; set; } + + /// + /// Gets or sets the primary text to display. For example, name of the person for people search. + /// + /// Primary text to display. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + + /// + /// Gets or sets action to invoke when the footer is selected. + /// + /// Selection action. + [JsonProperty(PropertyName = "onSelection")] + public IAction OnSelection { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextComponent.cs new file mode 100644 index 0000000000..29544f10e2 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextComponent.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension card text component. + /// + public class CardTextComponent : BaseCardComponent + { + /// + /// Initializes a new instance of the class. + /// + public CardTextComponent() + : base(CardComponentName.Text) + { + } + + /// + /// Gets or sets the text to display. + /// + /// Text to display. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputBaseButton.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputBaseButton.cs new file mode 100644 index 0000000000..0511e72b19 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputBaseButton.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Base Card text input button class. + /// + public class CardTextInputBaseButton : ICardButtonBase + { + /// + /// Gets or sets the button's action. + /// + /// Button's action. + [JsonProperty(PropertyName = "action")] + public IAction Action { get; set; } + + /// + /// Gets or sets unique Id of the button. + /// + /// Unique Id of the button. + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputComponent.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputComponent.cs new file mode 100644 index 0000000000..7c78146405 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputComponent.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension text input component. + /// + public class CardTextInputComponent : BaseCardComponent + { + /// + /// Initializes a new instance of the class. + /// + public CardTextInputComponent() + : base(CardComponentName.TextInput) + { + } + + /// + /// Gets or sets the placeholder text to display in the text input. + /// + /// Placeholder text to display. + [JsonProperty(PropertyName = "placeholder")] + public string Placeholder { get; set; } + + /// + /// Gets or sets the default text value of the text input. + /// + /// Default value to display in the text input. + [JsonProperty(PropertyName = "defaultValue")] + public string DefaultValue { get; set; } + + /// + /// Gets or sets the text input's button configuration. + /// + /// Text input's button configuration. + [JsonProperty(PropertyName = "button")] + public CardTextInputBaseButton Button { get; set; } + + /// + /// Gets or sets properties for an optional icon, displayed in the left end of the text input. + /// + /// Properties for an optional icon. + [JsonProperty(PropertyName = "iconBefore")] + public CardImage IconBefore { get; set; } + + /// + /// Gets or sets properties for an optional icon, displayed in the right end of the text input. + /// + /// Properties for an optional icon. + [JsonProperty(PropertyName = "iconAfter")] + public CardImage IconAfter { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputIconButton.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputIconButton.cs new file mode 100644 index 0000000000..e283c08ca5 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputIconButton.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Card text input button with icon. + /// + public class CardTextInputIconButton : CardTextInputBaseButton + { + /// + /// Gets or sets the icon to display. + /// + /// Icon to display in the button. + [JsonProperty(PropertyName = "icon")] + public CardImage Icon { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputTitleButton.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputTitleButton.cs new file mode 100644 index 0000000000..46c1eed9b4 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardTextInputTitleButton.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Card text input button with text. + /// + public class CardTextInputTitleButton : CardTextInputBaseButton + { + /// + /// Gets or sets the text to display. + /// + /// Text value to display in the button. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardViewParameters.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardViewParameters.cs new file mode 100644 index 0000000000..a29b51cc0e --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/CardViewParameters.cs @@ -0,0 +1,392 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension Card View Parameters. + /// + public class CardViewParameters + { + /// + /// Initializes a new instance of the class. + /// + protected CardViewParameters() + { + } + + /// + /// Gets or sets card view type. + /// + /// Card view type. + [JsonProperty(PropertyName = "cardViewType")] + public string CardViewType { get; set; } + + /// + /// Gets or sets image displayed on the card. + /// + /// Image displayed on the card. + [JsonProperty(PropertyName = "image")] + public CardImage Image { get; set; } + + /// + /// Gets or sets card view title area (card bar) components. + /// + /// Card bar area components. + [JsonProperty(PropertyName = "cardBar")] +#pragma warning disable CA2227 + public IList CardBar { get; set; } +#pragma warning restore CA2227 + + /// + /// Gets or sets card view header area components. + /// + /// Card header area components. + [JsonProperty(PropertyName = "header")] + public IEnumerable Header { get; set; } + + /// + /// Gets or sets card view body area components. + /// + /// Card body area components. + [JsonProperty(PropertyName = "body")] + public IEnumerable Body { get; set; } + + /// + /// Gets or sets card footer area components. + /// + /// Card footer area components. + [JsonProperty(PropertyName = "footer")] + public IEnumerable Footer { get; set; } + + /// + /// Helper method to create a Basic Text Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Up to two buttons or text input to display as footer. + /// Card view configuration. + /// The Basic Text card view displays the following: + /// - Card bar + /// - One primary text field + /// - Zero or one button in the Medium card size, up to two buttons in Large card size; or text input. + /// + public static CardViewParameters BasicCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + IList footer) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + ValidateGenericCardViewFooterConfiguration(footer); + + return new CardViewParameters() + { + CardViewType = "text", + CardBar = new List { cardBar }, + Header = new List { header }, + Footer = footer + }; + } + + /// + /// Helper method to create a Primary Text Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Text component to display as body. + /// Up to two buttons or text input to display as footer. + /// Card view configuration. + /// The Primary Text card view displays the following: + /// - Card bar + /// - One primary text field + /// - One description text field + /// - Zero or one button in the Medium card size, up to two buttons in Large card size; or text input. + /// + public static CardViewParameters PrimaryTextCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + CardTextComponent body, + IList footer) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + if (body == null) + { + throw new ArgumentNullException(nameof(header)); + } + + ValidateGenericCardViewFooterConfiguration(footer); + + return new CardViewParameters() + { + CardViewType = "text", + CardBar = new List { cardBar }, + Header = new List { header }, + Body = new List { body }, + Footer = footer + }; + } + + /// + /// Helper method to create an Image Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Up to two buttons or text input to display as footer. + /// Image to display. + /// Card view configuration. + /// The Image Card view displays the following: + /// - Card bar + /// - One primary text field + /// - One image + /// - Zero buttons in the Medium card size, up to two buttons in Large card size; or text input. + /// + public static CardViewParameters ImageCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + IList footer, + CardImage image) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + if (image == null) + { + throw new ArgumentNullException(nameof(image)); + } + + ValidateGenericCardViewFooterConfiguration(footer); + + return new CardViewParameters() + { + CardViewType = "text", + CardBar = new List { cardBar }, + Header = new List { header }, + Image = image, + Footer = footer + }; + } + + /// + /// Helper method to create a Text Input Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Text input component to display as body. + /// Up to two buttons to display as footer. + /// Optional image to display. + /// Card view configuration. + /// /// The Text Input Card view displays the following: + /// - Card bar + /// - One primary text field + /// - Zero or one image + /// - Zero text input in Medium card size if image is presented, one text input in Medium card size if no image is presented, one text input in Large card size + /// - Zero buttons in the Medium card size if image is presented, one button in Medium card size if no image is presented, up to two buttons in Large card size; or text input. + /// + public static CardViewParameters TextInputCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + CardTextInputComponent body, + IList footer, + CardImage image) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + if (footer.Count > 2) + { + throw new ArgumentException("Card view footer must contain up to two buttons.", nameof(footer)); + } + + return new CardViewParameters() + { + CardViewType = "textInput", + CardBar = new List { cardBar }, + Header = new List { header }, + Body = new List { body }, + Image = image, + Footer = footer + }; + } + + /// + /// Helper method to create a Search Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Search box to display as body. + /// Search footer component to display as footer. + /// Card view configuration. + /// /// The Search Card view displays the following: + /// - Card bar + /// - One primary text field + /// - One search box + /// - One search box footer. + /// + public static CardViewParameters SearchCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + CardSearchBoxComponent body, + CardSearchFooterComponent footer) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + if (footer == null) + { + throw new ArgumentNullException(nameof(footer)); + } + + return new CardViewParameters() + { + CardViewType = "search", + CardBar = new List { cardBar }, + Header = new List { header }, + Body = new List { body }, + Footer = new List { footer } + }; + } + + /// + /// Helper method to create a Sign In Card View. + /// + /// Card bar component. + /// Text component to display as header. + /// Text component to display as body. + /// Complete Sign in button. + /// Card view configuration. + public static CardViewParameters SignInCardViewParameters( + CardBarComponent cardBar, + CardTextComponent header, + CardTextComponent body, + CardButtonComponent footer) + { + // Validate parameters + if (cardBar == null) + { + throw new ArgumentNullException(nameof(cardBar)); + } + + if (header == null) + { + throw new ArgumentNullException(nameof(header)); + } + + if (body == null) + { + throw new ArgumentNullException(nameof(body)); + } + + if (footer == null) + { + throw new ArgumentNullException(nameof(footer)); + } + + return new CardViewParameters() + { + CardViewType = "signIn", + CardBar = new List { cardBar }, + Header = new List { header }, + Body = new List { body }, + Footer = new List { footer } + }; + } + + private static void ValidateGenericCardViewFooterConfiguration(IList footer) + { + if (footer == null) + { + // footer can be empty + return; + } + + int componentsCount = footer.Count; + + bool hasError; + + if (componentsCount == 0) + { + return; + } + else if (componentsCount > 2) + { + // we don't support more than 2 components in the footer. + hasError = true; + } + else if (componentsCount == 2) + { + // both components should be buttons. + hasError = !(footer[0] is CardButtonComponent) || !(footer[1] is CardButtonComponent); + } + else + { + // single component should be either a button or a text input + hasError = !(footer[0] is CardButtonComponent) && !(footer[0] is CardTextInputComponent); + } + + if (hasError) + { + throw new ArgumentException("Card view footer must contain up to two buttons or text input", nameof(footer)); + } + } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardView/ICardButtonBase.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/ICardButtonBase.cs new file mode 100644 index 0000000000..9cb8f88f0c --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardView/ICardButtonBase.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Base properties for the buttons used in Adaptive Card Extensions card view components. + /// + public interface ICardButtonBase + { + /// + /// Gets or sets the button's action. + /// + /// Button's action. + [JsonProperty(PropertyName = "action")] + public IAction Action { get; set; } + + /// + /// Gets or sets unique Id of the button. + /// + /// Unique Id of the button. + [JsonProperty(PropertyName = "id")] + public string Id { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs new file mode 100644 index 0000000000..aa4558cbb1 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension Client-side action response to render card view. + /// + public class CardViewHandleActionResponse : BaseHandleActionResponse + { + /// + /// Gets the response type. + /// + /// Card. + [JsonProperty(PropertyName = "responseType")] + public override ViewResponseType ResponseType => ViewResponseType.Card; + + /// + /// Gets or sets card view render arguments. + /// + /// Card view render arguments. + [JsonProperty(PropertyName = "renderArguments")] + public new CardViewResponse RenderArguments { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardViewResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewResponse.cs new file mode 100644 index 0000000000..4a1907bf62 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewResponse.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint Card View Data object. + /// + public class CardViewResponse + { + /// + /// Initializes a new instance of the class. + /// + public CardViewResponse() + { + // Do nothing + } + + /// + /// Gets or Sets AceData for the card view of type . + /// + /// This value is the ace data of the card view response. + [JsonProperty(PropertyName = "aceData")] + public AceData AceData { get; set; } + + /// + /// Gets or sets the card view configuration. + /// + /// Card view configuration. + [JsonProperty(PropertyName = "cardViewParameters")] + public CardViewParameters CardViewParameters { get; set; } + + /// + /// Gets or sets action to invoke when the card is selected. + /// + /// Action to invoke. + [JsonProperty(PropertyName = "onCardSelection")] + public IOnCardSelectionAction OnCardSelection { get; set; } + + /// + /// Gets or Sets the view Id of type . + /// + /// This value is the view id of the card view. + [JsonProperty(PropertyName = "viewId")] + public string ViewId { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/GetPropertyPaneConfigurationResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/GetPropertyPaneConfigurationResponse.cs new file mode 100644 index 0000000000..3a76f020c7 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/GetPropertyPaneConfigurationResponse.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using AdaptiveCards; +using Microsoft.Bot.Schema.Teams; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint GetPropertyPaneConfiguration response object. + /// + public class GetPropertyPaneConfigurationResponse + { + /// + /// Initializes a new instance of the class. + /// + public GetPropertyPaneConfigurationResponse() + { + // Do nothing + } + + /// + /// Gets or Sets the pages of type . + /// + /// This value is the pages of the property pane. + [JsonProperty(PropertyName = "pages")] + public IEnumerable Pages { get; set; } + + /// + /// Gets or Sets the current page of type . + /// + /// This value is the current page of the property pane. + [JsonProperty(PropertyName = "currentPage")] + public int CurrentPage { get; set; } + + /// + /// Gets or Sets the loading indicator delay time of type . + /// + /// This value is the loading indicator delay time of the property pane. + [JsonProperty(PropertyName = "loadingIndicatorDelayTime")] + public int LoadingIndicatorDelayTime { get; set; } + + /// + /// Gets or Sets a value indicating whether the loading indicator should be displayed on top of the property pane or not of type . + /// + /// This value sets whether the loading indicator is shown for the property pane. + [JsonProperty(PropertyName = "showLoadingIndicator")] + public bool ShowLoadingIndicator { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneFieldProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneFieldProperties.cs new file mode 100644 index 0000000000..2e894f589f --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneFieldProperties.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Interface for property pane field properties. + /// +#pragma warning disable CA1040 // Avoid empty interfaces + public interface IPropertyPaneFieldProperties +#pragma warning restore CA1040 // Avoid empty interfaces + { + // This interface has no common methods. + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneGroupOrConditionalGroup.cs b/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneGroupOrConditionalGroup.cs new file mode 100644 index 0000000000..b4b3619d07 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/IPropertyPaneGroupOrConditionalGroup.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Interface for property pane group or conditional group. + /// +#pragma warning disable CA1040 // Avoid empty interfaces + public interface IPropertyPaneGroupOrConditionalGroup +#pragma warning restore CA1040 // Avoid empty interfaces + { + // This interface has no common methods. + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs new file mode 100644 index 0000000000..214036414f --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension Client-side action no-op response. + /// + public class NoOpHandleActionResponse : BaseHandleActionResponse + { + /// + /// Gets the response type. + /// + /// Card. + [JsonProperty(PropertyName = "responseType")] + public override ViewResponseType ResponseType => ViewResponseType.NoOp; + + /// + /// Gets or sets card view render arguments. + /// + /// Card view render arguments. + [JsonProperty(PropertyName = "renderArguments")] + public new object RenderArguments + { + get => null; + set { } + } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneCheckboxProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneCheckboxProperties.cs new file mode 100644 index 0000000000..d394f06304 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneCheckboxProperties.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane checkbox properties object. + /// + public class PropertyPaneCheckboxProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneCheckboxProperties() + { + // Do nothing + } + + /// + /// Gets or Sets the label to display next to the checkbox of type . + /// + /// This value is the text of the checkbox property. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates if the control is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets a value indicating whether the property pane checkbox is checked or not of type . + /// + /// This value indicates if the control is checked. + [JsonProperty(PropertyName = "checked")] + public bool Checked { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupIconProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupIconProperties.cs new file mode 100644 index 0000000000..c8f4522c86 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupIconProperties.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane choice group icon properties object. + /// + public class PropertyPaneChoiceGroupIconProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneChoiceGroupIconProperties() + { + // Do nothing + } + + /// + /// Gets or Sets the name of the icon to use from the Office Fabric icon set of type . + /// + /// This value is the office fabric icon font name of the choice group. + [JsonProperty(PropertyName = "officeFabricIconFontName")] + public string OfficeFabricIconFontName { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupImageSize.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupImageSize.cs new file mode 100644 index 0000000000..2dcc4cca8a --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupImageSize.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane choice group image size object. + /// + public class PropertyPaneChoiceGroupImageSize + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneChoiceGroupImageSize() + { + // Do nothing + } + + /// + /// Gets or Sets the width of the image of type . + /// + /// This value is the width of the choice group. + [JsonProperty(PropertyName = "width")] + public int Width { get; set; } + + /// + /// Gets or Sets the height of the image of type . + /// + /// This value is the height of the choice group. + [JsonProperty(PropertyName = "height")] + public int Height { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupOption.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupOption.cs new file mode 100644 index 0000000000..547723654f --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupOption.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using static Microsoft.Bot.Schema.SharePoint.PropertyPaneDropDownOption; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane choice group option object. + /// + public class PropertyPaneChoiceGroupOption + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneChoiceGroupOption() + { + // Do nothing + } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the choice group. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets a value indicating whether the property pane choice group option is checked or not of type . + /// + /// This value indicates whether the control is checked. + [JsonProperty(PropertyName = "checked")] + public bool Checked { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the control is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets the Icon component props for choice field of type . + /// + /// This value is the icon properties of the choice group. + [JsonProperty(PropertyName = "iconProps")] + public PropertyPaneChoiceGroupIconProperties IconProps { get; set; } + + /// + /// Gets or Sets the width and height of the image in px for choice field of type . + /// + /// This value is the image size of the choice group. + [JsonProperty(PropertyName = "imageSize")] + public PropertyPaneChoiceGroupImageSize ImageSize { get; set; } + + /// + /// Gets or Sets the src of image for choice field of type . + /// + /// This value is the image source of the choice group. + [JsonProperty(PropertyName = "imageSrc")] + public string ImageSrc { get; set; } + + /// + /// Gets or Sets a key to uniquely identify this option of type . + /// + /// This value is the key of the choice group. + [JsonProperty(PropertyName = "key")] + public string Key { get; set; } + + /// + /// Gets or Sets text to render for this option of type . + /// + /// This value is the text of the choice group. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupProperties.cs new file mode 100644 index 0000000000..77d433a7a4 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneChoiceGroupProperties.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane choice group properties object. + /// + public class PropertyPaneChoiceGroupProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneChoiceGroupProperties() + { + // Do nothing + } + + /// + /// Gets or Sets the label of type . + /// + /// This value is the label of the choice group. + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } + + /// + /// Gets or Sets the collection of options for this choice group of type . + /// + /// This value is the icon properties of the choice group. + [JsonProperty(PropertyName = "options")] + public IEnumerable Options { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownOption.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownOption.cs new file mode 100644 index 0000000000..60440e7fac --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownOption.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane drop down option object. + /// + public class PropertyPaneDropDownOption + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneDropDownOption() + { + // Do nothing + } + + /// + /// This enum contains the different types of fields. + /// + public enum DropDownOptionType + { + /// + /// Render normal menu item. + /// + Normal = 0, + + /// + /// Render a divider. + /// + Divider = 1, + + /// + /// Render menu item as a header. + /// + Header = 2 + } + + /// + /// Gets or Sets index for this option of type . + /// + /// This value is the index of the drop down. + [JsonProperty(PropertyName = "index")] + public int Index { get; set; } + + /// + /// Gets or Sets a key to uniquely identify this option of type . + /// + /// This value is the key of the drop down. + [JsonProperty(PropertyName = "key")] + public string Key { get; set; } + + /// + /// Gets or Sets text to render for this option of type . + /// + /// This value is the text of the drop down. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + + /// + /// Gets or Sets the type of option. If omitted, the default is PropertyPaneDropdownMenuItemType.Normal of type . + /// + /// This value is the type of the drop down. + [JsonProperty(PropertyName = "type")] + public DropDownOptionType Type { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownProperties.cs new file mode 100644 index 0000000000..08f0d92ee4 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneDropDownProperties.cs @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane drop down properties object. + /// + public class PropertyPaneDropDownProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneDropDownProperties() + { + // Do nothing + } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the drop down. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets an element's number or position in the current set of controls. Maps to native aria-positionset attribute. It starts from 1 of type . + /// + /// This value is the aria position in set of the drop down. + [JsonProperty(PropertyName = "ariaPositionInSet")] + public int AriaPositionInSet { get; set; } + + /// + /// Gets or Sets the number of items in the current set of controls. Maps to native aria-setsize attribute of type . + /// + /// This value is the aria set size of the drop down. + [JsonProperty(PropertyName = "ariaSetSize")] + public int AriaSetSize { get; set; } + + /// + /// Gets or Sets the label of type . + /// + /// This value is the label of the drop down. + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the property is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets the error message of type . + /// + /// This value is the error message of the drop down. + [JsonProperty(PropertyName = "errorMessage")] + public string ErrorMessage { get; set; } + + /// + /// Gets or Sets the key of the initially selected option of type . + /// + /// This value is the selected key of the drop down. + [JsonProperty(PropertyName = "selectedKey")] + public string SelectedKey { get; set; } + + /// + /// Gets or Sets the collection of options for this Dropdown of type . + /// + /// This value is the options of the drop down. + [JsonProperty(PropertyName = "options")] + public IEnumerable Options { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroup.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroup.cs new file mode 100644 index 0000000000..f59f10c4b6 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroup.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane group object. + /// + public class PropertyPaneGroup : IPropertyPaneGroupOrConditionalGroup + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneGroup() + { + // Do nothing + } + + /// + /// Gets or Sets the group fields of type . + /// + /// This value is the group fields of the property pane group. + [JsonProperty(PropertyName = "groupFields")] + public IEnumerable GroupFields { get; set; } + + /// + /// Gets or Sets the group name of type . + /// + /// This value is the group name of the property pane group. + [JsonProperty(PropertyName = "groupName")] + public string GroupName { get; set; } + + /// + /// Gets or Sets a value indicating whether the PropertyPane group is collapsed or not of type . + /// + /// This value indicates whether the property pane group is collapsed. + [JsonProperty(PropertyName = "isCollapsed")] + public bool IsCollapsed { get; set; } + + /// + /// Gets or Sets a value indicating whether group name should be hidden of type . + /// + /// This value indicates whether the property pane group is hidden. + [JsonProperty(PropertyName = "isGroupNameHidden")] + public bool IsGroupNameHidden { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroupField.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroupField.cs new file mode 100644 index 0000000000..b05e5eb98a --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneGroupField.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane group field object. + /// + public class PropertyPaneGroupField + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneGroupField() + { + // Do nothing + } + + /// + /// This enum contains the different types of fields. + /// + public enum FieldType + { + /// + /// Checkbox field. + /// + CheckBox = 2, + + /// + /// TextField field. + /// + TextField = 3, + + /// + /// Toggle field. + /// + Toggle = 5, + + /// + /// Dropdown field. + /// + Dropdown = 6, + + /// + /// Label field. + /// + Label = 7, + + /// + /// Slider field. + /// + Slider = 8, + + /// + /// ChoiceGroup field. + /// + ChoiceGroup = 10, + + /// + /// Horizontal Rule field. + /// + HorizontalRule = 12, + + /// + /// Link field. + /// + Link = 13 + } + + /// + /// Gets or Sets the type of field enum. + /// + /// This value is the type of the property pane field. + [JsonProperty(PropertyName = "type")] + public FieldType Type { get; set; } + + /// + /// Gets or Sets the properties property of type . + /// + /// This value is the properties of the property pane field. + [JsonProperty(PropertyName = "properties")] + public IPropertyPaneFieldProperties Properties { get; set; } + + /// + /// Gets or Sets a value indicating whether this control should be focused of type . + /// + /// This value indicates whether the property pane field should focus. + [JsonProperty(PropertyName = "shouldFocus")] + public bool ShouldFocus { get; set; } + + /// + /// Gets or Sets the target property of type . + /// + /// This value is the target property of the property pane field. + [JsonProperty(PropertyName = "targetProperty")] + public string TargetProperty { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLabelProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLabelProperties.cs new file mode 100644 index 0000000000..b27aa7159b --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLabelProperties.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane label properties object. + /// + public class PropertyPaneLabelProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneLabelProperties() + { + // Do nothing + } + + /// + /// Gets or Sets the display text for the label of type . + /// + /// This value is the text of the property pane label. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + + /// + /// Gets or Sets a value indicating whether the associated form field is required or not. of type . + /// + /// This value indicates whether the property pane field is required. + [JsonProperty(PropertyName = "required")] + public bool Required { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkPopupWindowProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkPopupWindowProperties.cs new file mode 100644 index 0000000000..9e364592be --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkPopupWindowProperties.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using static Microsoft.Bot.Schema.SharePoint.PropertyPaneGroupField; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane link popup window properties object. + /// + public class PropertyPaneLinkPopupWindowProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneLinkPopupWindowProperties() + { + // Do nothing + } + + /// + /// This enum contains the different types of fields. + /// + public enum PopupWindowPosition + { + /// + /// Center. + /// + Center = 0, + + /// + /// Right Top. + /// + RightTop = 1, + + /// + /// Left Top . + /// + LeftTop = 2, + + /// + /// Right Bottom. + /// + RightBottom = 3, + + /// + /// Left Bottom. + /// + LeftBottom = 4, + } + + /// + /// Gets or Sets the height of the pop up window of type . + /// + /// This value is the height of the property pane popup. + [JsonProperty(PropertyName = "height")] + public int Height { get; set; } + + /// + /// Gets or Sets the position of pop up window enum. + /// + /// This value is the window position of the property pane popup. + [JsonProperty(PropertyName = "positionWindowPosition")] + public PopupWindowPosition PositionWindowPosition { get; set; } + + /// + /// Gets or Sets the title of pop up window of type . + /// + /// This value is the title of the property pane popup. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or Sets the width of the pop up window of type . + /// + /// This value is the width of the property pane popup. + [JsonProperty(PropertyName = "width")] + public int Width { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkProperties.cs new file mode 100644 index 0000000000..6927373c4c --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneLinkProperties.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane link properties object. + /// + public class PropertyPaneLinkProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneLinkProperties() + { + // Do nothing + } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the property pane link. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the property pane link is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets the location to which the link is targeted to of type . + /// + /// This value is the href of the property pane link. + [JsonProperty(PropertyName = "href")] + public string Href { get; set; } + + /// + /// Gets or Sets the props of popup window. of type . + /// + /// This value is the popup window properties of the property pane link. + [JsonProperty(PropertyName = "popupWindowProps")] + public PropertyPaneLinkPopupWindowProperties PopupWindowProps { get; set; } + + /// + /// Gets or Sets where to display the linked resource of type . + /// + /// This value is the target of the property pane link. + [JsonProperty(PropertyName = "target")] + public string Target { get; set; } + + /// + /// Gets or Sets the display text for the link of type . + /// + /// This value is the text of the property pane link. + [JsonProperty(PropertyName = "text")] + public string Text { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePage.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePage.cs new file mode 100644 index 0000000000..1a9ae76a43 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePage.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane page object. + /// + public class PropertyPanePage + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPanePage() + { + // Do nothing + } + + /// + /// Gets or Sets the groups of type . + /// + /// This value is the groups of the property pane page. + [JsonProperty(PropertyName = "groups")] + public IEnumerable Groups { get; set; } + + /// + /// Gets or Sets a value indicating whether the groups on the PropertyPanePage are displayed as accordion or not of type . + /// + /// This value indicates whether the property pane page is displayed as an accordion. + [JsonProperty(PropertyName = "displayGroupsAsAccordion")] + public bool DisplayGroupsAsAccordion { get; set; } + + /// + /// Gets or Sets the header for the property pane of type . + /// + /// This value is the header of the property pane page. + [JsonProperty(PropertyName = "header")] + public PropertyPanePageHeader Header { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePageHeader.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePageHeader.cs new file mode 100644 index 0000000000..45b7086d34 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPanePageHeader.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane page header object. + /// + public class PropertyPanePageHeader + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPanePageHeader() + { + // Do nothing + } + + /// + /// Gets or Sets the description of type . + /// + /// This value is the description of the property pane page header. + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneSliderProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneSliderProperties.cs new file mode 100644 index 0000000000..5a993949b2 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneSliderProperties.cs @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane slider properties object. + /// + public class PropertyPaneSliderProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneSliderProperties() + { + this.Step = 1; + } + + /// + /// Gets or Sets the label of type . + /// + /// This value is the label of the slider. + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } + + /// + /// Gets or Sets the value of type . + /// + /// This value is the value of the slider. + [JsonProperty(PropertyName = "value")] + public string Value { get; set; } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the slider. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the slider is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets the max value of the Slider of type . + /// + /// This value is the max value of the slider. + [JsonProperty(PropertyName = "max")] + public int Max { get; set; } + + /// + /// Gets or Sets the min value of the Slider of type . + /// + /// This value is the min value of the slider. + [JsonProperty(PropertyName = "min")] + public int Min { get; set; } + + /// + /// Gets or Sets a value indicating whether to show the value on the right of the Slider of type . + /// + /// This value indicates whether the value of the slider should be shown. + [JsonProperty(PropertyName = "showValue")] + public bool ShowValue { get; set; } + + /// + /// Gets or Sets the difference between the two adjacent values of the Slider. Defaults to 1. of type . + /// + /// This value is the step amount of the slider. + [JsonProperty(PropertyName = "step")] + public int Step { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneTextFieldProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneTextFieldProperties.cs new file mode 100644 index 0000000000..984217cae2 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneTextFieldProperties.cs @@ -0,0 +1,118 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane text field properties object. + /// + public class PropertyPaneTextFieldProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneTextFieldProperties() + { + // Do nothing + } + + /// + /// Gets or Sets the label of type . + /// + /// This value is the label of the text field. + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } + + /// + /// Gets or Sets the value of type . + /// + /// This value is the value of the text field. + [JsonProperty(PropertyName = "value")] + public string Value { get; set; } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the text field. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets the description of type . + /// + /// This value is the description of the text field. + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the text field is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets the error message of type . + /// + /// This value is the error message of the text field. + [JsonProperty(PropertyName = "errorMessage")] + public string ErrorMessage { get; set; } + + /// + /// Gets or Sets the name used to log PropertyPaneTextField value changes for engagement tracking of type . + /// + /// This value is the log name of the text field. + [JsonProperty(PropertyName = "logName")] + public string LogName { get; set; } + + /// + /// Gets or Sets the maximum number of characters that the PropertyPaneTextField can have of type . + /// + /// This value is the max length of the text field. + [JsonProperty(PropertyName = "maxLength")] + public int MaxLength { get; set; } + + /// + /// Gets or Sets a value indicating whether or not the text field is a multiline text field of type . + /// + /// This value indicates whether the text field is multiline. + [JsonProperty(PropertyName = "multiline")] + public bool Multiline { get; set; } + + /// + /// Gets or Sets the placeholder text to be displayed in the text field of type . + /// + /// This value is the place holder of the text field. + [JsonProperty(PropertyName = "placeholder")] + public string Placeholder { get; set; } + + /// + /// Gets or Sets a value indicating whether or not the multiline text field is resizable of type . + /// + /// This value indicates whether the text field is resiable. + [JsonProperty(PropertyName = "resizable")] + public bool Resizable { get; set; } + + /// + /// Gets or Sets the value that specifies the visible height of a text area(multiline text TextField), in lines.maximum number of characters that the PropertyPaneTextField can have of type . + /// + /// This value is the number of rows of the text field. + [JsonProperty(PropertyName = "rows")] + public int Rows { get; set; } + + /// + /// Gets or Sets a value indicating whether or not the text field is underlined of type . + /// + /// This value indicates whether the text field is underlined. + [JsonProperty(PropertyName = "underlined")] + public bool Underlined { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneToggleProperties.cs b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneToggleProperties.cs new file mode 100644 index 0000000000..d69f34521e --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/PropertyPaneToggleProperties.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint property pane toggle properties object. + /// + public class PropertyPaneToggleProperties : IPropertyPaneFieldProperties + { + /// + /// Initializes a new instance of the class. + /// + public PropertyPaneToggleProperties() + { + // Do nothing + } + + /// + /// Gets or Sets optional ariaLabel flag. Text for screen-reader to announce regardless of toggle state. Of type . + /// + /// This value is the aria label of the toggle field. + [JsonProperty(PropertyName = "ariaLabel")] + public string AriaLabel { get; set; } + + /// + /// Gets or Sets the label of type . + /// + /// This value is the label of the toggle field. + [JsonProperty(PropertyName = "label")] + public string Label { get; set; } + + /// + /// Gets or Sets a value indicating whether this control is enabled or not of type . + /// + /// This value indicates whether the toggle field is disabled. + [JsonProperty(PropertyName = "disabled")] + public bool Disabled { get; set; } + + /// + /// Gets or Sets a value indicating whether the property pane checkbox is checked or not of type . + /// + /// This value indicates whether the toggle field is checked. + [JsonProperty(PropertyName = "checked")] + public bool Checked { get; set; } + + /// + /// Gets or Sets a key to uniquely identify the field of type . + /// + /// This value is the key of the toggle field. + [JsonProperty(PropertyName = "key")] + public string Key { get; set; } + + /// + /// Gets or Sets text to display when toggle is OFF of type . + /// + /// This value is the label of the toggle field when off. + [JsonProperty(PropertyName = "offText")] + public string OffText { get; set; } + + /// + /// Gets or Sets text to display when toggle is ON of type . + /// + /// This value is the label of the toggle field when on. + [JsonProperty(PropertyName = "onText")] + public string OnText { get; set; } + + /// + /// Gets or Sets text for screen-reader to announce when toggle is OFF of type . + /// + /// This value is the aria label of the toggle field when off. + [JsonProperty(PropertyName = "offAriaLabel")] + public string OffAriaLabel { get; set; } + + /// + /// Gets or Sets text for screen-reader to announce when toggle is ON of type . + /// + /// This value is the aria label of the toggle field when on. + [JsonProperty(PropertyName = "onAriaLabel")] + public string OnAriaLabel { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewData.cs b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewData.cs new file mode 100644 index 0000000000..e77b074993 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewData.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint Quick View Data object. + /// + public class QuickViewData + { + /// + /// Initializes a new instance of the class. + /// + public QuickViewData() + { + // Do nothing + } + + /// + /// Gets or Sets the title of type . + /// + /// This value is the title of the quick view data. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or Sets the description of type . + /// + /// This value is the description of the quick view data. + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs new file mode 100644 index 0000000000..dd89c9ce13 --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// Adaptive Card Extension Client-side action response to render quick view. + /// + public class QuickViewHandleActionResponse : BaseHandleActionResponse + { + /// + /// Gets the response type. + /// + /// Card. + [JsonProperty(PropertyName = "responseType")] + public override ViewResponseType ResponseType => ViewResponseType.QuickView; + + /// + /// Gets or sets card view render arguments. + /// + /// Card view render arguments. + [JsonProperty(PropertyName = "renderArguments")] + public new QuickViewResponse RenderArguments { get; set; } + } +} diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewResponse.cs new file mode 100644 index 0000000000..27e1ce417d --- /dev/null +++ b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewResponse.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using AdaptiveCards; +using Microsoft.Bot.Schema.Teams; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Bot.Schema.SharePoint +{ + /// + /// SharePoint GetQuickView response object. + /// + public class QuickViewResponse + { + /// + /// Initializes a new instance of the class. + /// + public QuickViewResponse() + { + // Do nothing + } + + /// + /// Gets or Sets data for the quick view. + /// + /// This value is the data of the quick view response. + [JsonProperty(PropertyName = "data")] + public object Data { get; set; } + + /// + /// Gets or Sets data for the quick view template of type . + /// + /// This value is the template of the quick view response. + [JsonProperty(PropertyName = "template")] + public AdaptiveCard Template { get; set; } + + /// + /// Gets or Sets view Id of type . + /// + /// This value is the view Id of the quick view response. + [JsonProperty(PropertyName = "viewId")] + public string ViewId { get; set; } + + /// + /// Gets or Sets title of type . + /// + /// This value is the title of the quick view response. + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Gets or Sets the external link parameters of type . + /// + /// This value is the external link parameters of the quick view response. + [JsonProperty(PropertyName = "externalLink")] + public ExternalLinkActionParameters ExternalLink { get; set; } + + /// + /// Gets or Sets focus parameters of type . + /// + /// This value is the focus parameters of the quick view response. + [JsonProperty(PropertyName = "focusParameters")] + public FocusParameters FocusParameters { get; set; } + } +} diff --git a/tests/Microsoft.Bot.Builder.Tests/SharePoint/SharePointActivityHandlerTests.cs b/tests/Microsoft.Bot.Builder.Tests/SharePoint/SharePointActivityHandlerTests.cs new file mode 100644 index 0000000000..58c0f27c27 --- /dev/null +++ b/tests/Microsoft.Bot.Builder.Tests/SharePoint/SharePointActivityHandlerTests.cs @@ -0,0 +1,224 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Bot.Builder.Tests; +using Microsoft.Bot.Connector; +using Microsoft.Bot.Connector.Authentication; +using Microsoft.Bot.Schema; +using Microsoft.Bot.Schema.SharePoint; +using Microsoft.Bot.Schema.Teams; +using Microsoft.Rest.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using Xunit; + +namespace Microsoft.Bot.Builder.SharePoint.Tests +{ + public class SharePointActivityHandlerTests + { + [Fact] + public async Task TestSharePointGetCardViewAction() + { + // Arrange + var activity = new Activity + { + Type = ActivityTypes.Invoke, + Name = "cardExtension/getCardView", + Value = JObject.FromObject(new object()), + }; + + Activity[] activitiesToSend = null; + void CaptureSend(Activity[] arg) + { + activitiesToSend = arg; + } + + var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity); + + // Act + var bot = new TestActivityHandler(); + await ((IBot)bot).OnTurnAsync(turnContext); + + // Assert + Assert.Single(bot.Record); + Assert.Equal("OnSharePointTaskGetCardViewAsync", bot.Record[0]); + Assert.NotNull(activitiesToSend); + Assert.Single(activitiesToSend); + Assert.IsType(activitiesToSend[0].Value); + Assert.Equal(200, ((InvokeResponse)activitiesToSend[0].Value).Status); + } + + [Fact] + public async Task TestSharePointGetQuickViewAction() + { + // Arrange + var activity = new Activity + { + Type = ActivityTypes.Invoke, + Name = "cardExtension/getQuickView", + Value = JObject.FromObject(new object()), + }; + + Activity[] activitiesToSend = null; + void CaptureSend(Activity[] arg) + { + activitiesToSend = arg; + } + + var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity); + + // Act + var bot = new TestActivityHandler(); + await ((IBot)bot).OnTurnAsync(turnContext); + + // Assert + Assert.Single(bot.Record); + Assert.Equal("OnSharePointTaskGetQuickViewAsync", bot.Record[0]); + Assert.NotNull(activitiesToSend); + Assert.Single(activitiesToSend); + Assert.IsType(activitiesToSend[0].Value); + Assert.Equal(200, ((InvokeResponse)activitiesToSend[0].Value).Status); + } + + [Fact] + public async Task TestSharePointGetPropertyPaneConfigurationAction() + { + // Arrange + var activity = new Activity + { + Type = ActivityTypes.Invoke, + Name = "cardExtension/getPropertyPaneConfiguration", + Value = JObject.FromObject(new object()), + }; + + Activity[] activitiesToSend = null; + void CaptureSend(Activity[] arg) + { + activitiesToSend = arg; + } + + var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity); + + // Act + var bot = new TestActivityHandler(); + await ((IBot)bot).OnTurnAsync(turnContext); + + // Assert + Assert.Single(bot.Record); + Assert.Equal("OnSharePointTaskGetPropertyPaneConfigurationAsync", bot.Record[0]); + Assert.NotNull(activitiesToSend); + Assert.Single(activitiesToSend); + Assert.IsType(activitiesToSend[0].Value); + Assert.Equal(200, ((InvokeResponse)activitiesToSend[0].Value).Status); + } + + [Fact] + public async Task TestSharePointSetPropertyPaneConfigurationAction() + { + // Arrange + var activity = new Activity + { + Type = ActivityTypes.Invoke, + Name = "cardExtension/setPropertyPaneConfiguration", + Value = JObject.FromObject(new object()), + }; + + Activity[] activitiesToSend = null; + void CaptureSend(Activity[] arg) + { + activitiesToSend = arg; + } + + var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity); + + // Act + var bot = new TestActivityHandler(); + await ((IBot)bot).OnTurnAsync(turnContext); + + // Assert + Assert.Single(bot.Record); + Assert.Equal("OnSharePointTaskSetPropertyPaneConfigurationAsync", bot.Record[0]); + Assert.NotNull(activitiesToSend); + Assert.Single(activitiesToSend); + Assert.IsType(activitiesToSend[0].Value); + Assert.Equal(200, ((InvokeResponse)activitiesToSend[0].Value).Status); + } + + [Fact] + public async Task TestSharePointHandleActionAction() + { + // Arrange + var activity = new Activity + { + Type = ActivityTypes.Invoke, + Name = "cardExtension/handleAction", + Value = JObject.FromObject(new object()), + }; + + Activity[] activitiesToSend = null; + void CaptureSend(Activity[] arg) + { + activitiesToSend = arg; + } + + var turnContext = new TurnContext(new SimpleAdapter(CaptureSend), activity); + + // Act + var bot = new TestActivityHandler(); + await ((IBot)bot).OnTurnAsync(turnContext); + + // Assert + Assert.Single(bot.Record); + Assert.Equal("OnSharePointTaskHandleActionAsync", bot.Record[0]); + Assert.NotNull(activitiesToSend); + Assert.Single(activitiesToSend); + Assert.IsType(activitiesToSend[0].Value); + Assert.Equal(200, ((InvokeResponse)activitiesToSend[0].Value).Status); + } + + private class TestActivityHandler : SharePointActivityHandler + { + public List Record { get; } = new List(); + + // Invoke + protected override Task OnSharePointTaskGetCardViewAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + Record.Add(MethodBase.GetCurrentMethod().Name); + return Task.FromResult(new CardViewResponse()); + } + + protected override Task OnSharePointTaskGetPropertyPaneConfigurationAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + Record.Add(MethodBase.GetCurrentMethod().Name); + return Task.FromResult(new GetPropertyPaneConfigurationResponse()); + } + + protected override Task OnSharePointTaskGetQuickViewAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + Record.Add(MethodBase.GetCurrentMethod().Name); + return Task.FromResult(new QuickViewResponse()); + } + + protected override Task OnSharePointTaskSetPropertyPaneConfigurationAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + Record.Add(MethodBase.GetCurrentMethod().Name); + return Task.FromResult(new NoOpHandleActionResponse()); + } + + protected override Task OnSharePointTaskHandleActionAsync(ITurnContext turnContext, AceRequest aceRequest, CancellationToken cancellationToken) + { + Record.Add(MethodBase.GetCurrentMethod().Name); + return Task.FromResult(new NoOpHandleActionResponse()); + } + } + } +} From e4afa430ea73dd725be39a30d16fe361e77d07c8 Mon Sep 17 00:00:00 2001 From: Alex Terentiev Date: Thu, 2 Nov 2023 10:11:12 -0400 Subject: [PATCH 08/13] fix responseType (#6702) Co-authored-by: Alex Terentiev --- .../SharePoint/BaseHandleActionResponse.cs | 13 +++++++++++-- .../SharePoint/CardViewHandleActionResponse.cs | 10 ++++++---- .../SharePoint/NoOpHandleActionResponse.cs | 10 ++++++---- .../SharePoint/QuickViewHandleActionResponse.cs | 10 ++++++---- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs index 1be7543313..4aa33238e8 100644 --- a/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs +++ b/libraries/Microsoft.Bot.Schema/SharePoint/BaseHandleActionResponse.cs @@ -34,14 +34,23 @@ public enum ViewResponseType /// /// Response returned when handling a client-side action on an Adaptive Card Extension. /// - public abstract class BaseHandleActionResponse + public class BaseHandleActionResponse { /// /// Gets the response type. /// /// Response type. [JsonProperty(PropertyName = "responseType")] - public abstract ViewResponseType ResponseType { get; } + private readonly ViewResponseType responseType; + + /// + /// Initializes a new instance of the class. + /// + /// Response type. + protected BaseHandleActionResponse(ViewResponseType responseType) + { + this.responseType = responseType; + } /// /// Gets or sets render arguments. diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs index aa4558cbb1..fcdd10f5e2 100644 --- a/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs +++ b/libraries/Microsoft.Bot.Schema/SharePoint/CardViewHandleActionResponse.cs @@ -14,11 +14,13 @@ namespace Microsoft.Bot.Schema.SharePoint public class CardViewHandleActionResponse : BaseHandleActionResponse { /// - /// Gets the response type. + /// Initializes a new instance of the class. /// - /// Card. - [JsonProperty(PropertyName = "responseType")] - public override ViewResponseType ResponseType => ViewResponseType.Card; + public CardViewHandleActionResponse() + : base(ViewResponseType.Card) + { + // Do nothing + } /// /// Gets or sets card view render arguments. diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs index 214036414f..b0ae6ad1d0 100644 --- a/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs +++ b/libraries/Microsoft.Bot.Schema/SharePoint/NoOpHandleActionResponse.cs @@ -14,11 +14,13 @@ namespace Microsoft.Bot.Schema.SharePoint public class NoOpHandleActionResponse : BaseHandleActionResponse { /// - /// Gets the response type. + /// Initializes a new instance of the class. /// - /// Card. - [JsonProperty(PropertyName = "responseType")] - public override ViewResponseType ResponseType => ViewResponseType.NoOp; + public NoOpHandleActionResponse() + : base(ViewResponseType.NoOp) + { + // Do nothing + } /// /// Gets or sets card view render arguments. diff --git a/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs index dd89c9ce13..6774c0b12c 100644 --- a/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs +++ b/libraries/Microsoft.Bot.Schema/SharePoint/QuickViewHandleActionResponse.cs @@ -14,11 +14,13 @@ namespace Microsoft.Bot.Schema.SharePoint public class QuickViewHandleActionResponse : BaseHandleActionResponse { /// - /// Gets the response type. + /// Initializes a new instance of the class. /// - /// Card. - [JsonProperty(PropertyName = "responseType")] - public override ViewResponseType ResponseType => ViewResponseType.QuickView; + public QuickViewHandleActionResponse() + : base(ViewResponseType.QuickView) + { + // Do nothing + } /// /// Gets or sets card view render arguments. From ae0041a1d170bef7da43356616ff870b688e46b0 Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:25:21 +0100 Subject: [PATCH 09/13] Skip failing token expired test (#6707) --- .../CloudAdapterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/CloudAdapterTests.cs b/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/CloudAdapterTests.cs index 5dca83e8bd..2f7a743e72 100644 --- a/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/CloudAdapterTests.cs +++ b/tests/integration/Microsoft.Bot.Builder.Integration.AspNet.Core.Tests/CloudAdapterTests.cs @@ -805,7 +805,7 @@ public async Task CloudAdapterCreateConversation() Assert.Equal(expectedChannelId, actualChannelId); } - [Fact] + [Fact(Skip = "Expired token not working anymore, disabling it until fixed.")] public async Task ExpiredTokenShouldThrowUnauthorizedAccessException() { // Arrange From 9d807656a2f496aafaef0994df6780d124c3cdc8 Mon Sep 17 00:00:00 2001 From: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:54:21 +0100 Subject: [PATCH 10/13] Add error detection when EmitEventAsync fails (#6708) --- .../DialogExtensions.cs | 22 +++++- .../LanguageServiceTests.cs | 17 +++-- .../DialogExtensionsTests.cs | 67 +++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs b/libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs index 47b0157542..a76e29e1a7 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Security.Principal; @@ -74,8 +75,25 @@ internal static async Task InternalRunAsync(ITurnContext turnC } catch (Exception err) { - // fire error event, bubbling from the leaf. - var handled = await dialogContext.EmitEventAsync(DialogEvents.Error, err, bubble: true, fromLeaf: true, cancellationToken: cancellationToken).ConfigureAwait(false); + var handled = false; + var innerExceptions = new List(); + try + { + // fire error event, bubbling from the leaf. + handled = await dialogContext.EmitEventAsync(DialogEvents.Error, err, bubble: true, fromLeaf: true, cancellationToken: cancellationToken).ConfigureAwait(false); + } +#pragma warning disable CA1031 // Do not catch general exception types (capture the error in case it's not handled properly) + catch (Exception emitErr) +#pragma warning restore CA1031 // Do not catch general exception types + { + innerExceptions.Add(emitErr); + } + + if (innerExceptions.Any()) + { + innerExceptions.Add(err); + throw new AggregateException("Unable to emit the error as a DialogEvent.", innerExceptions); + } if (!handled) { diff --git a/tests/Microsoft.Bot.Builder.AI.QnA.Tests/LanguageServiceTests.cs b/tests/Microsoft.Bot.Builder.AI.QnA.Tests/LanguageServiceTests.cs index f4363b5663..14692c0c59 100644 --- a/tests/Microsoft.Bot.Builder.AI.QnA.Tests/LanguageServiceTests.cs +++ b/tests/Microsoft.Bot.Builder.AI.QnA.Tests/LanguageServiceTests.cs @@ -1119,17 +1119,26 @@ public void LanguageService_Test_Endpoint_EmptyKbId() [Trait("TestCategory", "LanguageService")] public async void LanguageService_Test_NotSpecifiedQnAServiceType() { + AggregateException result = null; var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetRequestUrl()) .Respond("application/json", GetResponse("LanguageService_ReturnsAnswer.json")); var rootDialog = CreateLanguageServiceActionDialog(mockHttp, true, ServiceType.QnAMaker); - await Assert.ThrowsAsync(() => CreateFlow(rootDialog, nameof(LanguageServiceAction_MultiTurnDialogBase_WithNoAnswer)) - .Send("What happens if I pass empty qnaServiceType with host of Language Service") - .StartTestAsync()); + try + { + await CreateFlow(rootDialog, nameof(LanguageServiceAction_MultiTurnDialogBase_WithNoAnswer)) + .Send("What happens if I pass empty qnaServiceType with host of Language Service") + .StartTestAsync(); + } + catch (AggregateException ex) + { + result = ex; + } - //Assert.Throws(() => new CustomQuestionAnswering(endpoint, qnaMakerOptions)); + Assert.Equal(2, result.InnerExceptions.Count); + Assert.All(result.InnerExceptions, (e) => Assert.IsType(e)); } /// diff --git a/tests/Microsoft.Bot.Builder.Dialogs.Tests/DialogExtensionsTests.cs b/tests/Microsoft.Bot.Builder.Dialogs.Tests/DialogExtensionsTests.cs index d661d06ea9..0fa5dad14d 100644 --- a/tests/Microsoft.Bot.Builder.Dialogs.Tests/DialogExtensionsTests.cs +++ b/tests/Microsoft.Bot.Builder.Dialogs.Tests/DialogExtensionsTests.cs @@ -2,11 +2,14 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.Builder.Adapters; +using Microsoft.Bot.Builder.Dialogs.Adaptive; +using Microsoft.Bot.Builder.Dialogs.Adaptive.Conditions; using Microsoft.Bot.Builder.Skills; using Microsoft.Bot.Connector.Authentication; using Microsoft.Bot.Schema; @@ -143,6 +146,40 @@ public async Task RunAsyncShouldSetTelemetryClient() Assert.Equal(telemetryClientMock.Object, dialog.TelemetryClient); } + [Fact] + public async Task RunAsyncWithCircularReferenceExceptionShouldFail() + { + var conversationReference = TestAdapter.CreateConversation(nameof(RunAsyncWithCircularReferenceExceptionShouldFail)); + + var adapter = new TestAdapter(conversationReference) + .UseBotState(new ConversationState(new MemoryStorage()), new UserState(new MemoryStorage())); + + try + { + var dm = new DialogManager(new AdaptiveDialog("adaptiveDialog") + { + Triggers = new List() + { + new OnBeginDialog() + { + Actions = new List() + { + new CustomExceptionDialog() + } + } + } + }); + + await new TestFlow((TestAdapter)adapter, dm.OnTurnAsync) + .Send("hi") + .StartTestAsync(); + } + catch (AggregateException ex) + { + Assert.Equal(2, ex.InnerExceptions.Count); + } + } + /// /// Creates a TestFlow instance with state data to recreate and assert the different test case. /// @@ -253,5 +290,35 @@ private static async Task FinalStepAsync(WaterfallStepContext return await stepContext.EndDialogAsync(stepContext.Result, cancellationToken); } } + + private class CustomExceptionDialog : Dialog + { + public CustomExceptionDialog() + : base("custom-exception") + { + } + + public override Task BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default) + { + var e1 = new CustomException("Parent: Self referencing Exception"); + var e2 = new CustomException("Child: Self referencing Exception", e1); + e1.Children.Add(e2); + throw e1; + } + + private class CustomException : Exception + { +#pragma warning disable SA1401 // Fields should be private + public List Children = new List(); + public CustomException Parent; +#pragma warning restore SA1401 // Fields should be private + + public CustomException(string message, CustomException parent = null) + : base("Error: " + message) + { + Parent = parent; + } + } + } } } From 979413cd7f57ce71914911dcaf123dd08cdd2d1a Mon Sep 17 00:00:00 2001 From: Jhonatan Sandoval Velasco <122501764+JhontSouth@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:59:24 -0500 Subject: [PATCH 11/13] Enable MSAL settings to save access token in cache (#6706) * add cache configuration for accessToken * remove WithCacheOptions config * add appTokenCache validation --- .../Authentication/MsalAppCredentials.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs index aaa048d5f6..777776a61d 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MsalAppCredentials.cs @@ -54,6 +54,10 @@ public MsalAppCredentials(IConfidentialClientApplication clientApplication, stri _scope = scope; _authority = authority; _validateAuthority = validateAuthority; + if (_clientApplication?.AppTokenCache != null) + { + _clientApplication.AppTokenCache.SetCacheOptions(CacheOptions.EnableSharedCacheOptions); + } } /// From 2693cb17ba62d53a1f4b82cd1d47576452566bfc Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Fri, 8 Dec 2023 13:43:48 -0600 Subject: [PATCH 12/13] Add obsolete warning to Orchestrator classes (#6711) Co-authored-by: Tracy Boehrer --- .../OrchestratorBotComponent.cs | 2 ++ .../OrchestratorRecognizer.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorBotComponent.cs b/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorBotComponent.cs index 09cbcb60b8..a213632d5d 100644 --- a/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorBotComponent.cs +++ b/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorBotComponent.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using Microsoft.Bot.Builder.Dialogs.Declarative; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -11,6 +12,7 @@ namespace Microsoft.Bot.Builder.AI.Orchestrator /// /// Define component assets for Orchestrator. /// + [Obsolete("The Bot Framework Orchestrator will be deprecated in the next version of the Bot Framework SDK.")] public class OrchestratorBotComponent : BotComponent { /// diff --git a/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorRecognizer.cs b/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorRecognizer.cs index f40e8de1f2..a7942b4986 100644 --- a/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorRecognizer.cs +++ b/libraries/Microsoft.Bot.Builder.AI.Orchestrator/OrchestratorRecognizer.cs @@ -24,6 +24,7 @@ namespace Microsoft.Bot.Builder.AI.Orchestrator /// /// Class that represents an adaptive Orchestrator recognizer. /// + [Obsolete("The Bot Framework Orchestrator will be deprecated in the next version of the Bot Framework SDK.")] public class OrchestratorRecognizer : AdaptiveRecognizer { /// From 77958564511c2fdce55e2bf5726b26cbf2c0e25a Mon Sep 17 00:00:00 2001 From: Jhonatan Sandoval Velasco <122501764+JhontSouth@users.noreply.github.com> Date: Thu, 14 Dec 2023 09:50:42 -0500 Subject: [PATCH 13/13] include HEAD method to http requests (#6713) --- .../Actions/HttpRequest.cs | 10 ++++++++-- .../Schemas/Actions/Microsoft.HttpRequest.schema | 3 ++- .../Microsoft.Bot.Builder.TestBot.Json/testbot.schema | 6 ++++-- tests/tests.schema | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Actions/HttpRequest.cs b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Actions/HttpRequest.cs index 2e4292bb36..2222d800ec 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Actions/HttpRequest.cs +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Actions/HttpRequest.cs @@ -126,7 +126,12 @@ public enum HttpMethod /// /// Http DELETE. /// - DELETE + DELETE, + + /// + /// Http HEAD. + /// + HEAD } /// @@ -315,7 +320,8 @@ public enum HttpMethod } break; - case HttpMethod.DELETE: + case HttpMethod.DELETE: + case HttpMethod.HEAD: response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false); break; } diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions/Microsoft.HttpRequest.schema b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions/Microsoft.HttpRequest.schema index 315d36ccb9..c9f918a2a2 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions/Microsoft.HttpRequest.schema +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions/Microsoft.HttpRequest.schema @@ -31,7 +31,8 @@ "POST", "PATCH", "PUT", - "DELETE" + "DELETE", + "HEAD" ], "examples": [ "GET", diff --git a/tests/Microsoft.Bot.Builder.TestBot.Json/testbot.schema b/tests/Microsoft.Bot.Builder.TestBot.Json/testbot.schema index 59fd9e1194..e7751e6417 100644 --- a/tests/Microsoft.Bot.Builder.TestBot.Json/testbot.schema +++ b/tests/Microsoft.Bot.Builder.TestBot.Json/testbot.schema @@ -3607,7 +3607,8 @@ "POST", "PATCH", "PUT", - "DELETE" + "DELETE", + "HEAD" ], "examples": [ "GET", @@ -9216,7 +9217,8 @@ "POST", "PATCH", "PUT", - "DELETE" + "DELETE", + "HEAD" ], "examples": [ "GET", diff --git a/tests/tests.schema b/tests/tests.schema index 85383b5cd6..ad41a31b42 100644 --- a/tests/tests.schema +++ b/tests/tests.schema @@ -3868,7 +3868,8 @@ "POST", "PATCH", "PUT", - "DELETE" + "DELETE", + "HEAD" ], "examples": [ "GET",