text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<?php
declare(strict_types=1);
namespace App\Services;
use App\Utils\ClassHelper;
use Psr\Http\Message\ResponseInterface;
final class Payment
{
public static function getAllPaymentMap(): array
{
$payments = [];
$helper = new ClassHelper();
$class_list = $helper->getClassesByNamespac... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services;
use App\Models\Config;
use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;
final class RateLimit
{
private Redis $redis;
public function __construct()
{
$this->redis = (new Cac... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>nvite_reg_money_reward');
$invite_reg_traffic_reward = Config::obtain('invite_reg_traffic_reward');
$user = (new User())->where('id', $user_id)->first();
$ref_user = (new User())->where('id', $ref_user_id)
->where('is_banned', 0)
->where('is_shadow_banned'... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
abstract class Base
{
abstract public function getContent($use<|fim_suffix|>
}
<|fim_middle|>r): string;<|endoftext|> | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>ype' => 'vmess',
'server' => $node_raw->server,
'port' => (int) $v2_port,
'uuid' => $user->uuid,
'alterId' => 0,
'cipher' => $encryption,
'udp' => (bool) $udp,
... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|> ],
]);
}
}
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Services\Subscribe;
final class Json extends Base
{
public function getContent($user): string
{
$sub_url = Subscribe::getUniversalSubLink($user);
return json_encode... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|> if ((int) $node_raw->sort === 0) {
$plugin = $node_custom_config['plugin'] ?? '';
$plugin_option = $node_custom_config['plugin_option'] ?? '';
$links .= $user->method . ':' . $user->passwd . '@' . $node_raw->server . ':' .
$user->port ... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Models\Config;
use App\Services\Subscribe;
use function json_decode;
use function json_encode;
final class SIP008 extends Base
{<|fim_suffix|>? '';
$node = [
'id' => $node_raw->id,
... | fim | Anankke/SSPanel-UIM | php |
<?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Models\Config;
use App\Services\Subscribe;
use function base64_encode;
use const PHP_EOL;
final class SS extends Base
{
public function getContent($user): string
{
$links = '';
//判断是否开启SS订阅
if (! Config::obtain(... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>ic',
'tag' => $node_raw->name,
'server' => $node_raw->server,
'server_port' => (int) $tuic_port,
'uuid' => $user->uuid,
'password' => $user->passwd,
'congestion_c... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Models\Config;
use App\Services\Subscribe;
use function json_decode;
use const PHP_EOL;
final class Trojan extends Base
{
public function getContent($user): string
{
$links = '';
//判断是否开启Trojan订阅
i... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|> 'tls' => $security,
];
$links .= 'vmess://' . base64_encode(json_encode($v2rayn_array)) . PHP_EOL;
}
}
return $links;
}
}
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Models\Config;
use App\S... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\Subscribe;
use App\Services\Subscribe;
use App\Utils\Tools;
use function array_filter;
use function array_merge;
use function json_decode;
use function json_encode;
final class V2RayJson extends Base
{
public function getContent($user): string
... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services;
use App\Models\Link;
use App\Models\Node;
use App\Services\Subscribe\Clash;
use App\Services\Subscribe\Json;
use App\Services\Subscribe\SingBox;
use App\Services\Subscribe\SIP002;
use App\Services\Subscribe\SIP008;
use App\Services\Subscribe\SS;
us... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services\SysLog;
use App\Models\SysLog;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
use function json_encode;
final class DBHandler extends AbstractProcessingHandler
{
protected function write(LogRecord $record): void
{
... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|> 'jump_delay' => $_ENV['jump_delay'],
'enable_kill' => $_ENV['enable_kill'],
'enable_change_email' => $_ENV['enable_change_email'],
'enable_r2_client_download' => $_ENV['enable_r2_client_download'],
'jsdelivr_url' => $_ENV['jsdelivr_url'],
... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>elf::$classes)) {
foreach (self::$classes as $class) {
$allClasses[] = '\\' . $class;
}
}
return $allClasses;
}
}
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
use function array_filter;
use function array_keys;
use functi... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
final class Cookie
{
public static function set(array $arg, int $time): void
{
foreach ($arg as $key => $value) {
setcookie($key, $value, $time, pat<|fim_suffix|>etcookie($key, $value, $time, path: '/', domain: $domain, sec... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>static function sha256WithSalt($pwd): string
{
return hash('sha256', $pwd . $_ENV['salt']);
}
public static function sha3WithSalt($pwd): string
{
return hash('sha3-256', $pwd . $_ENV['salt']);
}
}
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
use... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>tatic function successWithData(Response $response, string $msg = '', array $data = []): ResponseInterface
{
return $response->withJson([
'ret' => 1,
'msg' => $msg,
'data' => $data,
]);
}
/**
* Build a JSON response with ETag header.
... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
use App\Models\Config;
use App\Models\User;
use App\Services\GeoIP2;
use GeoIp2\Exception\AddressNotFoundException;
use MaxMind\Db\Reader\InvalidDatabaseException;
use Random\RandomException;
use function array_diff;
use function array_flip;
use funct... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Services;
use PHPUnit\Framework\TestCase;
class CacheTest extends TestCase
{
/**
* @covers App\Services\Cache::getRedisConfig
*/
public function testGetRedisConfig()
{
// Scenario 1: All parameters are set
$_ENV['redis_... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|> 'driver' => 'mariadb',
'read' => [
'host' => 'localhost',
],
'write' => [
'host' => 'localhost',
],
'sticky' => true,
'database' => 'test_db',
'username' => 'username',
... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>ate = 0.5;
$min_rate_time = 3;
$this->assertTrue(DynamicRate::validateData($max_rate, $max_rate_time, $min_rate, $min_rate_time));
$max_rate = -1;
$this->assertFalse(DynamicRate::validateData($max_rate, $max_rate_time, $min_rate, $min_rate_time));
$max_rate = 3;... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
<|fim_suffix|>'test@notexample.com'));
$_ENV['mail_filter'] = 2;
$_ENV['mail_filter_list'] = ['example.com'];
$this->assertTrue(Filter::checkEmailFilter('test@notexample.com'));
}
}
<|fim_middle|>
namespace App\Services;
use PHPUnit\Framework\Te... | fim | Anankke/SSPanel-UIM | php |
<?php
declare(strict_types=1);
namespace App\Services;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Translator;
require_once __DIR__ . '/../../../app/predefine.php';
final class I18nTest extends TestCase
{
/**
* @covers App\Services\I18n::trans
*/
public function testTrans():... | fim | Anankke/SSPanel-UIM | php |
<?php
declare(strict_types=1);
namespace App\Services;
use PHPUnit\Framework\TestCase;
use App\Models\User;
final class ViewTest extends TestCase
{
private View $view;
private User $user;
protected function setUp(): void
{
$this->view = new View();
$this->user = new User();
}
... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><<|fim_suffix|>;
$this->assertContains('\App\Utils\ClassHelper', $classes);
}
}
<|fim_middle|>?php
declare(strict_types=1);
namespace App\Utils;
use PHPUnit\Framework\TestCase;
final class ClassHelperTest extends TestCase
{
private ClassHelper $classHelper;
protected function setU... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
use PHPUnit\Framework\TestCase;
final class CookieTest extends TestCase
{
/**
* @covers App\Utils\Cookie::set
*/
public function testSet(): void
{
$data = ['testKey' => 'testValue'];
$time = time() + 3600;
... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|><?php
declare(strict_types=1);
namespace App\Utils;
use PHPUnit\Framework\TestCase;
use function strlen;
class HashTest extends TestCase
{
/**
* @covers App\Utils\Hash::cookieHash
*/
public function testCookieHash()
{
$_ENV['key'] = 'cookie_key';
$passHash = 'pass... | fim | Anankke/SSPanel-UIM | php |
<|fim_suffix|>tring) $result->getBody());
}
/**
* @covers App\Utils\ResponseHelper::successWithDataEtag
* @throws Exception
*/
public function testSuccessWithDataEtag()
{
$request = $this->createMock(ServerRequestInterface::class);
$request->method('getHeaderLine')->willR... | fim | Anankke/SSPanel-UIM | php |
<?php
declare(strict_types=1);
namespace App\Utils;
use PHPUnit\Framework\TestCase;
use function date_default_timezone_set;
use function strlen;
class ToolsTest extends TestCase
{
/**
* @covers App\Utils\Tools::getIpLocation
*/
public function testGetIpLocation()
{
$_ENV['maxmind_licen... | fim | Anankke/SSPanel-UIM | php |
<|fim_prefix|>namespace Polly.Benchmarks;
[Config(typeof(PollyConfig))]
public class Bulkhead
{
private static readonly Policy SyncPolicy = Policy.Bulkhead(2);
private static readonly AsyncPolicy AsyncPolicy = Policy.BulkheadAsync(2);
[Benchmark]
public vo<|fim_suffix|>> Workloads.FuncAsync<int>(toke... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>bject Cache_Synchronous_Miss() =>
SyncPolicyMiss.Execute(_ => GetObject(), MissContext);
[Benchmark]
public Task<object> Cache_Asynchronous_Miss() =>
AsyncPolicyMiss.ExecuteAsync((_, token) => GetObjectAsync(token), MissContext, CancellationToken.None);
private static object ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Benchmarks;
[Config(typeof(PollyConfig))]
public class CircuitBreaker
{
private static readonly Policy SyncPolicy = Policy.Handle<InvalidOperationException>().CircuitBreaker(2, TimeSpan.FromMinutes(1));
private static readonly As<|fim_suffix|>oken.None);
}
<|fim_middle|>yncPolicy... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>> AsyncPolicy = Policy<int>.Handle<InvalidOperationException>().FallbackAsync(0);
[Benchmark]
public int Fallback_Synchronous_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());
[Benchmark]
public Task<int> Fallback_Asynchronous_Succeeds() =>
AsyncPolicy.Execut... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> public void NoOp_Synchronous() =>
SyncPolicy.Execute(() => Workloads.Action());
[Benchmark]
public Task NoOp_Asynchronous() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionAsync(token), CancellationToken.None);
[Benchmark]
public int NoOp_Synchronous_With_Result() =... | fim | App-vNext/Polly | csharp |
namespace Polly.Benchmarks;
[Config(typeof(PollyConfig))]
public class PolicyWrap
{
private static readonly Policy SyncPolicy = Policy.Wrap(
Policy.Handle<InvalidOperationException>().Retry(),
Policy.Handle<InvalidOperationException>().CircuitBreaker(2, TimeSpan.FromMinutes(1)),
Policy.Tim... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Bench<|fim_suffix|>Default);
AddJob(Job.Default);
}
}
<|fim_middle|>marks;
internal class PollyConfig : ManualConfig
{
public PollyConfig()
{
AddDiagnoser(BenchmarkDotNet.Diagnosers.MemoryDiagnoser.<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_suffix|>Runner.Run(Assembly.GetCallingAssembly(), args: args);
<|fim_prefix|>Benc<|fim_middle|>hmark<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_suffix|>ous_With_Result_Succeeds() =>
SyncPolicy.Execute(() => Workloads.Func<int>());
[Benchmark]
public Task<int> RateLimit_Asynchronous_With_Result_Succeeds() =>
AsyncPolicy.ExecuteAsync(() => Workloads.FuncAsync<int>());
}
<|fim_prefix|>namespace Polly.Benchmarks;
[Config(typeof(Pol... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Benchmarks;
[Config(typeof(PollyConfig))]
public class Retry
{
private static readonly Policy SyncPolicy = Policy.Handle<InvalidOperationException>().Retry();
private static readonly AsyncPolicy AsyncPolicy = Policy.Handle<InvalidOperationException>().RetryAsync();
[Benchmar... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>h_Result_Succeeds_With_CancellationToken() =>
AsyncPolicy.ExecuteAsync(token => Workloads.FuncAsync<int>(token), CancellationToken.None);
[Benchmark]
public Task Timeout_Asynchronous_Times_Out_Optimistic() =>
AsyncPolicy.ExecuteAsync(token => Workloads.ActionInfiniteAsync(token), ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Benchmarks;
internal static class Workloads
{
internal static void Action()
{
// nothing
}
internal static Task ActionAsync() =>
Task.CompletedTask;
internal static Task ActionAs<|fim_suffix|>
internal static Task<TResult> FuncThrowsAsync<TResult... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>xecuteAsync(() => Task.FromResult("dummy"));
}
<|fim_prefix|>namespace Polly.Core.Benchmarks;
public class BridgeBenchmark
{
private IAsyncPolicy<string>? _policy;
private IAsyncPolicy<string>? _policyWrapped;
[GlobalSetup]
public void Setup()
{
_policy = Policy.NoOpAsync<str... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>chmark(Baseline = true)]
public ValueTask ExecuteCircuitBreaker_V7() => _circuitBreakerV7!.ExecuteAsync(PollyVersion.V7);
[Benchmark]
public ValueTask ExecuteCircuitBreaker_V8() => _circuitBreakerV8!.ExecuteAsync(PollyVersion.V8);
}
<|fim_prefix|>namespace Polly.Core.Benchmarks;
public class... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks;
public class CircuitBreakerOpenedBenchmark
{
private ResiliencePipeline? _pipeline;
private ResiliencePipeline? _reactivePipeline;
private IAsyncPolicy<string>? _policy;
[GlobalSetup]
public void Setup()
{
_reactivePipeline = (ResiliencePi... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly.Telemetry;
using Polly.Utils.Pipeline;
namespace Polly.Core.Benchmarks;
public class CompositeComponentBenchmark
{
private ResilienceContext? _context;
private PipelineComponent? _component;
[GlobalSet<|fim_suffix|> second };
_component = CompositeComponent.Create(comp... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>lt<string>(s => true)
.FallbackAsync(_ => Task.FromResult("fallback"));
[Benchmark]
public static void Fallback_V8() =>
new ResiliencePipelineBuilder<string>()
.AddFallback(new()
{
FallbackAction = _ => Outcome.FromResultAsValueTask("fal... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>e) => Outcome.FromResultAsValueTask(state), _context!, 42);
}
<|fim_prefix|>using Polly.Utils.Pipeline;
namespace Polly.Core.Benchmarks;
public class DelegatingComponentBenchmark : IAsyncDisposable
{
private ResilienceContext? _context;
private DelegatingComponent? _component;
[GlobalSetup... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Runtime.CompilerServices;
namespace Polly.Core.Benchmarks;
public class GenericOverheadBenchmark
{
private readonly GenericStrategy<strin<|fim_suffix|> => new ValueTask<string>("dummy")).ConfigureAwait(false);
[Benchmark]
public async ValueTask ExecuteAsync_NonGeneric() => awai... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks;
public class HedgingBenchmark
{
private ResiliencePipeline<string>? _pipeline;
[GlobalSetup]
public void Setup() => _pipeline = Helper.CreateHedging();
[Benchmark(Baseline = true)]
public async ValueTask Hedging_Primary()
=> await _pipeline!.... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Diagnostics.Metrics;
namespace Polly.Core.Benchmarks;
public class Multiple<|fim_suffix|>Async(
static (_, _) => new ValueTask<Outcome<string>>(Outcome.FromResult("dummy")),
context,
string.Empty).ConfigureAwait(false);
ResilienceContextPool.Shar... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>eV8;
[GlobalSetup]
public void Setup()
{
_pipelineV7 = Helper.CreatePipeline(PollyVersion.V7, Components);
_pipelineV8 = Helper.CreatePipeline(PollyVersion.V8, Components);
}
[Params(1, 2, 5, 10)]
public int Components { get; set; }
[Benchmark(Baseline = true... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks<|fim_suffix|>ollyVersion
{
V7,
V8
}
<|fim_middle|>;
public enum P<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_suffix|>t(new HttpResponseMessage(HttpStatusCode.OK)),
0);
private readonly RetryStrategyOptions<HttpResponseMessage> _delegate = new()
{
ShouldHandle = args => args.Outcome switch
{
{ Result: { StatusCode: HttpStatusCode.InternalServerError } } => PredicateResult.True... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Toolchains.InProcess.Emit;
va<|fim_suffix|>sembly(typeof(PollyVersion).Assembly).Run(args, config);
<|fim_middle|>r config = ManualConfig
.Create(DefaultConfig.Instance)
.AddJob(Job.MediumRun.WithToolchain(InProcessEmitToolchain.Instance))
... | fim | App-vNext/Polly | csharp |
namespace Polly.Core.Benchmarks;
public class RateLimiterBenchmark
{
private object? _rateLimiterV7;
private object? _rateLimiterV8;
[GlobalSetup]
public void Setup()
{
_rateLimiterV7 = Helper.CreateRateLimiter(PollyVersion.V7);
_rateLimiterV8 = Helper.CreateRateLimiter(PollyVersio... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Runtime.CompilerServices;
namespace Polly.Core.Benchmarks;
#pr<|fim_suffix|>()
{
var context = ResilienceContextPool.Shared.Get();
await ResiliencePipeline.Empty.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsValueTask("dummy"), context, "state").ConfigureAwait(false)... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Microsoft.Extensions.DependencyInjection;
namespace Polly.Core.Benchmarks;
public class ResiliencePipelineProviderBenchmark
{
private ResiliencePipelineProvider<string>? _provider;
[GlobalSetup]
public void Setup() =>
_provider = new ServiceCollection()
.AddResilie... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benc<|fim_suffix|> {
_retryV7 = Helper.CreateRetry(PollyVersion.V7);
_retryV8 = Helper.CreateRetry(PollyVersion.V8);
}
[Benchmark(Baseline = true)]
public ValueTask ExecuteRetry_V7() => _retryV7!.ExecuteAsync(PollyVersion.V7);
[Benchmark]
public ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Diagnostics.Metrics;
using Microsoft.Extensions.Logging.Abstractions;
using Polly.Telemetry;
namespace Polly.Core.Benchmarks;
public class TelemetryBenchmark
{
private ResiliencePipeline? _pipeline;
private MeterListener? _meterListener;
[GlobalSetup]
public void Prepare()
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>cuteTimeout_V8() => _timeoutV8!.ExecuteAsync(PollyVersion.V8);
}
<|fim_prefix|>namespace Polly.Core.Benchmarks;
public class TimeoutBenchmark
{
private object? _timeoutV7;
private object? _timeoutV8;
[GlobalSetup]
public void Setup()
{
_timeoutV7 = Helper.CreateTi<|fim_middle... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks.Utils;
internal sealed class EmptyResilienceOptions : Resil<|fim_suffix|>ns
{
}
<|fim_middle|>ienceStrategyOptio<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_suffix|>,
ResilienceContext context,
TState state) => callback(context, state);
}
<|fim_prefix|>namespace Polly.Core.Benchmarks.Utils;
internal class EmptyResilienceStrategy : ResilienceStrategy
{
protected internal override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
Fu... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>itch
{
PollyVersion.V7 =>
Policy
.HandleResult(Failure)
.Or<InvalidOperationException>()
.AdvancedCircuitBreakerAsync(0.5, TimeSpan.FromSeconds(30), 10, TimeSpan.FromSeconds(5)),
PollyVersion.V8 =>... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> builder.AddHedging(new HedgingStrategyOptions<string>
{
ShouldHandle = args => new ValueTask<bool>(args.Outcome.Result == Failure),
ActionGenerator = args => () => Outcome.FromResultAsValueTask("hedged response"),
});
});
}
<|fim_... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>> PredicateResult.True(),
{ Result: string result } when result == Failure => PredicateResult.True(),
_ => PredicateResult.False(),
}
})
.AddTimeout(TimeSpan.FromSeconds(1))
.AddCircuitBreaker(new()
{
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Sys<|fim_suffix|>ting;
namespace Polly.Core.Benchmarks.Utils;
internal static partial class Helper
{
public static object CreateRateLimiter(PollyVersion technology)
{
var timeout = TimeSpan.FromSeconds(10);
return technology switch
{
PollyVersion.V7 => ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>Strategy(builder =>
{
builder.AddRetry(new RetryStrategyOptions<string>
{
MaxRetryAttempts = 3,
BackoffType = DelayBackoffType.Constant,
Delay = delay,
ShouldHandle = args => args.Ou... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks.Utils;
internal static partial class Helper
{
public static object CreatePipeline(PollyVersion technology, int count) => technology switch
{
PollyVe<|fim_suffix|>n.V8 => CreateStrategy(builder =>
{
for (var i = 0; i < count; i++)
... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>namespace Polly.Core.Benchmarks.Utils;
internal static partial class Helper
{
public static object CreateTimeout(PollyVersion technology)
{
var timeout =<|fim_suffix|> _ => throw new NotSupportedException()
};
}
}
<|fim_middle|> TimeSpan.FromSeconds(10);
return... | fim | App-vNext/Polly | csharp |
#pragma warning disable S4225 // Extension methods should not extend "object"
namespace Polly.Core.Benchmarks.Utils;
internal static partial class Helper
{
public static async ValueTask ExecuteAsync(this object obj, PollyVersion version)
{
switch (version)
{
case PollyVersion.V7:
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> {
listener.EnableMeasurementEvents(instrument);
}
}
};
meterListener.SetMeasurementEventCallback<int>(OnMeasurementRecorded);
meterListener.Start();
static void OnMeasurementRecorded<T>(
Instrument... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>#:sdk Cake.Sdk
#:package Cake.FileHelpers
#:package Newtonsoft.Json
#:property ProjectType=Test
#:property SignAssembly=false
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var t... | fim | App-vNext/Polly | csharp |
export default {
iconLinks: [
{
icon: 'github',
href: 'https://github.com/App-vNext/Polly',
title: 'GitHub'
}
]
}
<|endoftext|> | fim | App-vNext/Polly | javascript |
<|fim_prefix|>using Polly;
namespace Chaos;
internal class ChaosManager(IWebHostEnvironment environment, IHttpContextAccess<|fim_suffix|>turn ValueTask.FromResult(0.05);
}
if (environment.IsProduction())
{
return ValueTask.FromResult(0.03);
}
return ValueTask.Fro... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
namespace Chaos;
/// <summary>
/// Abstrac<|fim_suffix|>eTask<bool> IsChaosEnabledAsync(ResilienceContext context);
ValueTask<double> GetInjectionRateAsync(ResilienceContext context);
}<|fim_middle|>tion for controlling chaos injection.
/// </summary>
public interface IChaosManager
{
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>seMessage>().AddResult(() => new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError))
});
});
// Run the app
var app = builder.Build();
app.MapGet("/", async (TodosClient client, HttpContext httpContext, CancellationToken cancellationToken) =>
{
return await client.GetTodosAsyn... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using System.Text.Json.Serialization;
namespace Chaos;
pub<|fim_suffix|>id")] int Id,
[property: JsonPropertyName("title")] string Title);<|fim_middle|>lic record TodoModel(
[property: JsonPropertyName("<|endoftext|> | fim | App-vNext/Polly | csharp |
<|fim_suffix|>)
{
public async Task<IEnumerable<TodoModel>> GetTodosAsync(CancellationToken cancellationToken)
=> await client.GetFromJsonAsync<IEnumerable<TodoModel>>("/todos", cancellationToken) ?? [];
}
<|fim_prefix|>namespace Chaos;
public c<|fim_middle|>lass TodosClient(HttpClient client<|endoftext|> | fim | App-vNext/Polly | csharp |
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Polly;
using Polly.Registry;
using Polly.Timeout;
// ------------------------------------------------------------------------
// 1. Register your resilience pipeline
// -----------------------------------------------------------... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
namespace Extensibility.Proactive;
#regio<|fim_suffix|>d { get; }
public TimeSpan Duration { get; }
// As per convention, all arguments should provide a "Context" property.
public ResilienceContext Context { get; }
}
#endregion
<|fim_middle|>n ext-proactive-args
// Structs ... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>oldExceededArguments, ValueTask>? onThresholdExceeded,
ResilienceStrategyTelemetry telemetry)
{
_threshold = threshold;
_telemetry = telemetry;
_onThresholdExceeded = onThresholdExceeded;
}
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResul... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
nam<|fim_suffix|>gResilienceStrategyBuilderExtensions
{
// The extensions should return the builder to support a fluent API.
// For proactive strategies, we can target both "ResiliencePipelineBuilderBase" and "ResiliencePipelineBuilder<T>"
// using generic constraints.
publi... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>hreshold is surpassed.
// Ideally, arguments should share the delegate's name, but with an "Arguments" suffix.
public Func<OnThresholdExceededArguments, ValueTask>? OnThresholdExceeded { get; set; }
}
#endregion
<|fim_prefix|>using Polly;
using System.ComponentModel.DataAnnotations;
namespace E... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Extensibility.Proactive;
using Extensibility.Reactive;
using Polly;
using System.Net;
#region ext-proactive-strategy-usage
// Add the proactive strategy to the builder
var pipeline = new ResiliencePipelineBuilder()
// This is custom extension defined in this sample
.AddTiming(new TimingSt... | fim | App-vNext/Polly | csharp |
using Polly;
namespace Extensibility.Reactive;
#region ext-reactive-event-args
public readonly struct OnReportResultArguments<TResult>
{
public OnReportResultArguments(ResilienceContext context, Outcome<TResult> outcome)
{
Context = context;
Outcome = outcome;
}
// Always include th... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
namespace Extensibility.Reactive;
#region ext-reactive-predicate-args
public readonly struct ResultReportingPredicateArguments<TResult>
{
public ResultReportingPredicateArguments(ResilienceContext context, Outcome<TResult> outcome)
{
Context = context;
Outcome = ou... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>)).ConfigureAwait(context.ContinueOnCapturedContext))
{
// Bundle information about the event into arguments.
var args = new OnReportResultArguments<T>(context, outcome);
// Report this as a resilience event with information severity level to the telemetry infr... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
namespace Extensibility.Reactive;
#pragma warning disable IDE0022 // Use expression body for method
#region ext-reactive-extensions
public static class ResultReportingResilienceStrategyBuilderExtensions
{
// Add extensions for the generic builder.
// Extensions should return the ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
using System.ComponentModel.DataAnnotations;
namespace Extensibility.Reactive;
#region ext-reactive-options
public class ResultReportingStrategyOptions<TResult> : ResilienceStrategyOptions
{
public ResultReportingStrategyOptions()
{
// Assign a default name to the options ... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>#pragma warning disable SA1633 // File should have header
using System.Net;
#pragma warning restore SA1633 // File should have header
using Polly;
using Polly.Fallback;
using Polly.Retry;
using Polly.Timeout;
// ----------------------------------------------------------------------------
// Create a gen... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>using Polly;
using Polly.Retry;
using Polly.Timeout;
// ------------------------------------------------------------------------
// 1. Create a simple resilience pipeline using ResiliencePipelineBuilder
// ------------------------------------------------------------------------
// The ResiliencePipelin... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> make it easier to use ValueTask. See https://github.com/TheAngryByrd/IcedTasks.
do! pipeline.ExecuteAsync(
fun token ->
valueTask {
printfn "Hello, world! Waiting for 2 seconds..."
do! Task.Delay(1000, token)
... | fim | App-vNext/Polly | fsharp |
<|fim_prefix|>using System.Net;
namespace Retries;
internal sealed class ExecuteHelper
{
public bool Fail { get; set; } = true;
public HttpResponseMessage ExecuteUnstable()
{
<|fim_suffix|> return new HttpResponseMessage(HttpStatusCode.OK);
}
}
<|fim_middle|>if (Fail)
{
... | fim | App-vNext/Polly | csharp |
<|fim_suffix|> BackoffType = DelayBackoffType.Exponential,
UseJitter = true,
})
.Build();
Console.WriteLine("---------------------------------------");
pipeline.Execute(helper.ExecuteUnstable);
// ------------------------------------------------------------------------
// 3. Register the callba... | fim | App-vNext/Polly | csharp |
<|fim_prefix|>// Copyright (c) Microsoft Corporation. All Rights Reserved.
#pragma warning disable IDE0079
#pragma warning disable SA1101
#pragma warning disable SA1512
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Syste... | fim | App-vNext/Polly | csharp |
<|fim_suffix|>eturn value;
}
return dictionary.GetOrAdd(key, valueFactory(key, factoryArgument));
}
}
#endif
<|fim_prefix|>namespace System.Collections.Concurrent;
#if !NETCOREAP<|fim_middle|>P
internal static class ConcurrentDictionaryExtensions
{
public static TValue GetOrAdd<TKey, TValue, ... | fim | App-vNext/Polly | csharp |
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#pragma warning disable IDE0079
#pragma warning disable SA1101
#pragma warning disable SA1116
#pragma warning disable SA1117
#pragma warning disable SA1512
#pragma warning disable SA... | 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.