Example #1
0
 private static void addBuiltInDiagnostics(BehaviorGraph graph)
 {
     if (FubuMode.InDevelopment())
     {
         graph.AddChain(RoutedChain.For<AboutDiagnostics>(x => x.get__about(), "_about"));
         graph.AddChain(RoutedChain.For<AboutDiagnostics>(x => x.get__loaded(), "_loaded"));
     }
 }
 public void SetUp()
 {
     _outputPolicy = new AttachOutputPolicy();
     _graph = new BehaviorGraph();
     _graph.AddChain(BehaviorChain.For<TestEndpoint>(e => e.X()));
     _graph.AddChain(BehaviorChain.For<TestEndpoint>(e => e.AnyNumber()));
     _outputPolicy.Configure(_graph);
 }
        public void Configure(BehaviorGraph graph)
        {
            if (!HasLogin(graph))
            {
                graph.AddChain().AddToEnd(ActionCall.For<LoginController>(x => x.Login(null)));
            }

            if (!HasLogout(graph))
            {
                graph.AddChain().AddToEnd(ActionCall.For<LogoutController>(x => x.Logout(null)));
            }
        }
Example #4
0
        public void should_throw_an_exception_if_the_result_is_not_unique()
        {
            var call1 = ActionCall.For<Issue101Endpoint>(x => x.get_hello());
            var call2 = ActionCall.For<Issue101Endpoint>(x => x.get_hello());

            var graph = new BehaviorGraph();
            graph.AddChain().AddToEnd(call1);
            graph.AddChain().AddToEnd(call2);

            Exception<FubuException>.ShouldBeThrownBy(() => {
                graph.ChainFor<Issue101Endpoint>(x => x.get_hello());
            });
        }
        public void Configure(BehaviorGraph graph)
        {
            var handlers = graph.Settings.Get<HandlerGraph>();

            // TODO -- move this to a HandlerSource after we fix the duplicate calls
            // across HandlerSource problem.
            handlers.Add(HandlerCall.For<SubscriptionsHandler>(x => x.Handle(new SubscriptionRequested())));
            handlers.Add(HandlerCall.For<SubscriptionsHandler>(x => x.Handle(new SubscriptionsChanged())));

            handlers.ApplyGeneralizedHandlers();

            var policies = graph.Settings.Get<HandlerPolicies>();
            handlers.ApplyPolicies(policies.GlobalPolicies);

            foreach (var chain in handlers)
            {
                // Apply the error handling node
                chain.InsertFirst(new ExceptionHandlerNode(chain));

                graph.AddChain(chain);

                // Hate how we're doing this, but disable tracing
                // on the polling job requests here.
                if (chain.InputType().Closes(typeof (JobRequest<>)))
                {
                    chain.Tags.Add(BehaviorChain.NoTracing);
                }
            }
        }
Example #6
0
 private static BehaviorChain createAssetContentChain(BehaviorGraph graph)
 {
     var chain = graph.AddChain();
     var pattern = "_content";
     chain.Route = RouteBuilder.Build(typeof(AssetPath), pattern);
     chain.Route.AddHttpMethodConstraint("GET");
     return chain;
 }
        public void has_logout_positive()
        {
            var graph = new BehaviorGraph();
            graph.AddChain().AddToEnd(ActionCall.For<LoginEndpoint>(x => x.get_logout(null)));

            FormsAuthenticationEndpointsRegistration.HasLogout(graph)
                .ShouldBeTrue();
        }
Example #8
0
        private static void addReloadedEndpoint(BehaviorGraph graph)
        {
            var action = ActionCall.For<AboutEndpoint>(x => x.get__loaded());
            var chain = new BehaviorChain();
            chain.AddToEnd(action);
            chain.Route = new RouteDefinition("_loaded");

            graph.AddChain(chain);
        }
        private static BehaviorChain createAssetContentChain(BehaviorGraph graph)
        {
            var chain = graph.AddChain();

            chain.Route = RouteBuilder.Build(typeof (AssetPath), Pattern);
            chain.Route.AddHttpMethodConstraint("GET");
            chain.Route.SessionStateRequirement = SessionStateRequirement.DoesNotUseSessionState;
            return chain;
        }
 public void Configure(BehaviorGraph graph)
 {
     var route = new RouteDefinition("");
     route.AddHttpMethodConstraint("GET");
     var chain = new BehaviorChain { Route = route };
     chain.AddToEnd(new RedirectNode());
     graph.AddChain(chain);
     graph.Services.AddService(this);
 }
