public override async Task InitializeAsync(CancellationToken cancellationToken = default) { var body = await _deserializer.DeserializeAsync <AnalyticsResultData>(ResponseStream, cancellationToken); MetaData = new AnalyticsMetaData { RequestId = body.requestID, ClientContextId = body.clientContextID, Signature = body.signature, Metrics = body.metrics?.ToMetrics() ?? new AnalyticsMetrics() }; if (Enum.TryParse(body.status, true, out AnalyticsStatus status)) { MetaData.Status = status; } if (body.warnings != null) { MetaData.Warnings.AddRange(body.warnings.Select(p => p.ToWarning())); } if (body.errors != null) { Errors.AddRange(body.errors.Select(p => p.ToError())); } _rows = body.results ?? Enumerable.Empty <T>(); }
internal async Task ReadResponseAttributes(CancellationToken cancellationToken) { if (_reader == null) { // Should not be possible throw new InvalidOperationException("_reader is null"); } if (MetaData == null) { MetaData = new AnalyticsMetaData(); } _hasReadToResult = false; while (true) { cancellationToken.ThrowIfCancellationRequested(); var path = await _reader !.ReadToNextAttributeAsync(cancellationToken).ConfigureAwait(false); if (path == null) { // Reached the end break; } switch (path) { case "requestID" when _reader.ValueType == typeof(string): MetaData.RequestId = _reader.Value?.ToString(); break; case "status" when _reader.ValueType == typeof(string): if (Enum.TryParse(_reader.Value?.ToString(), true, out AnalyticsStatus status)) { MetaData.Status = status; } break; case "clientContextID" when _reader.ValueType == typeof(string): MetaData.ClientContextId = _reader.Value?.ToString(); break; case "signature": MetaData.Signature = (await _reader.ReadTokenAsync(cancellationToken).ConfigureAwait(false)) .ToDynamic(); break; case "metrics": MetaData.Metrics = (await _reader.ReadObjectAsync <MetricsData>(cancellationToken).ConfigureAwait(false)) .ToMetrics(); break; case "results": // We've reached the result rows, return now _hasReadToResult = true; return; case "warnings": await foreach (var warning in _reader.ReadObjectsAsync <WarningData>(cancellationToken) .ConfigureAwait(false)) { MetaData.Warnings.Add(warning.ToWarning()); } break; case "errors": await foreach (var error in _reader.ReadObjectsAsync <ErrorData>(cancellationToken) .ConfigureAwait(false)) { Errors.Add(error.ToError()); } break; } } // We've reached the end of the object, mark that entire read is complete _hasFinishedReading = true; }