text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_suffix|> return factories[i](context);
}
}
return null;
};
}
}
<|fim_prefix|>namespace Polly.Simmy.Utils;
internal sealed class GeneratorHelper<TResult>(Func<int, int> weightGenerator)
{
<|fim_middle|>private readonly Func<int, int> _weightGenerator =... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Telemetry;
namespace Polly;
/// <summary>
/// The context used for building an individual resilience strategy.
/// </summary>
public sealed class StrategyBuilderContext
{
internal StrategyBuilderContext(ResilienceStrategyTelemetry telemetry, TimeProvider timeProvider)
{
TimeP... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;
#pragma <|fim_suffix|>ruct ExecutionAttemptArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecutionAttemptArguments"/> struct.
/// </summary>
/// <param name="attemptNumber">The execution attempt number.</param>
/// <param name="... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;<|fim_suffix|>t, otherwise we do not guarantee binary compatibility.
/// </remarks>
public readonly struct PipelineExecutedArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="PipelineExecutedArguments"/> struct.
/// </summary>
/// <param na... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>marks>
public readonly struct PipelineExecutingArguments
{
}
<|fim_prefix|>namespace Polly.Telemetry;
/// <summary>
/// Arguments that indicate the pipeline execution started.
/// </summary>
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee binary comp... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ce of the <see cref="ResilienceEvent"/> struct.
/// </summary>
/// <param name="severity">The severity of the event.</param>
/// <param name="eventName">The event name.</param>
public ResilienceEvent(ResilienceEventSeverity severity, string eventName)
{
Severity = severity;
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> a critical error.
/// </summary>
Critical,
}
<|fim_prefix|>namespace Polly.Telemetry;
/// <summary>
/// The severity of reported resilience event.
/// </summary>
public enum ResilienceEventSeverity
{
/// <summary>
/// The resilience event is not recorded.
/// </summary>
None = 0... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.ComponentModel;
namespace Polly.Telemetry;
/// <summary>
/// Resilience telemetry is used by individual resilience strategies to report some important events.
/// </summary>
/// <remarks>
/// For example, the timeout strategy reports "OnTimeout" event when the timeout is reached or "OnRetry... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;
/// <summary>
/// The source of resilience telemetry events.
/// </summary>
/// <remarks>
/// This class is used by the telemetry infrastructure and should not be used directly by user code.
/// </remarks>
public sealed class ResilienceTelemetrySource
{
/// <summary>
//... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>aram name="resilienceEvent">The resilience event.</param>
/// <param name="context">The context associated with the resilience event.</param>
/// <param name="args">The arguments associated with the resilience event.</param>
/// <param name="outcome">The outcome associated with the resilience ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>param name="args">The arguments associated with the event.</param>
public abstract void Write<TResult, TArgs>(in TelemetryEventArguments<TResult, TArgs> args);
}
<|fim_prefix|>namespace Polly.<|fim_middle|>Telemetry;
/// <summary>
/// Listener of resilience telemetry events.
/// </summary>
public ab... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;
internal static class TelemetryUtil
{
internal const string PollyDiagnosticSource = "Polly";
internal const string ExecutionAttempt = "ExecutionAttempt";
internal const string PipelineExecuting = "PipelineExecuting";
internal const string PipelineExecuted = "... | fim | App-vNext/Polly | csharp |
namespace Polly.Timeout;
#pragma warning disable CA1815 // Override equals and operator equals on value types
/// <summary>
/// Arguments used by the timeout strategy to notify that a timeout occurred.
/// </summary>
/// <remarks>
/// Always use the constructor when creating this struct, otherwise we do not guarantee... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> public const string OnTimeoutEvent = "OnTimeout";
}
<|fim_prefix|>namespace Polly.Timeout;
internal static class TimeoutConstants
{
public const string <|fim_middle|>DefaultName = "Timeout";
<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Timeout;
#pragma warning disable CA1815 // Override equals and operator equals on value types
/// <summary>
/// Arguments used by the timeout strategy to retrieve a timeout for current execution.
/// </summary>
/// <remarks>
/// Always use the constructor when creating this struct, other... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>#if !NETCOREAPP
using System.Runtime.Serialization;
#endif
namespace Polly.Timeout;
/// <summary>
/// Exception thrown when a delegate executed through a timeout resilience strategy does not complete, before the configured timeout.
/// </summary>
#if !NETCOREAPP
[Serializable]
#endif
public class Timeou... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ref name="builder"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when the options produced from the arguments are invalid.</exception>
public static TBuilder AddTimeout<TBuilder>(this TBuilder builder, TimeSpan timeout)
where TBuilder : Resilienc... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>g disable CA1849 // Call async methods when in an async method, OK here as the callback is synchronous
#pragma warning disable S6966
registration.Dispose();
#pragma warning restore S6966
#pragma warning restore CA1849 // Call async methods when in an async method
_cancellationTokenSourceP... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace Polly.Timeout;
/// <summary>
/// Represents the options for the timeout strategy.
/// </summary>
public class TimeoutStrategyOptions : ResilienceStrategyOptions
{
/// <summary>
/// Initializes a new ins... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>Timeout(TimeSpan timeout) => timeout > TimeSpan.Zero;
}
<|fim_prefix|>namespace Polly.Timeout;
internal static class TimeoutUtil
{
public const string TimeSpanInvalidMessage = "The '{0}' must be a positive TimeSpan (or <|fim_middle|>Timeout.InfiniteTimeSpan to indicate no timeout).";
public stat... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Po<|fim_suffix|>ial class CancellationTokenSourcePool
{
#if !NET8_0_OR_GREATER
private sealed class DisposableCancellationTokenSourcePool : CancellationTokenSourcePool
{
private readonly TimeProvider _timeProvider;
public DisposableCancellationTokenSourcePool(TimeProvide... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils;
internal abstract partial class CancellationTokenSourcePool
{
#if NET6_0_OR_GREATER
private sealed class PooledCancellationTokenSourcePool : CancellationTokenSourcePool
{
public static readonly PooledCancellationTokenSourcePool SystemInstance = new(TimeProvider.Syst... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> delay);
public abstract void Return(CancellationTokenSource source);
protected static bool IsCancellable(TimeSpan delay) => delay != System.Threading.Timeout.InfiniteTimeSpan;
}
<|fim_prefix|>namespace Polly.Utils;
#pragma warning dis<|fim_middle|>able CA1716 // Identifiers should not match ke... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils;
internal static class Constants
{
public const string OptionsValidation = """
This call validates the options using t<|fim_suffix|>t the options are included by adding the '[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(OptionsType))]' attribute to the calli... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils;
internal static class DefaultPredicat<|fim_suffix|> } and not OperationCanceledException);
}
<|fim_middle|>es<TArgs, TResult>
where TArgs : IOutcomeArguments<TResult>
{
public static readonly Func<TArgs, ValueTask<bool>> HandleOutcome = args => new(args.Outcome.Exception i... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namesp<|fim_suffix|>or
{
Ignore,
Allow,
Reject
}
<|fim_middle|>ace Polly.Utils;
internal enum DisposeBehavi<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils;
#pragma warning disable CA1031 // Do not catch general exception types
internal static class DisposeHelper
{
public static async ValueTask TryDisposeSafeAsync<T>(T value, bool isSynchronous)
{
try
{
// for synchronous executions we want to prefe... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>edType("TraceFormat", BindingFlags.NonPublic)!;
private static readonly MethodInfo TraceToString = typeof(StackTrace).GetMethod("ToString", BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { TraceFormat }, null)!;
private static readonly object[] TraceToStringArgs = new[] { Enum.GetValu... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>n value;
}
}
<|fim_prefix|>using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Polly.Utils;
[ExcludeFromCodeCoverage]
internal static class Guard
{
public static T NotNull<T>(T value, [CallerArgumentExpression("value")] string argumentName = "")
where ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>enceContext Context { get; }
/// <summary>
/// Gets the outcome.
/// </summary>
Outcome<TResult> Outcome { get; }
}
<|fim_prefix|>namespace Polly.Utils;
/// <summary>
/// Marker interface for outcome arguments.
/// </summary>
/// <typeparam name="TResult">The type of result.</typeparam>... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> if (Interlocked.Increment(ref _numItems) <= MaxCapacity)
{
_items.Enqueue(obj);
return;
}
// no room, clean up the count and drop the object on the floor
Interlocked.Decrement(ref _numItems);
}
}
}
<|fim_... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils;
internal static class OutcomeUtilities
{
/// <summary>
/// Ensures that an <see cref="OperationCanceledException"/> escaping a strategy that substituted the
/// execution <see cref="CancellationToken"/> (e.g. timeout or hedging) carries the caller's token when
/// t... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>pe is identical to strategy return type");
return Unsafe.As<ValueTask<Outcome<T>>, ValueTask<Outcome<TResult>>>(ref task);
}
else
{
var valueTask = Strategy.ExecuteCore(
static async (context, state) =>
{
v... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ienceStrategy Strategy { get; }
internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
ResilienceContext context,
TState state) => Strategy.ExecuteCore(callback, context, state);
}
<|fi... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>fo);
}
return new((TTo?)(object?)outcome.Result);
}
}
<|fim_prefix|>namespace Polly.Utils.Pipeline;
internal abstract class BridgeComponentBase(object strategy) : PipelineComponent
{
private readonly object _strategy = strategy;
public override ValueTask DisposeAsync()
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>
}
if (_disposeBehavior == DisposeBehavior.Reject)
{
throw new InvalidOperationException("Disposing this resilience pipeline is not allowed because it is owned by the pipeline registry.");
}
return !_disposed;
}
}
<|fim_prefix|>namespace Polly.Uti... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils.Pipeline;
internal sealed class ComponentWithDis<|fim_suffix|>mponent, List<Action> callbacks)
{
Component = component;
_callbacks = callbacks;
}
internal PipelineComponent Component { get; }
public override ValueTask DisposeAsync()
{
E... | fim | App-vNext/Polly | csharp |
using Polly.Telemetry;
namespace Polly.Utils.Pipeline;
/// <summary>
/// A combination of multiple components.
/// </summary>
[DebuggerDisplay("Pipeline, Strategies = {Components.Count}")]
[DebuggerTypeProxy(typeof(CompositeComponentDebuggerProxy))]
internal sealed class CompositeComponent : PipelineComponent
{
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils.Pipeline;
internal sealed class CompositeComponentDebuggerProxy
{
private readonly CompositeComponent _pipeline;
public CompositeComponentDebuggerProxy(CompositeComponent pipeline) => _pipeline = pipeline;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
pub... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>utcome.FromExceptionAsValueTask<TResult>(new OperationCanceledException(context.CancellationToken).TrySetStackTrace());
}
return next.ExecuteCore(callback, context, state);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ValueTask<Outcome<TResult>> ExecuteCompon... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils.Pipeline;
internal sealed class ExecutionTrackingComponent : PipelineComponent
{
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(30);
public static readonly TimeSpan SleepDelay = TimeSpan.FromSeconds(1);
private readonly TimeProvider _timeProvider;
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>e) => Component.ExecuteCore(callback, context, state);
public override ValueTask DisposeAsync() => default; // Don't dispose component that is external
}
<|fim_prefix|>namespace Polly.Utils.Pipeline;
[DebuggerDisplay("{Component}")]
internal sealed class ExternalComponent : PipelineComponent
{
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Utils.Pipeline;
/// <summary>
/// Represents a single component of a resilience pipeline.
/// </summary>
/// <remarks>
/// The component of the pipeline can be either a strategy, a generic strategy or a whole pipeline.
/// </remarks>
internal abstract class PipelineComponent : IAsyncDisp... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>new BridgeComponent(strategy);
public static PipelineComponent FromStrategy<T>(ResilienceStrategy<T> strategy) => new BridgeComponent<T>(strategy);
public static PipelineComponent WithDisposableCallbacks(PipelineComponent component, List<Action> callbacks)
=> callbacks.Count == 0 ? compo... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Telemetry;
namespace Polly.Utils.Pipeline;
#pragma warning disable CA1031 // Do not catch general exception types
internal sealed class ReloadableComponent : PipelineComponent
{<|fim_suffix|>telemetry = entry.Telemetry;
TryRegisterOnReload(entry.ReloadTokens);
}
public Pi... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ew Random());
public static double NextDouble() => Instance.Value.NextDouble();
public static int Next(int maxValue) => Instance.Value.Next(maxValue);
#endif
}
<|fim_prefix|>namespace Polly.Utils;
#pragma warning disable CA5394 // Do not use insecure randomness
internal static class RandomUtil
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>etAwaiter().GetResult();
}
}
<|fim_prefix|>names<|fim_middle|>pace Polly.Utils;
#pragma warning disable S3236 // Remove this argument from the method call; it hides the caller information.
#pragma warning disable S5034 // "ValueTask" should be consumed correctly
internal static class TaskHelper
{
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>;
#else
timeProvider.Delay(delay, context.CancellationToken).GetAwaiter().GetResult();
#endif
#pragma warning restore CA1849
return Task.CompletedTask;
}
#if NET8_0_OR_GREATER
return Task.Delay(delay, timeProvider, context.CancellationToken);
#else
return ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> {
return type.Name;
}
var args = type.GetGenericArguments();
if (args.Length != 1)
{
return type.Name;
}
#if NET6_0_OR_GREATER
var nameNoAirity = type.Name[..(type.Name.Length - GenericSuffixLength)];
#else
var nameNoAiri... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> (ValidatorLock)
{
valid = Validator.TryValidateObject(context.Instance, new(context.Instance), errors, true);
}
if (!valid)
{
var stringBuilder = new StringBuilder(context.PrimaryMessage);
stringBuilder.AppendLine();
string... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>tring() => "void";
}
<|fim_prefix|>namespace Polly;
/// <summary>
/// Class that r<|fim_middle|>epresents a void result.
/// </summary>
internal sealed class VoidResult
{
private VoidResult()
{
}
public static readonly VoidResult Instance = new();
public override string ToS<|endofte... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>f any.</param>
/// <returns>The options instance.</returns>
/// <remarks>
/// If <paramref name="name"/> is <see langword="null"/> then the global options are returned.
/// </remarks>
public TOptions GetOptions<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterl... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Utils;
namespace Polly.DependencyInjection;
/// <summary>
/// Represents the context for configuring resilience pipelines with the specified key.
/// </summary>
/// <typeparam name="TKey">The type of the key used to identify the resilience pipeline.</typeparam>
public sealed class AddResili... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Registry;
namespace Polly.DependencyInjection;
internal sealed c<|fim_suffix|>y : notnull
{
public List<Action<ResiliencePipelineRegistry<TKey>>> Actions { get; } = [];
}
<|fim_middle|>lass ConfigureResiliencePipelineRegistryOptions<TKey>
where TKe<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Polly.DependencyInjection;
using Polly.Registry;
using Polly.Telemetry;
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.Extensions.Options;
using Polly.Utils;
namespace Polly.Registry;
/// <summary>
/// Extensions for <see cref="ConfigureBuilderContext{TKey}"/>.
/// </summary>
public static class Configur<|fim_suffix|>ef name="TOptions"/> opt... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;
#pragma warning disable CA1815 // Override equals and operator equals on value types
/// <summary>
/// Enrichment context used when reporting resilience events.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <typeparam name="TArgs">The ty... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>EventId = 3,
Message = "Execution attempt. " +
SourceWithStrategy + Separator +
OperationKey + Separator +
Result + Separator +
"Handled: '{Handled}', " +
"Attempt: '{Attempt}', " +
ExecutionTime,
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Poll<|fim_suffix|>// <param name="context">The enrichment context.</param>
public abstract void Enrich<TResult, TArgs>(in EnrichmentContext<TResult, TArgs> context);
}
<|fim_middle|>y.Telemetry;
/// <summary>
/// Enricher used to enrich the metrics with additional information.
/// </summar... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Telemetry;
internal static class ResilienceTelemetryTags
{
public const string EventName = "event.name";
public const string EventSeverity = "event.severity";
public const string PipelineName = "pipeline.name<|fim_suffix|> public const string PipelineInstance = "pipeline.... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>tyProviderArguments
{
/// <summary>
/// Initializes a new instance of the <see cref="SeverityProviderArguments"/> struct.
/// </summary>
/// <param name="source">The source that produced the resilience event.</param>
/// <param name="resilienceEvent">The resilience event.</param>
/... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> once equality : no means to test this
if (Count > _tagsArray.Length)
{
Array.Resize(ref _tagsArray, Count);
}
CopyTo(_tagsArray, 0);
return _tagsArray.AsSpan(0, Count);
#endif
}
}
}
<|fim_prefix|>#if NET
using System... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Diagnostics.Metrics;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
namespace Polly.Telemetry;
internal sealed class TelemetryListenerImpl : TelemetryListener
{
private readonly ILogger _logger;
private readonly Func<ResilienceContext, object?, object?> _... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>gure the telemetry that is produced by the resilience strategies.
/// </summary>
public class TelemetryOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="TelemetryOptions"/> class.
/// </summary>
public TelemetryOptions()
{
}
/// <summary>
/// Initial... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>Listener = new TelemetryListenerImpl(options);
return builder;
}
}
<|fim_prefix|>using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Polly.Telemetry;
using Polly.Utils;
namespace Polly;
/// <summary>
/// The telemetry extensions for the <see cref="ResiliencePipe... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Diagnostics.Metrics;
namespace Polly.Telemetry;
internal sealed class TelemetrySource
{
internal const string Name = "Polly";
public static readonly TelemetrySource Instance = new();
private TelemetrySource()
{
<|fim_suffix|>
index = informationalVersion!.IndexO... | fim | App-vNext/Polly | csharp |
using Microsoft.Extensions.Logging;
namespace Polly.Telemetry;
internal static class TelemetryUtil
{
private const int MaxIntegers = 100;
private static readonly object[] Integers = [.. Enumerable.Range(0, MaxIntegers).Select(v => (object)v)];
private static readonly object True = true;
private sta... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> /// </summary>
public ResilienceContext Context { get; }
/// <summary>
/// Gets the lease that has no permits and was rejected by the rate limiter.
/// </summary>
public RateLimitLease Lease { get; }
}
<|fim_prefix|>using System.Threading.RateLimiting;
namespace Polly.RateLimitin... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Po<|fim_suffix|>.</param>
public RateLimiterArguments(ResilienceContext context) => Context = context;
/// <summary>
/// Gets the context associated with the execution of a user-provided callback.
/// </summary>
public ResilienceContext Context { get; }
}
<|fim_middle|>lly.... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.RateLimiting;
internal stati<|fim_suffix|>
<|fim_middle|>c class RateLimiterConstants
{
public const string DefaultName = "RateLimiter";
public const int DefaultPermitLimit = 1000;
public const int DefaultQueueLimit = 0;
public const string OnRateLimiterRejectedEvent = ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>#if !NETCOREAPP
using System.Runtime.Serialization;
#endif
using System.Threading.RateLimiting;
namespace Polly.RateLimiting;
/// <summary>
/// Exception thrown when a rate limiter rejects an execution.
/// </summary>
#if !NETCOREAPP
[Serializable]
#endif
public sealed class RateLimiterRejectedException... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Threading.RateLimiting;
using Polly.RateLimiting;
namespace Polly;
/// <summary>
/// Extensions for adding rate limiting to <see cref="ResiliencePipelineBuilder"/>.
/// </summary>
public static class RateLim... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Threading.RateLimiting;
using Polly.Telemetry;
namespace Polly.RateLimiting;
internal sealed class RateLimiterResilienceStrategy : ResilienceStrategy, IDisposable, IAsyncDisposable
{
private readonly ResilienceStrategyTelemetry _telemetry;
public RateLimiterResilienceStrategy(
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.ComponentModel.Da<|fim_suffix|>produces <see cref="RateLimitLease"/>.
/// </summary>
/// <value>
/// The default value is <see langword="null"/>. If this property is <see langword="null"/>, then the strategy
/// will use a <see cref="ConcurrencyLimiter"/> created using <see cr... | fim | App-vNext/Polly | csharp |
namespace Polly.Testing;
/// <summary>
/// Describes the resilience pipeline.
/// </summary>
public sealed class ResiliencePipelineDescriptor
{
internal ResiliencePipelineDescriptor(IReadOnlyList<ResilienceStrategyDescriptor> strategies, bool isReloadable)
{
Strategies = strategies;
IsReloadab... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> else if (component is ExecutionTrackingComponent tracking)
{
ExpandComponents(tracking.Component, components);
}
else if (component is ComponentWithDisposeCallbacks callbacks)
{
ExpandComponents(callbacks.Component, components);
}
el... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>any.
/// </summary>
public ResilienceStrategyOptions? Options { get; }
/// <summary>
/// Gets the strategy instance.
/// </summary>
public object StrategyInstance { get; }
}
<|fim_prefix|>namespace Polly.Testing;
/// <summary>
/// This class provides additional information a<|fi... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>#pragma warning disable
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT licens<|fim_suffix|>uteTargets.Method)]
internal sealed class DebuggerDisableUserUnhandledExceptionsAttribute : Attribute
{
}
<|fim_middle|>e.
// Adapte... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net.Http;
using Polly.Retry;
using Polly.Simmy;
using Polly.Simmy.Behavior;
using Polly.Simmy.Latency;
namespace Snippets.Docs;
internal static partial class Chaos
{
public static void BehaviorUsage()
{
#region chaos-behavior-usage
// To use a custom delegated for in... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net.Http;
using Polly.Retry;
using Polly.Simmy;
using Polly.Simmy.Fault;
namespace Snippets.Docs;
#pragma warning disable CA5394 // Do not use insecure randomness
internal static partial class Chaos
{
public static void FaultUsage()
{
#region chaos-fault-usage
// 10... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Polly.CircuitBreaker;
using Polly.Registry;
using Polly.Retry;
using Polly.Simmy;
using Polly.Simmy.Fault;
using Polly.Simmy.Latency;
namespace Snippets.Docs;
internal static partial class Ch... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> latency generator returns Zero, the strategy
// won't inject any delay and just invokes the user's callback.
_ => TimeSpan.Zero
};
return new ValueTask<TimeSpan>(latency);
},
InjectionRate = 0.1
};
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net;
using System.Net.Http;
using Polly.Retry;
using Polly.Simmy;
using Polly.Simmy.Fault;
using Polly.Simmy.Outcomes;
namespace Snippets.Docs;
#pragma warning disable CA5394 // Do not use insecure randomness
internal static partial class Chaos
{
private static readonly int RandomThre... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System;
using System.Net;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http.Resilience;
using Polly.CircuitBreaker;
using Snippets.Docs.Utils;
namespace Snippets.Docs;
internal static class CircuitBreaker
{
public static async Task Usage()
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>encePipelineProvider<MyPipelineKey> pipelineProvider = serviceProvider.GetRequiredService<ResiliencePipelineProvider<MyPipelineKey>>();
// The registry dynamically creates and caches instance-A using the associated builder action
ResiliencePipeline instanceA = pipelineProvider.GetPipeline... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Retry;
namespace Snippets.Docs;
internal static class Ext<|fim_suffix|>ult } when result is "Failure" => PredicateResult.True(),
{ Result: int result } when result is -1 => PredicateResult.True(),
_ => PredicateResult.False(),
},
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net;
using System.Net.Http;
using Polly.Fallback;
using Snippets.Docs.Utils;
namespace Snippets.Docs;
internal static class Fallback
{
public static void Usage()
{
#region fallback
// A fallback/substitute value if an operation fails.
var optionsSubstitute ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Snippets.Docs;
internal static class General
{
public static async Task SynchronizationContext()
{
ResiliencePipeline pipeline = ResiliencePipeline.Empty;
#region synchronization-context
// Retrieve an instance of ResilienceContext from the pool
// wit... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ancellationToken);
// Store the incoming request in the context
context.Properties.Set(ResilienceKeys.RequestMessage, request);
try
{
return await _pipeline.ExecuteAsync(async cxt =>
{
// Allow the pipeli... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>me)
.ConfigureHttpClient(client => client.BaseAddress = BaseAddress)
.AddResilienceHandler("restsharp_based_pipeline",
builder => builder.AddRetry(GetRetryOptions()));
using var provider = services.BuildServiceProvider();
// Resolve the... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> migration-bulkhead-v8
// Create pipeline with concurrency limiter. Because ResiliencePipeline supports both sync and async
// callbacks, there is no need to define it twice.
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
.AddConcurrencyLimiter(permitLim... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net.Http;
using Polly.CircuitBreaker;
using Snippets.Docs.Utils;
namespace Snippets.Docs;
internal static partial class Migration
{
public static void CircuitBreaker_V7()
{
#region migration-circuit-breaker-v7
// Create sync circuit breaker
ISyncPolicy syncP... | fim | App-vNext/Polly | csharp |
namespace Snippets.Docs;
internal static partial class Migration
{
private const string Key1 = nameof(Key1);
private const string Key2 = nameof(Key2);
public static void Context_V7()
{
#region migration-context-v7
// Create context
Context context = new Context();
// ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>= ResilienceContextPool.Shared.Get();
Outcome<int> pipelineResult =
await pipeline.ExecuteOutcomeAsync(
static async (ctx, state) =>
{
try
{
return Outcome.FromResult(await MethodAsync(ctx.... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Threading.RateLimiting;
using Snippets.Docs.Utils;
namespace Snippets.Docs;
internal static partial class Migration
{
public static void Interoperability()
{
#region migration-interoperability
// First, create a resilience<|fim_suffix|> IAsyncPolicy asyncPolicy = ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>wait GetResponseAsync(token);
}, cancellationToken);
#endregion
}
private static HttpResponseMessage GetResponse() => new();
private static Task<HttpResponseMessage> GetResponseAsync(CancellationToken cancellationToken) => Task.FromResult(new HttpResponseMessage());
}
<|fim_... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>er to the APIs exposed by the System.Threading.RateLimiting APIs.
// There is no need to create separate instances for sync and async flows as ResiliencePipeline handles both scenarios.
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
.AddRateLimiter(new SlidingWin... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> // Try get a pipeline
registry.TryGetPipeline(PipelineKey, out ResiliencePipeline? pipeline);
// Try get a generic pipeline
registry.TryGetPipeline(PipelineKey, out ResiliencePipeline<string>? genericPipeline);
// Get or add pipeline
registry.GetOrAddPipelin... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net;
using System.Net.Http;
using Polly.Retry;
using Snippets.Docs.Utils;
namespace Snippets.Docs;
internal static partial class Migration
{
public static void Retry_V7()
{
#region migration-retry-v7
// Retry once
Policy
.Handle<SomeExceptionTyp... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Net.Http;
namespace Snippets.Docs;
internal static partial class Migration
{
public static void Timeout_V7()
{
<|fim_suffix|>eoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(10));
#endregion
}
public static void Timeout_V8()
{
#region migration-t... | fim | App-vNext/Polly | csharp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.