Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            });
        }
Exemplo n.º 7
0
        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);
            });
        }
Exemplo n.º 8
0
        public bool Matches(ActionCall call, IConfigurationObserver log)
        {
            if (!call.IsDiagnosticsEndpoint())
            {
                return(false);
            }

            log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name));
            return(true);
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 12
0
        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;
        }
Exemplo n.º 14
0
        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>();
        }
Exemplo n.º 16
0
        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)));

            }
        }
Exemplo n.º 17
0
        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)
        {
            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;
        }
Exemplo n.º 20
0
        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());
            }
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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());
            }
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        public void VisitBehavior(BehaviorChain chain)
        {
            if (!_filters.MatchesAll(chain))
            {
                return;
            }

            var matchesDescriptions = _filters.GetDescriptionOfMatches(chain).Join(", ");

            if (matchesDescriptions == string.Empty)
            {
                matchesDescriptions = "(no filters defined)";
            }

            chain.Calls.Each(call => _observer.RecordCallStatus(call,
                                                                "Visiting: {0}. Matched on filters [{1}]".ToFormat
                                                                    (_reasonToVisit, matchesDescriptions)));

            _actions.Do(chain);
        }
Exemplo n.º 27
0
 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)));
 }
 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)));
 }
Exemplo n.º 29
0
        public virtual bool Matches(ActionCall call, IConfigurationObserver log)
        {
            if (!IsHandlerCall(call))
            {
                return false;
            }

            log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name));
            return true;
        }
Exemplo n.º 30
0
        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;
        }
Exemplo n.º 31
0
 public bool Matches(ActionCall call, IConfigurationObserver log)
 {
     log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name));
     return true;
 }
Exemplo n.º 32
0
 public bool Matches(ActionCall call, IConfigurationObserver log)
 {
     log.RecordCallStatus(call, "Matched on {0}".ToFormat(GetType().Name));
     return(true);
 }
 private static void ModifyChain(CommandChain chain, IConfigurationObserver observer)
 {
     chain.Calls.Each(c => observer.RecordCallStatus(c, "Wrapping with invocation tracer"));
     chain.ToArray().Each(node => node.AddBefore(new Wrapper(typeof(InvocationTracer<>).MakeGenericType(chain.EntityType))));
 }
Exemplo n.º 34
0
 public void Import(IConfigurationObserver import)
 {
     import.RecordedCalls().Each(call => import.GetLog(call)
                                 .Each(log => _importingObserver.RecordCallStatus(call, log)));
 }