public async Task Update()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroup rg = await CreateResourceGroup(subscription, "testRg-");

            string  afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            Profile afdProfile     = await CreateAfdProfile(rg, afdProfileName, SkuName.StandardAzureFrontDoor);

            string     afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSet afdRuleSet     = await CreateAfdRuleSet(afdProfile, afdRuleSetName);

            string  afdRuleName = Recording.GenerateAssetName("AFDRule");
            AfdRule afdRule     = await CreateAfdRule(afdRuleSet, afdRuleName);

            AfdRuleUpdateOptions updateOptions = new AfdRuleUpdateOptions
            {
                Order = 2
            };

            updateOptions.Conditions.Add(ResourceDataHelper.CreateDeliveryRuleCondition());
            updateOptions.Actions.Add(ResourceDataHelper.UpdateDeliveryRuleOperation());
            var lro = await afdRule.UpdateAsync(true, updateOptions);

            AfdRule updatedAfdRule = lro.Value;

            ResourceDataHelper.AssertAfdRuleUpdate(updatedAfdRule, updateOptions);
        }
        public async Task UpdateAfdRules()
        {
            #region Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            Profile AfdProfile = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            AfdRuleSet ruleSet = await AfdProfile.GetAfdRuleSets().GetAsync("myAfdRuleSet");

            AfdRuleCollection ruleCollection = ruleSet.GetAfdRules();
            // Now we can get the rule with GetAsync()
            AfdRule rule = await ruleCollection.GetAsync("myAfdRule");

            // With UpdateAsync(), we can update the rule
            AfdRuleUpdateOptions input = new AfdRuleUpdateOptions
            {
                Order = 2
            };
            input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersOdataType.MicrosoftAzureCdnModelsDeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = "00:00:30"
            }));
            ArmOperation <AfdRule> lro = await rule.UpdateAsync(true, input);

            rule = lro.Value;
            #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
        }
示例#3
0
        public virtual ArmOperation <AfdRule> Update(bool waitForCompletion, AfdRuleUpdateOptions options, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(options, nameof(options));

            using var scope = _afdRuleClientDiagnostics.CreateScope("AfdRule.Update");
            scope.Start();
            try
            {
                var response  = _afdRuleRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, options, cancellationToken);
                var operation = new CdnArmOperation <AfdRule>(new AfdRuleOperationSource(Client), _afdRuleClientDiagnostics, Pipeline, _afdRuleRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, options).Request, response, OperationFinalStateVia.AzureAsyncOperation);
                if (waitForCompletion)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
 public static void AssertAfdRuleUpdate(AfdRule updatedRule, AfdRuleUpdateOptions updateOptions)
 {
     Assert.AreEqual(updatedRule.Data.Order, updateOptions.Order);
 }