internal static TrainingDocumentInfo DeserializeTrainingDocumentInfo(JsonElement element)
        {
            TrainingDocumentInfo result = new TrainingDocumentInfo();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("documentName"))
                {
                    result.DocumentName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("pages"))
                {
                    result.PageCount = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        result.Errors.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                    }
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    result.Status = property.Value.GetString().ToTrainStatus();
                    continue;
                }
            }
            return(result);
        }
Пример #2
0
        partial void ExtractFailureContent(
            string?content,
            ResponseHeaders responseHeaders,
            ref string?message,
            ref string?errorCode,
            ref IDictionary <string, string>?additionalInfo)
#pragma warning restore CA1801 // Remove unused parameter
#pragma warning restore CA1822 // Member can be static
        {
            if (!string.IsNullOrEmpty(content))
            {
                try
                {
                    // Try to parse the failure content and use that as the
                    // default value for the message, error code, etc.
                    using JsonDocument doc = JsonDocument.Parse(content);
                    if (doc.RootElement.TryGetProperty("error", out JsonElement errorElement))
                    {
                        FormRecognizerError error = FormRecognizerError.DeserializeFormRecognizerError(errorElement);
                        message ??= error?.Message;
                        errorCode ??= error?.ErrorCode;
                    }
                }
                catch (JsonException)
                {
                    // Ignore any failures - unexpected content will be
                    // included verbatim in the detailed error message
                }
            }
        }
        internal static CopyResult DeserializeCopyResult(JsonElement element)
        {
            Guid modelId = default;
            Optional <IReadOnlyList <FormRecognizerError> > errors = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("modelId"))
                {
                    modelId = property.Value.GetGuid();
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    List <FormRecognizerError> array = new List <FormRecognizerError>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                    }
                    errors = array;
                    continue;
                }
            }
            return(new CopyResult(modelId, Optional.ToList(errors)));
        }
Пример #4
0
        internal static TrainingDocumentInfo DeserializeTrainingDocumentInfo(JsonElement element)
        {
            string documentName = default;
            int    pages        = default;
            IReadOnlyList <FormRecognizerError> errors = default;
            TrainingStatus status = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("documentName"))
                {
                    documentName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("pages"))
                {
                    pages = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    List <FormRecognizerError> array = new List <FormRecognizerError>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(FormRecognizerError.DeserializeFormRecognizerError(item));
                        }
                    }
                    errors = array;
                    continue;
                }
                if (property.NameEquals("status"))
                {
                    status = property.Value.GetString().ToTrainingStatus();
                    continue;
                }
            }
            return(new TrainingDocumentInfo(documentName, pages, errors, status));
        }
Пример #5
0
 internal ErrorResponse_internal(FormRecognizerError error)
 {
     Error = error;
 }