Beispiel #1
0
        public virtual AfdRuleSetCreateOperation CreateOrUpdate(string ruleSetName, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (ruleSetName == null)
            {
                throw new ArgumentNullException(nameof(ruleSetName));
            }

            using var scope = _clientDiagnostics.CreateScope("AfdRuleSetCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _afdRuleSetsRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName, cancellationToken);
                var operation = new AfdRuleSetCreateOperation(Parent, _clientDiagnostics, Pipeline, _afdRuleSetsRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName).Request, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async virtual Task <ArmOperation <AfdRuleSet> > CreateOrUpdateAsync(bool waitForCompletion, string ruleSetName, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(ruleSetName, nameof(ruleSetName));

            using var scope = _afdRuleSetClientDiagnostics.CreateScope("AfdRuleSetCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _afdRuleSetRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName, cancellationToken).ConfigureAwait(false);

                var operation = new CdnArmOperation <AfdRuleSet>(new AfdRuleSetOperationSource(Client), _afdRuleSetClientDiagnostics, Pipeline, _afdRuleSetRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName).Request, response, OperationFinalStateVia.AzureAsyncOperation);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }