Exemplo n.º 1
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");

            AfdRuleSetResource ruleSet = await AfdProfileResource.GetAfdRuleSets().GetAsync("myAfdRuleSet");

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

            // With UpdateAsync(), we can update the rule
            PatchableAfdRuleData input = new PatchableAfdRuleData
            {
                Order = 2
            };
            input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchConditionParameters(RequestUriMatchConditionParametersTypeName.DeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersTypeName.DeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = new TimeSpan(0, 0, 30)
            }));
            ArmOperation <AfdRuleResource> lro = await rule.UpdateAsync(WaitUntil.Completed, input);

            rule = lro.Value;
            #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
        }
Exemplo n.º 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 CdnSku {
                Name = CdnSkuName.StandardAzureFrontDoor
            });
            ArmOperation <ProfileResource> lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(WaitUntil.Completed, AfdProfileName, input1);

            ProfileResource AfdProfileResource = lro1.Value;
            // Get the rule set collection from the specific azure front door ProfileResource and create a rule set
            string ruleSetName = "myAfdRuleSet";
            ArmOperation <AfdRuleSetResource> lro2 = await AfdProfileResource.GetAfdRuleSets().CreateOrUpdateAsync(WaitUntil.Completed, ruleSetName);

            AfdRuleSetResource 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(RequestUriMatchConditionParametersTypeName.DeliveryRuleRequestUriConditionParameters, RequestUriOperator.Any)));
            input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionParameters(CacheExpirationActionParametersTypeName.DeliveryRuleCacheExpirationActionParameters, CacheBehavior.Override, CacheType.All)
            {
                CacheDuration = new TimeSpan(0, 0, 20)
            }));
            ArmOperation <AfdRuleResource> lro3 = await ruleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input3);

            AfdRuleResource rule = lro3.Value;
            #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
        }
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

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

            string             afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSetResource afdRuleSet     = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

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

            Assert.AreEqual(afdRuleName, afdRule.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, null, afdRule.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, afdRuleName, null));
        }
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

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

            string             afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSetResource afdRuleSet     = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

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

            AfdRuleResource getAfdRule = await afdRuleSet.GetAfdRules().GetAsync(afdRuleName);

            ResourceDataHelper.AssertValidAfdRule(afdRule, getAfdRule);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetAfdRules().GetAsync(null));
        }
Exemplo n.º 5
0
        protected async Task <AfdRuleResource> CreateAfdRule(AfdRuleSetResource ruleSet, string ruleName)
        {
            AfdRuleData           input = ResourceDataHelper.CreateAfdRuleData();
            DeliveryRuleCondition deliveryRuleCondition = ResourceDataHelper.CreateDeliveryRuleCondition();
            DeliveryRuleAction    deliveryRuleAction    = ResourceDataHelper.CreateDeliveryRuleOperation();

            input.Conditions.Add(deliveryRuleCondition);
            input.Actions.Add(deliveryRuleAction);
            var lro = await ruleSet.GetAfdRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input);

            return(lro.Value);
        }
Exemplo n.º 6
0
        public async Task ListAfdRules()
        {
            #region Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules
            // First we need to get the azure front door rule collection from the specific rule set
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            AfdRuleSetResource ruleSet = await AfdProfileResource.GetAfdRuleSets().GetAsync("myAfdRuleSet");

            AfdRuleCollection ruleCollection = ruleSet.GetAfdRules();
            // With GetAllAsync(), we can get a list of the rule in the collection
            AsyncPageable <AfdRuleResource> response = ruleCollection.GetAllAsync();
            await foreach (AfdRuleResource rule in response)
            {
                Console.WriteLine(rule.Data.Name);
            }
            #endregion Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules
        }
Exemplo n.º 7
0
        public async Task DeleteAfdRules()
        {
            #region Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            AfdRuleSetResource ruleSet = await AfdProfileResource.GetAfdRuleSets().GetAsync("myAfdRuleSet");

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

            // With DeleteAsync(), we can delete the rule
            await rule.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
        }
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

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

            string             afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSetResource afdRuleSet     = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

            string afdRuleName = Recording.GenerateAssetName("AFDRule");

            _ = await CreateAfdRule(afdRuleSet, afdRuleName);

            int count = 0;

            await foreach (var tempRule in afdRuleSet.GetAfdRules().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }