public void Apply(BehaviorGraph graph, BehaviorChain chain) { // Don't override the route if it already exists if (chain.Route != null) { return; } // Don't override the route if the chain is a partial if (chain.IsPartialOnly) { return; } _observer = graph.Observer; ActionCall call = chain.Calls.FirstOrDefault(); if (call == null) { return; } IUrlPolicy policy = _policies.FirstOrDefault(x => x.Matches(call, _observer)) ?? _defaultUrlPolicy; _observer.RecordCallStatus(call, "First matching UrlPolicy (or default): {0}".ToFormat(policy.GetType().Name)); IRouteDefinition route = policy.Build(call); _constraintPolicy.Apply(call, route, _observer); _observer.RecordCallStatus(call, "Route definition determined by url policy: [{0}]".ToFormat(route.ToRoute().Url)); chain.Route = route; }
public bool Matches(ActionCall call, IConfigurationObserver log) { var result = call.InputType() == _inputType; if (result && _foundCallAlready) { throw new FubuException(1003, "Cannot make input type '{0}' the default route as there is more than one action that uses that input type. Either choose a input type that is used by only one action, or use the other overload of '{1}' to specify the actual action method that will be called by the default route.", _inputType.Name, ReflectionHelper.GetMethod<RouteConventionExpression>(r => r.HomeIs<object>()). Name ); } if (result) _foundCallAlready = true; if (result && log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' is the default route since its input type is {1} which was specified in the configuration as the input model for the default route" .ToFormat(call.Method.Name, _inputType.Name)); } return result; }
public FubuRegistry() { _observer = new NulloConfigurationObserver(); _viewAttacher = new ViewAttacher(_types); // Default method filters Actions.IgnoreMethodsDeclaredBy<object>(); Actions.IgnoreMethodsDeclaredBy<MarshalByRefObject>(); Actions.IgnoreMethodsDeclaredBy<IDisposable>(); // Add Behaviors First addConvention(graph => _behaviorMatcher.BuildBehaviors(_types, graph)); addConvention(graph => _actionSourceMatcher.BuildBehaviors(_types, graph)); addConvention(graph => _routeResolver.ApplyToAll(graph)); Policies.Add<StringOutputPolicy>(); Policies.Add<WebFormsEndpointPolicy>(); Policies.Add<ContinuationHandlerConvention>(); _systemPolicies.Add(new AttachAuthorizationPolicy()); Output.ToHtml.WhenCallMatches(x => x.Method.HasAttribute<HtmlEndpointAttribute>()); Output.ToJson.WhenCallMatches(x => x.Method.HasAttribute<JsonEndpointAttribute>()); Output.ToJson.WhenTheOutputModelIs<JsonMessage>(); Output.To<RenderHtmlDocumentNode>().WhenTheOutputModelIs<HtmlDocument>(); Output.To<RenderHtmlTagNode>().WhenTheOutputModelIs<HtmlTag>(); _conventions.Add(_viewAttacher); Policies.Add<JsonMessageInputConvention>(); Policies.Add<UrlRegistryCategoryConvention>(); Policies.Add<UrlForNewConvention>(); }
public void AttemptToAttachViewToAction(ViewBag bag, ActionCall call, IConfigurationObserver observer) { foreach (var filter in _filters) { var viewTokens = filter.Apply(call, bag); var count = viewTokens.Count(); observer.RecordCallStatus(call, "View filter '{0}' found {1} view token{2}".ToFormat( filter.GetType().Name, count, (count != 1) ? "s" : "")); if (count > 0) { viewTokens.Each(t => observer.RecordCallStatus(call, "Found view token: {0}".ToFormat(t))); } // if the filter returned more than one, consider it "failed", ignore it, and move on to the next if (count != 1) { continue; } var token = viewTokens.First(); observer.RecordCallStatus(call, "Selected view token: {0}".ToFormat(token)); call.AddToEnd(token.ToBehavioralNode()); break; } }
public void Apply(BehaviorGraph graph, BehaviorChain chain) { // Don't override the route if it already exists if (chain.Route != null) { return; } // Don't override the route if the chain is a partial if (chain.IsPartialOnly) { return; } _observer = graph.Observer; ActionCall call = chain.Calls.FirstOrDefault(); if (call == null) return; IUrlPolicy policy = _policies.FirstOrDefault(x => x.Matches(call, _observer)) ?? _defaultUrlPolicy; _observer.RecordCallStatus(call, "First matching UrlPolicy (or default): {0}".ToFormat(policy.GetType().Name)); IRouteDefinition route = policy.Build(call); _constraintPolicy.Apply(call, route, _observer); _observer.RecordCallStatus(call, "Route definition determined by url policy: [{0}]".ToFormat(route.ToRoute().Url)); chain.Route = route; }
public bool Matches(ActionCall call, IConfigurationObserver log) { var result = call.InputType() == _inputType; if (result && _foundCallAlready) { throw new FubuException(1003, "Cannot make input type '{0}' the default route as there is more than one action that uses that input type. Either choose a input type that is used by only one action, or use the other overload of '{1}' to specify the actual action method that will be called by the default route.", _inputType.Name, ReflectionHelper.GetMethod <RouteConventionExpression>(r => r.HomeIs <object>()).Name ); } if (result) { _foundCallAlready = true; } if (result && log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' is the default route since its input type is {1} which was specified in the configuration as the input model for the default route" .ToFormat(call.Method.Name, _inputType.Name)); } return(result); }
public FubuRegistry() { _observer = new NulloConfigurationObserver(); _viewAttacher = new ViewAttacher(_types); setupDefaultConventionsAndPolicies(); }
public void AttemptToAttachViewToAction(ViewBag bag, ActionCall call, IConfigurationObserver observer) { foreach (var filter in _filters) { var viewTokens = filter.Apply(call, bag); var count = viewTokens.Count(); observer.RecordCallStatus(call, "View filter '{0}' found {1} view token{2}".ToFormat( filter.GetType().Name, count, (count != 1) ? "s" : "" )); if( count > 0 ) { viewTokens.Each(t => observer.RecordCallStatus(call, "Found view token: {0}".ToFormat(t))); } // if the filter returned more than one, consider it "failed", ignore it, and move on to the next if (count == 1) { var token = viewTokens.First(); observer.RecordCallStatus(call, "Selected view token: {0}".ToFormat(token)); call.AddToEnd(token.ToBehavioralNode()); break; } } }
public bool Matches(ActionCall call, IConfigurationObserver log) { var listingHandlerType = typeof(ListingHandler<,>); String handlerNamePrefix = listingHandlerType .Name.Substring(0, listingHandlerType.Name.IndexOf("`")); return call.HandlerType.Name.StartsWith(handlerNamePrefix); }
public FubuRegistry() { _behaviorMatcher = new BehaviorMatcher((type, methodInfo) => _actionCallProvider(type, methodInfo)); _observer = new NulloConfigurationObserver(); _viewAttacher = new ViewAttacher(_types); setupDefaultConventionsAndPolicies(); }
public void SetUp() { _observer = MockRepository.GenerateStub<IConfigurationObserver>(); _graph = new FubuRegistry(x => { x.Actions.IncludeType<FakeController>(); x.UsingObserver(_observer); }).BuildGraph(); }
public override bool Matches(ActionCall call, IConfigurationObserver log) { if (!call.IsDiagnosticsHandler()) { return(false); } return(base.Matches(call, log)); }
public void SetUp() { _observer = MockRepository.GenerateStub <IConfigurationObserver>(); _graph = new FubuRegistry(x => { x.Actions.IncludeType <FakeController>(); x.UsingObserver(_observer); }).BuildGraph(); }
public override bool Matches(ActionCall call, IConfigurationObserver log) { if(!call.IsDiagnosticsHandler()) { return false; } return base.Matches(call, log); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if(!call.IsDiagnosticsEndpoint()) { return false; } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return true; }
public virtual bool Matches(ActionCall call, IConfigurationObserver log) { if (!IsHandlerCall(call)) { return(false); } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return(true); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if(!call.Method.HasAttribute<FubuDiagnosticsUrlAttribute>()) { return false; } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return true; }
public FubuRegistry() { _behaviorAggregator = new BehaviorAggregator(_types, _actionSources); _observer = new NulloConfigurationObserver(); _viewAttacherConvention = new ViewAttacherConvention(); _bagRunner = new ViewBagConventionRunner(_types); _connegAttachmentPolicy = new ConnegAttachmentPolicy(_types); setupDefaultConventionsAndPolicies(); }
public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer) { _httpMethodFilters.Where(x => x.Filter(call)).Each(filter => { observer.RecordCallStatus(call, "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description)); routeDefinition.AddHttpMethodConstraint(filter.Method); }); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if(!call.HandlerType.Name.EndsWith(ENDPOINT)) { return false; } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return true; }
public bool Matches(ActionCall call, IConfigurationObserver log) { if (!call.Method.HasAttribute <FubuDiagnosticsUrlAttribute>()) { return(false); } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return(true); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if (!call.IsDiagnosticsEndpoint()) { return(false); } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return(true); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if ((!call.HandlerType.Name.ToLower().EndsWith(HANDLER.ToLower()) && !HandlerExpression.IsMatch(call.HandlerType.Name)) || call.Method.HasAttribute<UrlPatternAttribute>()) { return false; } log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return true; }
public bool Matches(ActionCall call, IConfigurationObserver log) { if (log.IsRecording) { log.RecordCallStatus(call, "This route will have /special in front of it"); } //Use FubuCore.TypeExtensions to aid the readability of your conventions //by using .CanBeCastTo<>() and other helper methods to match against types return call.HasOutput && call.OutputType().CanBeCastTo<string>(); }
public static void Alter(IRouteDefinition route, ActionCall call, IConfigurationObserver observer) { var properties = call.HasInput ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys : new string[0]; Alter(route, call.Method.Name, properties, text => observer.RecordCallStatus(call, text)); if (call.HasInput) { route.ApplyInputType(call.InputType()); } }
public bool Matches(ActionCall call, IConfigurationObserver log) { if (!call.Method.HasAttribute<FubuPartialAttribute>()) return false; if (log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' has the [{1}] defined. This action is only callable via a partial request from another action and cannot be navigated-to or routed-to from the client browser directly." .ToFormat(call.Method.Name, typeof (FubuPartialAttribute).Name)); } return true; }
public bool Matches(ActionCall call, IConfigurationObserver log) { var result = call.Method.HasAttribute <UrlPatternAttribute>(); if (result && log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' has the [{1}] defined. Using explicitly defined URL pattern." .ToFormat(call.Method.Name, typeof(UrlPatternAttribute).Name)); } return(result); }
public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer) { var matchingFilters = _httpMethodFilters.Where(x => x.Filter(call)); var httpMethods = matchingFilters.Select(x => x.Method).ToArray(); if (httpMethods.Length > 0) { routeDefinition.AddRouteConstraint(HTTP_METHOD_CONSTRAINT, new HttpMethodConstraint(httpMethods)); matchingFilters.Each(filter => observer.RecordCallStatus(call, "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description))); } }
public bool Matches(ActionCall call, IConfigurationObserver log) { var result = call.Method.HasAttribute<UrlPatternAttribute>(); if( result && log.IsRecording ) { log.RecordCallStatus(call, "Action '{0}' has the [{1}] defined. Using explicitly defined URL pattern." .ToFormat(call.Method.Name, typeof(UrlPatternAttribute).Name)); } return result; }
private void attachMediaHandling(BehaviorChain chain, IConfigurationObserver observer) { var firstAction = chain.FirstCall(); if (firstAction == null) return; observer.RecordCallStatus(firstAction, "Meets criteria {0} for Conneg".ToFormat(_description)); var node = new ConnegNode(){ InputType = chain.InputType(), OutputType = chain.Calls.Where(x => x.HasOutput).Select(x => x.OutputType()).LastOrDefault() }; firstAction.AddBefore(node); }
public bool Matches(ActionCall call, IConfigurationObserver log) { if (!call.Method.HasAttribute <FubuPartialAttribute>()) { return(false); } if (log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' has the [{1}] defined. This action is only callable via a partial request from another action and cannot be navigated-to or routed-to from the client browser directly." .ToFormat(call.Method.Name, typeof(FubuPartialAttribute).Name)); } return(true); }
public BehaviorGraph(IConfigurationObserver observer) { RouteIterator = new SortByRouteRankIterator(); // can override in a registry Observer = observer; _chainsForType.OnMissing = findChainsByType; _chainsForTypeAndCategory.OnMissing = type => new Cache <string, IEnumerable <BehaviorChain> >( category => { return(ChainsFor(type).Where(x => x.UrlCategory.Category == category).ToList()); }); _chainsForMethod = new Cache <Type, ChainGroup>(type => new ChainGroup(type, this)); _creators = new Cache <Type, BehaviorChain>( type => { return(Behaviors.SingleOrDefault(x => x.UrlCategory.Creates.Contains(type))); }); }
private void attachMediaHandling(BehaviorChain chain, IConfigurationObserver observer) { var firstAction = chain.FirstCall(); if (firstAction == null) { return; } observer.RecordCallStatus(firstAction, "Meets criteria {0} for Conneg".ToFormat(_description)); var node = new ConnegNode() { InputType = chain.InputType(), OutputType = chain.Calls.Where(x => x.HasOutput).Select(x => x.OutputType()).LastOrDefault() }; firstAction.AddBefore(node); }
protected override void OnWorkerStart(CancellationToken token) { IConfigurationObserver obs = null; try { obs = configurationObserverFactory.Invoke(); obs.PropertyChanged += (o, ea) => { var cfgDto = new ConfigurationDto { Timeout = obs.DocumentsJoinerConfiguration.Timeout, BarcodeSeparator = obs.DocumentsJoinerConfiguration.BarcodeSeparatorValue }; var cmd = new CommandMessage <ConfigurationDto> { CommandName = CommandMessageName.UPDATE_CONFIGURATION_COMMAND_NAME, Payload = cfgDto }; commandsQueue.SendMessage(cmd.Serialize()); }; obs.Start(); while (!token.IsCancellationRequested) { token.WaitHandle.WaitOne(SEND_STATUS_COMMAND_PERIOD_MS); if (token.IsCancellationRequested) { break; } var statusCmd = new CommandMessage <object> { CommandName = CommandMessageName.SEND_STATUS_COMMAND_NAME }; commandsQueue.SendMessage(statusCmd.Serialize()); } } finally { obs?.Dispose(); } }
public void BeforeEach() { _parent = new FubuRegistry(); _parent.IncludeDiagnostics(true); _import = new FubuRegistry(); _import.IncludeDiagnostics(true); _import.Actions .IncludeType<Handler1>() .IncludeType<Handler2>(); _import.Configure(x => { _importObserver = x.Observer; _importActions = x.Actions() .Where(a => a.HandlerType.Namespace == GetType().Namespace); }); _parent.Import(_import, "import"); _parentObserver = _parent.BuildGraph().Observer; }
public void BeforeEach() { _parent = new FubuRegistry(); _parent.IncludeDiagnostics(true); _import = new FubuRegistry(); _import.IncludeDiagnostics(true); _import.Actions .IncludeType <Handler1>() .IncludeType <Handler2>(); _import.Configure(x => { _importObserver = x.Observer; _importActions = x.Actions() .Where(a => a.HandlerType.Namespace == GetType().Namespace); }); _parent.Import(_import, "import"); _parentObserver = _parent.BuildGraph().Observer; }
private static void modifyChain(BehaviorChain chain, IConfigurationObserver observer) { chain.Calls.Each(c => observer.RecordCallStatus(c, "Wrapping with diagnostic tracer and behavior")); chain.ToArray().Each(node => node.AddBefore(Wrapper.For<BehaviorTracer>())); chain.Prepend(new Wrapper(typeof (DiagnosticBehavior))); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return call.Method.DeclaringType.Name == DefaultHomeControllerConvention && call.Method.Name == DefaultHomeMethodConvention; }
public BehaviorVisitor(IConfigurationObserver observer, string reasonToVisit) { _observer = observer; _reasonToVisit = reasonToVisit; }
public bool Matches(ActionCall call, IConfigurationObserver log) { return(call.Method == _method); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return(_filter(call)); }
public BehaviorGraph(IConfigurationObserver observer) { RouteIterator = new SortByRouteRankIterator(); // can override in a registry Observer = observer; }
public ObserverImporter(IConfigurationObserver importingObserver) { _importingObserver = importingObserver; }
public void Import(IConfigurationObserver import) { import.RecordedCalls().Each(call => import.GetLog(call) .Each(log => _importingObserver.RecordCallStatus(call, log))); }
public void Setup() { _policy = new DiagnosticsAttributeUrlPolicy(); _observer = new NulloConfigurationObserver(); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return(call.HandlerType.Closes(typeof(RestfulDeleteHandler <>))); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return call.HandlerType.Name.EndsWith("Handler"); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return _filter(call); }
public void UsingObserver(IConfigurationObserver observer) { _observer = observer; }
public bool Matches(ActionCall call, IConfigurationObserver log) { return call.HasAttribute<FubuDiagnosticsAttribute>(); }
public void Setup() { _policy = new DiagnosticsHandlerUrlPolicy(typeof(DiagnosticsFeatures)); _observer = new NulloConfigurationObserver(); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return call.HandlerType == typeof (BehaviorGraphWriter); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return(call.HandlerType.Closes(typeof(AwesomeEditHandler <>))); }
public bool Matches(ActionCall call, IConfigurationObserver log) { log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name)); return(true); }