< Summary

Class:Azure.Search.Documents.IndexersRestClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\IndexersRestClient.cs
Covered lines:166
Uncovered lines:120
Coverable lines:286
Total lines:649
Line coverage:58% (166 of 286)
Covered branches:41
Total branches:98
Branch coverage:41.8% (41 of 98)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-81.82%50%
CreateResetRequest(...)-0%0%
ResetAsync()-25%25%
Reset(...)-25%25%
CreateRunRequest(...)-92.86%50%
RunAsync()-87.5%75%
Run(...)-87.5%75%
CreateCreateOrUpdateRequest(...)-91.3%66.67%
CreateOrUpdateAsync()-75%50%
CreateOrUpdate(...)-75%50%
CreateDeleteRequest(...)-83.33%50%
DeleteAsync()-75%50%
Delete(...)-0%0%
CreateGetRequest(...)-0%0%
GetAsync()-20%25%
Get(...)-20%25%
CreateListRequest(...)-0%0%
ListAsync()-0%0%
List(...)-0%0%
CreateCreateRequest(...)-93.75%50%
CreateAsync()-90%75%
Create(...)-90%75%
CreateGetStatusRequest(...)-92.86%50%
GetStatusAsync()-80%50%
GetStatus(...)-80%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\IndexersRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Search.Documents.Indexes.Models;
 16
 17namespace 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
 734        public IndexersRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMs
 35        {
 736            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 740            if (apiVersion == null)
 41            {
 042                throw new ArgumentNullException(nameof(apiVersion));
 43            }
 44
 745            this.endpoint = endpoint;
 746            this.xMsClientRequestId = xMsClientRequestId;
 747            this.apiVersion = apiVersion;
 748            _clientDiagnostics = clientDiagnostics;
 749            _pipeline = pipeline;
 750        }
 51
 52        internal HttpMessage CreateResetRequest(string indexerName)
 53        {
 054            var message = _pipeline.CreateMessage();
 055            var request = message.Request;
 056            request.Method = RequestMethod.Post;
 057            var uri = new RawRequestUriBuilder();
 058            uri.AppendRaw(endpoint, false);
 059            uri.AppendPath("/indexers('", false);
 060            uri.AppendPath(indexerName, true);
 061            uri.AppendPath("')/search.reset", false);
 062            uri.AppendQuery("api-version", apiVersion, true);
 063            request.Uri = uri;
 064            if (xMsClientRequestId != null)
 65            {
 066                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 67            }
 068            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 069            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        {
 178            if (indexerName == null)
 79            {
 180                throw new ArgumentNullException(nameof(indexerName));
 81            }
 82
 083            using var message = CreateResetRequest(indexerName);
 084            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 085            switch (message.Response.Status)
 86            {
 87                case 204:
 088                    return message.Response;
 89                default:
 090                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 91            }
 092        }
 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        {
 1100            if (indexerName == null)
 101            {
 1102                throw new ArgumentNullException(nameof(indexerName));
 103            }
 104
 0105            using var message = CreateResetRequest(indexerName);
 0106            _pipeline.Send(message, cancellationToken);
 0107            switch (message.Response.Status)
 108            {
 109                case 204:
 0110                    return message.Response;
 111                default:
 0112                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 113            }
 0114        }
 115
 116        internal HttpMessage CreateRunRequest(string indexerName)
 117        {
 2118            var message = _pipeline.CreateMessage();
 2119            var request = message.Request;
 2120            request.Method = RequestMethod.Post;
 2121            var uri = new RawRequestUriBuilder();
 2122            uri.AppendRaw(endpoint, false);
 2123            uri.AppendPath("/indexers('", false);
 2124            uri.AppendPath(indexerName, true);
 2125            uri.AppendPath("')/search.run", false);
 2126            uri.AppendQuery("api-version", apiVersion, true);
 2127            request.Uri = uri;
 2128            if (xMsClientRequestId != null)
 129            {
 0130                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 131            }
 2132            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2133            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        {
 2142            if (indexerName == null)
 143            {
 1144                throw new ArgumentNullException(nameof(indexerName));
 145            }
 146
 1147            using var message = CreateRunRequest(indexerName);
 1148            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1149            switch (message.Response.Status)
 150            {
 151                case 202:
 1152                    return message.Response;
 153                default:
 0154                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 155            }
 1156        }
 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        {
 2164            if (indexerName == null)
 165            {
 1166                throw new ArgumentNullException(nameof(indexerName));
 167            }
 168
 1169            using var message = CreateRunRequest(indexerName);
 1170            _pipeline.Send(message, cancellationToken);
 1171            switch (message.Response.Status)
 172            {
 173                case 202:
 1174                    return message.Response;
 175                default:
 0176                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 177            }
 1178        }
 179
 180        internal HttpMessage CreateCreateOrUpdateRequest(string indexerName, SearchIndexer indexer, string ifMatch, stri
 181        {
 2182            var message = _pipeline.CreateMessage();
 2183            var request = message.Request;
 2184            request.Method = RequestMethod.Put;
 2185            var uri = new RawRequestUriBuilder();
 2186            uri.AppendRaw(endpoint, false);
 2187            uri.AppendPath("/indexers('", false);
 2188            uri.AppendPath(indexerName, true);
 2189            uri.AppendPath("')", false);
 2190            uri.AppendQuery("api-version", apiVersion, true);
 2191            request.Uri = uri;
 2192            if (xMsClientRequestId != null)
 193            {
 0194                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 195            }
 2196            if (ifMatch != null)
 197            {
 2198                request.Headers.Add("If-Match", ifMatch);
 199            }
 2200            if (ifNoneMatch != null)
 201            {
 0202                request.Headers.Add("If-None-Match", ifNoneMatch);
 203            }
 2204            request.Headers.Add("Prefer", "return=representation");
 2205            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2206            request.Headers.Add("Content-Type", "application/json");
 2207            var content = new Utf8JsonRequestContent();
 2208            content.JsonWriter.WriteObjectValue(indexer);
 2209            request.Content = content;
 2210            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        {
 1222            if (indexerName == null)
 223            {
 0224                throw new ArgumentNullException(nameof(indexerName));
 225            }
 1226            if (indexer == null)
 227            {
 0228                throw new ArgumentNullException(nameof(indexer));
 229            }
 230
 1231            using var message = CreateCreateOrUpdateRequest(indexerName, indexer, ifMatch, ifNoneMatch);
 1232            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1233            switch (message.Response.Status)
 234            {
 235                case 200:
 236                case 201:
 237                    {
 238                        SearchIndexer value = default;
 1239                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1240                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 1241                        return Response.FromValue(value, message.Response);
 242                    }
 243                default:
 0244                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 245            }
 1246        }
 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        {
 1257            if (indexerName == null)
 258            {
 0259                throw new ArgumentNullException(nameof(indexerName));
 260            }
 1261            if (indexer == null)
 262            {
 0263                throw new ArgumentNullException(nameof(indexer));
 264            }
 265
 1266            using var message = CreateCreateOrUpdateRequest(indexerName, indexer, ifMatch, ifNoneMatch);
 1267            _pipeline.Send(message, cancellationToken);
 1268            switch (message.Response.Status)
 269            {
 270                case 200:
 271                case 201:
 272                    {
 273                        SearchIndexer value = default;
 1274                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1275                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 1276                        return Response.FromValue(value, message.Response);
 277                    }
 278                default:
 0279                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 280            }
 1281        }
 282
 283        internal HttpMessage CreateDeleteRequest(string indexerName, string ifMatch, string ifNoneMatch)
 284        {
 1285            var message = _pipeline.CreateMessage();
 1286            var request = message.Request;
 1287            request.Method = RequestMethod.Delete;
 1288            var uri = new RawRequestUriBuilder();
 1289            uri.AppendRaw(endpoint, false);
 1290            uri.AppendPath("/indexers('", false);
 1291            uri.AppendPath(indexerName, true);
 1292            uri.AppendPath("')", false);
 1293            uri.AppendQuery("api-version", apiVersion, true);
 1294            request.Uri = uri;
 1295            if (xMsClientRequestId != null)
 296            {
 0297                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 298            }
 1299            if (ifMatch != null)
 300            {
 0301                request.Headers.Add("If-Match", ifMatch);
 302            }
 1303            if (ifNoneMatch != null)
 304            {
 0305                request.Headers.Add("If-None-Match", ifNoneMatch);
 306            }
 1307            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 1308            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        {
 1319            if (indexerName == null)
 320            {
 0321                throw new ArgumentNullException(nameof(indexerName));
 322            }
 323
 1324            using var message = CreateDeleteRequest(indexerName, ifMatch, ifNoneMatch);
 1325            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1326            switch (message.Response.Status)
 327            {
 328                case 204:
 329                case 404:
 1330                    return message.Response;
 331                default:
 0332                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 333            }
 1334        }
 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        {
 0344            if (indexerName == null)
 345            {
 0346                throw new ArgumentNullException(nameof(indexerName));
 347            }
 348
 0349            using var message = CreateDeleteRequest(indexerName, ifMatch, ifNoneMatch);
 0350            _pipeline.Send(message, cancellationToken);
 0351            switch (message.Response.Status)
 352            {
 353                case 204:
 354                case 404:
 0355                    return message.Response;
 356                default:
 0357                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 358            }
 0359        }
 360
 361        internal HttpMessage CreateGetRequest(string indexerName)
 362        {
 0363            var message = _pipeline.CreateMessage();
 0364            var request = message.Request;
 0365            request.Method = RequestMethod.Get;
 0366            var uri = new RawRequestUriBuilder();
 0367            uri.AppendRaw(endpoint, false);
 0368            uri.AppendPath("/indexers('", false);
 0369            uri.AppendPath(indexerName, true);
 0370            uri.AppendPath("')", false);
 0371            uri.AppendQuery("api-version", apiVersion, true);
 0372            request.Uri = uri;
 0373            if (xMsClientRequestId != null)
 374            {
 0375                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 376            }
 0377            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 0378            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        {
 1387            if (indexerName == null)
 388            {
 1389                throw new ArgumentNullException(nameof(indexerName));
 390            }
 391
 0392            using var message = CreateGetRequest(indexerName);
 0393            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0394            switch (message.Response.Status)
 395            {
 396                case 200:
 397                    {
 398                        SearchIndexer value = default;
 0399                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0400                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 0401                        return Response.FromValue(value, message.Response);
 402                    }
 403                default:
 0404                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 405            }
 0406        }
 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        {
 1414            if (indexerName == null)
 415            {
 1416                throw new ArgumentNullException(nameof(indexerName));
 417            }
 418
 0419            using var message = CreateGetRequest(indexerName);
 0420            _pipeline.Send(message, cancellationToken);
 0421            switch (message.Response.Status)
 422            {
 423                case 200:
 424                    {
 425                        SearchIndexer value = default;
 0426                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0427                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 0428                        return Response.FromValue(value, message.Response);
 429                    }
 430                default:
 0431                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 432            }
 0433        }
 434
 435        internal HttpMessage CreateListRequest(string select)
 436        {
 0437            var message = _pipeline.CreateMessage();
 0438            var request = message.Request;
 0439            request.Method = RequestMethod.Get;
 0440            var uri = new RawRequestUriBuilder();
 0441            uri.AppendRaw(endpoint, false);
 0442            uri.AppendPath("/indexers", false);
 0443            if (select != null)
 444            {
 0445                uri.AppendQuery("$select", select, true);
 446            }
 0447            uri.AppendQuery("api-version", apiVersion, true);
 0448            request.Uri = uri;
 0449            if (xMsClientRequestId != null)
 450            {
 0451                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 452            }
 0453            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 0454            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        {
 0462            using var message = CreateListRequest(select);
 0463            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0464            switch (message.Response.Status)
 465            {
 466                case 200:
 467                    {
 468                        ListIndexersResult value = default;
 0469                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0470                        value = ListIndexersResult.DeserializeListIndexersResult(document.RootElement);
 0471                        return Response.FromValue(value, message.Response);
 472                    }
 473                default:
 0474                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 475            }
 0476        }
 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        {
 0483            using var message = CreateListRequest(select);
 0484            _pipeline.Send(message, cancellationToken);
 0485            switch (message.Response.Status)
 486            {
 487                case 200:
 488                    {
 489                        ListIndexersResult value = default;
 0490                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0491                        value = ListIndexersResult.DeserializeListIndexersResult(document.RootElement);
 0492                        return Response.FromValue(value, message.Response);
 493                    }
 494                default:
 0495                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 496            }
 0497        }
 498
 499        internal HttpMessage CreateCreateRequest(SearchIndexer indexer)
 500        {
 3501            var message = _pipeline.CreateMessage();
 3502            var request = message.Request;
 3503            request.Method = RequestMethod.Post;
 3504            var uri = new RawRequestUriBuilder();
 3505            uri.AppendRaw(endpoint, false);
 3506            uri.AppendPath("/indexers", false);
 3507            uri.AppendQuery("api-version", apiVersion, true);
 3508            request.Uri = uri;
 3509            if (xMsClientRequestId != null)
 510            {
 0511                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 512            }
 3513            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 3514            request.Headers.Add("Content-Type", "application/json");
 3515            var content = new Utf8JsonRequestContent();
 3516            content.JsonWriter.WriteObjectValue(indexer);
 3517            request.Content = content;
 3518            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        {
 3527            if (indexer == null)
 528            {
 1529                throw new ArgumentNullException(nameof(indexer));
 530            }
 531
 2532            using var message = CreateCreateRequest(indexer);
 2533            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 2534            switch (message.Response.Status)
 535            {
 536                case 201:
 537                    {
 538                        SearchIndexer value = default;
 2539                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 2540                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 2541                        return Response.FromValue(value, message.Response);
 542                    }
 543                default:
 0544                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 545            }
 2546        }
 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        {
 2554            if (indexer == null)
 555            {
 1556                throw new ArgumentNullException(nameof(indexer));
 557            }
 558
 1559            using var message = CreateCreateRequest(indexer);
 1560            _pipeline.Send(message, cancellationToken);
 1561            switch (message.Response.Status)
 562            {
 563                case 201:
 564                    {
 565                        SearchIndexer value = default;
 1566                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1567                        value = SearchIndexer.DeserializeSearchIndexer(document.RootElement);
 1568                        return Response.FromValue(value, message.Response);
 569                    }
 570                default:
 0571                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 572            }
 1573        }
 574
 575        internal HttpMessage CreateGetStatusRequest(string indexerName)
 576        {
 5577            var message = _pipeline.CreateMessage();
 5578            var request = message.Request;
 5579            request.Method = RequestMethod.Get;
 5580            var uri = new RawRequestUriBuilder();
 5581            uri.AppendRaw(endpoint, false);
 5582            uri.AppendPath("/indexers('", false);
 5583            uri.AppendPath(indexerName, true);
 5584            uri.AppendPath("')/search.status", false);
 5585            uri.AppendQuery("api-version", apiVersion, true);
 5586            request.Uri = uri;
 5587            if (xMsClientRequestId != null)
 588            {
 0589                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 590            }
 5591            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 5592            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        {
 3601            if (indexerName == null)
 602            {
 0603                throw new ArgumentNullException(nameof(indexerName));
 604            }
 605
 3606            using var message = CreateGetStatusRequest(indexerName);
 3607            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 3608            switch (message.Response.Status)
 609            {
 610                case 200:
 611                    {
 612                        SearchIndexerStatus value = default;
 3613                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 3614                        value = SearchIndexerStatus.DeserializeSearchIndexerStatus(document.RootElement);
 3615                        return Response.FromValue(value, message.Response);
 616                    }
 617                default:
 0618                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 619            }
 3620        }
 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        {
 2628            if (indexerName == null)
 629            {
 0630                throw new ArgumentNullException(nameof(indexerName));
 631            }
 632
 2633            using var message = CreateGetStatusRequest(indexerName);
 2634            _pipeline.Send(message, cancellationToken);
 2635            switch (message.Response.Status)
 636            {
 637                case 200:
 638                    {
 639                        SearchIndexerStatus value = default;
 2640                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 2641                        value = SearchIndexerStatus.DeserializeSearchIndexerStatus(document.RootElement);
 2642                        return Response.FromValue(value, message.Response);
 643                    }
 644                default:
 0645                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 646            }
 2647        }
 648    }
 649}