Example #11
0
 public void Configure(BehaviorGraph graph)
 {
     _sources
         .SelectMany(src => src.FindActions(_types))
         .Each(call =>
                   {
                       var chain = new BehaviorChain();
                       chain.AddToEnd(call);
                       graph.AddChain(chain);
                   });
 }
        public void Configure(BehaviorGraph graph)
        {
            var actions = _source.FindActions(graph.ApplicationAssembly);

            var existing = graph.Actions().ToList();

            actions.Where(x => !existing.Contains(x)).Each(call => {
                var chain = new BehaviorChain();
                chain.AddToEnd(call);
                graph.AddChain(chain);
            });
        }
        private void buildChain(BehaviorGraph graph, Type t)
        {
            var chain = graph.AddChain();
            chain.Origin = "SmartGridConvention";
            chain.Route = new RouteDefinition("_griddata/" + t.NameForGrid().ToLower());

            var call = typeof (GridActionCall<>).CloseAndBuildAs<ActionCall>(t);
            chain.AddToEnd(call);

            t.GetAllAttributes<ModifyChainAttribute>().Each(att => att.Alter(call));

            chain.MakeAsymmetricJson();
        }
Example #14
0
        public void Configure(BehaviorGraph graph)
        {
            // This needs to be forced to true here
            _types.ShouldScanAssemblies = true;
            _types.TypesMatching(_viewTypeFilter).Each(type =>
            {
                var chain = graph.AddChain();
                var node = _facilities.FirstValue(x => x.CreateViewNode(type));
                chain.AddToEnd(node);

                _configureChain(chain);
            });
        }
Example #15
0
        public void Configure(BehaviorGraph graph)
        {
            if (!_views.Views.Any()) return;

            FindLastActions(graph.Behaviors).Each(attachToAction);

            _views.Views.Where(x => x.ViewModel != null && !_attached.Contains(x)).Each(view => {
                var chain = buildChainForView(view);
                chain.Output.AddView(view, Always.Flyweight);

                graph.AddChain(chain);
            });
        }
Example #16
0
        public void Configure(ViewBag bag, BehaviorGraph graph)
        {
            bag
                .Views
                .Where(token => _viewTokenFilter(token))
                .Each(token =>
                          {
                              var chain = graph.AddChain();
                              var output = token.ToBehavioralNode();
                              chain.AddToEnd(output);

                              _configureChain(chain);
                          });
        }
        public void Configure(BehaviorGraph graph)
        {
            if (!graph.Behaviors.Any(x => x.Route != null && x.GetRoutePattern().IsEmpty()))
            {
                var action = ActionCall.For<DefaultHome>(x => x.GoToDiagnostics());
                var continuer = new ContinuationNode();

                var chain = new BehaviorChain();
                chain.Route = new RouteDefinition("");
                chain.AddToEnd(action);
                chain.AddToEnd(continuer);

                graph.AddChain(chain);
            }
        }
        public void Configure(BehaviorGraph graph)
        {
            var pool = TypePool.AppDomainTypes();
            pool.TypesMatching(type => type.IsConcreteTypeOf<ISendMessages>()).Each(type => {
                type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                    .Where(ActionSource.IsCandidate)
                    .Each(method => {
                        var transform = new ActionCall(type, method);
                        var chain = new BehaviorChain();
                        chain.AddToEnd(transform);

                        graph.AddChain(chain);
                    });
            });
        }
        public void Configure(BehaviorGraph graph)
        {
            var attachedViews = graph.Behaviors
                .Where(x => x.HasOutput())
                .SelectMany(x => x.Output.Writers.OfType<ViewNode>())
                .Select(x => x.View).ToList();

            var unattached = graph.Settings.Get<ViewEngines>().Views.Views.Where(x => x.ViewModel != null && !attachedViews.Contains(x));

            unattached.Each(v =>
            {
                var chain = BehaviorChain.ForWriter(new ViewNode(v));
                chain.IsPartialOnly = true;

                graph.AddChain(chain);
            });
        }
