Ejemplo n.º 1
0
        public async Task <Response <ForwardingRuleData> > CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string dnsForwardingRulesetName, string forwardingRuleName, ForwardingRuleData data, string ifMatch = null, string ifNoneMatch = null, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId));
            Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName));
            Argument.AssertNotNullOrEmpty(dnsForwardingRulesetName, nameof(dnsForwardingRulesetName));
            Argument.AssertNotNullOrEmpty(forwardingRuleName, nameof(forwardingRuleName));
            Argument.AssertNotNull(data, nameof(data));

            using var message = CreateCreateOrUpdateRequest(subscriptionId, resourceGroupName, dnsForwardingRulesetName, forwardingRuleName, data, ifMatch, ifNoneMatch);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            case 201:
            {
                ForwardingRuleData value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = ForwardingRuleData.DeserializeForwardingRuleData(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
        public virtual async Task <ArmOperation <ForwardingRuleResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string forwardingRuleName, ForwardingRuleData data, string ifMatch = null, string ifNoneMatch = null, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(forwardingRuleName, nameof(forwardingRuleName));
            Argument.AssertNotNull(data, nameof(data));

            using var scope = _forwardingRuleClientDiagnostics.CreateScope("ForwardingRuleCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _forwardingRuleRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, forwardingRuleName, data, ifMatch, ifNoneMatch, cancellationToken).ConfigureAwait(false);

                var operation = new DnsResolverArmOperation <ForwardingRuleResource>(Response.FromValue(new ForwardingRuleResource(Client, response), response.GetRawResponse()));
                if (waitUntil == WaitUntil.Completed)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
 internal ForwardingRuleResource(ArmClient client, ForwardingRuleData data) : this(client, data.Id)
 {
     HasData = true;
     _data   = data;
 }
Ejemplo n.º 4
0
        internal HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string resourceGroupName, string dnsForwardingRulesetName, string forwardingRuleName, ForwardingRuleData data, string ifMatch, string ifNoneMatch)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

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

            uri.Reset(_endpoint);
            uri.AppendPath("/subscriptions/", false);
            uri.AppendPath(subscriptionId, true);
            uri.AppendPath("/resourceGroups/", false);
            uri.AppendPath(resourceGroupName, true);
            uri.AppendPath("/providers/Microsoft.Network/dnsForwardingRulesets/", false);
            uri.AppendPath(dnsForwardingRulesetName, true);
            uri.AppendPath("/forwardingRules/", false);
            uri.AppendPath(forwardingRuleName, true);
            uri.AppendQuery("api-version", _apiVersion, true);
            request.Uri = uri;
            if (ifMatch != null)
            {
                request.Headers.Add("If-Match", ifMatch);
            }
            if (ifNoneMatch != null)
            {
                request.Headers.Add("If-None-Match", ifNoneMatch);
            }
            request.Headers.Add("Accept", "application/json");
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(data);
            request.Content = content;
            _userAgent.Apply(message);
            return(message);
        }