Exemple #1
0
        internal Task FindRoutes(JasperRuntime runtime, JasperRegistry registry, PerfTimer timer)
        {
            var applicationAssembly = registry.ApplicationAssembly;
            var generation          = registry.CodeGeneration;

            return(FindActions(applicationAssembly).ContinueWith(t =>
            {
                timer.Record("Find Routes", () =>
                {
                    var actions = t.Result;
                    foreach (var methodCall in actions)
                    {
                        Routes.AddRoute(methodCall);
                    }

                    if (_transport.ListeningEnabled)
                    {
#pragma warning disable 4014
                        Routes.AddRoute <TransportEndpoint>(nameof(TransportEndpoint.put__messages),
                                                            _transport.RelativeUrl).Route.HttpMethod = "PUT";


                        Routes.AddRoute <TransportEndpoint>(nameof(TransportEndpoint.put__messages_durable),
                                                            _transport.RelativeUrl.AppendUrl("durable")).Route.HttpMethod = "PUT";

#pragma warning restore 4014
                    }
                });

                var rules = timer.Record("Fetching Conneg Rules",
                                         () => runtime.Container.QuickBuild <ConnegRules>());

                timer.Record("Build Routing Tree", () => { Routes.BuildRoutingTree(rules, generation, runtime); });
            }));
        }
        internal async Task <RouteTree> BuildRouting(IContainer container, JasperGenerationRules generation)
        {
            if (!Enabled)
            {
                return(null);
            }

            var actions = await FindActions(ApplicationAssembly);

            foreach (var methodCall in actions)
            {
                var chain = Routes.AddRoute(methodCall);
                Urls.Register(chain.Route);
            }

            foreach (var policy in _policies)
            {
                policy.Apply(Routes, generation);
            }

            Routes.AssertNoDuplicateRoutes();

            Routes.Seal();

            var tree = new RouteTree(this, generation);

            tree.CompileAll(container);

            return(tree);
        }
Exemple #3
0
        private async Task <Registry> bootstrap(JasperRegistry registry)
        {
            var actions = await Actions.FindActions(registry.ApplicationAssembly);

            foreach (var methodCall in actions)
            {
                Routes.AddRoute(methodCall);
            }

            return(new HttpServices(Routes));
        }
Exemple #4
0
        // Call this in UseJasper()
        internal void StartFindingRoutes(Assembly assembly)
        {
            if (!Enabled)
            {
                return;
            }

            _findActions = FindActions(assembly).ContinueWith(t =>
            {
                var actions = t.Result;
                foreach (var methodCall in actions)
                {
                    Routes.AddRoute(methodCall);
                }
            });
        }
Exemple #5
0
        public CompilationContext()
        {
            _container = new Lazy <IContainer>(() => new Container(services));


            _graph = new Lazy <RouteGraph>(() =>
            {
                config        = new GenerationConfig("Jasper.Testing.Codegen.Generated");
                var container = _container.Value;
                config.Sources.Add(new StructureMapServices(container));

                config.Assemblies.Add(typeof(IContainer).GetTypeInfo().Assembly);
                config.Assemblies.Add(GetType().GetTypeInfo().Assembly);


                var graph = new RouteGraph();

                var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
                              .Where(x => x.DeclaringType != typeof(object) && x != null && !x.IsSpecialName);

                foreach (var method in methods)
                {
                    graph.AddRoute(typeof(T), method);
                }

                return(graph);
            });



            _code = new Lazy <string>(() => Graph.GenerateCode(config));

            _routes = new Lazy <Dictionary <string, RouteHandler> >(() =>
            {
                var routers = Graph.CompileAndBuildAll(config, _container.Value);
                var dict    = new Dictionary <string, RouteHandler>();
                foreach (var router in routers)
                {
                    dict.Add(router.Chain.Action.Method.Name, router);
                }

                return(dict);
            });
        }
Exemple #6
0
        internal Task FindRoutes(JasperRuntime runtime, JasperRegistry registry, PerfTimer timer)
        {
            var applicationAssembly = registry.ApplicationAssembly;
            var generation          = registry.CodeGeneration;

            return(FindActions(applicationAssembly).ContinueWith(t =>
            {
                timer.Record("Find Routes", () =>
                {
                    var actions = t.Result;
                    foreach (var methodCall in actions)
                    {
                        Routes.AddRoute(methodCall);
                    }
                });

                var rules = timer.Record("Fetching Conneg Rules",
                                         () => runtime.Container.QuickBuild <ConnegRules>());

                timer.Record("Build Routing Tree", () => { Routes.BuildRoutingTree(rules, generation, runtime); });
            }));
        }