Ejemplo n.º 1
0
        public async Task <Response <ResourceLink> > CreateOrUpdateAsync(string linkId, ResourceLink parameters, CancellationToken cancellationToken = default)
        {
            if (linkId == null)
            {
                throw new ArgumentNullException(nameof(linkId));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var message = CreateCreateOrUpdateRequest(linkId, parameters);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            case 201:
            {
                ResourceLink 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 = ResourceLink.DeserializeResourceLink(document.RootElement);
                }
                return(Response.FromValue(value, message.Response));
            }
Ejemplo n.º 2
0
 public virtual Response <ResourceLink> CreateOrUpdate(string linkId, ResourceLink parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ResourceLinksOperations.CreateOrUpdate");
     scope.Start();
     try
     {
         return(RestClient.CreateOrUpdate(linkId, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 3
0
        internal Core.HttpMessage CreateCreateOrUpdateRequest(string linkId, ResourceLink parameters)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Put;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendPath("/", false);
            uri.AppendPath(linkId, false);
            uri.AppendQuery("api-version", "2016-09-01", true);
            request.Uri = uri;
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(parameters);
            request.Content = content;
            return(message);
        }
Ejemplo n.º 4
0
 public virtual async Task <Response <ResourceLink> > CreateOrUpdateAsync(string linkId, ResourceLink parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ResourceLinksOperations.CreateOrUpdate");
     scope.Start();
     try
     {
         return(await RestClient.CreateOrUpdateAsync(linkId, parameters, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }