示例#1
0
        protected void Application_Start(object sender, EventArgs e)
        {
            Debug.WriteLine("Starting routes registration");

            RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            RouteTable.Routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

            Debug.WriteLine("Routes registration done");

            Debug.WriteLine("Setting up the container");
            DiSetup.SetupContainer(m_container, new FileLogWriter("Frontend"));
            Debug.WriteLine("Container set up");

            Debug.WriteLine("Initializing RoboApi");
            var installer = new RoboApiInstaller();

            installer.Install(
                ControllerBuilder.Current,
                m_container,
                (context, locator) =>
            {
                var session = locator.Get <IWebSession>();
                session.Initialize(context);
            } /*,
               * typeof(ElsaControllerBase).Assembly,
               * typeof(ProfileController).Assembly,
               * typeof(UserController).Assembly*/);
            Debug.WriteLine("RoboApi initialized");

            Debug.WriteLine("Loading startup jobs");
            using (var startupJobsLocator = m_container.GetLocator())
            {
                var jobs   = startupJobsLocator.GetCollection <IStartupJob>();
                var logger = startupJobsLocator.Get <ILog>();

                logger.Info("Starting startup jobs");
                foreach (var job in jobs)
                {
                    try
                    {
                        logger.Info($"Starting job {job.GetType().Name}");

                        job.Execute();

                        logger.Info($"Job {job.GetType().Name} complete");
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"StartupJob {job.GetType().Name} failed", ex);
                        if (job.IsExceptionFatal)
                        {
                            throw;
                        }
                    }
                }
                logger.Info("Startup jobs done");
            }

            Debug.WriteLine("Application startup complete");
        }