| | 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.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.Search.Documents.Indexes.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.Search.Documents |
| | 18 | | { |
| | 19 | | internal partial class IndexersRestClient |
| | 20 | | { |
| | 21 | | private string endpoint; |
| | 22 | | private Guid? xMsClientRequestId; |
| | 23 | | private string apiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of IndexersRestClient. </summary> |
| | 28 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 29 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 30 | | /// <param name="endpoint"> The endpoint URL of the search service. </param> |
| | 31 | | /// <param name="xMsClientRequestId"> The tracking ID sent with the request to help with debugging. </param> |
| | 32 | | /// <param name="apiVersion"> Api Version. </param> |
| | 33 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="apiVersion"/> is nul |
| 7 | 34 | | public IndexersRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMs |
| | 35 | | { |
| 7 | 36 | | if (endpoint == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 39 | | } |
| 7 | 40 | | if (apiVersion == null) |
| | 41 | | { |
| 0 | 42 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 43 | | } |
| | 44 | |
|
| 7 | 45 | | this.endpoint = endpoint; |
| 7 | 46 | | this.xMsClientRequestId = xMsClientRequestId; |
| 7 | 47 | | this.apiVersion = apiVersion; |
| 7 | 48 | | _clientDiagnostics = clientDiagnostics; |
| 7 | 49 | | _pipeline = pipeline; |
| 7 | 50 | | } |
| | 51 | |
|
| | 52 | | internal HttpMessage CreateResetRequest(string indexerName) |
| | 53 | | { |
| 0 | 54 | | var message = _pipeline.CreateMessage(); |
| 0 | 55 | | var request = message.Request; |
| 0 | 56 | | request.Method = RequestMethod.Post; |
| 0 | 57 | | var uri = new RawRequestUriBuilder(); |
| 0 | 58 | | uri.AppendRaw(endpoint, false); |
| 0 | 59 | | uri.AppendPath("/indexers('", false); |
| 0 | 60 | | uri.AppendPath(indexerName, true); |
| 0 | 61 | | uri.AppendPath("')/search.reset", false); |
| 0 | 62 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 63 | | request.Uri = uri; |
| 0 | 64 | | if (xMsClientRequestId != null) |
| | 65 | | { |
| 0 | 66 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 67 | | } |
| 0 | 68 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 0 | 69 | | return message; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | /// <summary> Resets the change tracking state associated with an indexer. </summary> |
| | 73 | | /// <param name="indexerName"> The name of the indexer to reset. </param> |
| | 74 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 75 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 76 | | public async Task<Response> ResetAsync(string indexerName, CancellationToken cancellationToken = default) |
| | 77 | | { |
| 1 | 78 | | if (indexerName == null) |
| | 79 | | { |
| 1 | 80 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 81 | | } |
| | 82 | |
|
| 0 | 83 | | using var message = CreateResetRequest(indexerName); |
| 0 | 84 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 85 | | switch (message.Response.Status) |
| | 86 | | { |
| | 87 | | case 204: |
| 0 | 88 | | return message.Response; |
| | 89 | | default: |
| 0 | 90 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 91 | | } |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | /// <summary> Resets the change tracking state associated with an indexer. </summary> |
| | 95 | | /// <param name="indexerName"> The name of the indexer to reset. </param> |
| | 96 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 97 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 98 | | public Response Reset(string indexerName, CancellationToken cancellationToken = default) |
| | 99 | | { |
| 1 | 100 | | if (indexerName == null) |
| | 101 | | { |
| 1 | 102 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 103 | | } |
| | 104 | |
|
| 0 | 105 | | using var message = CreateResetRequest(indexerName); |
| 0 | 106 | | _pipeline.Send(message, cancellationToken); |
| 0 | 107 | | switch (message.Response.Status) |
| | 108 | | { |
| | 109 | | case 204: |
| 0 | 110 | | return message.Response; |
| | 111 | | default: |
| 0 | 112 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 113 | | } |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | internal HttpMessage CreateRunRequest(string indexerName) |
| | 117 | | { |
| 2 | 118 | | var message = _pipeline.CreateMessage(); |
| 2 | 119 | | var request = message.Request; |
| 2 | 120 | | request.Method = RequestMethod.Post; |
| 2 | 121 | | var uri = new RawRequestUriBuilder(); |
| 2 | 122 | | uri.AppendRaw(endpoint, false); |
| 2 | 123 | | uri.AppendPath("/indexers('", false); |
| 2 | 124 | | uri.AppendPath(indexerName, true); |
| 2 | 125 | | uri.AppendPath("')/search.run", false); |
| 2 | 126 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 127 | | request.Uri = uri; |
| 2 | 128 | | if (xMsClientRequestId != null) |
| | 129 | | { |
| 0 | 130 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 131 | | } |
| 2 | 132 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 133 | | return message; |
| | 134 | | } |
| | 135 | |
|
| | 136 | | /// <summary> Runs an indexer on-demand. </summary> |
| | 137 | | /// <param name="indexerName"> The name of the indexer to run. </param> |
| | 138 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 139 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 140 | | public async Task<Response> RunAsync(string indexerName, CancellationToken cancellationToken = default) |
| | 141 | | { |
| 2 | 142 | | if (indexerName == null) |
| | 143 | | { |
| 1 | 144 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 145 | | } |
| | 146 | |
|
| 1 | 147 | | using var message = CreateRunRequest(indexerName); |
| 1 | 148 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 149 | | switch (message.Response.Status) |
| | 150 | | { |
| | 151 | | case 202: |
| 1 | 152 | | return message.Response; |
| | 153 | | default: |
| 0 | 154 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 155 | | } |
| 1 | 156 | | } |
| | 157 | |
|
| | 158 | | /// <summary> Runs an indexer on-demand. </summary> |
| | 159 | | /// <param name="indexerName"> The name of the indexer to run. </param> |
| | 160 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 161 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 162 | | public Response Run(string indexerName, CancellationToken cancellationToken = default) |
| | 163 | | { |
| 2 | 164 | | if (indexerName == null) |
| | 165 | | { |
| 1 | 166 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 167 | | } |
| | 168 | |
|
| 1 | 169 | | using var message = CreateRunRequest(indexerName); |
| 1 | 170 | | _pipeline.Send(message, cancellationToken); |
| 1 | 171 | | switch (message.Response.Status) |
| | 172 | | { |
| | 173 | | case 202: |
| 1 | 174 | | return message.Response; |
| | 175 | | default: |
| 0 | 176 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 177 | | } |
| 1 | 178 | | } |
| | 179 | |
|
| | 180 | | internal HttpMessage CreateCreateOrUpdateRequest(string indexerName, SearchIndexer indexer, string ifMatch, stri |
| | 181 | | { |
| 2 | 182 | | var message = _pipeline.CreateMessage(); |
| 2 | 183 | | var request = message.Request; |
| 2 | 184 | | request.Method = RequestMethod.Put; |
| 2 | 185 | | var uri = new RawRequestUriBuilder(); |
| 2 | 186 | | uri.AppendRaw(endpoint, false); |
| 2 | 187 | | uri.AppendPath("/indexers('", false); |
| 2 | 188 | | uri.AppendPath(indexerName, true); |
| 2 | 189 | | uri.AppendPath("')", false); |
| 2 | 190 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 191 | | request.Uri = uri; |
| 2 | 192 | | if (xMsClientRequestId != null) |
| | 193 | | { |
| 0 | 194 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 195 | | } |
| 2 | 196 | | if (ifMatch != null) |
| | 197 | | { |
| 2 | 198 | | request.Headers.Add("If-Match", ifMatch); |
| | 199 | | } |
| 2 | 200 | | if (ifNoneMatch != null) |
| | 201 | | { |
| 0 | 202 | | request.Headers.Add("If-None-Match", ifNoneMatch); |
| | 203 | | } |
| 2 | 204 | | request.Headers.Add("Prefer", "return=representation"); |
| 2 | 205 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 206 | | request.Headers.Add("Content-Type", "application/json"); |
| 2 | 207 | | var content = new Utf8JsonRequestContent(); |
| 2 | 208 | | content.JsonWriter.WriteObjectValue(indexer); |
| 2 | 209 | | request.Content = content; |
| 2 | 210 | | return message; |
| | 211 | | } |
| | 212 | |
|
| | 213 | | /// <summary> Creates a new indexer or updates an indexer if it already exists. </summary> |
| | 214 | | /// <param name="indexerName"> The name of the indexer to create or update. </param> |
| | 215 | | /// <param name="indexer"> The definition of the indexer to create or update. </param> |
| | 216 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 217 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 218 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 219 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> or <paramref name="indexer"/> is nul |
| | 220 | | public async Task<Response<SearchIndexer>> CreateOrUpdateAsync(string indexerName, SearchIndexer indexer, string |
| | 221 | | { |
| 1 | 222 | | if (indexerName == null) |
| | 223 | | { |
| 0 | 224 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 225 | | } |
| 1 | 226 | | if (indexer == null) |
| | 227 | | { |
| 0 | 228 | | throw new ArgumentNullException(nameof(indexer)); |
| | 229 | | } |
| | 230 | |
|
| 1 | 231 | | using var message = CreateCreateOrUpdateRequest(indexerName, indexer, ifMatch, ifNoneMatch); |
| 1 | 232 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 233 | | switch (message.Response.Status) |
| | 234 | | { |
| | 235 | | case 200: |
| | 236 | | case 201: |
| | 237 | | { |
| | 238 | | SearchIndexer value = default; |
| 1 | 239 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 240 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 1 | 241 | | return Response.FromValue(value, message.Response); |
| | 242 | | } |
| | 243 | | default: |
| 0 | 244 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 245 | | } |
| 1 | 246 | | } |
| | 247 | |
|
| | 248 | | /// <summary> Creates a new indexer or updates an indexer if it already exists. </summary> |
| | 249 | | /// <param name="indexerName"> The name of the indexer to create or update. </param> |
| | 250 | | /// <param name="indexer"> The definition of the indexer to create or update. </param> |
| | 251 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 252 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 253 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 254 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> or <paramref name="indexer"/> is nul |
| | 255 | | public Response<SearchIndexer> CreateOrUpdate(string indexerName, SearchIndexer indexer, string ifMatch = null, |
| | 256 | | { |
| 1 | 257 | | if (indexerName == null) |
| | 258 | | { |
| 0 | 259 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 260 | | } |
| 1 | 261 | | if (indexer == null) |
| | 262 | | { |
| 0 | 263 | | throw new ArgumentNullException(nameof(indexer)); |
| | 264 | | } |
| | 265 | |
|
| 1 | 266 | | using var message = CreateCreateOrUpdateRequest(indexerName, indexer, ifMatch, ifNoneMatch); |
| 1 | 267 | | _pipeline.Send(message, cancellationToken); |
| 1 | 268 | | switch (message.Response.Status) |
| | 269 | | { |
| | 270 | | case 200: |
| | 271 | | case 201: |
| | 272 | | { |
| | 273 | | SearchIndexer value = default; |
| 1 | 274 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 275 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 1 | 276 | | return Response.FromValue(value, message.Response); |
| | 277 | | } |
| | 278 | | default: |
| 0 | 279 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 280 | | } |
| 1 | 281 | | } |
| | 282 | |
|
| | 283 | | internal HttpMessage CreateDeleteRequest(string indexerName, string ifMatch, string ifNoneMatch) |
| | 284 | | { |
| 1 | 285 | | var message = _pipeline.CreateMessage(); |
| 1 | 286 | | var request = message.Request; |
| 1 | 287 | | request.Method = RequestMethod.Delete; |
| 1 | 288 | | var uri = new RawRequestUriBuilder(); |
| 1 | 289 | | uri.AppendRaw(endpoint, false); |
| 1 | 290 | | uri.AppendPath("/indexers('", false); |
| 1 | 291 | | uri.AppendPath(indexerName, true); |
| 1 | 292 | | uri.AppendPath("')", false); |
| 1 | 293 | | uri.AppendQuery("api-version", apiVersion, true); |
| 1 | 294 | | request.Uri = uri; |
| 1 | 295 | | if (xMsClientRequestId != null) |
| | 296 | | { |
| 0 | 297 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 298 | | } |
| 1 | 299 | | if (ifMatch != null) |
| | 300 | | { |
| 0 | 301 | | request.Headers.Add("If-Match", ifMatch); |
| | 302 | | } |
| 1 | 303 | | if (ifNoneMatch != null) |
| | 304 | | { |
| 0 | 305 | | request.Headers.Add("If-None-Match", ifNoneMatch); |
| | 306 | | } |
| 1 | 307 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 1 | 308 | | return message; |
| | 309 | | } |
| | 310 | |
|
| | 311 | | /// <summary> Deletes an indexer. </summary> |
| | 312 | | /// <param name="indexerName"> The name of the indexer to delete. </param> |
| | 313 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 314 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 315 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 316 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 317 | | public async Task<Response> DeleteAsync(string indexerName, string ifMatch = null, string ifNoneMatch = null, Ca |
| | 318 | | { |
| 1 | 319 | | if (indexerName == null) |
| | 320 | | { |
| 0 | 321 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 322 | | } |
| | 323 | |
|
| 1 | 324 | | using var message = CreateDeleteRequest(indexerName, ifMatch, ifNoneMatch); |
| 1 | 325 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 326 | | switch (message.Response.Status) |
| | 327 | | { |
| | 328 | | case 204: |
| | 329 | | case 404: |
| 1 | 330 | | return message.Response; |
| | 331 | | default: |
| 0 | 332 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 333 | | } |
| 1 | 334 | | } |
| | 335 | |
|
| | 336 | | /// <summary> Deletes an indexer. </summary> |
| | 337 | | /// <param name="indexerName"> The name of the indexer to delete. </param> |
| | 338 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 339 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 340 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 341 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 342 | | public Response Delete(string indexerName, string ifMatch = null, string ifNoneMatch = null, CancellationToken c |
| | 343 | | { |
| 0 | 344 | | if (indexerName == null) |
| | 345 | | { |
| 0 | 346 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 347 | | } |
| | 348 | |
|
| 0 | 349 | | using var message = CreateDeleteRequest(indexerName, ifMatch, ifNoneMatch); |
| 0 | 350 | | _pipeline.Send(message, cancellationToken); |
| 0 | 351 | | switch (message.Response.Status) |
| | 352 | | { |
| | 353 | | case 204: |
| | 354 | | case 404: |
| 0 | 355 | | return message.Response; |
| | 356 | | default: |
| 0 | 357 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 358 | | } |
| 0 | 359 | | } |
| | 360 | |
|
| | 361 | | internal HttpMessage CreateGetRequest(string indexerName) |
| | 362 | | { |
| 0 | 363 | | var message = _pipeline.CreateMessage(); |
| 0 | 364 | | var request = message.Request; |
| 0 | 365 | | request.Method = RequestMethod.Get; |
| 0 | 366 | | var uri = new RawRequestUriBuilder(); |
| 0 | 367 | | uri.AppendRaw(endpoint, false); |
| 0 | 368 | | uri.AppendPath("/indexers('", false); |
| 0 | 369 | | uri.AppendPath(indexerName, true); |
| 0 | 370 | | uri.AppendPath("')", false); |
| 0 | 371 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 372 | | request.Uri = uri; |
| 0 | 373 | | if (xMsClientRequestId != null) |
| | 374 | | { |
| 0 | 375 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 376 | | } |
| 0 | 377 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 0 | 378 | | return message; |
| | 379 | | } |
| | 380 | |
|
| | 381 | | /// <summary> Retrieves an indexer definition. </summary> |
| | 382 | | /// <param name="indexerName"> The name of the indexer to retrieve. </param> |
| | 383 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 384 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 385 | | public async Task<Response<SearchIndexer>> GetAsync(string indexerName, CancellationToken cancellationToken = de |
| | 386 | | { |
| 1 | 387 | | if (indexerName == null) |
| | 388 | | { |
| 1 | 389 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 390 | | } |
| | 391 | |
|
| 0 | 392 | | using var message = CreateGetRequest(indexerName); |
| 0 | 393 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 394 | | switch (message.Response.Status) |
| | 395 | | { |
| | 396 | | case 200: |
| | 397 | | { |
| | 398 | | SearchIndexer value = default; |
| 0 | 399 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 400 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 0 | 401 | | return Response.FromValue(value, message.Response); |
| | 402 | | } |
| | 403 | | default: |
| 0 | 404 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 405 | | } |
| 0 | 406 | | } |
| | 407 | |
|
| | 408 | | /// <summary> Retrieves an indexer definition. </summary> |
| | 409 | | /// <param name="indexerName"> The name of the indexer to retrieve. </param> |
| | 410 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 411 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 412 | | public Response<SearchIndexer> Get(string indexerName, CancellationToken cancellationToken = default) |
| | 413 | | { |
| 1 | 414 | | if (indexerName == null) |
| | 415 | | { |
| 1 | 416 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 417 | | } |
| | 418 | |
|
| 0 | 419 | | using var message = CreateGetRequest(indexerName); |
| 0 | 420 | | _pipeline.Send(message, cancellationToken); |
| 0 | 421 | | switch (message.Response.Status) |
| | 422 | | { |
| | 423 | | case 200: |
| | 424 | | { |
| | 425 | | SearchIndexer value = default; |
| 0 | 426 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 427 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 0 | 428 | | return Response.FromValue(value, message.Response); |
| | 429 | | } |
| | 430 | | default: |
| 0 | 431 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 432 | | } |
| 0 | 433 | | } |
| | 434 | |
|
| | 435 | | internal HttpMessage CreateListRequest(string select) |
| | 436 | | { |
| 0 | 437 | | var message = _pipeline.CreateMessage(); |
| 0 | 438 | | var request = message.Request; |
| 0 | 439 | | request.Method = RequestMethod.Get; |
| 0 | 440 | | var uri = new RawRequestUriBuilder(); |
| 0 | 441 | | uri.AppendRaw(endpoint, false); |
| 0 | 442 | | uri.AppendPath("/indexers", false); |
| 0 | 443 | | if (select != null) |
| | 444 | | { |
| 0 | 445 | | uri.AppendQuery("$select", select, true); |
| | 446 | | } |
| 0 | 447 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 448 | | request.Uri = uri; |
| 0 | 449 | | if (xMsClientRequestId != null) |
| | 450 | | { |
| 0 | 451 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 452 | | } |
| 0 | 453 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 0 | 454 | | return message; |
| | 455 | | } |
| | 456 | |
|
| | 457 | | /// <summary> Lists all indexers available for a search service. </summary> |
| | 458 | | /// <param name="select"> Selects which top-level properties of the indexers to retrieve. Specified as a comma-s |
| | 459 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 460 | | public async Task<Response<ListIndexersResult>> ListAsync(string select = null, CancellationToken cancellationTo |
| | 461 | | { |
| 0 | 462 | | using var message = CreateListRequest(select); |
| 0 | 463 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 464 | | switch (message.Response.Status) |
| | 465 | | { |
| | 466 | | case 200: |
| | 467 | | { |
| | 468 | | ListIndexersResult value = default; |
| 0 | 469 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 470 | | value = ListIndexersResult.DeserializeListIndexersResult(document.RootElement); |
| 0 | 471 | | return Response.FromValue(value, message.Response); |
| | 472 | | } |
| | 473 | | default: |
| 0 | 474 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 475 | | } |
| 0 | 476 | | } |
| | 477 | |
|
| | 478 | | /// <summary> Lists all indexers available for a search service. </summary> |
| | 479 | | /// <param name="select"> Selects which top-level properties of the indexers to retrieve. Specified as a comma-s |
| | 480 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 481 | | public Response<ListIndexersResult> List(string select = null, CancellationToken cancellationToken = default) |
| | 482 | | { |
| 0 | 483 | | using var message = CreateListRequest(select); |
| 0 | 484 | | _pipeline.Send(message, cancellationToken); |
| 0 | 485 | | switch (message.Response.Status) |
| | 486 | | { |
| | 487 | | case 200: |
| | 488 | | { |
| | 489 | | ListIndexersResult value = default; |
| 0 | 490 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 491 | | value = ListIndexersResult.DeserializeListIndexersResult(document.RootElement); |
| 0 | 492 | | return Response.FromValue(value, message.Response); |
| | 493 | | } |
| | 494 | | default: |
| 0 | 495 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 496 | | } |
| 0 | 497 | | } |
| | 498 | |
|
| | 499 | | internal HttpMessage CreateCreateRequest(SearchIndexer indexer) |
| | 500 | | { |
| 3 | 501 | | var message = _pipeline.CreateMessage(); |
| 3 | 502 | | var request = message.Request; |
| 3 | 503 | | request.Method = RequestMethod.Post; |
| 3 | 504 | | var uri = new RawRequestUriBuilder(); |
| 3 | 505 | | uri.AppendRaw(endpoint, false); |
| 3 | 506 | | uri.AppendPath("/indexers", false); |
| 3 | 507 | | uri.AppendQuery("api-version", apiVersion, true); |
| 3 | 508 | | request.Uri = uri; |
| 3 | 509 | | if (xMsClientRequestId != null) |
| | 510 | | { |
| 0 | 511 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 512 | | } |
| 3 | 513 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 3 | 514 | | request.Headers.Add("Content-Type", "application/json"); |
| 3 | 515 | | var content = new Utf8JsonRequestContent(); |
| 3 | 516 | | content.JsonWriter.WriteObjectValue(indexer); |
| 3 | 517 | | request.Content = content; |
| 3 | 518 | | return message; |
| | 519 | | } |
| | 520 | |
|
| | 521 | | /// <summary> Creates a new indexer. </summary> |
| | 522 | | /// <param name="indexer"> The definition of the indexer to create. </param> |
| | 523 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 524 | | /// <exception cref="ArgumentNullException"> <paramref name="indexer"/> is null. </exception> |
| | 525 | | public async Task<Response<SearchIndexer>> CreateAsync(SearchIndexer indexer, CancellationToken cancellationToke |
| | 526 | | { |
| 3 | 527 | | if (indexer == null) |
| | 528 | | { |
| 1 | 529 | | throw new ArgumentNullException(nameof(indexer)); |
| | 530 | | } |
| | 531 | |
|
| 2 | 532 | | using var message = CreateCreateRequest(indexer); |
| 2 | 533 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 534 | | switch (message.Response.Status) |
| | 535 | | { |
| | 536 | | case 201: |
| | 537 | | { |
| | 538 | | SearchIndexer value = default; |
| 2 | 539 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 540 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 2 | 541 | | return Response.FromValue(value, message.Response); |
| | 542 | | } |
| | 543 | | default: |
| 0 | 544 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 545 | | } |
| 2 | 546 | | } |
| | 547 | |
|
| | 548 | | /// <summary> Creates a new indexer. </summary> |
| | 549 | | /// <param name="indexer"> The definition of the indexer to create. </param> |
| | 550 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 551 | | /// <exception cref="ArgumentNullException"> <paramref name="indexer"/> is null. </exception> |
| | 552 | | public Response<SearchIndexer> Create(SearchIndexer indexer, CancellationToken cancellationToken = default) |
| | 553 | | { |
| 2 | 554 | | if (indexer == null) |
| | 555 | | { |
| 1 | 556 | | throw new ArgumentNullException(nameof(indexer)); |
| | 557 | | } |
| | 558 | |
|
| 1 | 559 | | using var message = CreateCreateRequest(indexer); |
| 1 | 560 | | _pipeline.Send(message, cancellationToken); |
| 1 | 561 | | switch (message.Response.Status) |
| | 562 | | { |
| | 563 | | case 201: |
| | 564 | | { |
| | 565 | | SearchIndexer value = default; |
| 1 | 566 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 567 | | value = SearchIndexer.DeserializeSearchIndexer(document.RootElement); |
| 1 | 568 | | return Response.FromValue(value, message.Response); |
| | 569 | | } |
| | 570 | | default: |
| 0 | 571 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 572 | | } |
| 1 | 573 | | } |
| | 574 | |
|
| | 575 | | internal HttpMessage CreateGetStatusRequest(string indexerName) |
| | 576 | | { |
| 5 | 577 | | var message = _pipeline.CreateMessage(); |
| 5 | 578 | | var request = message.Request; |
| 5 | 579 | | request.Method = RequestMethod.Get; |
| 5 | 580 | | var uri = new RawRequestUriBuilder(); |
| 5 | 581 | | uri.AppendRaw(endpoint, false); |
| 5 | 582 | | uri.AppendPath("/indexers('", false); |
| 5 | 583 | | uri.AppendPath(indexerName, true); |
| 5 | 584 | | uri.AppendPath("')/search.status", false); |
| 5 | 585 | | uri.AppendQuery("api-version", apiVersion, true); |
| 5 | 586 | | request.Uri = uri; |
| 5 | 587 | | if (xMsClientRequestId != null) |
| | 588 | | { |
| 0 | 589 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 590 | | } |
| 5 | 591 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 5 | 592 | | return message; |
| | 593 | | } |
| | 594 | |
|
| | 595 | | /// <summary> Returns the current status and execution history of an indexer. </summary> |
| | 596 | | /// <param name="indexerName"> The name of the indexer for which to retrieve status. </param> |
| | 597 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 598 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 599 | | public async Task<Response<SearchIndexerStatus>> GetStatusAsync(string indexerName, CancellationToken cancellati |
| | 600 | | { |
| 3 | 601 | | if (indexerName == null) |
| | 602 | | { |
| 0 | 603 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 604 | | } |
| | 605 | |
|
| 3 | 606 | | using var message = CreateGetStatusRequest(indexerName); |
| 3 | 607 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 3 | 608 | | switch (message.Response.Status) |
| | 609 | | { |
| | 610 | | case 200: |
| | 611 | | { |
| | 612 | | SearchIndexerStatus value = default; |
| 3 | 613 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 3 | 614 | | value = SearchIndexerStatus.DeserializeSearchIndexerStatus(document.RootElement); |
| 3 | 615 | | return Response.FromValue(value, message.Response); |
| | 616 | | } |
| | 617 | | default: |
| 0 | 618 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 619 | | } |
| 3 | 620 | | } |
| | 621 | |
|
| | 622 | | /// <summary> Returns the current status and execution history of an indexer. </summary> |
| | 623 | | /// <param name="indexerName"> The name of the indexer for which to retrieve status. </param> |
| | 624 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 625 | | /// <exception cref="ArgumentNullException"> <paramref name="indexerName"/> is null. </exception> |
| | 626 | | public Response<SearchIndexerStatus> GetStatus(string indexerName, CancellationToken cancellationToken = default |
| | 627 | | { |
| 2 | 628 | | if (indexerName == null) |
| | 629 | | { |
| 0 | 630 | | throw new ArgumentNullException(nameof(indexerName)); |
| | 631 | | } |
| | 632 | |
|
| 2 | 633 | | using var message = CreateGetStatusRequest(indexerName); |
| 2 | 634 | | _pipeline.Send(message, cancellationToken); |
| 2 | 635 | | switch (message.Response.Status) |
| | 636 | | { |
| | 637 | | case 200: |
| | 638 | | { |
| | 639 | | SearchIndexerStatus value = default; |
| 2 | 640 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 641 | | value = SearchIndexerStatus.DeserializeSearchIndexerStatus(document.RootElement); |
| 2 | 642 | | return Response.FromValue(value, message.Response); |
| | 643 | | } |
| | 644 | | default: |
| 0 | 645 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 646 | | } |
| 2 | 647 | | } |
| | 648 | | } |
| | 649 | | } |