public async Task <ImmutableArray <StoredValue> > GetAsync(MonikerVersionPartId monikerVersionPartId) { if (_notExists) { return(ImmutableArray <StoredValue> .Empty); } if (_loaded) { return(_storedValue); } var items = await _dataSourceClient.Get( new DataSourceGetRequest { Id = new MonikerId { Version = new MonikerVersionId { Id = monikerVersionPartId.Id, Version = monikerVersionPartId.Version, Timestamp = monikerVersionPartId.Timestamp } } }).ResponseStream.ReadAllAsync().ToArrayAsync(); var anyError = items.FirstOrDefault(item => item.RespCase == Error); if (anyError != null) { throw new Exception($"Unexpected Error: '{anyError.Error}'"); } var anyNotFound = items.FirstOrDefault(item => item.RespCase == NotFound); if (anyNotFound != null) { _storedValue = ImmutableArray <StoredValue> .Empty; _loaded = true; _notExists = true; } else { _storedValue = ImmutableArray.Create(items.Select(item => item.Success).ToArray()); _loaded = true; } return(_storedValue); }
public override async Task Get(DataSourceGetRequest request, IServerStreamWriter <DataSourceGetResponse> responseStream, ServerCallContext context) { var requestUid = Guid.NewGuid().ToString(); // TODO: Bind the UID to the request _logger.LogInformation($"Started processing Get request: '{requestUid}' from '{context.Peer}'"); await Task.Run(async() => { await foreach (var dsgr in _grpcClient.Get(request).ResponseStream.ReadAllAsync()) { await responseStream.WriteAsync(dsgr); } }); _logger.LogInformation($"Finished processing Get request: '{requestUid}' from '{context.Peer}'"); }