示例#1
0
        public static void PreStart()
        {
            using (DisposableTimer.StartNew("PRE_START"))
            {
                var cfg = BootstrapperSection.Initialize();

                //cria um text logger somente para o startup
                //remove no post start
                try
                {
                    _traceFileName = HostingEnvironment.MapPath(cfg.TraceOutput);
                    if (File.Exists(_traceFileName))
                    {
                        File.Delete(_traceFileName);
                    }

                    var listener = new TextWriterTraceListener(_traceFileName, "StartupListener");

                    Trace.Listeners.Add(listener);
                }
                catch { }


                var executingAssembly = Assembly.GetExecutingAssembly();
                Trace.TraceInformation("Entry Assembly: {0}", executingAssembly.GetName().Name);


                if (cfg.HttpModules.Trace.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(TracerHttpModule));
                }

                if (cfg.StopMonitoring)
                {
                    HttpInternals.StopFileMonitoring();
                }

                if (cfg.HttpModules.CustomError.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(CustomErrorHttpModule));
                }

                if (cfg.HttpModules.WhiteSpace.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(WhitespaceModule));
                }

                using (DisposableTimer.StartNew("DbFileContext"))
                {
                    DbFileContext.Initialize();
                }

                if (cfg.PluginLoader.Enabled)
                {
                    using (DisposableTimer.StartNew("PluginLoader"))
                    {
                        PluginLoaderEntryPoint.Initialize();
                    }
                }

                if (cfg.VirtualPathProviders.SubFolderVpp.Enabled)
                {
                    SubfolderVpp.SelfRegister();
                }

                if (cfg.DumpToLocal.Enabled)
                {
                    using (DisposableTimer.StartNew("DumpToLocal"))
                    {
                        DbToLocal.Execute();
                    }
                }

                //todo: Dependency Injection
                if (cfg.VirtualPathProviders.DbFileSystemVpp.Enabled)
                {
                    var customvpp = new CustomVirtualPathProvider()
                                    .AddImpl(new CachedDbServiceFileSystemProvider(new DefaultDbService(), new WebCacheWrapper()));
                    HostingEnvironment.RegisterVirtualPathProvider(customvpp);
                }

                KompilerEntryPoint.AddReferences(
                    typeof(Controller),
                    typeof(WebPageRenderingBase),
                    typeof(WebCacheWrapper),
                    typeof(ViewRenderer),
                    typeof(DbToLocal),
                    typeof(ErrorModel));

                if (cfg.Kompiler.Enabled)
                {
                    using (DisposableTimer.StartNew("Kompiler"))
                    {
                        KompilerEntryPoint.Execute();
                    }
                }

                if (cfg.InsertRoutes)
                {
                    var routes = RouteTable.Routes;

                    routes.RouteExistingFiles  = false;
                    routes.LowercaseUrls       = true;
                    routes.AppendTrailingSlash = true;

                    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                    routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
                    routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|txt|png|gif|jpg|jpeg|bmp)(/.*)?" });

                    routes.IgnoreRoute("Content/{*pathInfo}");
                    routes.IgnoreRoute("Scripts/{*pathInfo}");
                    routes.IgnoreRoute("Bundles/{*pathInfo}");

                    //routes.MapRoute("MvcLib", "{controller}/{action}", new string[] { "" });


                    if (cfg.TraceOutput.IsNotNullOrWhiteSpace())
                    {
                        //routes.MapHttpHandler<WebPagesRouteHandler>("~/dump.cshtml");
                    }
                }
            }
        }
