Skip to content

Commit 574cca2

Browse files
authored
[FR] Add post response to Operation classes (Azure#24561)
1 parent fc81eb7 commit 574cca2

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/src/AnalyzeDocumentOperation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ public AnalyzeDocumentOperation(string operationId, DocumentAnalysisClient clien
103103
/// <param name="serviceClient">The client for communicating with the Form Recognizer Azure Cognitive Service through its REST API.</param>
104104
/// <param name="diagnostics">The client diagnostics for exception creation in case of failure.</param>
105105
/// <param name="operationLocation">The address of the long-running operation. It can be obtained from the response headers upon starting the operation.</param>
106-
internal AnalyzeDocumentOperation(DocumentAnalysisRestClient serviceClient, ClientDiagnostics diagnostics, string operationLocation)
106+
/// <param name="postResponse">Response from the POSt request that initiated the operation.</param>
107+
internal AnalyzeDocumentOperation(DocumentAnalysisRestClient serviceClient, ClientDiagnostics diagnostics, string operationLocation, Response postResponse)
107108
{
108109
_serviceClient = serviceClient;
109110
_diagnostics = diagnostics;
110-
_operationInternal = new(_diagnostics, this, rawResponse: null);
111+
_operationInternal = new(_diagnostics, this, rawResponse: postResponse);
111112

112113
// TODO: Use regex to parse ids.
113114
// https://github.com/Azure/azure-sdk-for-net/issues/11505

sdk/formrecognizer/Azure.AI.FormRecognizer/src/BuildModelOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ public override async ValueTask<Response<DocumentModel>> WaitForCompletionAsync(
9494

9595
internal BuildModelOperation(
9696
string location,
97+
Response postResponse,
9798
DocumentAnalysisRestClient allOperations,
9899
ClientDiagnostics diagnostics)
99100
{
100101
_serviceClient = allOperations;
101102
_diagnostics = diagnostics;
102-
_operationInternal = new(_diagnostics, this, rawResponse: null, nameof(BuildModelOperation));
103+
_operationInternal = new(_diagnostics, this, rawResponse: postResponse);
103104

104105
Id = location.Split('/').Last().Split('?').FirstOrDefault();
105106
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/CopyModelOperation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ public CopyModelOperation(string operationId, DocumentModelAdministrationClient
7979
/// <param name="serviceClient">The client for communicating with the Form Recognizer Azure Cognitive Service through its REST API.</param>
8080
/// <param name="diagnostics">The client diagnostics for exception creation in case of failure.</param>
8181
/// <param name="operationLocation">The address of the long-running operation. It can be obtained from the response headers upon starting the operation.</param>
82-
internal CopyModelOperation(DocumentAnalysisRestClient serviceClient, ClientDiagnostics diagnostics, string operationLocation)
82+
/// <param name="postResponse">Response from the POSt request that initiated the operation.</param>
83+
internal CopyModelOperation(DocumentAnalysisRestClient serviceClient, ClientDiagnostics diagnostics, string operationLocation, Response postResponse)
8384
{
8485
_serviceClient = serviceClient;
8586
_diagnostics = diagnostics;
86-
_operationInternal = new(_diagnostics, this, rawResponse: null);
87+
_operationInternal = new(_diagnostics, this, rawResponse: postResponse);
8788

8889
Id = operationLocation.Split('/').Last().Split('?').FirstOrDefault();
8990
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/DocumentAnalysisClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public virtual async Task<AnalyzeDocumentOperation> StartAnalyzeDocumentAsync(st
150150
document,
151151
cancellationToken).ConfigureAwait(false);
152152

153-
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
153+
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
154154
}
155155
catch (Exception e)
156156
{
@@ -200,7 +200,7 @@ public virtual AnalyzeDocumentOperation StartAnalyzeDocument(string modelId, Str
200200
document,
201201
cancellationToken);
202202

203-
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
203+
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
204204
}
205205
catch (Exception e)
206206
{
@@ -250,7 +250,7 @@ public virtual async Task<AnalyzeDocumentOperation> StartAnalyzeDocumentFromUriA
250250
request,
251251
cancellationToken).ConfigureAwait(false);
252252

253-
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
253+
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
254254
}
255255
catch (Exception e)
256256
{
@@ -300,7 +300,7 @@ public virtual AnalyzeDocumentOperation StartAnalyzeDocumentFromUri(string model
300300
request,
301301
cancellationToken);
302302

303-
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
303+
return new AnalyzeDocumentOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
304304
}
305305
catch (Exception e)
306306
{

sdk/formrecognizer/Azure.AI.FormRecognizer/src/DocumentModelAdministrationClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public virtual BuildModelOperation StartBuildModel(Uri trainingFilesUri, string
148148
};
149149

150150
var response = ServiceClient.DocumentAnalysisBuildDocumentModel(request, cancellationToken);
151-
return new BuildModelOperation(response.Headers.OperationLocation, ServiceClient, Diagnostics);
151+
return new BuildModelOperation(response.Headers.OperationLocation, response.GetRawResponse(), ServiceClient, Diagnostics);
152152
}
153153
catch (Exception e)
154154
{
@@ -194,7 +194,7 @@ public virtual async Task<BuildModelOperation> StartBuildModelAsync(Uri training
194194
};
195195

196196
var response = await ServiceClient.DocumentAnalysisBuildDocumentModelAsync(request, cancellationToken).ConfigureAwait(false);
197-
return new BuildModelOperation(response.Headers.OperationLocation, ServiceClient, Diagnostics);
197+
return new BuildModelOperation(response.Headers.OperationLocation, response.GetRawResponse(), ServiceClient, Diagnostics);
198198
}
199199
catch (Exception e)
200200
{
@@ -603,7 +603,7 @@ public virtual CopyModelOperation StartCopyModel(string modelId, CopyAuthorizati
603603
try
604604
{
605605
var response = ServiceClient.DocumentAnalysisCopyDocumentModelTo(modelId, target, cancellationToken);
606-
return new CopyModelOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
606+
return new CopyModelOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
607607
}
608608
catch (Exception e)
609609
{
@@ -632,7 +632,7 @@ public virtual async Task<CopyModelOperation> StartCopyModelAsync(string modelId
632632
try
633633
{
634634
var response = await ServiceClient.DocumentAnalysisCopyDocumentModelToAsync(modelId, target, cancellationToken).ConfigureAwait(false);
635-
return new CopyModelOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation);
635+
return new CopyModelOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation, response.GetRawResponse());
636636
}
637637
catch (Exception e)
638638
{
@@ -739,7 +739,7 @@ public virtual BuildModelOperation StartCreateComposedModel(IEnumerable<string>
739739
};
740740

741741
var response = ServiceClient.DocumentAnalysisComposeDocumentModel(composeRequest, cancellationToken);
742-
return new BuildModelOperation(response.Headers.OperationLocation, ServiceClient, Diagnostics);
742+
return new BuildModelOperation(response.Headers.OperationLocation, response.GetRawResponse(), ServiceClient, Diagnostics);
743743
}
744744
catch (Exception e)
745745
{
@@ -778,7 +778,7 @@ public virtual async Task<BuildModelOperation> StartCreateComposedModelAsync(IEn
778778
};
779779

780780
var response = await ServiceClient.DocumentAnalysisComposeDocumentModelAsync(composeRequest, cancellationToken).ConfigureAwait(false);
781-
return new BuildModelOperation(response.Headers.OperationLocation, ServiceClient, Diagnostics);
781+
return new BuildModelOperation(response.Headers.OperationLocation, response.GetRawResponse(), ServiceClient, Diagnostics);
782782
}
783783
catch (Exception e)
784784
{

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/DocumentAnalysisModels/OperationsLiveTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public async Task AnalyzeDocumentOperationCanPollFromNewObject()
3838

3939
var uri = DocumentAnalysisTestEnvironment.CreateUri(TestFile.Blank);
4040
var operation = await client.StartAnalyzeDocumentFromUriAsync(modelId, uri);
41+
Assert.IsNotNull(operation.GetRawResponse());
4142

4243
var sameOperation = InstrumentOperation(new AnalyzeDocumentOperation(operation.Id, nonInstrumentedClient));
4344
await sameOperation.WaitForCompletionAsync();
@@ -54,6 +55,7 @@ public async Task BuildModelOperationCanPollFromNewObject()
5455
var modelId = Recording.GenerateId();
5556

5657
var operation = await client.StartBuildModelAsync(trainingFilesUri, modelId);
58+
Assert.IsNotNull(operation.GetRawResponse());
5759

5860
var sameOperation = InstrumentOperation(new BuildModelOperation(operation.Id, nonInstrumentedClient));
5961
await sameOperation.WaitForCompletionAsync();
@@ -90,6 +92,7 @@ public async Task CopyModelOperationCanPollFromNewObject()
9092
CopyAuthorization targetAuth = await client.GetCopyAuthorizationAsync(targetModelId);
9193

9294
var operation = await client.StartCopyModelAsync(trainedModel.ModelId, targetAuth);
95+
Assert.IsNotNull(operation.GetRawResponse());
9396

9497
var sameOperation = InstrumentOperation(new CopyModelOperation(operation.Id, nonInstrumentedClient));
9598
await sameOperation.WaitForCompletionAsync();

0 commit comments

Comments
 (0)