コード例 #1
0
        /// <summary>
        /// Inserts a user into the database to keep track of how many users RemindMe has (after version 2.6.02)
        /// </summary>
        /// <param name="uniqueString"></param>
        public static void InsertOrUpdateUser(string uniqueString, string remindMeVersion)
        {
            using (remindmesqldbEntities db = new remindmesqldbEntities())
            {
                int attemptCount = 0;
                while (!terminateDatabaseAccess && !CanConnect(db))
                {
                    Thread.Sleep(500);
                    if (attemptCount > MAX_ATTEMPTS)
                    {
                        break;
                    }
                }

                Users usr;
                //If the user doesn't exist in the db yet...
                if (db.Users.Where(u => u.UniqueString == uniqueString).Count() == 0)
                {
                    usr                   = new Users();
                    usr.Username          = Environment.UserName;
                    usr.UniqueString      = uniqueString;
                    usr.LastOnline        = DateTime.UtcNow;
                    usr.RemindMeVersion   = remindMeVersion;
                    usr.Material          = 1;
                    usr.AutoUpdate        = 1;
                    usr.ActiveReminders   = 0;
                    usr.DisabledReminders = 0;
                    usr.DeletedReminders  = 0;
                    usr.ArchivedReminders = 0;
                    usr.TotalReminders    = 0;

                    db.Users.Add(usr);
                }
                else
                {
                    //Update the LastOnline attribute
                    usr = db.Users.Where(u => u.UniqueString == uniqueString).SingleOrDefault();
                    usr.UniqueString = uniqueString;
                    usr.LastOnline   = DateTime.UtcNow;
                    usr.SignIns++;
                    usr.RemindMeVersion = remindMeVersion;
                    usr.Material        = (int)DLLocalDatabase.Setting.Settings.MaterialDesign.Value;
                    usr.AutoUpdate      = (int)DLLocalDatabase.Setting.Settings.AutoUpdate;
                }

                usr.ActiveReminders   = DLReminders.GetReminders().Where(r => r.Enabled == 1).Count();
                usr.DisabledReminders = DLReminders.GetReminders().Where(r => r.Enabled == 0).Count();
                usr.DeletedReminders  = DLReminders.GetDeletedReminders().Count;
                usr.ArchivedReminders = DLReminders.GetArchivedReminders().Count;
                usr.TotalReminders    = DLReminders.GetAllReminders().Count;

                db.SaveChanges();
            }
        }
コード例 #2
0
        /// <summary>
        /// Inserts a user into the database to keep track of how many users RemindMe has (after version 2.6.02)
        /// </summary>
        /// <param name="uniqueString"></param>
        public static void InsertOrUpdateUser(string uniqueString, string remindMeVersion)
        {
            try
            {
                Users usr;
                //If the user doesn't exist in the db yet...
                if (db.Users.Where(u => u.UniqueString == uniqueString).Count() == 0)
                {
                    usr                 = new Users();
                    usr.Username        = Environment.UserName;
                    usr.UniqueString    = uniqueString;
                    usr.LastOnline      = DateTime.UtcNow;
                    usr.RemindMeVersion = remindMeVersion;

                    db.Users.Add(usr);
                }
                else
                {
                    //Update the LastOnline attribute
                    usr            = db.Users.Where(u => u.UniqueString == uniqueString).SingleOrDefault();
                    usr.LastOnline = DateTime.UtcNow;
                    usr.SignIns++;
                    usr.RemindMeVersion = remindMeVersion;
                }

                usr.ActiveReminders   = DLReminders.GetReminders().Where(r => r.Enabled == 1).Count();
                usr.DisabledReminders = DLReminders.GetReminders().Where(r => r.Enabled == 0).Count();
                usr.DeletedReminders  = DLReminders.GetDeletedReminders().Count;
                usr.ArchivedReminders = DLReminders.GetArchivedReminders().Count;
                usr.TotalReminders    = DLReminders.GetAllReminders().Count;

                db.SaveChanges();
            }
            catch (DbUpdateException) { }
            catch  { }
        }