public NexusModsIssueMonitor(ILogger <NexusModsIssueMonitor> logger, IClock clock, IServiceScopeFactory scopeFactory, IApplicationEnder applicationEnder) : base(applicationEnder) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _clock = clock ?? throw new ArgumentNullException(nameof(clock)); _scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory)); _timeLimiter = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromSeconds(90)); }
public IgdbApi(UpdatableAppSettings settings) { this.settings = settings; requestLimiterHandler = TimeLimiter .GetFromMaxCountByInterval(4, TimeSpan.FromSeconds(1)) .AsDelegatingHandler(); HttpClient = new HttpClient(requestLimiterHandler); HttpClient.DefaultRequestHeaders.Add("Accept", "application/json"); CacheRoot = settings.Settings.IGDB.CacheDirectory; if (!Path.IsPathRooted(CacheRoot)) { CacheRoot = Path.Combine(Paths.ExecutingDirectory, CacheRoot); } Games = new Games(this); AlternativeNames = new AlternativeNames(this); InvolvedCompanies = new InvolvedCompanies(this); Genres = new Genres(this); Websites = new Websites(this); GameModes = new GameModes(this); PlayerPerspectives = new PlayerPerspectives(this); Covers = new Covers(this); Artworks = new Artworks(this); Screenshots = new Screenshots(this); AgeRatings = new AgeRatings(this); Collections = new Collections(this); }
public async Task <WorkloadResult> Execute(IBucket bucket, int workloadIndex) { Ensure.That(bucket, "bucket").IsNotNull(); await OnPreExecute(bucket, workloadIndex, 0); var workloadResult = CreateWorkloadResult(); var workloadTimer = Stopwatch.StartNew(); if (_rateLimit == 0) { for (var i = 0; i < WorkloadSize; i++) { await CreateWorkloadTask(bucket, workloadIndex, 0, workloadResult); } } else { var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(_rateLimit, TimeSpan.FromSeconds(1)); for (var i = 0; i < WorkloadSize; i++) { await timeConstraint; await CreateWorkloadTask(bucket, workloadIndex, 0, workloadResult); } } workloadResult.TimeTaken = workloadTimer.Elapsed; await OnPostExecute(bucket); return(workloadResult); }
private static async Task CreateSearchUserCollaboration(BoxFolder topFolder, BoxClient auClient, TimeLimiter throttle) { var requestParams = new BoxCollaborationRequest() { Item = new BoxRequestEntity() { Type = BoxType.folder, Id = topFolder.Id }, Role = Config.SearchUserRole, AccessibleBy = new BoxCollaborationUserRequest() { Id = Config.SearchUserId } }; try { await throttle; await auClient.CollaborationsManager.AddCollaborationAsync(requestParams); } catch (BoxException be) { if (be.Message.Contains("user_already_collaborator")) { // ignore Console.WriteLine("コラボレーション設定済み"); } else { throw; } } }
private static async Task <BoxFolder> EnsureTopFolder(BoxClient auClient, TimeLimiter throttle) { BoxFolder topFolder; try { // トップレベルに親フォルダを作成 var folderParams = new BoxFolderRequest() { Name = Config.TopFolderName, Parent = new BoxRequestEntity() { Id = "0" } }; await throttle; topFolder = await auClient.FoldersManager.CreateAsync(folderParams); } catch (BoxConflictException <BoxFolder> bce) { // スクリプトを一度実行して、既にトップレベルフォルダが存在している topFolder = bce.ConflictingItems.First(); Console.WriteLine($"{topFolder.Name} already exists"); } return(topFolder); }
public RPCInterceptorState() { GeneralConstraintMulti = new CountByIntervalAwaitableConstraint(2, TimeSpan.FromSeconds(1)); GeneralConstraintSingle = new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(400)); TimeConstraint = TimeLimiter.Compose(GeneralConstraintSingle, GeneralConstraintMulti); TimeConstraintLogs = TimeLimiter.Compose(new CountByIntervalAwaitableConstraint(1, TimeSpan.FromSeconds(2))); }
public PokeAPIClient(string baseURL, IRestClientFactory restClientFactory, IRestRequestFactory restRequestFactory) { BaseURL = baseURL; RestClientFactory = restClientFactory; RestRequestFactory = restRequestFactory; Limiter = InitializeLimiter(); }
/// <summary> /// Register all the services that are specific to an external eve xml api web service /// </summary> /// <param name="builder"></param> private void registerEVEAPIServices(ContainerBuilder builder) { builder.Register <EveXmlWebClient>(c => new EveXmlWebClient( c.ResolveKeyed <IHttpClientWrapper>(WebServices.EVEXMLAPI), c.Resolve <IConfigurationProvider>())) .As <IEveXmlWebClient>() .InstancePerLifetimeScope(); builder.Register <HttpClient>(c => HttpClientFactory.Create( new HttpClientHandler(), new RateLimitHandler(c.ResolveKeyed <IRateLimiter>(WebServices.EVEXMLAPI)), new LoggingHandler(c.Resolve <ILogger>()))) .Keyed <HttpClient>(WebServices.EVEXMLAPI); builder.Register(c => new HttpClientWrapper( c.ResolveKeyed <HttpClient>(WebServices.EVEXMLAPI), c.Resolve <MediaTypeFormatterCollection>() )).Keyed <IHttpClientWrapper>(WebServices.EVEXMLAPI) .SingleInstance(); builder.Register <TimeLimiter>(c => TimeLimiter.GetFromMaxCountByInterval(c.Resolve <IConfigurationProvider>().EveAPIRateLimit, TimeSpan.FromSeconds(1))) .Keyed <IRateLimiter>(WebServices.EVEXMLAPI) .SingleInstance(); }
public PokeAPIClient(string baseURL) { BaseURL = baseURL; RestClientFactory = new RestSharpRestClientFactory(); RestRequestFactory = new RestSharpRestRequestFactory(); Limiter = InitializeLimiter(); }
public CryptoService(IDataCache cache, IHttpClientFactory httpFactory) { _log = LogManager.GetCurrentClassLogger(); _cache = cache; _httpFactory = httpFactory; ratelimit = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromSeconds(2)); }
public async Task UsageWithFactory() { var wrapped = new TimeLimited(_Output); var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(5, TimeSpan.FromMilliseconds(100)); var timeLimited = timeConstraint.Proxify <ITimeLimited>(wrapped); var watch = Stopwatch.StartNew(); for (var i = 0; i < 50; i++) { await timeLimited.GetValue(); } watch.Stop(); watch.Elapsed.Should().BeGreaterThan(TimeSpan.FromMilliseconds(900)); _Output.WriteLine($"Elapsed: {watch.Elapsed}"); var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(110)); Func <Task> cancellable = async() => { while (true) { await timeLimited.GetValue(cts.Token); } }; await cancellable.Should().ThrowAsync <OperationCanceledException>(); var res = await timeLimited.GetValue(); res.Should().Be(56); }
public GitHubRateLimiter(IGlobalConfigurationProvider globalConfigurationProvider) { limiter = TimeLimiter.GetFromMaxCountByInterval( globalConfigurationProvider.GetMaxRequestsPerPeriod(), TimeSpan.FromSeconds(globalConfigurationProvider.GetPeriodDurationInSeconds()) ); }
static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); SimpleIoc.Default.Register <IRateLimiter>(() => TimeLimiter.GetFromMaxCountByInterval(2, TimeSpan.FromSeconds(1))); SimpleIoc.Default.Register <ITwitchAPI>(() => new TwitchAPI(null, null, null)); SimpleIoc.Default.Register <MainViewModel>(); SimpleIoc.Default.Register <ApiExamplesViewModel>(); }
//private List<Task> tasks; public SendMessage(ITelegramBotClient botClient) { //queue = new ConcurrentQueue<SendModel>(); GroupLimit = TimeLimiter.GetFromMaxCountByInterval(20, TimeSpan.FromMinutes(1)); GlobalLimit = TimeLimiter.GetFromMaxCountByInterval(30, TimeSpan.FromSeconds(1)); tasks = new ConcurrentQueue <Task>(); this.botClient = botClient; }
private static async Task <BoxCollection <BoxItem> > GetTopLevelFolderItems(BoxClient auClient, int offset, TimeLimiter throttle) { await throttle; var folderItems = await auClient.FoldersManager.GetFolderItemsAsync("0", 1000, offset : offset); return(folderItems); }
public JsonServerHistoryPublisher(Settings settings, HttpMessageHandler httpMessageHandler) { _settings = settings; _rateLimiter = TimeLimiter.GetFromMaxCountByInterval(5, TimeSpan.FromSeconds(1)); _httpClient = new HttpClient(httpMessageHandler) { Timeout = TimeSpan.FromSeconds(4) }; }
public async Task SimpleUsage() { var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(5, TimeSpan.FromSeconds(1)); for (int i = 0; i < 1000; i++) { await timeConstraint.Enqueue(() => ConsoleIt()); } }
static GetMarketDataTask() { CountByIntervalAwaitableConstraint constraint = new CountByIntervalAwaitableConstraint(3, TimeSpan.FromSeconds(5)); CountByIntervalAwaitableConstraint constraint2 = new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(1500)); TimeConstraint = TimeLimiter.Compose(constraint, constraint2); }
public JsApi(HttpMessageHandler httpClientHandler, HistorySettings historySettings) { _historySettings = historySettings; _httpClient = new HttpClient(httpClientHandler) { Timeout = TimeSpan.FromSeconds(4) }; _rateLimiter = TimeLimiter.GetFromMaxCountByInterval(3, TimeSpan.FromSeconds(1.00f)); }
public ToolsTask() : base("Find Nodes By Wallet") { CountByIntervalAwaitableConstraint constraint = new CountByIntervalAwaitableConstraint(4, TimeSpan.FromSeconds(1)); CountByIntervalAwaitableConstraint constraint2 = new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(200)); TimeConstraint = TimeLimiter.Compose(constraint, constraint2); }
public RateLimiterTest() { _FuncTask = Substitute.For <Func <Task> >(); _FuncTaskInt = Substitute.For <Func <Task <int> > >(); _IAwaitableConstraint = Substitute.For <IAwaitableConstraint>(); _Diposable = Substitute.For <IDisposable>(); _IAwaitableConstraint.WaitForReadiness(Arg.Any <CancellationToken>()).Returns(Task.FromResult(_Diposable)); _TimeConstraint = new TimeLimiter(_IAwaitableConstraint); }
public FaceIdentifierBase(string apiKey, string apiEndpoint) { Client = new FaceClient(new ApiKeyServiceClientCredentials(apiKey)) { Endpoint = apiEndpoint }; RateLimit = TimeLimiter.GetFromMaxCountByInterval(RateLimitRequests, RateLimitInterval); }
protected override HttpMessageHandler CreateHandler(CreateHttpClientArgs args) { var handler = TimeLimiter .GetFromMaxCountByInterval(1000, TimeSpan.FromSeconds(100)) .AsDelegatingHandler(); handler.InnerHandler = base.CreateHandler(args); return(handler); }
public async Task SimpleUsageAwaitable() { var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(5, TimeSpan.FromSeconds(1)); for (var i = 0; i < 50; i++) { await timeConstraint; ConsoleIt(); } }
public async Task TestOneThread() { var constraint = new CountByIntervalAwaitableConstraint(5, TimeSpan.FromSeconds(1)); var constraint2 = new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(100)); var timeConstraint = TimeLimiter.Compose(constraint, constraint2); for (var i = 0; i < 1000; i++) { await timeConstraint.Enqueue(() => ConsoleIt()); } }
public Server() { Limiter = new IpRateLimiter(ip => { var constraint = new CountByIntervalAwaitableConstraint(10, TimeSpan.FromSeconds(1)); var constraint2 = new CountByIntervalAwaitableConstraint(35, TimeSpan.FromSeconds(10)); // Compose the two constraints return TimeLimiter.Compose(constraint, constraint2); }); }
public Twitch(IConfigurationRoot config) { // Build handler with RateLimit DelegatingHandler handler = TimeLimiter.GetFromMaxCountByInterval(750, TimeSpan.FromMinutes(1)).AsDelegatingHandler(); twitch = new HttpClient(handler); // Set headers for the twitch api request twitch.DefaultRequestHeaders.Add("Client-ID", config.GetApiKey("Twitch")); twitch.DefaultRequestHeaders.Add("Authorization", config.GetApiKey("Twitch_OAuth")); configuration = config; }
public async Task Compose_composes_the_contraints() { var constraints = Enumerable.Range(0, 3).Select(_ => GetSubstituteAwaitableConstraint()).ToArray(); var composed = TimeLimiter.Compose(constraints); await composed.Enqueue(() => { }); await Task.WhenAll( constraints.Select(c => c.Received().WaitForReadiness(Arg.Any <CancellationToken>())).ToArray() ); }
public VkApi(AccessToken token, HttpMessageHandler httpClientHandler) { _token = token; _httpClient = new HttpClient(httpClientHandler) { Timeout = TimeSpan.FromSeconds(4) }; _responseCache = new ConcurrentDictionary <string, VkApiResponseInfo>(); _requestLog = new ConcurrentDictionary <string, DateTimeOffset>(); _rateLimiter = TimeLimiter.GetFromMaxCountByInterval(3, TimeSpan.FromSeconds(1.00f)); }
/// <summary>Initializes a new instance of the <see cref="CoinMarketCapClient"/> class.</summary> /// <param name="httpClient">The HTTP client.</param> /// <param name="requestsPerMinute">The requests per minute.</param> /// <exception cref="System.ArgumentNullException">httpClient</exception> public CoinMarketCapClient(IRestClient httpClient, int requestsPerMinute) { this.gate = TimeLimiter.GetFromMaxCountByInterval(requestsPerMinute, new TimeSpan(0, 1, 0)); this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); var serializer = new CoinMarketCapSerializer(); this.HttpClient.UserAgent = "Inixe CoinManager"; this.HttpClient.AddHandler("application/json", serializer); this.crytocurrencies = new Lazy <IList <string> >(this.LoadCrytoCurrencies); }