public virtual NatGatewayCreateOrUpdateOperation CreateOrUpdate(string natGatewayName, NatGatewayData parameters, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (natGatewayName == null) { throw new ArgumentNullException(nameof(natGatewayName)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _clientDiagnostics.CreateScope("NatGatewayCollection.CreateOrUpdate"); scope.Start(); try { var response = _natGatewaysRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, natGatewayName, parameters, cancellationToken); var operation = new NatGatewayCreateOrUpdateOperation(Parent, _clientDiagnostics, Pipeline, _natGatewaysRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, natGatewayName, parameters).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <ArmOperation <NatGatewayResource> > CreateOrUpdateAsync(WaitUntil waitUntil, string natGatewayName, NatGatewayData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(natGatewayName, nameof(natGatewayName)); Argument.AssertNotNull(data, nameof(data)); using var scope = _natGatewayClientDiagnostics.CreateScope("NatGatewayCollection.CreateOrUpdate"); scope.Start(); try { var response = await _natGatewayRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, natGatewayName, data, cancellationToken).ConfigureAwait(false); var operation = new NetworkArmOperation <NatGatewayResource>(new NatGatewayOperationSource(Client), _natGatewayClientDiagnostics, Pipeline, _natGatewayRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, natGatewayName, data).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }