Esempio n. 1
0
        public async Task Update()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

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

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

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

            FrontDoorRulePatch updateOptions = new FrontDoorRulePatch
            {
                Order = 2
            };

            updateOptions.Conditions.Add(ResourceDataHelper.CreateDeliveryRuleCondition());
            updateOptions.Actions.Add(ResourceDataHelper.CreateDeliveryRuleOperation());
            var lro = await afdRule.UpdateAsync(WaitUntil.Completed, updateOptions);

            FrontDoorRuleResource updatedAfdRule = lro.Value;

            ResourceDataHelper.AssertAfdRuleUpdate(updatedAfdRule, updateOptions);
        }
Esempio n. 2
0
        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
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet");

            FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules();
            // Now we can get the rule with GetAsync()
            FrontDoorRuleResource rule = await ruleCollection.GetAsync("myAfdRule");

            // With UpdateAsync(), we can update the rule
            FrontDoorRulePatch input = new FrontDoorRulePatch
            {
                Order = 2
            };
            input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchCondition(RequestUriMatchConditionType.RequestUriCondition, RequestUriOperator.Any)));
            input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionProperties(CacheExpirationActionType.CacheExpirationAction, CacheBehaviorSetting.Override, CacheLevel.All)
            {
                CacheDuration = new TimeSpan(0, 0, 30)
            }));
            ArmOperation <FrontDoorRuleResource> lro = await rule.UpdateAsync(WaitUntil.Completed, input);

            rule = lro.Value;
            #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
        }
Esempio n. 3
0
 public static void AssertAfdRuleUpdate(FrontDoorRuleResource updatedRule, FrontDoorRulePatch updateOptions)
 {
     Assert.AreEqual(updatedRule.Data.Order, updateOptions.Order);
 }
Esempio n. 4
0
        public virtual ArmOperation <FrontDoorRuleResource> Update(WaitUntil waitUntil, FrontDoorRulePatch patch, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(patch, nameof(patch));

            using var scope = _frontDoorRuleClientDiagnostics.CreateScope("FrontDoorRuleResource.Update");
            scope.Start();
            try
            {
                var response  = _frontDoorRuleRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, patch, cancellationToken);
                var operation = new CdnArmOperation <FrontDoorRuleResource>(new FrontDoorRuleOperationSource(Client), _frontDoorRuleClientDiagnostics, Pipeline, _frontDoorRuleRestClient.CreateUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, patch).Request, response, OperationFinalStateVia.AzureAsyncOperation);
                if (waitUntil == WaitUntil.Completed)
                {
                    operation.WaitForCompletion(cancellationToken);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }