/// <summary> /// Instance a new Stack Client plugin container. /// </summary> /// <param name="defaults">Defaults values for queries executed against this client.</param> /// <param name="handler">A request handler for this client.</param> /// <param name="logger">Event log message dispatcher.</param> /// <param name="cache">API Response cache store.</param> /// <param name="throttler">Request throttler.</param> public StackClientPlugins(IDefaults defaults, IRequestHandler handler, IEventLog logger, IResponseCache cache, IRequestThrottler throttler) { if (defaults == null) { throw new ArgumentNullException("defaults"); } if (handler == null) { throw new ArgumentNullException("handler"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (cache == null) { throw new ArgumentNullException("cache"); } if (throttler == null) { throw new ArgumentNullException("throttler"); } Default = defaults; RequestHandler = handler; EventLog = logger; Cache = cache; Throttler = throttler; }
public async Task <byte[]> ExecuteAsync(IHttpClient httpClient, IResponseCache cache) { var senderToSend = generateCertificateIfAbsent ? await ObtainCertificate(httpClient, cache) : sender; var xml = await GenerateFufXml(httpClient, senderToSend); return(transformFromUtf8ToCp1251 ? TransformUtf8ToCp1251Encoding(xml) : xml); }
public ExternTestTool(string apiKey, IResponseCache cache, ILifetime lifetime, ILog log) { this.apiKey = apiKey; this.cache = cache; this.lifetime = lifetime; httpClient = new HttpClientImplementation("https://extern-api.testkontur.ru/test-tools/v1/", apiKey, lifetime, log); driveCertificatesReader = new DriveCertificatesReader(lifetime); }
/// <summary> /// Initializes a new instance of the <see cref="Client"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="requestTimeout">The requestTimeout.</param> /// <param name="bufferTimeout">The buffer timeout.</param> /// <param name="cache">The response cache.</param> public Client(string key, TimeSpan requestTimeout, TimeSpan bufferTimeout, IResponseCache cache) { if (string.IsNullOrEmpty(key)) throw new ArgumentException("Embedly account key cannot be empty", "key"); Key = key; RequestTimeout = requestTimeout; BufferTimeout = bufferTimeout; Cache = cache; }
/// <summary> /// Initializes a new instance of the <see cref="Client"/> class. /// </summary> /// <param name="key">The key.</param> /// <param name="requestTimeout">The requestTimeout.</param> /// <param name="bufferTimeout">The buffer timeout.</param> /// <param name="cache">The response cache.</param> public Client(string key, TimeSpan requestTimeout, TimeSpan bufferTimeout, IResponseCache cache) { if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Embedly account key cannot be empty", "key"); } Key = key; RequestTimeout = requestTimeout; BufferTimeout = bufferTimeout; Cache = cache; }
protected BasecampApiBase(string accountId, string username, string password, IResponseCache responseCache) { Username = username; Password = password; AccountId = accountId; ResponseCache = responseCache; Projects = new ProjectsEndpoint(ResponseCache); People = new PeopleEndpoint(ResponseCache); Todos = new TodosEndpoint(ResponseCache); Events = new EventsEndpoint(ResponseCache); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:EasyCaching.ResponseCaching.EasyCachingResponseCachingMiddleware"/> class. /// </summary> /// <param name="next">Next.</param> /// <param name="options">Options.</param> /// <param name="cache">Cache.</param> /// <param name="loggerFactory">Logger factory.</param> /// <param name="policyProvider">Policy provider.</param> /// <param name="keyProvider">Key provider.</param> public EasyCachingResponseCachingMiddleware( RequestDelegate next, IOptions <ResponseCachingOptions> options, IResponseCache cache, ILoggerFactory loggerFactory, IResponseCachingPolicyProvider policyProvider, IResponseCachingKeyProvider keyProvider) : base(next, options, loggerFactory, policyProvider, keyProvider) { FieldInfo cacheFieldInfo = typeof(ResponseCachingMiddleware).GetField("_cache", BindingFlags.NonPublic | BindingFlags.Instance); cacheFieldInfo.SetValue(this, cache); }
internal Resolver(ResolverContext context) { Retries = context.Retries; TimeOut = context.Timeout; TransportType = context.TransportType; Recursion = context.UseRecursion; DnsServers = context.DnsServers.Count == 0 ? GetDnsServers() : context.DnsServers; UseCache = context.UseCache; if (context.UseCache) { _cache = new ResponseCache(context.CacheSize); } }
public NullCacheEntryTests() { // Setup Distributed Cache _fakeDistributedCache = A.Fake <IDistributedCache>(); A.CallTo(() => _fakeDistributedCache.Get(Key)).Returns(null); A.CallTo(() => _fakeDistributedCache.GetAsync(Key, default(CancellationToken))).Returns(Task.FromResult <byte[]>(null)); // Setup Serializer _fakeCacheSerializer = A.Fake <IDistributedCacheSerializer>(); // Setup DistributedResponseCache _distributedResponseCache = new DistributedResponseCache(_fakeDistributedCache, _fakeCacheSerializer); }
public IsolatedAccountEnvironment(IMessageSink messageSink) { authTestData = AuthTestData.LoadFromJsonFile(); IResponseCache responseCache = authTestData.TestDataGenerateLevel switch { TestDataGenerationLevel.TestRun => new EmptyCache(), TestDataGenerationLevel.TempFolder => JsonFileResponseCache.InTempFolder(), TestDataGenerationLevel.CurrentDirectory => JsonFileResponseCache.InCurrentFolder(), _ => throw new ArgumentOutOfRangeException(nameof(authTestData.TestDataGenerateLevel), authTestData.TestDataGenerateLevel, null) }; var log = new TestLog(messageSink); lifetime = new Lifetime(log); externTestTool = new ExternTestTool(authTestData.ApiKey, responseCache, lifetime, log); }
public OrchestrationTests() { // Setup Distributed Cache _fakeDistributedCache = A.Fake <IDistributedCache>(); A.CallTo(() => _fakeDistributedCache.Get(Key)).Returns(_serializedValue); A.CallTo(() => _fakeDistributedCache.GetAsync(Key, default(CancellationToken))).Returns(_serializedValue); // Setup Serializer _fakeCacheSerializer = A.Fake <IDistributedCacheSerializer>(); A.CallTo(() => _fakeCacheSerializer.Serialize(_deserializedValue)).Returns(_serializedValue); A.CallTo(() => _fakeCacheSerializer.Deserialize(_serializedValue)).Returns(_deserializedValue); // Setup DistributedResponseCache _distributedResponseCache = new DistributedResponseCache(_fakeDistributedCache, _fakeCacheSerializer); }
public async Task <GeneratedAccount> ExecuteAsync(IHttpClient httpClient, IResponseCache cache) { var responseBody = await cache.TryGetAsync(organizationName) ?? await GenerateNewAccount(); var response = DeserializeAccount(responseBody); var publicPartOfCertificate = await driveCertificatesReader.GetPublicPartOfCertificate(response.CertificateInfo.CertificateDrivePath); if (publicPartOfCertificate == null) { responseBody = await GenerateNewAccount(); response = DeserializeAccount(responseBody); publicPartOfCertificate = await driveCertificatesReader.GetPublicPartOfCertificate(response.CertificateInfo.CertificateDrivePath) ?? throw new InvalidOperationException("The content of newly generated account was not found"); } return(ToGeneratedAccount(response, publicPartOfCertificate));
public DistributedResponseCachingMiddleware( RequestDelegate next, IOptions <ResponseCachingOptions> options, ILoggerFactory loggerFactory, IResponseCachingPolicyProvider policyProvider, IResponseCache cache, IResponseCachingKeyProvider keyProvider) : base(next, options, loggerFactory, policyProvider, keyProvider) { var cacheFieldInfo = typeof(ResponseCachingMiddleware) .GetField(InternalCacheFieldName, BindingFlags.NonPublic | BindingFlags.Instance); if (cacheFieldInfo == null) { throw new Exception($"Failed to internal cache field named '{InternalCacheFieldName}'."); } cacheFieldInfo.SetValue(this, cache); }
private async Task <Sender> ObtainCertificate(IHttpClient httpClient, IResponseCache cache) { if (sender.Certificate != null) { return(sender); } var certificateGenerationData = new CertificateGenerationData( sender.Inn, sender.Kpp, sender.OrgName, Surname: payer?.ChiefFullName?.Surname, FirstName: payer?.ChiefFullName?.Name, Patronymic: payer?.ChiefFullName?.Patronymic ); var generatedCertificate = await new GenerateCertificateCommand(certificateGenerationData).ExecuteAsync(httpClient, cache); return(sender with { Certificate = Base64String.Encode(generatedCertificate.PublicKeyCertificate) }); }
public EasyCachingResponseCachingMiddleware( RequestDelegate next, IOptions <ResponseCachingOptions> options, ILoggerFactory loggerFactory, IResponseCache cache, IResponseCachingPolicyProvider policyProvider, IResponseCachingKeyProvider keyProvider) { ArgumentCheck.NotNull(next, nameof(next)); ArgumentCheck.NotNull(options, nameof(options)); ArgumentCheck.NotNull(loggerFactory, nameof(loggerFactory)); ArgumentCheck.NotNull(policyProvider, nameof(policyProvider)); ArgumentCheck.NotNull(cache, nameof(cache)); ArgumentCheck.NotNull(keyProvider, nameof(keyProvider)); _next = next; _options = options.Value; _logger = loggerFactory.CreateLogger <ResponseCachingMiddleware>(); _policyProvider = policyProvider; _cache = cache; _keyProvider = keyProvider; }
/// <summary> /// <inheritdoc cref="ResponseCachingContext"/> /// </summary> /// <param name="metadatas">Action端点的 <see cref="EndpointMetadataCollection"/></param> /// <param name="cacheKeyGenerator"></param> /// <param name="responseCache"></param> /// <param name="cacheDeterminer"></param> /// <param name="options"></param> /// <param name="interceptorAggregator"></param> /// <param name="dumpStreamCapacity"></param> public ResponseCachingContext(EndpointMetadataCollection metadatas, ICacheKeyGenerator cacheKeyGenerator, IResponseCache responseCache, IResponseCacheDeterminer cacheDeterminer, ResponseCachingOptions options, InterceptorAggregator interceptorAggregator, int dumpStreamCapacity) { if (metadatas is null) { throw new ArgumentNullException(nameof(metadatas)); } MaxCacheableResponseLength = Checks.ThrowIfMaxCacheableResponseLengthTooSmall(Metadata <IMaxCacheableResponseLengthMetadata>()?.MaxCacheableResponseLength ?? options.MaxCacheableResponseLength); MaxCacheKeyLength = options.MaxCacheKeyLength; KeyGenerator = cacheKeyGenerator ?? throw new ArgumentNullException(nameof(cacheKeyGenerator)); ResponseCache = responseCache ?? throw new ArgumentNullException(nameof(responseCache)); CacheDeterminer = cacheDeterminer ?? throw new ArgumentNullException(nameof(cacheDeterminer)); Duration = Checks.ThrowIfDurationTooSmall(RequiredMetadata <IResponseDurationMetadata>().Duration); DurationMilliseconds = Duration * 1000; var executingLockMetadata = Metadata <IExecutingLockMetadata>(); LockMillisecondsTimeout = Checks.ThrowIfLockMillisecondsTimeoutInvalid(executingLockMetadata?.LockMillisecondsTimeout ?? options.DefaultLockMillisecondsTimeout).Value; Interceptors = interceptorAggregator; DumpStreamCapacity = Checks.ThrowIfDumpStreamInitialCapacityTooSmall(dumpStreamCapacity, nameof(dumpStreamCapacity)); OnCannotExecutionThroughLock = options.OnCannotExecutionThroughLock ?? DefaultExecutionLockTimeoutFallback.SetStatus429; OnExecutionLockTimeout = executingLockMetadata?.OnExecutionLockTimeout ?? options.OnExecutionLockTimeoutFallback ?? DefaultExecutionLockTimeoutFallback.SetStatus429; TMetadata?Metadata <TMetadata>() where TMetadata : class => metadatas.GetMetadata <TMetadata>();
public PeopleEndpoint(IResponseCache responseCache) : base(responseCache) { }
public EventsEndpoint(IResponseCache responseCache) : base(responseCache) { }
public CachingActionProxy(IAction proxiedAction, IResponseCache cache) { this.proxiedAction = proxiedAction; this.cache = cache; }
public BasecampApi(string accountId, string username, string password, IResponseCache responseCache) : base(accountId, username, password, responseCache) { }
public TodosEndpoint(IResponseCache responseCache) : base(responseCache) { }
public EndpointBase(IResponseCache responseCache) { ResponseCache = responseCache; }