forked from loafle/openapi-generator-original
Make TokenProvider not contain state so subclassing actually works correctly with JIT requested tokens (for long lived ApiClients) (#22233)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// <auto-generated>
|
||||
{{>partial_header}}
|
||||
|
||||
{{#nrt}}
|
||||
#nullable enable
|
||||
|
||||
@@ -17,21 +16,21 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
{{>visibility}} class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
{{#lambda.copy}}
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -45,7 +44,7 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -65,7 +64,7 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
{{/hasApiKeyMethods}}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
{{#hasApiKeyMethods}}
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
@@ -86,7 +85,7 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>{{nrt?}} tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler{{nrt?}} TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler{{nrt?}} TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// <auto-generated>
|
||||
{{>partial_header}}
|
||||
|
||||
{{#nrt}}
|
||||
#nullable enable
|
||||
|
||||
@@ -17,25 +16,6 @@ namespace {{packageName}}
|
||||
/// </summary>
|
||||
{{>visibility}} abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
* Contact: support@files.com
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -23,15 +22,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -42,7 +41,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -50,16 +49,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -75,7 +74,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* Contact: support@files.com
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -23,25 +22,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,15 +21,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -41,7 +40,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -49,16 +48,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -74,7 +73,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,15 +21,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -41,7 +40,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -49,16 +48,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -74,7 +73,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,33 +19,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,33 +21,33 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 0.0.1
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,25 +21,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,15 +19,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -39,7 +38,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -47,16 +46,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
internal delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
internal event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,25 +19,6 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of tokens.
|
||||
/// </summary>
|
||||
protected TTokenBase[] _tokens;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an authentication token to be used in request authorization.
|
||||
/// </summary>
|
||||
/// <param name="header"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a TokenProvider.
|
||||
/// </summary>
|
||||
/// <param name="tokens"></param>
|
||||
public TokenProvider(IEnumerable<TTokenBase> tokens)
|
||||
{
|
||||
_tokens = tokens.ToArray();
|
||||
}
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
@@ -22,15 +21,15 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
|
||||
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
|
||||
{
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
|
||||
|
||||
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
|
||||
@@ -41,7 +40,7 @@ namespace Org.OpenAPITools.Client
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
@@ -49,16 +48,16 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
else
|
||||
{
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
|
||||
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
|
||||
{
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
|
||||
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
|
||||
};
|
||||
|
||||
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
|
||||
}
|
||||
|
||||
foreach (var availableToken in AvailableTokens)
|
||||
foreach(TTokenBase token in _tokens)
|
||||
foreach(TTokenBase token in container.Tokens)
|
||||
{
|
||||
if (token is ApiKeyToken apiKeyToken)
|
||||
{
|
||||
@@ -74,7 +73,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user