Skip to content

Commit f4c0d4c

Browse files
Add string batchId overloads to CreateBatchOperation.Rehydrate methods
1 parent 9308b2b commit f4c0d4c

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/Custom/Batch/CreateBatchOperation.Protocol.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ public static async Task<CreateBatchOperation> RehydrateAsync(BatchClient client
6060

6161
CreateBatchOperationToken token = CreateBatchOperationToken.FromToken(rehydrationToken);
6262

63-
ClientResult result = await client.GetBatchAsync(token.BatchId, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
64-
PipelineResponse response = result.GetRawResponse();
65-
66-
using JsonDocument doc = JsonDocument.Parse(response.Content);
67-
string status = doc.RootElement.GetProperty("status"u8).GetString()!;
68-
69-
return client.CreateCreateBatchOperation(token.BatchId, status, response);
63+
return await RehydrateAsync(client, token.BatchId, cancellationToken).ConfigureAwait(false);
7064
}
7165

7266
/// <summary>
@@ -87,13 +81,53 @@ public static CreateBatchOperation Rehydrate(BatchClient client, ContinuationTok
8781

8882
CreateBatchOperationToken token = CreateBatchOperationToken.FromToken(rehydrationToken);
8983

90-
ClientResult result = client.GetBatch(token.BatchId, cancellationToken.ToRequestOptions());
84+
return Rehydrate(client, token.BatchId, cancellationToken);
85+
}
86+
87+
/// <summary>
88+
/// Recreates a <see cref="CreateBatchOperation"/> from a batch ID.
89+
/// </summary>
90+
/// <param name="client"> The <see cref="BatchClient"/> used to obtain the
91+
/// operation status from the service. </param>
92+
/// <param name="batchId"> The ID of the batch operation to rehydrate. </param>
93+
/// <param name="cancellationToken"> A token that can be used to cancel the
94+
/// request. </param>
95+
/// <returns> The rehydrated operation. </returns>
96+
/// <exception cref="ArgumentNullException"> <paramref name="client"/> is null. </exception>
97+
public static async Task<CreateBatchOperation> RehydrateAsync(BatchClient client, string batchId, CancellationToken cancellationToken = default)
98+
{
99+
Argument.AssertNotNull(client, nameof(client));
100+
101+
ClientResult result = await client.GetBatchAsync(batchId, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
102+
PipelineResponse response = result.GetRawResponse();
103+
104+
using JsonDocument doc = JsonDocument.Parse(response.Content);
105+
string status = doc.RootElement.GetProperty("status"u8).GetString()!;
106+
107+
return client.CreateCreateBatchOperation(batchId, status, response);
108+
}
109+
110+
/// <summary>
111+
/// Recreates a <see cref="CreateBatchOperation"/> from a batch ID.
112+
/// </summary>
113+
/// <param name="client"> The <see cref="BatchClient"/> used to obtain the
114+
/// operation status from the service. </param>
115+
/// <param name="batchId"> The ID of the batch operation to rehydrate. </param>
116+
/// <param name="cancellationToken"> A token that can be used to cancel the
117+
/// request. </param>
118+
/// <returns> The rehydrated operation. </returns>
119+
/// <exception cref="ArgumentNullException"> <paramref name="client"/> is null. </exception>
120+
public static CreateBatchOperation Rehydrate(BatchClient client, string batchId, CancellationToken cancellationToken = default)
121+
{
122+
Argument.AssertNotNull(client, nameof(client));
123+
124+
ClientResult result = client.GetBatch(batchId, cancellationToken.ToRequestOptions());
91125
PipelineResponse response = result.GetRawResponse();
92126

93127
using JsonDocument doc = JsonDocument.Parse(response.Content);
94128
string status = doc.RootElement.GetProperty("status"u8).GetString()!;
95129

96-
return client.CreateCreateBatchOperation(token.BatchId, status, response);
130+
return client.CreateCreateBatchOperation(batchId, status, response);
97131
}
98132

99133
/// <inheritdoc/>

0 commit comments

Comments
 (0)