| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.IO; |
| | 10 | | using System.Text.Json; |
| | 11 | | using System.Threading; |
| | 12 | | using System.Threading.Tasks; |
| | 13 | | using Azure; |
| | 14 | | using Azure.AI.FormRecognizer.Models; |
| | 15 | | using Azure.Core; |
| | 16 | | using Azure.Core.Pipeline; |
| | 17 | |
|
| | 18 | | namespace Azure.AI.FormRecognizer |
| | 19 | | { |
| | 20 | | internal partial class ServiceRestClient |
| | 21 | | { |
| | 22 | | private string endpoint; |
| | 23 | | private ClientDiagnostics _clientDiagnostics; |
| | 24 | | private HttpPipeline _pipeline; |
| | 25 | |
|
| | 26 | | /// <summary> Initializes a new instance of ServiceRestClient. </summary> |
| | 27 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 28 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 29 | | /// <param name="endpoint"> Supported Cognitive Services endpoints (protocol and hostname, for example: https:// |
| | 30 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> |
| 524 | 31 | | public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) |
| | 32 | | { |
| 524 | 33 | | if (endpoint == null) |
| | 34 | | { |
| 0 | 35 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 36 | | } |
| | 37 | |
|
| 524 | 38 | | this.endpoint = endpoint; |
| 524 | 39 | | _clientDiagnostics = clientDiagnostics; |
| 524 | 40 | | _pipeline = pipeline; |
| 524 | 41 | | } |
| | 42 | |
|
| | 43 | | internal HttpMessage CreateTrainCustomModelAsyncRequest(TrainRequest trainRequest) |
| | 44 | | { |
| 148 | 45 | | var message = _pipeline.CreateMessage(); |
| 148 | 46 | | var request = message.Request; |
| 148 | 47 | | request.Method = RequestMethod.Post; |
| 148 | 48 | | var uri = new RawRequestUriBuilder(); |
| 148 | 49 | | uri.AppendRaw(endpoint, false); |
| 148 | 50 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 148 | 51 | | uri.AppendPath("/custom/models", false); |
| 148 | 52 | | request.Uri = uri; |
| 148 | 53 | | request.Headers.Add("Content-Type", "application/json"); |
| 148 | 54 | | var content = new Utf8JsonRequestContent(); |
| 148 | 55 | | content.JsonWriter.WriteObjectValue(trainRequest); |
| 148 | 56 | | request.Content = content; |
| 148 | 57 | | return message; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | /// <summary> Create and train a custom model. The request must include a source parameter that is either an ext |
| | 61 | | /// <param name="trainRequest"> Training request parameters. </param> |
| | 62 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 63 | | /// <exception cref="ArgumentNullException"> <paramref name="trainRequest"/> is null. </exception> |
| | 64 | | public async Task<ResponseWithHeaders<ServiceTrainCustomModelAsyncHeaders>> TrainCustomModelAsyncAsync(TrainRequ |
| | 65 | | { |
| 76 | 66 | | if (trainRequest == null) |
| | 67 | | { |
| 0 | 68 | | throw new ArgumentNullException(nameof(trainRequest)); |
| | 69 | | } |
| | 70 | |
|
| 76 | 71 | | using var message = CreateTrainCustomModelAsyncRequest(trainRequest); |
| 76 | 72 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 76 | 73 | | var headers = new ServiceTrainCustomModelAsyncHeaders(message.Response); |
| 76 | 74 | | switch (message.Response.Status) |
| | 75 | | { |
| | 76 | | case 201: |
| 76 | 77 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 78 | | default: |
| 0 | 79 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 80 | | } |
| 76 | 81 | | } |
| | 82 | |
|
| | 83 | | /// <summary> Create and train a custom model. The request must include a source parameter that is either an ext |
| | 84 | | /// <param name="trainRequest"> Training request parameters. </param> |
| | 85 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 86 | | /// <exception cref="ArgumentNullException"> <paramref name="trainRequest"/> is null. </exception> |
| | 87 | | public ResponseWithHeaders<ServiceTrainCustomModelAsyncHeaders> TrainCustomModelAsync(TrainRequest trainRequest, |
| | 88 | | { |
| 72 | 89 | | if (trainRequest == null) |
| | 90 | | { |
| 0 | 91 | | throw new ArgumentNullException(nameof(trainRequest)); |
| | 92 | | } |
| | 93 | |
|
| 72 | 94 | | using var message = CreateTrainCustomModelAsyncRequest(trainRequest); |
| 72 | 95 | | _pipeline.Send(message, cancellationToken); |
| 72 | 96 | | var headers = new ServiceTrainCustomModelAsyncHeaders(message.Response); |
| 72 | 97 | | switch (message.Response.Status) |
| | 98 | | { |
| | 99 | | case 201: |
| 72 | 100 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 101 | | default: |
| 0 | 102 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 103 | | } |
| 72 | 104 | | } |
| | 105 | |
|
| | 106 | | internal HttpMessage CreateGetCustomModelRequest(Guid modelId, bool? includeKeys) |
| | 107 | | { |
| 1074 | 108 | | var message = _pipeline.CreateMessage(); |
| 1074 | 109 | | var request = message.Request; |
| 1074 | 110 | | request.Method = RequestMethod.Get; |
| 1074 | 111 | | var uri = new RawRequestUriBuilder(); |
| 1074 | 112 | | uri.AppendRaw(endpoint, false); |
| 1074 | 113 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 1074 | 114 | | uri.AppendPath("/custom/models/", false); |
| 1074 | 115 | | uri.AppendPath(modelId, true); |
| 1074 | 116 | | if (includeKeys != null) |
| | 117 | | { |
| 1074 | 118 | | uri.AppendQuery("includeKeys", includeKeys.Value, true); |
| | 119 | | } |
| 1074 | 120 | | request.Uri = uri; |
| 1074 | 121 | | return message; |
| | 122 | | } |
| | 123 | |
|
| | 124 | | /// <summary> Get detailed information about a custom model. </summary> |
| | 125 | | /// <param name="modelId"> Model identifier. </param> |
| | 126 | | /// <param name="includeKeys"> Include list of extracted keys in model information. </param> |
| | 127 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 128 | | public async Task<Response<Model>> GetCustomModelAsync(Guid modelId, bool? includeKeys = null, CancellationToken |
| | 129 | | { |
| 1064 | 130 | | using var message = CreateGetCustomModelRequest(modelId, includeKeys); |
| 1064 | 131 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1064 | 132 | | switch (message.Response.Status) |
| | 133 | | { |
| | 134 | | case 200: |
| | 135 | | { |
| | 136 | | Model value = default; |
| 1060 | 137 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1060 | 138 | | value = Model.DeserializeModel(document.RootElement); |
| 1060 | 139 | | return Response.FromValue(value, message.Response); |
| | 140 | | } |
| | 141 | | default: |
| 4 | 142 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 143 | | } |
| 1060 | 144 | | } |
| | 145 | |
|
| | 146 | | /// <summary> Get detailed information about a custom model. </summary> |
| | 147 | | /// <param name="modelId"> Model identifier. </param> |
| | 148 | | /// <param name="includeKeys"> Include list of extracted keys in model information. </param> |
| | 149 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 150 | | public Response<Model> GetCustomModel(Guid modelId, bool? includeKeys = null, CancellationToken cancellationToke |
| | 151 | | { |
| 10 | 152 | | using var message = CreateGetCustomModelRequest(modelId, includeKeys); |
| 10 | 153 | | _pipeline.Send(message, cancellationToken); |
| 10 | 154 | | switch (message.Response.Status) |
| | 155 | | { |
| | 156 | | case 200: |
| | 157 | | { |
| | 158 | | Model value = default; |
| 6 | 159 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 6 | 160 | | value = Model.DeserializeModel(document.RootElement); |
| 6 | 161 | | return Response.FromValue(value, message.Response); |
| | 162 | | } |
| | 163 | | default: |
| 4 | 164 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 165 | | } |
| 6 | 166 | | } |
| | 167 | |
|
| | 168 | | internal HttpMessage CreateDeleteCustomModelRequest(Guid modelId) |
| | 169 | | { |
| 108 | 170 | | var message = _pipeline.CreateMessage(); |
| 108 | 171 | | var request = message.Request; |
| 108 | 172 | | request.Method = RequestMethod.Delete; |
| 108 | 173 | | var uri = new RawRequestUriBuilder(); |
| 108 | 174 | | uri.AppendRaw(endpoint, false); |
| 108 | 175 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 108 | 176 | | uri.AppendPath("/custom/models/", false); |
| 108 | 177 | | uri.AppendPath(modelId, true); |
| 108 | 178 | | request.Uri = uri; |
| 108 | 179 | | return message; |
| | 180 | | } |
| | 181 | |
|
| | 182 | | /// <summary> Mark model for deletion. Model artifacts will be permanently removed within a predetermined period |
| | 183 | | /// <param name="modelId"> Model identifier. </param> |
| | 184 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 185 | | public async Task<Response> DeleteCustomModelAsync(Guid modelId, CancellationToken cancellationToken = default) |
| | 186 | | { |
| 54 | 187 | | using var message = CreateDeleteCustomModelRequest(modelId); |
| 54 | 188 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 54 | 189 | | switch (message.Response.Status) |
| | 190 | | { |
| | 191 | | case 204: |
| 52 | 192 | | return message.Response; |
| | 193 | | default: |
| 2 | 194 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 195 | | } |
| 52 | 196 | | } |
| | 197 | |
|
| | 198 | | /// <summary> Mark model for deletion. Model artifacts will be permanently removed within a predetermined period |
| | 199 | | /// <param name="modelId"> Model identifier. </param> |
| | 200 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 201 | | public Response DeleteCustomModel(Guid modelId, CancellationToken cancellationToken = default) |
| | 202 | | { |
| 54 | 203 | | using var message = CreateDeleteCustomModelRequest(modelId); |
| 54 | 204 | | _pipeline.Send(message, cancellationToken); |
| 54 | 205 | | switch (message.Response.Status) |
| | 206 | | { |
| | 207 | | case 204: |
| 52 | 208 | | return message.Response; |
| | 209 | | default: |
| 2 | 210 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 211 | | } |
| 52 | 212 | | } |
| | 213 | |
|
| | 214 | | internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, FormContentType contentType, Stream fileS |
| | 215 | | { |
| 68 | 216 | | var message = _pipeline.CreateMessage(); |
| 68 | 217 | | var request = message.Request; |
| 68 | 218 | | request.Method = RequestMethod.Post; |
| 68 | 219 | | var uri = new RawRequestUriBuilder(); |
| 68 | 220 | | uri.AppendRaw(endpoint, false); |
| 68 | 221 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 68 | 222 | | uri.AppendPath("/custom/models/", false); |
| 68 | 223 | | uri.AppendPath(modelId, true); |
| 68 | 224 | | uri.AppendPath("/analyze", false); |
| 68 | 225 | | if (includeTextDetails != null) |
| | 226 | | { |
| 68 | 227 | | uri.AppendQuery("includeTextDetails", includeTextDetails.Value, true); |
| | 228 | | } |
| 68 | 229 | | request.Uri = uri; |
| 68 | 230 | | request.Headers.Add("Content-Type", contentType.ToSerialString()); |
| 68 | 231 | | request.Content = RequestContent.Create(fileStream); |
| 68 | 232 | | return message; |
| | 233 | | } |
| | 234 | |
|
| | 235 | | /// <summary> Extract key-value pairs, tables, and semantic values from a given document. The input document mus |
| | 236 | | /// <param name="modelId"> Model identifier. </param> |
| | 237 | | /// <param name="contentType"> Upload file type. </param> |
| | 238 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 239 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 240 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 241 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 242 | | public async Task<ResponseWithHeaders<ServiceAnalyzeWithCustomModelHeaders>> AnalyzeWithCustomModelAsync(Guid mo |
| | 243 | | { |
| 36 | 244 | | if (fileStream == null) |
| | 245 | | { |
| 0 | 246 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 247 | | } |
| | 248 | |
|
| 36 | 249 | | using var message = CreateAnalyzeWithCustomModelRequest(modelId, contentType, fileStream, includeTextDetails |
| 36 | 250 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 34 | 251 | | var headers = new ServiceAnalyzeWithCustomModelHeaders(message.Response); |
| 34 | 252 | | switch (message.Response.Status) |
| | 253 | | { |
| | 254 | | case 202: |
| 34 | 255 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 256 | | default: |
| 0 | 257 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 258 | | } |
| 34 | 259 | | } |
| | 260 | |
|
| | 261 | | /// <summary> Extract key-value pairs, tables, and semantic values from a given document. The input document mus |
| | 262 | | /// <param name="modelId"> Model identifier. </param> |
| | 263 | | /// <param name="contentType"> Upload file type. </param> |
| | 264 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 265 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 266 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 267 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 268 | | public ResponseWithHeaders<ServiceAnalyzeWithCustomModelHeaders> AnalyzeWithCustomModel(Guid modelId, FormConten |
| | 269 | | { |
| 32 | 270 | | if (fileStream == null) |
| | 271 | | { |
| 0 | 272 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 273 | | } |
| | 274 | |
|
| 32 | 275 | | using var message = CreateAnalyzeWithCustomModelRequest(modelId, contentType, fileStream, includeTextDetails |
| 32 | 276 | | _pipeline.Send(message, cancellationToken); |
| 30 | 277 | | var headers = new ServiceAnalyzeWithCustomModelHeaders(message.Response); |
| 30 | 278 | | switch (message.Response.Status) |
| | 279 | | { |
| | 280 | | case 202: |
| 30 | 281 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 282 | | default: |
| 0 | 283 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 284 | | } |
| 30 | 285 | | } |
| | 286 | |
|
| | 287 | | internal HttpMessage CreateAnalyzeWithCustomModelRequest(Guid modelId, bool? includeTextDetails, SourcePath file |
| | 288 | | { |
| 40 | 289 | | var message = _pipeline.CreateMessage(); |
| 40 | 290 | | var request = message.Request; |
| 40 | 291 | | request.Method = RequestMethod.Post; |
| 40 | 292 | | var uri = new RawRequestUriBuilder(); |
| 40 | 293 | | uri.AppendRaw(endpoint, false); |
| 40 | 294 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 40 | 295 | | uri.AppendPath("/custom/models/", false); |
| 40 | 296 | | uri.AppendPath(modelId, true); |
| 40 | 297 | | uri.AppendPath("/analyze", false); |
| 40 | 298 | | if (includeTextDetails != null) |
| | 299 | | { |
| 40 | 300 | | uri.AppendQuery("includeTextDetails", includeTextDetails.Value, true); |
| | 301 | | } |
| 40 | 302 | | request.Uri = uri; |
| 40 | 303 | | request.Headers.Add("Content-Type", "application/json"); |
| 40 | 304 | | if (fileStream != null) |
| | 305 | | { |
| 40 | 306 | | var content = new Utf8JsonRequestContent(); |
| 40 | 307 | | content.JsonWriter.WriteObjectValue(fileStream); |
| 40 | 308 | | request.Content = content; |
| | 309 | | } |
| 40 | 310 | | return message; |
| | 311 | | } |
| | 312 | |
|
| | 313 | | /// <summary> Extract key-value pairs, tables, and semantic values from a given document. The input document mus |
| | 314 | | /// <param name="modelId"> Model identifier. </param> |
| | 315 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 316 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 317 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 318 | | public async Task<ResponseWithHeaders<ServiceAnalyzeWithCustomModelHeaders>> AnalyzeWithCustomModelAsync(Guid mo |
| | 319 | | { |
| 20 | 320 | | using var message = CreateAnalyzeWithCustomModelRequest(modelId, includeTextDetails, fileStream); |
| 20 | 321 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 18 | 322 | | var headers = new ServiceAnalyzeWithCustomModelHeaders(message.Response); |
| 18 | 323 | | switch (message.Response.Status) |
| | 324 | | { |
| | 325 | | case 202: |
| 18 | 326 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 327 | | default: |
| 0 | 328 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 329 | | } |
| 18 | 330 | | } |
| | 331 | |
|
| | 332 | | /// <summary> Extract key-value pairs, tables, and semantic values from a given document. The input document mus |
| | 333 | | /// <param name="modelId"> Model identifier. </param> |
| | 334 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 335 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 336 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 337 | | public ResponseWithHeaders<ServiceAnalyzeWithCustomModelHeaders> AnalyzeWithCustomModel(Guid modelId, bool? incl |
| | 338 | | { |
| 20 | 339 | | using var message = CreateAnalyzeWithCustomModelRequest(modelId, includeTextDetails, fileStream); |
| 20 | 340 | | _pipeline.Send(message, cancellationToken); |
| 18 | 341 | | var headers = new ServiceAnalyzeWithCustomModelHeaders(message.Response); |
| 18 | 342 | | switch (message.Response.Status) |
| | 343 | | { |
| | 344 | | case 202: |
| 18 | 345 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 346 | | default: |
| 0 | 347 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 348 | | } |
| 18 | 349 | | } |
| | 350 | |
|
| | 351 | | internal HttpMessage CreateGetAnalyzeFormResultRequest(Guid modelId, Guid resultId) |
| | 352 | | { |
| 734 | 353 | | var message = _pipeline.CreateMessage(); |
| 734 | 354 | | var request = message.Request; |
| 734 | 355 | | request.Method = RequestMethod.Get; |
| 734 | 356 | | var uri = new RawRequestUriBuilder(); |
| 734 | 357 | | uri.AppendRaw(endpoint, false); |
| 734 | 358 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 734 | 359 | | uri.AppendPath("/custom/models/", false); |
| 734 | 360 | | uri.AppendPath(modelId, true); |
| 734 | 361 | | uri.AppendPath("/analyzeResults/", false); |
| 734 | 362 | | uri.AppendPath(resultId, true); |
| 734 | 363 | | request.Uri = uri; |
| 734 | 364 | | return message; |
| | 365 | | } |
| | 366 | |
|
| | 367 | | /// <summary> Obtain current status and the result of the analyze form operation. </summary> |
| | 368 | | /// <param name="modelId"> Model identifier. </param> |
| | 369 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 370 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 371 | | public async Task<Response<AnalyzeOperationResult>> GetAnalyzeFormResultAsync(Guid modelId, Guid resultId, Cance |
| | 372 | | { |
| 734 | 373 | | using var message = CreateGetAnalyzeFormResultRequest(modelId, resultId); |
| 734 | 374 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 734 | 375 | | switch (message.Response.Status) |
| | 376 | | { |
| | 377 | | case 200: |
| | 378 | | { |
| | 379 | | AnalyzeOperationResult value = default; |
| 734 | 380 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 734 | 381 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 734 | 382 | | return Response.FromValue(value, message.Response); |
| | 383 | | } |
| | 384 | | default: |
| 0 | 385 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 386 | | } |
| 734 | 387 | | } |
| | 388 | |
|
| | 389 | | /// <summary> Obtain current status and the result of the analyze form operation. </summary> |
| | 390 | | /// <param name="modelId"> Model identifier. </param> |
| | 391 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 392 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 393 | | public Response<AnalyzeOperationResult> GetAnalyzeFormResult(Guid modelId, Guid resultId, CancellationToken canc |
| | 394 | | { |
| 0 | 395 | | using var message = CreateGetAnalyzeFormResultRequest(modelId, resultId); |
| 0 | 396 | | _pipeline.Send(message, cancellationToken); |
| 0 | 397 | | switch (message.Response.Status) |
| | 398 | | { |
| | 399 | | case 200: |
| | 400 | | { |
| | 401 | | AnalyzeOperationResult value = default; |
| 0 | 402 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 403 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 0 | 404 | | return Response.FromValue(value, message.Response); |
| | 405 | | } |
| | 406 | | default: |
| 0 | 407 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 408 | | } |
| 0 | 409 | | } |
| | 410 | |
|
| | 411 | | internal HttpMessage CreateCopyCustomModelRequest(Guid modelId, CopyRequest copyRequest) |
| | 412 | | { |
| 12 | 413 | | var message = _pipeline.CreateMessage(); |
| 12 | 414 | | var request = message.Request; |
| 12 | 415 | | request.Method = RequestMethod.Post; |
| 12 | 416 | | var uri = new RawRequestUriBuilder(); |
| 12 | 417 | | uri.AppendRaw(endpoint, false); |
| 12 | 418 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 12 | 419 | | uri.AppendPath("/custom/models/", false); |
| 12 | 420 | | uri.AppendPath(modelId, true); |
| 12 | 421 | | uri.AppendPath("/copy", false); |
| 12 | 422 | | request.Uri = uri; |
| 12 | 423 | | request.Headers.Add("Content-Type", "application/json"); |
| 12 | 424 | | var content = new Utf8JsonRequestContent(); |
| 12 | 425 | | content.JsonWriter.WriteObjectValue(copyRequest); |
| 12 | 426 | | request.Content = content; |
| 12 | 427 | | return message; |
| | 428 | | } |
| | 429 | |
|
| | 430 | | /// <summary> Copy custom model stored in this resource (the source) to user specified target Form Recognizer re |
| | 431 | | /// <param name="modelId"> Model identifier. </param> |
| | 432 | | /// <param name="copyRequest"> Copy request parameters. </param> |
| | 433 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 434 | | /// <exception cref="ArgumentNullException"> <paramref name="copyRequest"/> is null. </exception> |
| | 435 | | public async Task<ResponseWithHeaders<ServiceCopyCustomModelHeaders>> CopyCustomModelAsync(Guid modelId, CopyReq |
| | 436 | | { |
| 8 | 437 | | if (copyRequest == null) |
| | 438 | | { |
| 0 | 439 | | throw new ArgumentNullException(nameof(copyRequest)); |
| | 440 | | } |
| | 441 | |
|
| 8 | 442 | | using var message = CreateCopyCustomModelRequest(modelId, copyRequest); |
| 8 | 443 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 8 | 444 | | var headers = new ServiceCopyCustomModelHeaders(message.Response); |
| 8 | 445 | | switch (message.Response.Status) |
| | 446 | | { |
| | 447 | | case 202: |
| 8 | 448 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 449 | | default: |
| 0 | 450 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 451 | | } |
| 8 | 452 | | } |
| | 453 | |
|
| | 454 | | /// <summary> Copy custom model stored in this resource (the source) to user specified target Form Recognizer re |
| | 455 | | /// <param name="modelId"> Model identifier. </param> |
| | 456 | | /// <param name="copyRequest"> Copy request parameters. </param> |
| | 457 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 458 | | /// <exception cref="ArgumentNullException"> <paramref name="copyRequest"/> is null. </exception> |
| | 459 | | public ResponseWithHeaders<ServiceCopyCustomModelHeaders> CopyCustomModel(Guid modelId, CopyRequest copyRequest, |
| | 460 | | { |
| 4 | 461 | | if (copyRequest == null) |
| | 462 | | { |
| 0 | 463 | | throw new ArgumentNullException(nameof(copyRequest)); |
| | 464 | | } |
| | 465 | |
|
| 4 | 466 | | using var message = CreateCopyCustomModelRequest(modelId, copyRequest); |
| 4 | 467 | | _pipeline.Send(message, cancellationToken); |
| 4 | 468 | | var headers = new ServiceCopyCustomModelHeaders(message.Response); |
| 4 | 469 | | switch (message.Response.Status) |
| | 470 | | { |
| | 471 | | case 202: |
| 4 | 472 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 473 | | default: |
| 0 | 474 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 475 | | } |
| 4 | 476 | | } |
| | 477 | |
|
| | 478 | | internal HttpMessage CreateGetCustomModelCopyResultRequest(Guid modelId, Guid resultId) |
| | 479 | | { |
| 186 | 480 | | var message = _pipeline.CreateMessage(); |
| 186 | 481 | | var request = message.Request; |
| 186 | 482 | | request.Method = RequestMethod.Get; |
| 186 | 483 | | var uri = new RawRequestUriBuilder(); |
| 186 | 484 | | uri.AppendRaw(endpoint, false); |
| 186 | 485 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 186 | 486 | | uri.AppendPath("/custom/models/", false); |
| 186 | 487 | | uri.AppendPath(modelId, true); |
| 186 | 488 | | uri.AppendPath("/copyResults/", false); |
| 186 | 489 | | uri.AppendPath(resultId, true); |
| 186 | 490 | | request.Uri = uri; |
| 186 | 491 | | return message; |
| | 492 | | } |
| | 493 | |
|
| | 494 | | /// <summary> Obtain current status and the result of a custom model copy operation. </summary> |
| | 495 | | /// <param name="modelId"> Model identifier. </param> |
| | 496 | | /// <param name="resultId"> Copy operation result identifier. </param> |
| | 497 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 498 | | public async Task<Response<CopyOperationResult>> GetCustomModelCopyResultAsync(Guid modelId, Guid resultId, Canc |
| | 499 | | { |
| 186 | 500 | | using var message = CreateGetCustomModelCopyResultRequest(modelId, resultId); |
| 186 | 501 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 186 | 502 | | switch (message.Response.Status) |
| | 503 | | { |
| | 504 | | case 200: |
| | 505 | | { |
| | 506 | | CopyOperationResult value = default; |
| 186 | 507 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 186 | 508 | | value = CopyOperationResult.DeserializeCopyOperationResult(document.RootElement); |
| 186 | 509 | | return Response.FromValue(value, message.Response); |
| | 510 | | } |
| | 511 | | default: |
| 0 | 512 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 513 | | } |
| 186 | 514 | | } |
| | 515 | |
|
| | 516 | | /// <summary> Obtain current status and the result of a custom model copy operation. </summary> |
| | 517 | | /// <param name="modelId"> Model identifier. </param> |
| | 518 | | /// <param name="resultId"> Copy operation result identifier. </param> |
| | 519 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 520 | | public Response<CopyOperationResult> GetCustomModelCopyResult(Guid modelId, Guid resultId, CancellationToken can |
| | 521 | | { |
| 0 | 522 | | using var message = CreateGetCustomModelCopyResultRequest(modelId, resultId); |
| 0 | 523 | | _pipeline.Send(message, cancellationToken); |
| 0 | 524 | | switch (message.Response.Status) |
| | 525 | | { |
| | 526 | | case 200: |
| | 527 | | { |
| | 528 | | CopyOperationResult value = default; |
| 0 | 529 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 530 | | value = CopyOperationResult.DeserializeCopyOperationResult(document.RootElement); |
| 0 | 531 | | return Response.FromValue(value, message.Response); |
| | 532 | | } |
| | 533 | | default: |
| 0 | 534 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 535 | | } |
| 0 | 536 | | } |
| | 537 | |
|
| | 538 | | internal HttpMessage CreateGenerateModelCopyAuthorizationRequest() |
| | 539 | | { |
| 20 | 540 | | var message = _pipeline.CreateMessage(); |
| 20 | 541 | | var request = message.Request; |
| 20 | 542 | | request.Method = RequestMethod.Post; |
| 20 | 543 | | var uri = new RawRequestUriBuilder(); |
| 20 | 544 | | uri.AppendRaw(endpoint, false); |
| 20 | 545 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 20 | 546 | | uri.AppendPath("/custom/models/copyAuthorization", false); |
| 20 | 547 | | request.Uri = uri; |
| 20 | 548 | | return message; |
| | 549 | | } |
| | 550 | |
|
| | 551 | | /// <summary> Generate authorization to copy a model into the target Form Recognizer resource. </summary> |
| | 552 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 553 | | public async Task<ResponseWithHeaders<CopyAuthorizationResult, ServiceGenerateModelCopyAuthorizationHeaders>> Ge |
| | 554 | | { |
| 12 | 555 | | using var message = CreateGenerateModelCopyAuthorizationRequest(); |
| 12 | 556 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 12 | 557 | | var headers = new ServiceGenerateModelCopyAuthorizationHeaders(message.Response); |
| 12 | 558 | | switch (message.Response.Status) |
| | 559 | | { |
| | 560 | | case 201: |
| | 561 | | { |
| | 562 | | CopyAuthorizationResult value = default; |
| 12 | 563 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 12 | 564 | | value = CopyAuthorizationResult.DeserializeCopyAuthorizationResult(document.RootElement); |
| 12 | 565 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 566 | | } |
| | 567 | | default: |
| 0 | 568 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 569 | | } |
| 12 | 570 | | } |
| | 571 | |
|
| | 572 | | /// <summary> Generate authorization to copy a model into the target Form Recognizer resource. </summary> |
| | 573 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 574 | | public ResponseWithHeaders<CopyAuthorizationResult, ServiceGenerateModelCopyAuthorizationHeaders> GenerateModelC |
| | 575 | | { |
| 8 | 576 | | using var message = CreateGenerateModelCopyAuthorizationRequest(); |
| 8 | 577 | | _pipeline.Send(message, cancellationToken); |
| 8 | 578 | | var headers = new ServiceGenerateModelCopyAuthorizationHeaders(message.Response); |
| 8 | 579 | | switch (message.Response.Status) |
| | 580 | | { |
| | 581 | | case 201: |
| | 582 | | { |
| | 583 | | CopyAuthorizationResult value = default; |
| 8 | 584 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 8 | 585 | | value = CopyAuthorizationResult.DeserializeCopyAuthorizationResult(document.RootElement); |
| 8 | 586 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 587 | | } |
| | 588 | | default: |
| 0 | 589 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 590 | | } |
| 8 | 591 | | } |
| | 592 | |
|
| | 593 | | internal HttpMessage CreateAnalyzeReceiptAsyncRequest(FormContentType contentType, Stream fileStream, bool? incl |
| | 594 | | { |
| 36 | 595 | | var message = _pipeline.CreateMessage(); |
| 36 | 596 | | var request = message.Request; |
| 36 | 597 | | request.Method = RequestMethod.Post; |
| 36 | 598 | | var uri = new RawRequestUriBuilder(); |
| 36 | 599 | | uri.AppendRaw(endpoint, false); |
| 36 | 600 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 36 | 601 | | uri.AppendPath("/prebuilt/receipt/analyze", false); |
| 36 | 602 | | if (includeTextDetails != null) |
| | 603 | | { |
| 36 | 604 | | uri.AppendQuery("includeTextDetails", includeTextDetails.Value, true); |
| | 605 | | } |
| 36 | 606 | | request.Uri = uri; |
| 36 | 607 | | request.Headers.Add("Content-Type", contentType.ToSerialString()); |
| 36 | 608 | | request.Content = RequestContent.Create(fileStream); |
| 36 | 609 | | return message; |
| | 610 | | } |
| | 611 | |
|
| | 612 | | /// <summary> Extract field text and semantic values from a given receipt document. The input document must be o |
| | 613 | | /// <param name="contentType"> Upload file type. </param> |
| | 614 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 615 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 616 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 617 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 618 | | public async Task<ResponseWithHeaders<ServiceAnalyzeReceiptAsyncHeaders>> AnalyzeReceiptAsyncAsync(FormContentTy |
| | 619 | | { |
| 18 | 620 | | if (fileStream == null) |
| | 621 | | { |
| 0 | 622 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 623 | | } |
| | 624 | |
|
| 18 | 625 | | using var message = CreateAnalyzeReceiptAsyncRequest(contentType, fileStream, includeTextDetails); |
| 18 | 626 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 16 | 627 | | var headers = new ServiceAnalyzeReceiptAsyncHeaders(message.Response); |
| 16 | 628 | | switch (message.Response.Status) |
| | 629 | | { |
| | 630 | | case 202: |
| 14 | 631 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 632 | | default: |
| 2 | 633 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 634 | | } |
| 14 | 635 | | } |
| | 636 | |
|
| | 637 | | /// <summary> Extract field text and semantic values from a given receipt document. The input document must be o |
| | 638 | | /// <param name="contentType"> Upload file type. </param> |
| | 639 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 640 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 641 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 642 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 643 | | public ResponseWithHeaders<ServiceAnalyzeReceiptAsyncHeaders> AnalyzeReceiptAsync(FormContentType contentType, S |
| | 644 | | { |
| 18 | 645 | | if (fileStream == null) |
| | 646 | | { |
| 0 | 647 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 648 | | } |
| | 649 | |
|
| 18 | 650 | | using var message = CreateAnalyzeReceiptAsyncRequest(contentType, fileStream, includeTextDetails); |
| 18 | 651 | | _pipeline.Send(message, cancellationToken); |
| 16 | 652 | | var headers = new ServiceAnalyzeReceiptAsyncHeaders(message.Response); |
| 16 | 653 | | switch (message.Response.Status) |
| | 654 | | { |
| | 655 | | case 202: |
| 14 | 656 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 657 | | default: |
| 2 | 658 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 659 | | } |
| 14 | 660 | | } |
| | 661 | |
|
| | 662 | | internal HttpMessage CreateAnalyzeReceiptAsyncRequest(bool? includeTextDetails, SourcePath fileStream) |
| | 663 | | { |
| 32 | 664 | | var message = _pipeline.CreateMessage(); |
| 32 | 665 | | var request = message.Request; |
| 32 | 666 | | request.Method = RequestMethod.Post; |
| 32 | 667 | | var uri = new RawRequestUriBuilder(); |
| 32 | 668 | | uri.AppendRaw(endpoint, false); |
| 32 | 669 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 32 | 670 | | uri.AppendPath("/prebuilt/receipt/analyze", false); |
| 32 | 671 | | if (includeTextDetails != null) |
| | 672 | | { |
| 32 | 673 | | uri.AppendQuery("includeTextDetails", includeTextDetails.Value, true); |
| | 674 | | } |
| 32 | 675 | | request.Uri = uri; |
| 32 | 676 | | request.Headers.Add("Content-Type", "application/json"); |
| 32 | 677 | | if (fileStream != null) |
| | 678 | | { |
| 32 | 679 | | var content = new Utf8JsonRequestContent(); |
| 32 | 680 | | content.JsonWriter.WriteObjectValue(fileStream); |
| 32 | 681 | | request.Content = content; |
| | 682 | | } |
| 32 | 683 | | return message; |
| | 684 | | } |
| | 685 | |
|
| | 686 | | /// <summary> Extract field text and semantic values from a given receipt document. The input document must be o |
| | 687 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 688 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 689 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 690 | | public async Task<ResponseWithHeaders<ServiceAnalyzeReceiptAsyncHeaders>> AnalyzeReceiptAsyncAsync(bool? include |
| | 691 | | { |
| 18 | 692 | | using var message = CreateAnalyzeReceiptAsyncRequest(includeTextDetails, fileStream); |
| 18 | 693 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 16 | 694 | | var headers = new ServiceAnalyzeReceiptAsyncHeaders(message.Response); |
| 16 | 695 | | switch (message.Response.Status) |
| | 696 | | { |
| | 697 | | case 202: |
| 14 | 698 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 699 | | default: |
| 2 | 700 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 701 | | } |
| 14 | 702 | | } |
| | 703 | |
|
| | 704 | | /// <summary> Extract field text and semantic values from a given receipt document. The input document must be o |
| | 705 | | /// <param name="includeTextDetails"> Include text lines and element references in the result. </param> |
| | 706 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 707 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 708 | | public ResponseWithHeaders<ServiceAnalyzeReceiptAsyncHeaders> AnalyzeReceiptAsync(bool? includeTextDetails = nul |
| | 709 | | { |
| 14 | 710 | | using var message = CreateAnalyzeReceiptAsyncRequest(includeTextDetails, fileStream); |
| 14 | 711 | | _pipeline.Send(message, cancellationToken); |
| 12 | 712 | | var headers = new ServiceAnalyzeReceiptAsyncHeaders(message.Response); |
| 12 | 713 | | switch (message.Response.Status) |
| | 714 | | { |
| | 715 | | case 202: |
| 10 | 716 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 717 | | default: |
| 2 | 718 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 719 | | } |
| 10 | 720 | | } |
| | 721 | |
|
| | 722 | | internal HttpMessage CreateGetAnalyzeReceiptResultRequest(Guid resultId) |
| | 723 | | { |
| 144 | 724 | | var message = _pipeline.CreateMessage(); |
| 144 | 725 | | var request = message.Request; |
| 144 | 726 | | request.Method = RequestMethod.Get; |
| 144 | 727 | | var uri = new RawRequestUriBuilder(); |
| 144 | 728 | | uri.AppendRaw(endpoint, false); |
| 144 | 729 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 144 | 730 | | uri.AppendPath("/prebuilt/receipt/analyzeResults/", false); |
| 144 | 731 | | uri.AppendPath(resultId, true); |
| 144 | 732 | | request.Uri = uri; |
| 144 | 733 | | return message; |
| | 734 | | } |
| | 735 | |
|
| | 736 | | /// <summary> Track the progress and obtain the result of the analyze receipt operation. </summary> |
| | 737 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 738 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 739 | | public async Task<Response<AnalyzeOperationResult>> GetAnalyzeReceiptResultAsync(Guid resultId, CancellationToke |
| | 740 | | { |
| 144 | 741 | | using var message = CreateGetAnalyzeReceiptResultRequest(resultId); |
| 144 | 742 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 144 | 743 | | switch (message.Response.Status) |
| | 744 | | { |
| | 745 | | case 200: |
| | 746 | | { |
| | 747 | | AnalyzeOperationResult value = default; |
| 144 | 748 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 144 | 749 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 144 | 750 | | return Response.FromValue(value, message.Response); |
| | 751 | | } |
| | 752 | | default: |
| 0 | 753 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 754 | | } |
| 144 | 755 | | } |
| | 756 | |
|
| | 757 | | /// <summary> Track the progress and obtain the result of the analyze receipt operation. </summary> |
| | 758 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 759 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 760 | | public Response<AnalyzeOperationResult> GetAnalyzeReceiptResult(Guid resultId, CancellationToken cancellationTok |
| | 761 | | { |
| 0 | 762 | | using var message = CreateGetAnalyzeReceiptResultRequest(resultId); |
| 0 | 763 | | _pipeline.Send(message, cancellationToken); |
| 0 | 764 | | switch (message.Response.Status) |
| | 765 | | { |
| | 766 | | case 200: |
| | 767 | | { |
| | 768 | | AnalyzeOperationResult value = default; |
| 0 | 769 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 770 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 0 | 771 | | return Response.FromValue(value, message.Response); |
| | 772 | | } |
| | 773 | | default: |
| 0 | 774 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 775 | | } |
| 0 | 776 | | } |
| | 777 | |
|
| | 778 | | internal HttpMessage CreateAnalyzeLayoutAsyncRequest(FormContentType contentType, Stream fileStream) |
| | 779 | | { |
| 44 | 780 | | var message = _pipeline.CreateMessage(); |
| 44 | 781 | | var request = message.Request; |
| 44 | 782 | | request.Method = RequestMethod.Post; |
| 44 | 783 | | var uri = new RawRequestUriBuilder(); |
| 44 | 784 | | uri.AppendRaw(endpoint, false); |
| 44 | 785 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 44 | 786 | | uri.AppendPath("/layout/analyze", false); |
| 44 | 787 | | request.Uri = uri; |
| 44 | 788 | | request.Headers.Add("Content-Type", contentType.ToSerialString()); |
| 44 | 789 | | request.Content = RequestContent.Create(fileStream); |
| 44 | 790 | | return message; |
| | 791 | | } |
| | 792 | |
|
| | 793 | | /// <summary> Extract text and layout information from a given document. The input document must be of one of th |
| | 794 | | /// <param name="contentType"> Upload file type. </param> |
| | 795 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 796 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 797 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 798 | | public async Task<ResponseWithHeaders<ServiceAnalyzeLayoutAsyncHeaders>> AnalyzeLayoutAsyncAsync(FormContentType |
| | 799 | | { |
| 22 | 800 | | if (fileStream == null) |
| | 801 | | { |
| 0 | 802 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 803 | | } |
| | 804 | |
|
| 22 | 805 | | using var message = CreateAnalyzeLayoutAsyncRequest(contentType, fileStream); |
| 22 | 806 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 20 | 807 | | var headers = new ServiceAnalyzeLayoutAsyncHeaders(message.Response); |
| 20 | 808 | | switch (message.Response.Status) |
| | 809 | | { |
| | 810 | | case 202: |
| 16 | 811 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 812 | | default: |
| 4 | 813 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 814 | | } |
| 16 | 815 | | } |
| | 816 | |
|
| | 817 | | /// <summary> Extract text and layout information from a given document. The input document must be of one of th |
| | 818 | | /// <param name="contentType"> Upload file type. </param> |
| | 819 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 820 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 821 | | /// <exception cref="ArgumentNullException"> <paramref name="fileStream"/> is null. </exception> |
| | 822 | | public ResponseWithHeaders<ServiceAnalyzeLayoutAsyncHeaders> AnalyzeLayoutAsync(FormContentType contentType, Str |
| | 823 | | { |
| 22 | 824 | | if (fileStream == null) |
| | 825 | | { |
| 0 | 826 | | throw new ArgumentNullException(nameof(fileStream)); |
| | 827 | | } |
| | 828 | |
|
| 22 | 829 | | using var message = CreateAnalyzeLayoutAsyncRequest(contentType, fileStream); |
| 22 | 830 | | _pipeline.Send(message, cancellationToken); |
| 20 | 831 | | var headers = new ServiceAnalyzeLayoutAsyncHeaders(message.Response); |
| 20 | 832 | | switch (message.Response.Status) |
| | 833 | | { |
| | 834 | | case 202: |
| 16 | 835 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 836 | | default: |
| 4 | 837 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 838 | | } |
| 16 | 839 | | } |
| | 840 | |
|
| | 841 | | internal HttpMessage CreateAnalyzeLayoutAsyncRequest(SourcePath fileStream) |
| | 842 | | { |
| 36 | 843 | | var message = _pipeline.CreateMessage(); |
| 36 | 844 | | var request = message.Request; |
| 36 | 845 | | request.Method = RequestMethod.Post; |
| 36 | 846 | | var uri = new RawRequestUriBuilder(); |
| 36 | 847 | | uri.AppendRaw(endpoint, false); |
| 36 | 848 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 36 | 849 | | uri.AppendPath("/layout/analyze", false); |
| 36 | 850 | | request.Uri = uri; |
| 36 | 851 | | request.Headers.Add("Content-Type", "application/json"); |
| 36 | 852 | | if (fileStream != null) |
| | 853 | | { |
| 36 | 854 | | var content = new Utf8JsonRequestContent(); |
| 36 | 855 | | content.JsonWriter.WriteObjectValue(fileStream); |
| 36 | 856 | | request.Content = content; |
| | 857 | | } |
| 36 | 858 | | return message; |
| | 859 | | } |
| | 860 | |
|
| | 861 | | /// <summary> Extract text and layout information from a given document. The input document must be of one of th |
| | 862 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 863 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 864 | | public async Task<ResponseWithHeaders<ServiceAnalyzeLayoutAsyncHeaders>> AnalyzeLayoutAsyncAsync(SourcePath file |
| | 865 | | { |
| 20 | 866 | | using var message = CreateAnalyzeLayoutAsyncRequest(fileStream); |
| 20 | 867 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 16 | 868 | | var headers = new ServiceAnalyzeLayoutAsyncHeaders(message.Response); |
| 16 | 869 | | switch (message.Response.Status) |
| | 870 | | { |
| | 871 | | case 202: |
| 14 | 872 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 873 | | default: |
| 2 | 874 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 875 | | } |
| 14 | 876 | | } |
| | 877 | |
|
| | 878 | | /// <summary> Extract text and layout information from a given document. The input document must be of one of th |
| | 879 | | /// <param name="fileStream"> .json, .pdf, .jpg, .png or .tiff type file stream. </param> |
| | 880 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 881 | | public ResponseWithHeaders<ServiceAnalyzeLayoutAsyncHeaders> AnalyzeLayoutAsync(SourcePath fileStream = null, Ca |
| | 882 | | { |
| 16 | 883 | | using var message = CreateAnalyzeLayoutAsyncRequest(fileStream); |
| 16 | 884 | | _pipeline.Send(message, cancellationToken); |
| 12 | 885 | | var headers = new ServiceAnalyzeLayoutAsyncHeaders(message.Response); |
| 12 | 886 | | switch (message.Response.Status) |
| | 887 | | { |
| | 888 | | case 202: |
| 10 | 889 | | return ResponseWithHeaders.FromValue(headers, message.Response); |
| | 890 | | default: |
| 2 | 891 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 892 | | } |
| 10 | 893 | | } |
| | 894 | |
|
| | 895 | | internal HttpMessage CreateGetAnalyzeLayoutResultRequest(Guid resultId) |
| | 896 | | { |
| 180 | 897 | | var message = _pipeline.CreateMessage(); |
| 180 | 898 | | var request = message.Request; |
| 180 | 899 | | request.Method = RequestMethod.Get; |
| 180 | 900 | | var uri = new RawRequestUriBuilder(); |
| 180 | 901 | | uri.AppendRaw(endpoint, false); |
| 180 | 902 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 180 | 903 | | uri.AppendPath("/layout/analyzeResults/", false); |
| 180 | 904 | | uri.AppendPath(resultId, true); |
| 180 | 905 | | request.Uri = uri; |
| 180 | 906 | | return message; |
| | 907 | | } |
| | 908 | |
|
| | 909 | | /// <summary> Track the progress and obtain the result of the analyze layout operation. </summary> |
| | 910 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 911 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 912 | | public async Task<Response<AnalyzeOperationResult>> GetAnalyzeLayoutResultAsync(Guid resultId, CancellationToken |
| | 913 | | { |
| 180 | 914 | | using var message = CreateGetAnalyzeLayoutResultRequest(resultId); |
| 180 | 915 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 180 | 916 | | switch (message.Response.Status) |
| | 917 | | { |
| | 918 | | case 200: |
| | 919 | | { |
| | 920 | | AnalyzeOperationResult value = default; |
| 180 | 921 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 180 | 922 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 180 | 923 | | return Response.FromValue(value, message.Response); |
| | 924 | | } |
| | 925 | | default: |
| 0 | 926 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 927 | | } |
| 180 | 928 | | } |
| | 929 | |
|
| | 930 | | /// <summary> Track the progress and obtain the result of the analyze layout operation. </summary> |
| | 931 | | /// <param name="resultId"> Analyze operation result identifier. </param> |
| | 932 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 933 | | public Response<AnalyzeOperationResult> GetAnalyzeLayoutResult(Guid resultId, CancellationToken cancellationToke |
| | 934 | | { |
| 0 | 935 | | using var message = CreateGetAnalyzeLayoutResultRequest(resultId); |
| 0 | 936 | | _pipeline.Send(message, cancellationToken); |
| 0 | 937 | | switch (message.Response.Status) |
| | 938 | | { |
| | 939 | | case 200: |
| | 940 | | { |
| | 941 | | AnalyzeOperationResult value = default; |
| 0 | 942 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 943 | | value = AnalyzeOperationResult.DeserializeAnalyzeOperationResult(document.RootElement); |
| 0 | 944 | | return Response.FromValue(value, message.Response); |
| | 945 | | } |
| | 946 | | default: |
| 0 | 947 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 948 | | } |
| 0 | 949 | | } |
| | 950 | |
|
| | 951 | | internal HttpMessage CreateListCustomModelsRequest() |
| | 952 | | { |
| 8 | 953 | | var message = _pipeline.CreateMessage(); |
| 8 | 954 | | var request = message.Request; |
| 8 | 955 | | request.Method = RequestMethod.Get; |
| 8 | 956 | | var uri = new RawRequestUriBuilder(); |
| 8 | 957 | | uri.AppendRaw(endpoint, false); |
| 8 | 958 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 8 | 959 | | uri.AppendPath("/custom/models", false); |
| 8 | 960 | | uri.AppendQuery("op", "full", true); |
| 8 | 961 | | request.Uri = uri; |
| 8 | 962 | | return message; |
| | 963 | | } |
| | 964 | |
|
| | 965 | | /// <summary> Get information about all custom models. </summary> |
| | 966 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 967 | | public async Task<Response<Models.Models>> ListCustomModelsAsync(CancellationToken cancellationToken = default) |
| | 968 | | { |
| 4 | 969 | | using var message = CreateListCustomModelsRequest(); |
| 4 | 970 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 971 | | switch (message.Response.Status) |
| | 972 | | { |
| | 973 | | case 200: |
| | 974 | | { |
| | 975 | | Models.Models value = default; |
| 4 | 976 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 4 | 977 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 4 | 978 | | return Response.FromValue(value, message.Response); |
| | 979 | | } |
| | 980 | | default: |
| 0 | 981 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 982 | | } |
| 4 | 983 | | } |
| | 984 | |
|
| | 985 | | /// <summary> Get information about all custom models. </summary> |
| | 986 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 987 | | public Response<Models.Models> ListCustomModels(CancellationToken cancellationToken = default) |
| | 988 | | { |
| 4 | 989 | | using var message = CreateListCustomModelsRequest(); |
| 4 | 990 | | _pipeline.Send(message, cancellationToken); |
| 4 | 991 | | switch (message.Response.Status) |
| | 992 | | { |
| | 993 | | case 200: |
| | 994 | | { |
| | 995 | | Models.Models value = default; |
| 4 | 996 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 4 | 997 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 4 | 998 | | return Response.FromValue(value, message.Response); |
| | 999 | | } |
| | 1000 | | default: |
| 0 | 1001 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 1002 | | } |
| 4 | 1003 | | } |
| | 1004 | |
|
| | 1005 | | internal HttpMessage CreateGetCustomModelsRequest() |
| | 1006 | | { |
| 16 | 1007 | | var message = _pipeline.CreateMessage(); |
| 16 | 1008 | | var request = message.Request; |
| 16 | 1009 | | request.Method = RequestMethod.Get; |
| 16 | 1010 | | var uri = new RawRequestUriBuilder(); |
| 16 | 1011 | | uri.AppendRaw(endpoint, false); |
| 16 | 1012 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 16 | 1013 | | uri.AppendPath("/custom/models", false); |
| 16 | 1014 | | uri.AppendQuery("op", "summary", true); |
| 16 | 1015 | | request.Uri = uri; |
| 16 | 1016 | | return message; |
| | 1017 | | } |
| | 1018 | |
|
| | 1019 | | /// <summary> Get information about all custom models. </summary> |
| | 1020 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1021 | | public async Task<Response<Models.Models>> GetCustomModelsAsync(CancellationToken cancellationToken = default) |
| | 1022 | | { |
| 8 | 1023 | | using var message = CreateGetCustomModelsRequest(); |
| 8 | 1024 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 6 | 1025 | | switch (message.Response.Status) |
| | 1026 | | { |
| | 1027 | | case 200: |
| | 1028 | | { |
| | 1029 | | Models.Models value = default; |
| 4 | 1030 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 4 | 1031 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 4 | 1032 | | return Response.FromValue(value, message.Response); |
| | 1033 | | } |
| | 1034 | | default: |
| 2 | 1035 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 1036 | | } |
| 4 | 1037 | | } |
| | 1038 | |
|
| | 1039 | | /// <summary> Get information about all custom models. </summary> |
| | 1040 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1041 | | public Response<Models.Models> GetCustomModels(CancellationToken cancellationToken = default) |
| | 1042 | | { |
| 8 | 1043 | | using var message = CreateGetCustomModelsRequest(); |
| 8 | 1044 | | _pipeline.Send(message, cancellationToken); |
| 6 | 1045 | | switch (message.Response.Status) |
| | 1046 | | { |
| | 1047 | | case 200: |
| | 1048 | | { |
| | 1049 | | Models.Models value = default; |
| 4 | 1050 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 4 | 1051 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 4 | 1052 | | return Response.FromValue(value, message.Response); |
| | 1053 | | } |
| | 1054 | | default: |
| 2 | 1055 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 1056 | | } |
| 4 | 1057 | | } |
| | 1058 | |
|
| | 1059 | | internal HttpMessage CreateListCustomModelsNextPageRequest(string nextLink) |
| | 1060 | | { |
| 4 | 1061 | | var message = _pipeline.CreateMessage(); |
| 4 | 1062 | | var request = message.Request; |
| 4 | 1063 | | request.Method = RequestMethod.Get; |
| 4 | 1064 | | var uri = new RawRequestUriBuilder(); |
| 4 | 1065 | | uri.AppendRaw(endpoint, false); |
| 4 | 1066 | | uri.AppendRaw("/formrecognizer/v2.0", false); |
| 4 | 1067 | | uri.AppendRawNextLink(nextLink, false); |
| 4 | 1068 | | request.Uri = uri; |
| 4 | 1069 | | return message; |
| | 1070 | | } |
| | 1071 | |
|
| | 1072 | | /// <summary> Get information about all custom models. </summary> |
| | 1073 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 1074 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1075 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 1076 | | public async Task<Response<Models.Models>> ListCustomModelsNextPageAsync(string nextLink, CancellationToken canc |
| | 1077 | | { |
| 4 | 1078 | | if (nextLink == null) |
| | 1079 | | { |
| 0 | 1080 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 1081 | | } |
| | 1082 | |
|
| 4 | 1083 | | using var message = CreateListCustomModelsNextPageRequest(nextLink); |
| 4 | 1084 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 1085 | | switch (message.Response.Status) |
| | 1086 | | { |
| | 1087 | | case 200: |
| | 1088 | | { |
| | 1089 | | Models.Models value = default; |
| 4 | 1090 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 4 | 1091 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 4 | 1092 | | return Response.FromValue(value, message.Response); |
| | 1093 | | } |
| | 1094 | | default: |
| 0 | 1095 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 1096 | | } |
| 4 | 1097 | | } |
| | 1098 | |
|
| | 1099 | | /// <summary> Get information about all custom models. </summary> |
| | 1100 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 1101 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 1102 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 1103 | | public Response<Models.Models> ListCustomModelsNextPage(string nextLink, CancellationToken cancellationToken = d |
| | 1104 | | { |
| 0 | 1105 | | if (nextLink == null) |
| | 1106 | | { |
| 0 | 1107 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 1108 | | } |
| | 1109 | |
|
| 0 | 1110 | | using var message = CreateListCustomModelsNextPageRequest(nextLink); |
| 0 | 1111 | | _pipeline.Send(message, cancellationToken); |
| 0 | 1112 | | switch (message.Response.Status) |
| | 1113 | | { |
| | 1114 | | case 200: |
| | 1115 | | { |
| | 1116 | | Models.Models value = default; |
| 0 | 1117 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 1118 | | value = Models.Models.DeserializeModels(document.RootElement); |
| 0 | 1119 | | return Response.FromValue(value, message.Response); |
| | 1120 | | } |
| | 1121 | | default: |
| 0 | 1122 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 1123 | | } |
| 0 | 1124 | | } |
| | 1125 | | } |
| | 1126 | | } |