Example #20
0
        public static BehaviorGraph Import(FubuRegistry registry, SettingsCollection parentSettings)
        {
            var graph = new BehaviorGraph(parentSettings);
            startBehaviorGraph(registry, graph);
            var config = registry.Config;

            config.RunActions(ConfigurationType.Settings, graph);

            config.Sources.Union(config.Imports).SelectMany(x => x.BuildChains(graph.Settings)).Each(chain => graph.AddChain(chain));

            config.RunActions(ConfigurationType.Explicit, graph);
            config.RunActions(ConfigurationType.Policy, graph);
            config.RunActions(ConfigurationType.Reordering, graph);
            config.RunActions(ConfigurationType.InjectNodes, graph);

            return graph;
        }
Example #21
0
        public void should_throw_2151_if_the_input_type_has_multiple_possible_behavior_chains()
        {
            var graph = new BehaviorGraph(null);

            graph.AddChain(BehaviorChain.For<ControllerTarget>(x => x.OneInOneOut(null)));
            graph.AddChain(BehaviorChain.For<ControllerTarget>(x => x.OneInZeroOut(null)));

            Exception<FubuException>.ShouldBeThrownBy(() => { graph.IdForType(typeof (Model1)); }).ErrorCode.ShouldEqual
                (2151);
        }
Example #22
0
        public void when_there_is_only_one_chain_for_that_input_model()
        {
            var graph = new BehaviorGraph(null);

            BehaviorChain chain = BehaviorChain.For<ControllerTarget>(x => x.OneInOneOut(null));
            graph.AddChain(chain);
            graph.IdForType(typeof (Model1)).ShouldEqual(chain.UniqueId);
        }
Example #23
0
        public void SetUp()
        {
            graph1 = new FubuRegistry(x =>
            {
                x.Route<InputModel>("method1/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route<InputModel>("method2/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();

                x.Route<InputModel>("method3/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();
            }).BuildGraph();

            chain = new BehaviorChain();
            graph1.AddChain(chain);

            graph2 = new FubuRegistry(x =>
            {
                x.Route<InputModel>("/root/{Name}/{Age}")
                    .Calls<TestController>(c => c.AnotherAction(null)).OutputToJson();
            }).BuildGraph();

            graph2.Import(graph1, "area1");
        }
Example #24
0
        private static void discoverChains(ConfigGraph config, BehaviorGraph graph)
        {
            var chainSources = config.Sources.Union(config.UniqueImports()).ToList();
            if (FubuMode.InDevelopment())
            {
                var aggregator = new ActionSourceAggregator(null);
                aggregator.Add(new RegisterAbout());

                chainSources.Add(aggregator);
            }

            var tasks =
                chainSources.Select(
                    x => {
                        return
                            Task.Factory.StartNew(() => { x.BuildChains(graph.Settings).Each(chain => graph.AddChain(chain)); });
                    }).ToArray();

            Task.WaitAll(tasks);
        }
Example #25
0
        public void SetUp()
        {
            graph = new BehaviorGraph(null);

            chain1 = BehaviorChain.For<ControllerTarget>(x => x.OneInOneOut(null));
            graph.AddChain(chain1);

            chain2 = BehaviorChain.For<ControllerTarget>(x => x.OneInZeroOut(null));
            graph.AddChain(chain2);
        }
        public void Configure(BehaviorGraph graph)
        {
            var action = ActionCall.For<AboutEndpoint>(x => x.get__about());
            var chain = new BehaviorChain();
            chain.AddToEnd(action);
            chain.Route = new RouteDefinition("_about");

            graph.AddChain(chain);
        }