Browse Source

Use Enumerable.Contains() instead of ImmutableArray.Contains() and add missing cancellation tokens

pull/827/head
Kévin Chalet 6 years ago
parent
commit
2c5e9c6a69
  1. 38
      src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs
  2. 28
      src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs
  3. 38
      src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs
  4. 34
      src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs
  5. 22
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  6. 22
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  7. 22
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  8. 16
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  9. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs
  10. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs
  11. 8
      src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs
  12. 4
      src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs
  13. 6
      src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs
  14. 2
      src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs
  15. 6
      src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs

38
src/OpenIddict.EntityFramework/Stores/OpenIddictApplicationStore.cs

@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Applications.LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Applications.LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of applications that match the specified query.
@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Applications).LongCountAsync());
return await query(Applications).LongCountAsync(cancellationToken);
}
/// <summary>
@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework
/// <param name="application">The application to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework
Applications.Add(application);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -233,7 +233,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
public virtual ValueTask<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TApplication> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
@ -242,9 +242,9 @@ namespace OpenIddict.EntityFramework
var key = ConvertIdentifierFromString(identifier);
return new ValueTask<TApplication>((from application in Applications
where application.Id.Equals(key)
select application).FirstOrDefaultAsync());
return await (from application in Applications
where application.Id.Equals(key)
select application).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -256,16 +256,16 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the client application corresponding to the identifier.
/// </returns>
public virtual ValueTask<TApplication> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TApplication> FindByClientIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return new ValueTask<TApplication>((from application in Applications
where application.ClientId == identifier
select application).FirstOrDefaultAsync());
return await (from application in Applications
where application.ClientId == identifier
select application).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -330,7 +330,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -339,7 +339,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(Applications, state).FirstOrDefaultAsync(cancellationToken));
return await query(Applications, state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -488,7 +488,7 @@ namespace OpenIddict.EntityFramework
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.Permissions)
.Select(element => (string) element)
.Select(permission => (string) permission)
.ToImmutableArray();
});
@ -525,7 +525,7 @@ namespace OpenIddict.EntityFramework
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.PostLogoutRedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});
@ -597,7 +597,7 @@ namespace OpenIddict.EntityFramework
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.RedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});

28
src/OpenIddict.EntityFramework/Stores/OpenIddictAuthorizationStore.cs

@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Authorizations.LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Authorizations.LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of authorizations that match the specified query.
@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Authorizations).LongCountAsync());
return await query(Authorizations).LongCountAsync(cancellationToken);
}
/// <summary>
@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework
/// <param name="authorization">The authorization to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework
Authorizations.Add(authorization);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -366,7 +366,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorization corresponding to the identifier.
/// </returns>
public virtual ValueTask<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TAuthorization> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
@ -375,9 +375,9 @@ namespace OpenIddict.EntityFramework
var key = ConvertIdentifierFromString(identifier);
return new ValueTask<TAuthorization>((from authorization in Authorizations.Include(authorization => authorization.Application)
where authorization.Id.Equals(key)
select authorization).FirstOrDefaultAsync(cancellationToken));
return await (from authorization in Authorizations.Include(authorization => authorization.Application)
where authorization.Id.Equals(key)
select authorization).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -447,7 +447,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -456,8 +456,8 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(
Authorizations.Include(authorization => authorization.Application), state).FirstOrDefaultAsync(cancellationToken));
return await query(
Authorizations.Include(authorization => authorization.Application), state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -544,7 +544,7 @@ namespace OpenIddict.EntityFramework
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(authorization.Scopes)
.Select(element => (string) element)
.Select(scope => (string) scope)
.ToImmutableArray();
});

38
src/OpenIddict.EntityFramework/Stores/OpenIddictScopeStore.cs

