예제 #1
0
        public static void AssemblyInitialize(TestContext context)
        {
            if (ConfigurationManager.AppSettings["PreventDatabaseDrop"] != "true")
            {
                //Force db to drop & seed
                Database.SetInitializer(new VoatDataInitializer());
                using (var db = new voatEntities())
                {
                    var data = db.DefaultSubverses.ToList();
                }
            }

            //load web.config.live monitor
            LiveConfigurationManager.Reload(ConfigurationManager.AppSettings);
            LiveConfigurationManager.Start();

            //This causes the voat rules engine to init using config section for load
            var rulesEngine = VoatRulesEngine.Instance;

            //purge redis for unit tests if enabled
            var defaultHandler = CacheHandlerSection.Instance.Handlers.FirstOrDefault(x => x.Enabled && x.Type.ToLower().Contains("redis"));

            if (defaultHandler != null)
            {
                var instance = defaultHandler.Construct();
                instance.Purge();
            }
        }
예제 #2
0
        protected void Application_Start()
        {
            LiveConfigurationManager.Reload(ConfigurationManager.AppSettings);
            LiveConfigurationManager.Start();

            if (!Settings.SignalRDisabled)
            {
                Microsoft.AspNet.SignalR.GlobalHost.DependencyResolver.Register(typeof(Microsoft.AspNet.SignalR.Hubs.IJavaScriptMinifier), () => new HubMinifier());
            }
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());

            ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

            ContentProcessor.UserNotificationChanged = new Action <string>(recipient => {
                //get count of unread notifications
                int unreadNotifications = UserHelper.UnreadTotalNotificationsCount(recipient);
                // send SignalR realtime notification to recipient
                var hubContext = GlobalHost.ConnectionManager.GetHubContext <MessagingHub>();
                hubContext.Clients.User(recipient).setNotificationsPending(unreadNotifications);
            });

            // USE ONLY FOR DEBUG: clear all sessions used for online users count
            // SessionTracker.RemoveAllSessions();
        }
예제 #3
0
파일: Global.asax.cs 프로젝트: Souric/voat
        protected void Application_Start()
        {
            LiveConfigurationManager.Reload(ConfigurationManager.AppSettings);
            LiveConfigurationManager.Start();

            if (!MvcApplication.SignalRDisabled)
            {
                Microsoft.AspNet.SignalR.GlobalHost.DependencyResolver.Register(typeof(Microsoft.AspNet.SignalR.Hubs.IJavaScriptMinifier), () => new Utils.HubMinifier());
            }
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());

            ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

            // USE ONLY FOR DEBUG: clear all sessions used for online users count
            // SessionTracker.RemoveAllSessions();
        }
예제 #4
0
        protected void Application_Start()
        {
            var formatters = GlobalConfiguration.Configuration.Formatters;

            formatters.Remove(formatters.XmlFormatter);

            LiveConfigurationManager.Reload(ConfigurationManager.AppSettings);
            LiveConfigurationManager.Start();

            //forces Rules Engine to load
            var x = VoatRulesEngine.Instance;
            //forces thumbgenerator to initialize
            var p = ThumbGenerator.DestinationPathThumbs;

            if (!Settings.SignalRDisabled)
            {
                Microsoft.AspNet.SignalR.GlobalHost.DependencyResolver.Register(typeof(Microsoft.AspNet.SignalR.Hubs.IJavaScriptMinifier), () => new HubMinifier());
            }
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //register global error handler
            GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new VoatExceptionLogger());

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewEngine());

            ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

            JsonConvert.DefaultSettings = () => { return(JsonSettings.GetSerializationSettings()); };

            #region Hook Events

            EventHandler <MessageReceivedEventArgs> updateNotificationCount = delegate(object s, MessageReceivedEventArgs e)
            {
                if (!Settings.SignalRDisabled)
                {
                    var userDef = UserDefinition.Parse(e.TargetUserName);
                    if (userDef.Type == IdentityType.User)
                    {
                        //get count of unread notifications
                        var q = new QueryMessageCounts(userDef.Name, userDef.Type, MessageTypeFlag.All, MessageState.Unread);
                        var unreadNotifications = q.Execute().Total;
                        // send SignalR realtime notification to recipient
                        var hubContext = GlobalHost.ConnectionManager.GetHubContext <MessagingHub>();
                        hubContext.Clients.User(e.TargetUserName).setNotificationsPending(unreadNotifications);
                    }
                }
            };
            EventNotification.Instance.OnMessageReceived      += updateNotificationCount;
            EventNotification.Instance.OnMentionReceived      += updateNotificationCount;
            EventNotification.Instance.OnCommentReplyReceived += updateNotificationCount;

            EventNotification.Instance.OnVoteReceived += (s, e) =>
            {
                if (!Settings.SignalRDisabled)
                {
                    var hubContext = GlobalHost.ConnectionManager.GetHubContext <MessagingHub>();
                    switch (e.ReferenceType)
                    {
                    case Domain.Models.ContentType.Submission:
                        hubContext.Clients.User(e.TargetUserName).voteChange(1, e.ChangeValue);
                        break;

                    case Domain.Models.ContentType.Comment:
                        hubContext.Clients.User(e.TargetUserName).voteChange(2, e.ChangeValue);
                        break;
                    }
                }
            };

            //TODO: Fuzzy can't wait for this feature!
            EventNotification.Instance.OnHeadButtReceived    += (s, e) => { };
            EventNotification.Instance.OnChatMessageReceived += (s, e) => { };

            #endregion


            //BLOCK: Temp Log ThreadPool Stats
            timer = new Timer(new TimerCallback(o => {
                int workerThreads;
                int completionPortThreads;
                int maxWorkerThreads;
                int maxCompletionPortThreads;

                ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
                ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionPortThreads);

                var data = new
                {
                    InUse   = maxWorkerThreads - workerThreads,
                    InUseIO = maxCompletionPortThreads - completionPortThreads,
                    AvailableWorkerThreads = workerThreads,
                    AvailableIOThreads     = completionPortThreads,
                    MaxWorkerThreads       = maxWorkerThreads,
                    MaxIOThreads           = maxCompletionPortThreads
                };


                var logEntry = new LogInformation
                {
                    Origin   = Settings.Origin.ToString(),
                    Type     = LogType.Debug,
                    UserName = null,
                    Message  = "ThreadPool Stats",
                    Category = "Monitor",
                    Data     = data
                };

                EventLogger.Instance.Log(logEntry);
            }), null, TimeSpan.Zero, TimeSpan.FromSeconds(15));


            // USE ONLY FOR DEBUG: clear all sessions used for online users count
            // SessionTracker.RemoveAllSessions();
        }