public async virtual Task <AfdRuleCreateOperation> CreateOrUpdateAsync(string ruleName, AfdRuleData rule, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (ruleName == null)
            {
                throw new ArgumentNullException(nameof(ruleName));
            }
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            using var scope = _clientDiagnostics.CreateScope("AfdRuleCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _afdRulesRestClient.CreateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, ruleName, rule, cancellationToken).ConfigureAwait(false);

                var operation = new AfdRuleCreateOperation(Parent, _clientDiagnostics, Pipeline, _afdRulesRestClient.CreateCreateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, ruleName, rule).Request, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Пример #2
0
        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
            });
            ProfileCreateOperation 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";
            AfdRuleSetCreateOperation 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"
            }));
            AfdRuleCreateOperation lro3 = await ruleSet.GetAfdRules().CreateOrUpdateAsync(true, ruleName, input3);

            AfdRule rule = lro3.Value;
            #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
        }