@ -89,8 +89,8 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Scopes.LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Scopes.LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of scopes that match the specified query.
@ -102,14 +102,14 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Scopes).LongCountAsync());
return await query(Scopes).LongCountAsync(cancellationToken);
}
/// <summary>
@ -118,7 +118,7 @@ namespace OpenIddict.EntityFramework
/// <param name="scope">The scope to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -127,7 +127,7 @@ namespace OpenIddict.EntityFramework
Scopes.Add(scope);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -168,7 +168,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the identifier.
/// </returns>
public virtual ValueTask<TScope> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TScope> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
@ -177,9 +177,9 @@ namespace OpenIddict.EntityFramework
var key = ConvertIdentifierFromString(identifier);
return new ValueTask<TScope>((from scope in Scopes
where scope.Id.Equals(key)
select scope).FirstOrDefaultAsync(cancellationToken));
return await (from scope in Scopes
where scope.Id.Equals(key)
select scope).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -191,16 +191,16 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the scope corresponding to the specified name.
/// </returns>
public virtual ValueTask<TScope> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken)
public virtual async ValueTask<TScope> FindByNameAsync([NotNull] string name, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("The scope name cannot be null or empty.", nameof(name));
}
return new ValueTask<TScope>((from scope in Scopes
where scope.Name == name
select scope).FirstOrDefaultAsync(cancellationToken));
return await (from scope in Scopes
where scope.Name == name
select scope).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -217,8 +217,10 @@ namespace OpenIddict.EntityFramework
throw new ArgumentException("Scope names cannot be null or empty.", nameof(names));
}
// Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure
// ImmutableArray.Contains() (which is not fully supported by Entity Framework 6.x) is not used instead.
return (from scope in Scopes
where names.Contains(scope.Name)
where Enumerable.Contains(names, scope.Name)
select scope).AsAsyncEnumerable(cancellationToken);
}
@ -258,7 +260,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -267,7 +269,7 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(Scopes, state).FirstOrDefaultAsync(cancellationToken));
return await query(Scopes, state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -411,7 +413,7 @@ namespace OpenIddict.EntityFramework
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(scope.Resources)
.Select(element => (string) element)
.Select(resource => (string) resource)
.ToImmutableArray();
});

34
src/OpenIddict.EntityFramework/Stores/OpenIddictTokenStore.cs

@ -106,8 +106,8 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Tokens.LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Tokens.LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of tokens that match the specified query.
@ -119,14 +119,14 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of tokens that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Tokens).LongCountAsync());
return await query(Tokens).LongCountAsync(cancellationToken);
}
/// <summary>
@ -135,7 +135,7 @@ namespace OpenIddict.EntityFramework
/// <param name="token">The token to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -144,7 +144,7 @@ namespace OpenIddict.EntityFramework
Tokens.Add(token);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -338,7 +338,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the token corresponding to the unique identifier.
/// </returns>
public virtual ValueTask<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TToken> FindByIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
@ -347,9 +347,9 @@ namespace OpenIddict.EntityFramework
var key = ConvertIdentifierFromString(identifier);
return new ValueTask<TToken>((from token in Tokens.Include(token => token.Application).Include(token => token.Authorization)
where token.Id.Equals(key)
select token).FirstOrDefaultAsync(cancellationToken));
return await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization)
where token.Id.Equals(key)
select token).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -362,16 +362,16 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the tokens corresponding to the specified reference identifier.
/// </returns>
public virtual ValueTask<TToken> FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
public virtual async ValueTask<TToken> FindByReferenceIdAsync([NotNull] string identifier, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(identifier))
{
throw new ArgumentException("The identifier cannot be null or empty.", nameof(identifier));
}
return new ValueTask<TToken>((from token in Tokens.Include(token => token.Application).Include(token => token.Authorization)
where token.ReferenceId == identifier
select token).FirstOrDefaultAsync(cancellationToken));
return await (from token in Tokens.Include(token => token.Application).Include(token => token.Authorization)
where token.ReferenceId == identifier
select token).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -440,7 +440,7 @@ namespace OpenIddict.EntityFramework
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TToken>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -449,9 +449,9 @@ namespace OpenIddict.EntityFramework
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(
return await query(
Tokens.Include(token => token.Application)
.Include(token => token.Authorization), state).FirstOrDefaultAsync(cancellationToken));
.Include(token => token.Authorization), state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>

22
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -127,8 +127,8 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Applications.AsQueryable().LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Applications.AsQueryable().LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of applications that match the specified query.
@ -140,14 +140,14 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Applications).LongCountAsync());
return await query(Applications).LongCountAsync(cancellationToken);
}
/// <summary>
@ -156,7 +156,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="application">The application to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TApplication application, CancellationToken cancellationToken)
{
if (application == null)
{
@ -165,7 +165,7 @@ namespace OpenIddict.EntityFrameworkCore
Context.Add(application);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -377,7 +377,7 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TApplication>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -386,7 +386,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken));
return await query(Applications.AsTracking(), state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -535,7 +535,7 @@ namespace OpenIddict.EntityFrameworkCore
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.Permissions)
.Select(element => (string) element)
.Select(permission => (string) permission)
.ToImmutableArray();
});
@ -572,7 +572,7 @@ namespace OpenIddict.EntityFrameworkCore
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.PostLogoutRedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});
@ -644,7 +644,7 @@ namespace OpenIddict.EntityFrameworkCore
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.RedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});

22
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -127,8 +127,8 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Authorizations.AsQueryable().LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Authorizations.AsQueryable().LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of authorizations that match the specified query.
@ -140,14 +140,14 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Authorizations).LongCountAsync());
return await query(Authorizations).LongCountAsync(cancellationToken);
}
/// <summary>
@ -156,7 +156,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="authorization">The authorization to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TAuthorization authorization, CancellationToken cancellationToken)
{
if (authorization == null)
{
@ -165,7 +165,7 @@ namespace OpenIddict.EntityFrameworkCore
Context.Add(authorization);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -500,7 +500,7 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TAuthorization>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -509,9 +509,9 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(
return await query(
Authorizations.Include(authorization => authorization.Application)
.AsTracking(), state).FirstOrDefaultAsync(cancellationToken));
.AsTracking(), state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -598,7 +598,7 @@ namespace OpenIddict.EntityFrameworkCore
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(authorization.Scopes)
.Select(element => (string) element)
.Select(scope => (string) scope)
.ToImmutableArray();
});
@ -853,7 +853,7 @@ namespace OpenIddict.EntityFrameworkCore
// Warning: FindAsync() is deliberately not used to work around a breaking change introduced
// in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned).
var application = await Applications.AsQueryable()
.FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken);
.FirstOrDefaultAsync(application => application.Id.Equals(key), cancellationToken);
if (application == null)
{

22
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs

@ -106,8 +106,8 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Scopes.AsQueryable().LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Scopes.AsQueryable().LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of scopes that match the specified query.
@ -119,14 +119,14 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of scopes that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TScope>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Scopes).LongCountAsync());
return await query(Scopes).LongCountAsync(cancellationToken);
}
/// <summary>
@ -135,7 +135,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="scope">The scope to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TScope scope, CancellationToken cancellationToken)
{
if (scope == null)
{
@ -144,7 +144,7 @@ namespace OpenIddict.EntityFrameworkCore
Scopes.Add(scope);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -234,8 +234,10 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentException("Scope names cannot be null or empty.", nameof(names));
}
// Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure
// ImmutableArray.Contains() (which is not fully supported by Entity Framework Core) is not used instead.
return (from scope in Scopes.AsTracking()
where names.Contains(scope.Name)
where Enumerable.Contains(names, scope.Name)
select scope).AsAsyncEnumerable();
}
@ -273,7 +275,7 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
public virtual ValueTask<TResult> GetAsync<TState, TResult>(
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<TScope>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken)
{
@ -282,7 +284,7 @@ namespace OpenIddict.EntityFrameworkCore
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<TResult>(query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken));
return await query(Scopes.AsTracking(), state).FirstOrDefaultAsync(cancellationToken);
}
/// <summary>
@ -426,7 +428,7 @@ namespace OpenIddict.EntityFrameworkCore
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(scope.Resources)
.Select(element => (string) element)
.Select(resource => (string) resource)
.ToImmutableArray();
});

