public Func <IDictionary <string, object>, Task> WrapAppFunc(FubuRuntime runtime,
                                                                     Func <IDictionary <string, object>, Task> inner)
        {
            if (TraceLevel == TraceLevel.None)
            {
                return(inner);
            }

            var logger = runtime.Get <IExecutionLogger>();

            return(env =>
            {
                var log = new ChainExecutionLog();
                env.Log(log);

                return inner(env).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        t.Exception.Flatten().InnerExceptions.Each(log.LogException);
                    }

                    log.MarkFinished();

                    if (log.RootChain != null && ApplyTracing.ShouldApply(log.RootChain))
                    {
                        logger.Record(log, env);
                    }
                });
            });
        }
        public void behavior_tracers_deeper()
        {
            var node  = Wrapper.For <SimpleBehavior>();
            var chain = new BehaviorChain();

            chain.AddToEnd(node);
            node.AddAfter(Wrapper.For <DifferentBehavior>());

            ApplyTracing.ApplyToChain(chain);



            var objectDef = chain.As <IContainerModel>().ToObjectDef().FindDependencyDefinitionFor <IActionBehavior>();

            objectDef.Type.ShouldEqual(typeof(BehaviorTracer));
            var child1 = objectDef.FindDependencyDefinitionFor <IActionBehavior>();

            child1.Type.ShouldEqual(typeof(SimpleBehavior));

            var child2 = child1.FindDependencyDefinitionFor <IActionBehavior>();

            child2.Type.ShouldEqual(typeof(BehaviorTracer));

            var child3 = child2.FindDependencyDefinitionFor <IActionBehavior>();

            child3.Type.ShouldEqual(typeof(DifferentBehavior));
        }
Exemple #3
0
        public static BehaviorGraph Build(FubuRegistry registry, IPerfTimer perfTimer,
                                          IEnumerable <Assembly> packageAssemblies, IActivationDiagnostics diagnostics, IFubuApplicationFiles files)
        {
            var featureLoader = new FeatureLoader();

            featureLoader.LookForFeatures();

            if (registry.Mode.InDevelopment())
            {
                registry.AlterSettings <DiagnosticsSettings>(_ => _.TraceLevel = TraceLevel.Verbose);
                registry.AlterSettings <AssetSettings>(_ => _.SetupForDevelopment());
            }



            var graph = new BehaviorGraph
            {
                ApplicationAssembly = registry.ApplicationAssembly,
                PackageAssemblies   = packageAssemblies
            };

            var accessorRules         = AccessorRulesCompiler.Compile(graph, perfTimer);
            var validationCompilation = ValidationCompiler.Compile(graph, perfTimer, registry);



            var config = registry.Config;

            perfTimer.Record("Applying Settings", () => applySettings(config, graph, diagnostics, files));

            perfTimer.Record("Enable built in polling jobs", () => enableBuiltInJobs(graph));
            perfTimer.Record("Applying Feature Settings", () => featureLoader.ApplyAll(graph.Settings, registry).Wait(30.Seconds()).AssertFinished());


            config.Add(new ActionlessViewChainSource());
            perfTimer.Record("Local Application BehaviorGraph", () => config.BuildLocal(graph, perfTimer));

            perfTimer.Record("Explicit Configuration", () => config.Global.Explicits.RunActions(graph));
            perfTimer.Record("Global Policies", () => config.Global.Policies.RunActions(graph));

            perfTimer.Record("Inserting Conneg and Authorization Nodes",
                             () => insertConnegAndAuthorizationNodes(graph));

            perfTimer.Record("Applying Global Reorderings", () => config.ApplyGlobalReorderings(graph));


            if (registry.Mode.InDevelopment() || graph.Settings.Get <DiagnosticsSettings>().TraceLevel != TraceLevel.None)
            {
                perfTimer.Record("Applying Tracing", () => ApplyTracing.Configure(graph));
            }


            Task.WaitAll(new Task[] { accessorRules, validationCompilation }, 30.Seconds()).AssertFinished();

            new AutoImportModelNamespacesConvention().Configure(graph);

            return(graph);
        }