public async Task <Response <Models.Index> > CreateAsync(Models.Index index, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { if (index == null) { throw new ArgumentNullException(nameof(index)); } using var message = CreateCreateRequest(index, requestOptions); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 201: { Models.Index value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); if (document.RootElement.ValueKind == JsonValueKind.Null) { value = null; } else { value = Models.Index.DeserializeIndex(document.RootElement); } return(Response.FromValue(value, message.Response)); }
public virtual Response <Models.Index> Create(Models.Index index, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("IndexesClient.Create"); scope.Start(); try { return(RestClient.Create(index, requestOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response <Models.Index> > CreateAsync(Models.Index index, RequestOptions requestOptions = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("IndexesClient.Create"); scope.Start(); try { return(await RestClient.CreateAsync(index, requestOptions, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <Models.Index> CreateOrUpdate(string indexName, Models.Index index, bool?allowIndexDowntime = null, RequestOptions requestOptions = null, AccessCondition accessCondition = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("IndexesClient.CreateOrUpdate"); scope.Start(); try { return(RestClient.CreateOrUpdate(indexName, index, allowIndexDowntime, requestOptions, accessCondition, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
internal HttpMessage CreateCreateRequest(Models.Index index, RequestOptions requestOptions) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Post; var uri = new RawRequestUriBuilder(); uri.AppendRaw(endpoint, false); uri.AppendPath("/indexes", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; if (requestOptions?.XMsClientRequestId != null) { request.Headers.Add("x-ms-client-request-id", requestOptions.XMsClientRequestId.Value); } request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(index); request.Content = content; return(message); }