Example #1
0
        public async virtual Task <AfdRuleSetCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string ruleSetName, CancellationToken cancellationToken = default)
        {
            if (ruleSetName == null)
            {
                throw new ArgumentNullException(nameof(ruleSetName));
            }

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

                var operation = new AfdRuleSetCreateOrUpdateOperation(this, _clientDiagnostics, Pipeline, _afdRuleSetsRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName).Request, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async Task CreateAfdRules()
        {
            #region Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
            // Create a new azure front door profile
            string AfdProfileName = "myAfdProfile";
            var    input1         = new ProfileData("Global", new Models.Sku {
                Name = SkuName.StandardAzureFrontDoor
            });
            ProfileCreateOrUpdateOperation lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(true, AfdProfileName, input1);

            Profile AfdProfile = lro1.Value;
            // Get the rule set collection from the specific azure front door profile and create a rule set
            string ruleSetName = "myAfdRuleSet";
            AfdRuleSetCreateOrUpdateOperation lro2 = await AfdProfile.GetAfdRuleSets().CreateOrUpdateAsync(true, ruleSetName);

            AfdRuleSet ruleSet = lro2.Value;
            // Get the rule collection from the specific rule set and create a rule
            string      ruleName = "myAfdRule";
            AfdRuleData input3   = new AfdRuleData
            {
                Order = 1
            };
            input3.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = "00:00:20"
            }));
            AfdRuleCreateOrUpdateOperation lro3 = await ruleSet.GetAfdRules().CreateOrUpdateAsync(true, ruleName, input3);

            AfdRule rule = lro3.Value;
            #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
        }
Example #3
0
        public virtual AfdRuleSetCreateOrUpdateOperation CreateOrUpdate(bool waitForCompletion, string ruleSetName, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(ruleSetName, nameof(ruleSetName));

            using var scope = _afdRuleSetClientDiagnostics.CreateScope("AfdRuleSetCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response  = _afdRuleSetRestClient.Create(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName, cancellationToken);
                var operation = new AfdRuleSetCreateOrUpdateOperation(ArmClient, _afdRuleSetClientDiagnostics, Pipeline, _afdRuleSetRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, ruleSetName).Request, response);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }