Exemplo n.º 1
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            // Start unity
            var unityContainer = UnityHelper.Start();

            // Set Hangfire to use SQL Server and the connection string
            GlobalConfiguration.Configuration.UseSqlServerStorage(SiteConstants.Instance.MvcForumContext);

            // Make hangfire use unity container
            GlobalConfiguration.Configuration.UseUnityActivator(unityContainer);

            // Add Hangfire
            // TODO - Do I need this dashboard?
            //app.UseHangfireDashboard();
            app.UseHangfireServer();

            // Make DB update to latest migration
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <MvcForumContext, Configuration>());

            // Get services needed
            var mvcForumContext   = DependencyResolver.Current.GetService <IMvcForumContext>();
            var badgeService      = DependencyResolver.Current.GetService <IBadgeService>();
            var settingsService   = DependencyResolver.Current.GetService <ISettingsService>();
            var loggingService    = DependencyResolver.Current.GetService <ILoggingService>();
            var reflectionService = DependencyResolver.Current.GetService <IReflectionService>();

            // Routes
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // If the same carry on as normal
            loggingService.Initialise(ConfigUtils.GetAppSettingInt32("LogFileMaxSizeBytes", 10000));
            loggingService.Error("START APP");

            // Get assemblies for badges, events etc...
            var loadedAssemblies = reflectionService.GetAssemblies();

            // Do the badge processing
            try
            {
                badgeService.SyncBadges(loadedAssemblies);
                mvcForumContext.SaveChanges();
            }
            catch (Exception ex)
            {
                loggingService.Error($"Error processing badge classes: {ex.Message}");
            }

            // Set the view engine
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ForumViewEngine(settingsService.GetSettings().Theme));

            // Initialise the events
            EventManager.Instance.Initialize(loggingService, loadedAssemblies);

            // Finally trigger any Cron jobs
            RecurringJob.AddOrUpdate <RecurringJobService>(x => x.SendMarkAsSolutionReminders(), Cron.HourInterval(6), queue: "solutionreminders");
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            AreaRegistration.RegisterAllAreas();
            System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            // Start unity
            UnityHelper.InitialiseUnityContainer();

            // Make DB update to latest migration
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<MvcForumContext, Configuration>());

            // Set the rest of the Ioc
            UnityHelper.BuildUnityContainer();

            // Grab the container as we will need to use it
            var unityContainer = UnityHelper.Container;

            // Set Hangfire to use SQL Server and the connection string
            //GlobalConfiguration.Configuration.UseSqlServerStorage(ForumConfiguration.Instance.MvcForumContext);

            // Make hangfire use unity container
            //GlobalConfiguration.Configuration.UseUnityActivator(unityContainer);

            // Add Hangfire
            // TODO - Do I need this dashboard?
            //app.UseHangfireDashboard();

            //app.UseHangfireServer();

            // Get services needed
            var mvcForumContext = unityContainer.Resolve <IMvcForumContext>();
            //var badgeService = unityContainer.Resolve<IBadgeService>();
            var loggingService   = unityContainer.Resolve <ILoggingService>();
            var assemblyProvider = unityContainer.Resolve <IAssemblyProvider>();

            // Routes
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // If the same carry on as normal
            var logFileSize = ForumConfiguration.Instance.LogFileMaxSizeBytes;

            loggingService.Initialise(logFileSize > 100000 ? logFileSize : 100000);
            loggingService.Error("START APP");

            // Find the plugin, pipeline and badge assemblies
            var assemblies = assemblyProvider.GetAssemblies(ForumConfiguration.Instance.PluginSearchLocations).ToList();

            ImplementationManager.SetAssemblies(assemblies);

            // Do the badge processing
            //try
            //{
            //    badgeService.SyncBadges(assemblies);
            //    mvcForumContext.SaveChanges();
            //}
            //catch (Exception ex)
            //{
            //    loggingService.Error($"Error processing badge classes: {ex.Message}");
            //}

            var theme = "Metro";

            //var settings = mvcForumContext.Setting.FirstOrDefault();
            //if (settings != null)
            //{
            //    theme = settings.Theme;
            //}

            // Set the view engine
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ForumViewEngine(theme));

            // Initialise the events
            EventManager.Instance.Initialize(loggingService, assemblies);

            // Finally trigger any Cron jobs
            //RecurringJob.AddOrUpdate<RecurringJobService>(x => x.SendMarkAsSolutionReminders(), Cron.HourInterval(6), queue: "solutionreminders");
        }