Esempio n. 1
0
 internal Task TryInitializeAsync(EncompassRestClient client, ClientParameters parameters, CancellationToken cancellationToken)
 {
     if (parameters.CustomFieldsCacheInitialization != CacheInitialization.Never && !((DateTime.UtcNow - CustomFieldsLastRefreshedUtc)?.TotalMinutes < (int)parameters.CustomFieldsCacheInitialization))
     {
         return(RefreshCustomFieldsAsync(client, cancellationToken));
     }
     return(TaskHelper.CompletedTask);
 }
Esempio n. 2
0
        public static EncompassRestClient CreateFromAccessToken(ClientParameters parameters, string accessToken)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(accessToken, nameof(accessToken));

            var client = new EncompassRestClient(parameters);

            client.AccessToken.Token = accessToken;
            return(client);
        }
Esempio n. 3
0
        public static async Task <EncompassRestClient> CreateAsync(ClientParameters parameters, Func <TokenCreator, Task <string> > tokenInitializer, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));

            var client      = new EncompassRestClient(parameters, tokenInitializer);
            var accessToken = await tokenInitializer(new TokenCreator(client, cancellationToken)).ConfigureAwait(false);

            client.AccessToken.Token = accessToken;
            return(client);
        }
Esempio n. 4
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
        public static EncompassRestClient CreateFromAccessToken(ClientParameters parameters, string accessToken)
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(accessToken, nameof(accessToken));

            var client = new EncompassRestClient(parameters);

            client.AccessToken.Token = accessToken;
            return(client);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a client object from an existing access token.
        /// </summary>
        /// <param name="parameters">The parameters to initialize the client object with.</param>
        /// <param name="accessToken">The access token to use.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task <EncompassRestClient> CreateFromAccessTokenAsync(ClientParameters parameters, string accessToken, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(accessToken, nameof(accessToken));

            var client = new EncompassRestClient(parameters);

            client.AccessToken.Token = accessToken;
            await client.CommonCache.TryInitializeAsync(client, parameters, cancellationToken).ConfigureAwait(false);

            return(client);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a client object from an authorization code.
        /// </summary>
        /// <param name="parameters">The parameters to initialize the client object with.</param>
        /// <param name="redirectUri">The redirect uri associated with the authorization code.</param>
        /// <param name="authorizationCode">The authorization code to use.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task <EncompassRestClient> CreateFromAuthorizationCodeAsync(ClientParameters parameters, string redirectUri, string authorizationCode, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(redirectUri, nameof(redirectUri));
            Preconditions.NotNullOrEmpty(authorizationCode, nameof(authorizationCode));

            var client      = new EncompassRestClient(parameters);
            var accessToken = await client.AccessToken.GetTokenFromAuthorizationCodeAsync(redirectUri, authorizationCode, nameof(CreateFromAuthorizationCodeAsync), cancellationToken).ConfigureAwait(false);

            client.AccessToken.Token = accessToken;
            await client.CommonCache.TryInitializeAsync(client, parameters, cancellationToken).ConfigureAwait(false);

            return(client);
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a client object from user credentials. It does not automatically retrieve a new token when the current one expires so most of the time you'll probably want to use the CreateAsync method instead.
        /// </summary>
        /// <param name="parameters">The parameters to initialize the client object with.</param>
        /// <param name="instanceId">The encompass instance id.</param>
        /// <param name="userId">The encompass user id.</param>
        /// <param name="password">The encompass user password.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public static async Task <EncompassRestClient> CreateFromUserCredentialsAsync(ClientParameters parameters, string instanceId, string userId, string password, CancellationToken cancellationToken = default)
        {
            Preconditions.NotNull(parameters, nameof(parameters));
            Preconditions.NotNullOrEmpty(instanceId, nameof(instanceId));
            Preconditions.NotNullOrEmpty(userId, nameof(userId));
            Preconditions.NotNullOrEmpty(password, nameof(password));

            var client      = new EncompassRestClient(parameters);
            var accessToken = await client.AccessToken.GetTokenFromUserCredentialsAsync(instanceId, userId, password, nameof(CreateFromUserCredentialsAsync), cancellationToken).ConfigureAwait(false);

            client.AccessToken.Token = accessToken;
            await client.CommonCache.TryInitializeAsync(client, parameters, cancellationToken).ConfigureAwait(false);

            return(client);
        }