public static RulesEngineAction ToSdkRulesEngineAction(PSRulesEngineAction psRulesEngineAction) { return(new RulesEngineAction ( requestHeaderActions: psRulesEngineAction.RequestHeaderActions? .Select(x => ToSdkHeaderAction(x)) .ToList(), responseHeaderActions: psRulesEngineAction.ResponseHeaderActions? .Select(x => ToSdkHeaderAction(x)) .ToList(), routeConfigurationOverride: ToSdkRouteConfiguration(psRulesEngineAction.RouteConfigurationOverride) )); }
public override void ExecuteCmdlet() { var action = new PSRulesEngineAction { RequestHeaderActions = this.IsParameterBound(c => c.RequestHeaderAction) ? RequestHeaderAction : new List <PSHeaderAction>(), ResponseHeaderActions = this.IsParameterBound(c => c.ResponseHeaderAction) ? ResponseHeaderAction : new List <PSHeaderAction>(), }; if (ParameterSetName == FieldsWithForwardingParameterSet) { string BackendPoolId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/frontDoors/{2}/BackendPools/{3}", DefaultContext.Subscription.Id, ResourceGroupName, FrontDoorName, BackendPoolName); action.RouteConfigurationOverride = new PSForwardingConfiguration { CustomForwardingPath = CustomForwardingPath, ForwardingProtocol = !this.IsParameterBound(c => c.ForwardingProtocol) ? PSForwardingProtocol.MatchRequest.ToString() : ForwardingProtocol, QueryParameterStripDirective = !this.IsParameterBound(c => c.QueryParameterStripDirective) ? PSQueryParameterStripDirective.StripAll.ToString() : QueryParameterStripDirective, DynamicCompression = !this.IsParameterBound(c => c.DynamicCompression) ? PSEnabledState.Enabled : DynamicCompression, BackendPoolId = BackendPoolId, EnableCaching = !this.IsParameterBound(c => c.EnableCaching) ? false : EnableCaching }; } else if (ParameterSetName == FieldsWithRedirectParameterSet) { action.RouteConfigurationOverride = new PSRedirectConfiguration { RedirectProtocol = !this.IsParameterBound(c => c.RedirectProtocol) ? PSRedirectProtocol.MatchRequest.ToString() : RedirectProtocol, RedirectType = !this.IsParameterBound(c => c.RedirectType) ? PSRedirectType.Moved.ToString() : RedirectType, CustomHost = !this.IsParameterBound(c => c.CustomHost) ? "" : CustomHost, CustomFragment = CustomFragment, CustomPath = !this.IsParameterBound(c => c.CustomPath) ? "" : CustomPath, CustomQueryString = CustomQueryString }; } // At least one of the 3 possible actions much be present if (action.RequestHeaderActions.Count == 0 && action.ResponseHeaderActions.Count == 0 && action.RouteConfigurationOverride == null) { throw new PSArgumentException( "Rules engine action must contain at least one of the following actions: RequestHeaderActions, ResponseHeaderActions, or RouteConfigurationOverride "); } WriteObject(action); }