public Task <TResponse> RequestAsync <TRequest, TResponse>(TRequest message = default(TRequest), Guid globalMessageId = new Guid(), Action <IRequestConfigurationBuilder> configuration = null) { var config = _configEval.GetConfiguration <TRequest, TResponse>(configuration); _logger.LogDebug($"Requsting message '{typeof(TRequest).Name}' on exchange '{config.Exchange.ExchangeName}' with routing key {config.RoutingKey}."); return(_requester.RequestAsync <TRequest, TResponse>(message, globalMessageId, config)); }
public async Task <IResponse> RequestAsync(IRequest request, CancellationToken cancel) { try { if ((await _cacheClient.SearchKeysAsync(request.Address.Href)).Count() != 0) { _logger.LogInformation($"Cache hit for: {request.Address.Href}"); return(await _cacheClient.GetAsync <CachedResponse>(request.Address.Href)); } _logger.LogInformation($"Cache miss for: {request.Address.Href}"); _logger.LogInformation($"requesting: {request.Address.Href}"); Response response = (Response)await _innerRequestor.RequestAsync(request, cancel); _logger.LogInformation($"response recieved from: {request.Address.Href}"); var cachedRequest = new CachedResponse(response); _logger.LogInformation($"caching entry: {request.Address.Href}"); await _cacheClient.AddAsync(request.Address.Href, cachedRequest); return(cachedRequest); } catch (Exception ex) { throw; } }
/// <summary> /// Loads the given URI by using an asynchronous GET request. /// </summary> /// <param name="requester">The requester to use.</param> /// <param name="url">The url that yields the path to the desired action.</param> /// <param name="cancel">The token which can be used to cancel the request.</param> /// <returns>The task which will eventually return the response.</returns> public static Task <IResponse> LoadAsync(this IRequester requester, Url url, CancellationToken cancel) { return(requester.RequestAsync(new DefaultRequest { Address = url, Method = HttpMethod.Get }, cancel)); }
/// <summary> /// Performs a potentially CORS-enabled fetch from the given URI by using an asynchronous GET request. /// </summary> /// <param name="requester">The requester to use.</param> /// <param name="url">The url that yields the path to the desired action.</param> /// <param name="cors">The cross origin settings to use.</param> /// <param name="origin">The origin of the page that requests the loading.</param> /// <param name="defaultBehavior">The default behavior in case it is undefined.</param> /// <param name="cancel">The token which can be used to cancel the request.</param> /// <returns>The task which will eventually return the stream.</returns> public static Task <IResponse> LoadWithCorsAsync(this IRequester requester, Url url, CorsSetting cors, String origin, OriginBehavior defaultBehavior, CancellationToken cancel) { //TODO //http://www.w3.org/TR/html5/infrastructure.html#potentially-cors-enabled-fetch return(requester.RequestAsync(new DefaultRequest { Address = url, Method = HttpMethod.Get }, cancel)); }
/// <summary> /// Loads the given URI by using an asynchronous request with the given method and body. /// </summary> /// <param name="requester">The requester to use.</param> /// <param name="url">The url that yields the path to the desired action.</param> /// <param name="content">The body that should be used in the request.</param> /// <param name="mimeType">The mime-type of the request.</param> /// <param name="method">The method that is used for sending the request asynchronously.</param> /// <param name="cancel">The token which can be used to cancel the request.</param> /// <returns>The task which will eventually return the response.</returns> public static Task <IResponse> SendAsync(this IRequester requester, Url url, Stream content, String mimeType, HttpMethod method, CancellationToken cancel) { var request = new DefaultRequest { Address = url, Content = content, Method = method }; if (mimeType != null) { request.Headers[HeaderNames.ContentType] = mimeType; } return(requester.RequestAsync(request, cancel)); }
public async Task <IEnumerable <Bar> > GetDataAsync(string ticker, Timeframes tf, DateTime date1, DateTime date2) { if (_requester == null) { return(null); } if (_tickers.All(td => td.Ticker != ticker)) { return(null); } if (_tfds.All(t => t.Tf != tf)) { return(null); } byte[] data = ReadCache(ticker, tf, date1, date2); if (data == null) { string url = ReplParams(_baseUrl, ticker, tf, date1, date2); data = await _requester.RequestAsync(url); if (data != null) { WriteCache(ticker, tf, date1, date2, data); } } ParserSettings ps = new ParserSettings(); ps.SkipLinesCount = 1; if (tf == Timeframes.Tick) { ps.OpenPriceIndex = ps.HighPriceIndex = ps.LowPriceIndex = ps.ClosePriceIndex = ps.VolumeIndex = -1; ps.FieldCount = 6; } else { ps.TickPriceIndex = ps.TickVolumeIndex = -1; ps.FieldCount = 9; } Parser parser = new Parser(ps); return(await parser.ParseAsync(data)); }
/// <summary>Sends the specified packet to Sentry.</summary> /// <param name="packet">The packet to send.</param> /// <returns> /// The <see cref="JsonPacket.EventID" /> of the successfully captured JSON packet, or <c>null</c> if it fails. /// </returns> protected virtual async Task <string> SendAsync(JsonPacket packet) { IRequester requester = null; try { requester = CreateRequester(packet); if (BeforeSend != null) { requester = BeforeSend(requester); } return(await requester.RequestAsync()); } catch (Exception exception) { return(HandleException(exception, requester)); } }
/// <summary> /// Performs an asynchronous http request with the given options without /// taking a custom cancellation token. /// </summary> /// <param name="requester">The requester to use.</param> /// <param name="request">The options to consider.</param> /// <returns>The task that will eventually give the response data.</returns> public static Task <IResponse> RequestAsync(this IRequester requester, IRequest request) { return(requester.RequestAsync(request, CancellationToken.None)); }