private List <DeliveryRuleAction> CreateAfdRuleActions()
        {
            List <DeliveryRuleAction> afdRuleActions = new List <DeliveryRuleAction>();

            foreach (PSAfdRuleAction afdAction in this.Action)
            {
                if (afdAction is PSAfdRuleCacheExpirationAction)
                {
                    PSAfdRuleCacheExpirationAction psCacheExpirationAction = (PSAfdRuleCacheExpirationAction)afdAction;

                    DeliveryRuleCacheExpirationAction cacheExpirationAction = new DeliveryRuleCacheExpirationAction
                    {
                        Parameters = new CacheExpirationActionParameters
                        {
                            CacheBehavior = psCacheExpirationAction.CacheBehavior,
                            CacheDuration = psCacheExpirationAction.CacheDuration
                        }
                    };

                    afdRuleActions.Add(cacheExpirationAction);
                }

                if (afdAction is PSAfdRuleHeaderAction)
                {
                    PSAfdRuleHeaderAction psHeaderAction = (PSAfdRuleHeaderAction)afdAction;

                    if (psHeaderAction.HeaderType == "ModifyRequestHeader")
                    {
                        DeliveryRuleRequestHeaderAction requestHeaderAction = new DeliveryRuleRequestHeaderAction
                        {
                            Parameters = new HeaderActionParameters
                            {
                                HeaderAction = psHeaderAction.HeaderAction,
                                HeaderName   = psHeaderAction.HeaderName,
                                Value        = psHeaderAction.HeaderValue
                            }
                        };

                        afdRuleActions.Add(requestHeaderAction);
                    }
                    else if (psHeaderAction.HeaderType == "ModifyResponeHeader")
                    {
                        DeliveryRuleResponseHeaderAction responseHeaderAction = new DeliveryRuleResponseHeaderAction
                        {
                            Parameters = new HeaderActionParameters
                            {
                                HeaderAction = psHeaderAction.HeaderAction,
                                HeaderName   = psHeaderAction.HeaderName,
                                Value        = psHeaderAction.HeaderValue
                            }
                        };

                        afdRuleActions.Add(responseHeaderAction);
                    }
                }

                if (afdAction is PSAfdRuleCacheKeyQueryStringAction)
                {
                    PSAfdRuleCacheKeyQueryStringAction psCacheKeyQueryString = (PSAfdRuleCacheKeyQueryStringAction)afdAction;

                    DeliveryRuleCacheKeyQueryStringAction cacheKeyQueryStringAction = new DeliveryRuleCacheKeyQueryStringAction
                    {
                        Parameters = new CacheKeyQueryStringActionParameters
                        {
                            QueryParameters     = psCacheKeyQueryString.QueryParameters,
                            QueryStringBehavior = psCacheKeyQueryString.QueryStringBehavior
                        }
                    };

                    afdRuleActions.Add(cacheKeyQueryStringAction);
                }

                if (afdAction is PSAfdRuleUrlRedirectAction)
                {
                    PSAfdRuleUrlRedirectAction psUrlRedirectAction = (PSAfdRuleUrlRedirectAction)afdAction;

                    UrlRedirectAction urlRedirectAction = new UrlRedirectAction
                    {
                        Parameters = new UrlRedirectActionParameters
                        {
                            CustomFragment      = psUrlRedirectAction.CustomFragment,
                            CustomHostname      = psUrlRedirectAction.CustomHostname,
                            CustomPath          = psUrlRedirectAction.CustomPath,
                            CustomQueryString   = psUrlRedirectAction.CustomQueryString,
                            DestinationProtocol = psUrlRedirectAction.DestinationProtocol,
                            RedirectType        = psUrlRedirectAction.RedirectType
                        }
                    };

                    afdRuleActions.Add(urlRedirectAction);
                }

                if (afdAction is PSAfdRuleUrlRewriteAction)
                {
                    PSAfdRuleUrlRewriteAction psUrlRewriteAction = (PSAfdRuleUrlRewriteAction)afdAction;

                    UrlRewriteAction urlRewriteAction = new UrlRewriteAction
                    {
                        Parameters = new UrlRewriteActionParameters
                        {
                            SourcePattern         = psUrlRewriteAction.SourcePattern,
                            Destination           = psUrlRewriteAction.Destination,
                            PreserveUnmatchedPath = psUrlRewriteAction.PreservePath
                        }
                    };

                    afdRuleActions.Add(urlRewriteAction);
                }

                if (afdAction is PSAfdRuleOriginGroupOverrideAction)
                {
                    PSAfdRuleOriginGroupOverrideAction psOriginGroupOverrideAction = (PSAfdRuleOriginGroupOverrideAction)afdAction;

                    OriginGroupOverrideAction originGroupOverrideAction = new OriginGroupOverrideAction
                    {
                        Parameters = new OriginGroupOverrideActionParameters
                        {
                            OriginGroup = new ResourceReference(psOriginGroupOverrideAction.OriginGroup)
                        }
                    };

                    afdRuleActions.Add(originGroupOverrideAction);
                }
            }

            return(afdRuleActions);
        }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            PSAfdRuleAction afdRuleAction = new PSAfdRuleAction();

            if (ParameterSetName == AfdParameterSet.AfdRuleCacheExpirationAction)
            {
                afdRuleAction = new PSAfdRuleCacheExpirationAction
                {
                    CacheBehavior = this.CacheBehavior,
                    CacheDuration = this.CacheDuration
                };
            }
            else if (ParameterSetName == AfdParameterSet.AfdRuleHeaderTypeAction)
            {
                afdRuleAction = new PSAfdRuleHeaderAction
                {
                    HeaderType   = this.HeaderType,
                    HeaderAction = this.HeaderAction,
                    HeaderName   = this.HeaderName,
                    HeaderValue  = this.HeaderValue
                };
            }
            else if (ParameterSetName == AfdParameterSet.AfdRuleCacheKeyQueryStringAction)
            {
                afdRuleAction = new PSAfdRuleCacheKeyQueryStringAction
                {
                    QueryParameters     = this.QueryParameter,
                    QueryStringBehavior = this.QueryStringBehavior
                };
            }
            else if (ParameterSetName == AfdParameterSet.AfdRuleUrlRedirectAction)
            {
                afdRuleAction = new PSAfdRuleUrlRedirectAction
                {
                    CustomFragment      = this.CustomFragment,
                    CustomHostname      = this.CustomHostname,
                    CustomPath          = this.CustomPath,
                    CustomQueryString   = this.CustomQueryString,
                    DestinationProtocol = this.DestinationProtocol,
                    RedirectType        = this.RedirectType
                };
            }
            else if (ParameterSetName == AfdParameterSet.AfdRuleUrlRewriteAction)
            {
                afdRuleAction = new PSAfdRuleUrlRewriteAction
                {
                    SourcePattern = this.SourcePattern,
                    Destination   = this.Destination,
                    PreservePath  = this.PreservePath
                };
            }
            else if (ParameterSetName == AfdParameterSet.AfdRuleOriginGroupOverrideAction)
            {
                afdRuleAction = new PSAfdRuleOriginGroupOverrideAction
                {
                    OriginGroup = this.OriginGroupOverride
                };
            }

            WriteObject(afdRuleAction);
        }