public JsonNetResult() { Settings = JsonSettings.GetSerializationSettings(); }
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(); }