Example #1
0
        private void ClearExpiredSessions()
        {
            using (var db = new RHBGameRepository())
            {
                var currentTime     = DateTime.UtcNow;
                var expiredSessions = db.Sessions.Where(x => DbFunctions.DiffSeconds(x.LastActivity, currentTime) > _timeOut.TotalSeconds).ToList();

                if (expiredSessions.Count > 0)
                {
                    foreach (var session in expiredSessions)
                    {
                        db.Sessions.Remove(session);
                    }

                    db.SaveChanges();
                }
            }
        }
Example #2
0
        void Application_Start(Object sender, EventArgs e)
        {
            // Force the creation of the databae (or update) at startup
            using (var db = new RHBGameRepository())
            {
                db.Topics.FirstOrDefault();
            }

            GlobalConfiguration.Configure(config =>
            {
                config.MapHttpAttributeRoutes();

                // Dependency injection
                var container = new UnityContainer();
                container.RegisterType <RHBGameRepository>();
                container.RegisterType <AuthenticationHelper>();

                config.DependencyResolver = new DependencyResolver(container);
            });

            // Timer that will remove the expired user sessions
            _expiredSessionsTimer = new Timer(_ => ClearExpiredSessions(), null, TimeSpan.Zero, TimeSpan.FromMinutes(20));
        }
Example #3
0
 public CommentController(RHBGameRepository repository, AuthenticationHelper authentication)
 {
     _repository     = repository;
     _authentication = authentication;
 }
 public AuthenticationHelper(RHBGameRepository repository)
 {
     _repository = repository;
 }