16
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -126,8 +126,8 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of applications in the database.
/// </returns>
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> new ValueTask<long>(Tokens.AsQueryable().LongCountAsync());
public virtual async ValueTask<long> CountAsync(CancellationToken cancellationToken)
=> await Tokens.AsQueryable().LongCountAsync(cancellationToken);
/// <summary>
/// Determines the number of tokens that match the specified query.
@ -139,14 +139,14 @@ namespace OpenIddict.EntityFrameworkCore
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of tokens that match the specified query.
/// </returns>
public virtual ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken)
public virtual async ValueTask<long> CountAsync<TResult>([NotNull] Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken)
{
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
return new ValueTask<long>(query(Tokens).LongCountAsync());
return await query(Tokens).LongCountAsync(cancellationToken);
}
/// <summary>
@ -155,7 +155,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <param name="token">The token to create.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
/// <returns>A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.</returns>
public virtual ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken)
public virtual async ValueTask CreateAsync([NotNull] TToken token, CancellationToken cancellationToken)
{
if (token == null)
{
@ -164,7 +164,7 @@ namespace OpenIddict.EntityFrameworkCore
Context.Add(token);
return new ValueTask(Context.SaveChangesAsync(cancellationToken));
await Context.SaveChangesAsync(cancellationToken);
}
/// <summary>
@ -914,7 +914,7 @@ namespace OpenIddict.EntityFrameworkCore
// Warning: FindAsync() is deliberately not used to work around a breaking change introduced
// in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned).
var application = await Applications.AsQueryable()
.FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken);
.FirstOrDefaultAsync(application => application.Id.Equals(key), cancellationToken);
if (application == null)
{
@ -966,7 +966,7 @@ namespace OpenIddict.EntityFrameworkCore
// Warning: FindAsync() is deliberately not used to work around a breaking change introduced
// in Entity Framework Core 3.x (where a ValueTask instead of a Task is now returned).
var authorization = await Authorizations.AsQueryable()
.FirstOrDefaultAsync(element => element.Id.Equals(key), cancellationToken);
.FirstOrDefaultAsync(authorization => authorization.Id.Equals(key), cancellationToken);
if (authorization == null)
{

4
src/OpenIddict.MongoDb/Stores/OpenIddictApplicationStore.cs

@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TApplication>(Options.CurrentValue.ApplicationsCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TApplication>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TApplication>.Empty, null, cancellationToken);
}
/// <summary>
@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TApplication>(Options.CurrentValue.ApplicationsCollectionName);
return await ((IMongoQueryable<TApplication>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TApplication>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

4
src/OpenIddict.MongoDb/Stores/OpenIddictAuthorizationStore.cs

@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TAuthorization>(Options.CurrentValue.AuthorizationsCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TAuthorization>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TAuthorization>.Empty, null, cancellationToken);
}
/// <summary>
@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TAuthorization>(Options.CurrentValue.AuthorizationsCollectionName);
return await ((IMongoQueryable<TAuthorization>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TAuthorization>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

8
src/OpenIddict.MongoDb/Stores/OpenIddictScopeStore.cs

@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(Options.CurrentValue.ScopesCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TScope>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TScope>.Empty, null, cancellationToken);
}
/// <summary>
@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(Options.CurrentValue.ScopesCollectionName);
return await ((IMongoQueryable<TScope>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TScope>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>
@ -200,7 +200,9 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TScope>(Options.CurrentValue.ScopesCollectionName);
await foreach (var scope in collection.Find(scope => names.Contains(scope.Name)).ToAsyncEnumerable(cancellationToken))
// Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure
// ImmutableArray.Contains() (which is not fully supported by MongoDB) is not used instead.
await foreach (var scope in collection.Find(scope => Enumerable.Contains(names, scope.Name)).ToAsyncEnumerable(cancellationToken))
{
yield return scope;
}

4
src/OpenIddict.MongoDb/Stores/OpenIddictTokenStore.cs

@ -62,7 +62,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TToken>(Options.CurrentValue.TokensCollectionName);
return await collection.CountDocumentsAsync(FilterDefinition<TToken>.Empty);
return await collection.CountDocumentsAsync(FilterDefinition<TToken>.Empty, null, cancellationToken);
}
/// <summary>
@ -86,7 +86,7 @@ namespace OpenIddict.MongoDb
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection<TToken>(Options.CurrentValue.TokensCollectionName);
return await ((IMongoQueryable<TToken>) query(collection.AsQueryable())).LongCountAsync();
return await ((IMongoQueryable<TToken>) query(collection.AsQueryable())).LongCountAsync(cancellationToken);
}
/// <summary>

6
src/OpenIddict.NHibernate/Stores/OpenIddictApplicationStore.cs

@ -475,7 +475,7 @@ namespace OpenIddict.NHibernate
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.Permissions)
.Select(element => (string) element)
.Select(permission => (string) permission)
.ToImmutableArray();
});
@ -512,7 +512,7 @@ namespace OpenIddict.NHibernate
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.PostLogoutRedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});
@ -573,7 +573,7 @@ namespace OpenIddict.NHibernate
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(application.RedirectUris)
.Select(element => (string) element)
.Select(address => (string) address)
.ToImmutableArray();
});

2
src/OpenIddict.NHibernate/Stores/OpenIddictAuthorizationStore.cs

@ -551,7 +551,7 @@ namespace OpenIddict.NHibernate
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(authorization.Scopes)
.Select(element => (string) element)
.Select(scope => (string) scope)
.ToImmutableArray();
});

6
src/OpenIddict.NHibernate/Stores/OpenIddictScopeStore.cs

@ -235,8 +235,10 @@ namespace OpenIddict.NHibernate
{
var session = await Context.GetSessionAsync(cancellationToken);
// Note: Enumerable.Contains() is deliberately used without the extension method syntax to ensure
// ImmutableArray.Contains() (which is not fully supported by NHibernate) is not used instead.
await foreach (var scope in (from scope in session.Query<TScope>()
where names.Contains(scope.Name)
where Enumerable.Contains(names, scope.Name)
select scope).AsAsyncEnumerable(cancellationToken))
{
yield return scope;
@ -433,7 +435,7 @@ namespace OpenIddict.NHibernate
.SetSlidingExpiration(TimeSpan.FromMinutes(1));
return JArray.Parse(scope.Resources)
.Select(element => (string) element)
.Select(resource => (string) resource)
.ToImmutableArray();
});

Loading…
Cancel
Save