Esempio n. 1
0
        public ControllerBase()
        {
            //set up DB
            Db = OsbideContext.DefaultWebConnection;

            //set up current user
            Authentication auth    = new Authentication();
            string         authKey = auth.GetAuthenticationKey();
            int            id      = auth.GetActiveUserId(authKey);

            //make sure that we got back a good key
            if (id > 0)
            {
                CurrentUser = Db.Users.Find(id);
                if (CurrentUser != null)
                {
                    CurrentUser.PropertyChanged += CurrentUser_PropertyChanged;
                }
                else
                {
                    CurrentUser = new OsbideUser();
                }
            }
            else
            {
                CurrentUser = new OsbideUser();
            }

            //set up caches
            GlobalCache = FileCacheHelper.GetGlobalCacheInstance();
            UserCache   = FileCacheHelper.GetCacheInstance(CurrentUser);

            //update all users scores if necessary
            object lastScoreUpdate  = GlobalCache["lastScoreUpdate"];
            bool   needsScoreUpdate = true;

            if (lastScoreUpdate != null)
            {
                DateTime lastUpdate = (DateTime)lastScoreUpdate;
                if (lastUpdate.AddDays(1) > DateTime.UtcNow)
                {
                    needsScoreUpdate = false;
                }
            }
            if (needsScoreUpdate == true)
            {
                //UpdateUserScores();
                GlobalCache["lastScoreUpdate"] = DateTime.UtcNow;
            }

            //make current user available to all views
            ViewBag.CurrentUser = CurrentUser;
        }