public async Task <TItem> FindAsync(TIdentity identity, CancellationToken cancellationToken = default) { try { using (var client = new snh.HttpClient()) using (var streamReader = new StreamReader( await client.GetStreamWithAuthenticationAsync( $"{this.Config.BaseControllerPath}{this.ItemControllerPath}/{identity.ToUrlSegment()}", this.AuthenticationHeaderGenerator, this.Logger, cancellationToken).ConfigureAwait(false))) using (var jsonTextReader = new JsonTextReader(streamReader)) { cancellationToken.ThrowIfCancellationRequested(); return(new JsonSerializer().Deserialize <TItem>(jsonTextReader)); } } catch (Exception ex) { this.Logger?.LogError(ex, "Failure to FindAsync. Identity {Identity}", identity); throw; } }
public async Task <IQueryable <TItem> > GetAllAsync(CancellationToken cancellationToken = default) { try { using (var client = new snh.HttpClient()) using (var streamReader = new StreamReader( await client.GetStreamWithAuthenticationAsync( $"{this.Config.BaseControllerPath}{this.ItemsControllerPath}", this.AuthenticationHeaderGenerator, this.Logger, cancellationToken).ConfigureAwait(false))) using (var jsonTextReader = new JsonTextReader(streamReader)) { cancellationToken.ThrowIfCancellationRequested(); return(new JsonSerializer().Deserialize <List <TItem> >(jsonTextReader)?.AsQueryable()); } } catch (Exception ex) { this.Logger?.LogError(ex, "Failure to GetAllAsync"); throw; } }