示例#2
0
        public static void PreStart()
        {
            var cfg = BootstrapperSection.Initialize();

            //cria um text logger somente para o startup
            //remove no post start
            try
            {
                _traceFileName = HostingEnvironment.MapPath(cfg.TraceOutput);
                if (!string.IsNullOrWhiteSpace(_traceFileName))
                {
                    if (File.Exists(_traceFileName))
                    {
                        try
                        {
                            File.Delete(_traceFileName);
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError(ex.ToString());
                        }
                    }

                    var listener = new TextWriterTraceListener(_traceFileName, "StartupListener");

                    Trace.Listeners.Add(listener);

                    Trace.TraceInformation("[Bootstrapper]: StartupLog added: {0}", listener);
                }
            }
            catch
            {
            }

            using (DisposableTimer.StartNew("Frankstein PRE_START"))
            {
                var executingAssembly = Assembly.GetExecutingAssembly();
                Trace.TraceInformation("[Bootstrapper]:Entry Assembly: {0}", executingAssembly.GetName().Name);

                DynamicModuleUtility.RegisterModule(typeof(FranksteinHttpModule));

                Trace.TraceInformation("[Bootstrapper]:cfg.HttpModules.Trace.Enabled = {0}", cfg.HttpModules.Trace.Enabled);
                if (cfg.HttpModules.Trace.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(TracerHttpModule));
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.HttpModules.TransactionScope.Enabled = {0}", cfg.HttpModules.TransactionScope.Enabled);
                if (cfg.HttpModules.TransactionScope.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(TransactionScopeHttpModule));
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.StopMonitoring = {0}", cfg.StopMonitoring);
                if (cfg.StopMonitoring)
                {
                    HttpInternals.StopFileMonitoring();
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.HttpModules.CustomError.Enabled = {0}", cfg.HttpModules.CustomError.Enabled);
                if (cfg.HttpModules.CustomError.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(CustomErrorHttpModule));
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.HttpModules.WhiteSpace.Enabled = {0}", cfg.HttpModules.WhiteSpace.Enabled);
                if (cfg.HttpModules.WhiteSpace.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(WhitespaceModule));
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.HttpModules.PathRewriter.Enabled = {0}", cfg.HttpModules.PathRewriter.Enabled);
                if (cfg.HttpModules.PathRewriter.Enabled)
                {
                    DynamicModuleUtility.RegisterModule(typeof(PathRewriterHttpModule));
                }

                using (DisposableTimer.StartNew("DbFileContext"))
                {
                    DbFileContext.Initialize();
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.PluginLoader.Enabled = {0}", cfg.PluginLoader.Enabled);
                if (cfg.PluginLoader.Enabled)
                {
                    using (DisposableTimer.StartNew("PluginLoader"))
                    {
                        PluginLoaderEntryPoint.Initialize();
                    }
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.VirtualPathProviders.SubFolderVpp.Enabled = {0}", cfg.VirtualPathProviders.SubFolderVpp.Enabled);
                if (cfg.VirtualPathProviders.SubFolderVpp.Enabled)
                {
                    SubfolderVpp.SelfRegister();
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.VirtualPathProviders.DbFileSystemVpp.Enabled = {0}", cfg.VirtualPathProviders.DbFileSystemVpp.Enabled);
                if (cfg.VirtualPathProviders.DbFileSystemVpp.Enabled)
                {
                    var customvpp = new CustomVirtualPathProvider()
                                    .AddImpl(new CachedDbServiceFileSystemProvider(new DefaultDbService(), new WebCacheWrapper()));
                    HostingEnvironment.RegisterVirtualPathProvider(customvpp);
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.DumpToLocal.Enabled = {0}", cfg.DumpToLocal.Enabled);
                if (cfg.DumpToLocal.Enabled)
                {
                    using (DisposableTimer.StartNew("DumpToLocal"))
                    {
                        DbToLocal.Execute();
                    }
                }

                Trace.TraceInformation("[Bootstrapper]:cfg.Kompiler.Enabled = {0}", cfg.Kompiler.Enabled);
                var bin = new DirectoryInfo(HttpRuntime.BinDirectory);

                foreach (var fileInfo in bin.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                {
                    if (cfg.Verbose)
                    {
                        Trace.Indent();
                        Trace.TraceInformation("[BinFolder]: {0}", fileInfo.FullName);
                        Trace.Unindent();
                    }
                    KompilerEntryPoint.AddReferences(fileInfo.FullName);
                }

                foreach (var keyValuePair in CustomConfig.RefreshConfig())
                {
                    KompilerEntryPoint.AddReferences(keyValuePair);
                }


                if (cfg.Kompiler.Enabled)
                {
                    using (DisposableTimer.StartNew("Kompiler"))
                    {
                        KompilerEntryPoint.Execute();
                    }
                }
            }
        }