Exemplo n.º 1
0
        internal static LogsBatchQueryResult DeserializeLogsBatchQueryResult(JsonElement element)
        {
            Optional <IReadOnlyList <LogQueryResponse> > responses = default;
            Optional <BatchResponseError> error = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("responses"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <LogQueryResponse> array = new List <LogQueryResponse>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(LogQueryResponse.DeserializeLogQueryResponse(item));
                    }
                    responses = array;
                    continue;
                }
                if (property.NameEquals("error"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    error = BatchResponseError.DeserializeBatchResponseError(property.Value);
                    continue;
                }
            }
            return(new LogsBatchQueryResult(Optional.ToList(responses), error.Value));
        }
        public LogsQueryResult GetResult(string queryId)
        {
            LogQueryResponse result = Responses.SingleOrDefault(r => r.Id == queryId);

            if (result == null)
            {
                throw new ArgumentException($"Query with ID '{queryId}' wasn't part of the batch." +
                                            $" Please use the return value of the {nameof(LogsBatchQuery)}.{nameof(LogsBatchQuery.AddQuery)} as the '{nameof(queryId)}' argument.", nameof(queryId));
            }

            if (result.Body.Error != null)
            {
                throw new RequestFailedException(result.Status ?? 0, result.Body.Error.Message, result.Body.Error.Code, null);
            }

            return(result.Body);
        }