Example #1
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);
        }
        public static PSDeliveryRuleAction ToPsDeliveryRuleAction(this DeliveryRuleAction deliveryRuleAction)
        {
            var deliveryRuleCacheExpirationAction = deliveryRuleAction as DeliveryRuleCacheExpirationAction;

            if (deliveryRuleCacheExpirationAction != null)
            {
                return(new PSDeliveryRuleCacheExpirationAction
                {
                    Parameters = new PSCacheExpirationActionParameters
                    {
                        CacheBehavior = deliveryRuleCacheExpirationAction.Parameters.CacheBehavior,
                        CacheDuration = deliveryRuleCacheExpirationAction.Parameters.CacheDuration
                    }
                });
            }
            return(new PSDeliveryRuleAction());
        }
Example #3
0
 public static PSDeliveryRuleAction ToPsDeliveryRuleAction(this DeliveryRuleAction deliveryRuleAction)
 {
     if (deliveryRuleAction is DeliveryRuleRequestHeaderAction requestHeaderAction)
     {
         return(new PSDeliveryRuleHeaderAction
         {
             HeaderActionType = "ModifyRequestHeader",
             Action = requestHeaderAction.Parameters.HeaderAction,
             HeaderName = requestHeaderAction.Parameters.HeaderName,
             Value = requestHeaderAction.Parameters.Value
         });
     }
     else if (deliveryRuleAction is DeliveryRuleResponseHeaderAction responseHeaderAction)
     {
         return(new PSDeliveryRuleHeaderAction
         {
             HeaderActionType = "ModifyRequestHeader",
             Action = responseHeaderAction.Parameters.HeaderAction,
             HeaderName = responseHeaderAction.Parameters.HeaderName,
             Value = responseHeaderAction.Parameters.Value
         });
     }
     else if (deliveryRuleAction is DeliveryRuleCacheExpirationAction cacheExpirationAction)
     {
         return(new PSDeliveryRuleCacheExpirationAction
         {
             Parameters = new PSCacheExpirationActionParameters
             {
                 CacheBehavior = cacheExpirationAction.Parameters.CacheBehavior,
                 CacheDuration = cacheExpirationAction.Parameters.CacheDuration
             }
         });
     }
     else if (deliveryRuleAction is UrlRedirectAction urlRedirectAction)
     {
         return(new PSDeliveryRuleUrlRedirectAction
         {
             RedirectType = urlRedirectAction.Parameters.RedirectType
         });
     }
     else
     {
         return(new PSDeliveryRuleAction());
     }
 }
Example #4
0
        internal static FrontDoorRuleData DeserializeFrontDoorRuleData(JsonElement element)
        {
            ResourceIdentifier id          = default;
            string             name        = default;
            ResourceType       type        = default;
            SystemData         systemData  = default;
            Optional <string>  ruleSetName = default;
            Optional <int>     order       = default;
            Optional <IList <DeliveryRuleCondition> > conditions = default;
            Optional <IList <DeliveryRuleAction> >    actions    = default;
            Optional <MatchProcessingBehavior>        matchProcessingBehavior = default;
            Optional <FrontDoorProvisioningState>     provisioningState       = default;
            Optional <FrontDoorDeploymentStatus>      deploymentStatus        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("ruleSetName"))
                        {
                            ruleSetName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("order"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            order = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("conditions"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeliveryRuleCondition> array = new List <DeliveryRuleCondition>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeliveryRuleCondition.DeserializeDeliveryRuleCondition(item));
                            }
                            conditions = array;
                            continue;
                        }
                        if (property0.NameEquals("actions"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeliveryRuleAction> array = new List <DeliveryRuleAction>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeliveryRuleAction.DeserializeDeliveryRuleAction(item));
                            }
                            actions = array;
                            continue;
                        }
                        if (property0.NameEquals("matchProcessingBehavior"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            matchProcessingBehavior = new MatchProcessingBehavior(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new FrontDoorProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("deploymentStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            deploymentStatus = new FrontDoorDeploymentStatus(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new FrontDoorRuleData(id, name, type, systemData, ruleSetName.Value, Optional.ToNullable(order), Optional.ToList(conditions), Optional.ToList(actions), Optional.ToNullable(matchProcessingBehavior), Optional.ToNullable(provisioningState), Optional.ToNullable(deploymentStatus)));
        }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="DeliveryRuleAction" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => DeliveryRuleAction.CreateFrom(sourceValue);
 internal DeliveryRuleActionAutoGenerated(DeliveryRuleAction name)
 {
     Name = name;
 }
Example #7
0
 public static PSDeliveryRuleAction ToPsDeliveryRuleAction(this DeliveryRuleAction deliveryRuleAction)
 {
     if (deliveryRuleAction is DeliveryRuleRequestHeaderAction requestHeaderAction)
     {
         return(new PSDeliveryRuleHeaderAction
         {
             HeaderActionType = "ModifyRequestHeader",
             Action = requestHeaderAction.Parameters.HeaderAction,
             HeaderName = requestHeaderAction.Parameters.HeaderName,
             Value = requestHeaderAction.Parameters.Value
         });
     }
     else if (deliveryRuleAction is DeliveryRuleResponseHeaderAction responseHeaderAction)
     {
         return(new PSDeliveryRuleHeaderAction
         {
             HeaderActionType = "ModifyResponseHeader",
             Action = responseHeaderAction.Parameters.HeaderAction,
             HeaderName = responseHeaderAction.Parameters.HeaderName,
             Value = responseHeaderAction.Parameters.Value
         });
     }
     else if (deliveryRuleAction is DeliveryRuleCacheExpirationAction cacheExpirationAction)
     {
         return(new PSDeliveryRuleCacheExpirationAction
         {
             Parameters = new PSCacheExpirationActionParameters
             {
                 CacheBehavior = cacheExpirationAction.Parameters.CacheBehavior,
                 CacheDuration = cacheExpirationAction.Parameters.CacheDuration
             }
         });
     }
     else if (deliveryRuleAction is UrlRedirectAction urlRedirectAction)
     {
         return(new PSDeliveryRuleUrlRedirectAction
         {
             RedirectType = urlRedirectAction.Parameters.RedirectType,
             DestinationProtocol = urlRedirectAction.Parameters.DestinationProtocol,
             CustomHostname = urlRedirectAction.Parameters.CustomHostname,
             CustomPath = urlRedirectAction.Parameters.CustomPath,
             CustomFragment = urlRedirectAction.Parameters.CustomFragment,
             CustomQueryString = urlRedirectAction.Parameters.CustomQueryString
         });
     }
     else if (deliveryRuleAction is UrlRewriteAction urlRewriteAction)
     {
         return(new PSDeliveryRuleUrlRewriteAction
         {
             SourcePattern = urlRewriteAction.Parameters.SourcePattern,
             Destination = urlRewriteAction.Parameters.Destination,
             PreservePath = urlRewriteAction.Parameters.PreserveUnmatchedPath ?? true
         });
     }
     else if (deliveryRuleAction is DeliveryRuleCacheKeyQueryStringAction deliveryRuleCacheKeyQueryStringAction)
     {
         return(new PSDeliveryRuleCacheKeyQueryStringAction
         {
             QueryStringBehavior = deliveryRuleCacheKeyQueryStringAction.Parameters.QueryStringBehavior,
             QueryParameter = deliveryRuleCacheKeyQueryStringAction.Parameters.QueryParameters
         });
     }
     else
     {
         return(new PSDeliveryRuleAction());
     }
 }