Inheritance: IDisposable
Example #1
0
        public void SetUser(TestUser user)
        {
            bool update = false;
            // read old data for indexes
            TestUser oldVersion = GetUser(user.info.id);
            if (oldVersion != null) update = true;

            // last login will be last set :)
            user.info.LastLogin = System.DateTime.Now.ToShortDateString();

            // set user row
            table.Set(System.Text.Encoding.UTF8.GetBytes(user.info.id), Utils.JsonSerialize(user.info));

            if (update)
            {
                // set nick index
                if (oldVersion.info.Nick == user.info.Nick)
                {
                    // just set
                    tableByNick.Set(System.Text.Encoding.UTF8.GetBytes(user.info.Nick + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }
                else
                {
                    // delete old
                    tableByNick.Delete(oldVersion.info.Nick + "|" + user.info.id.ToString());
                    // set new
                    tableByNick.Set(System.Text.Encoding.UTF8.GetBytes(user.info.Nick + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }

                // set dateofbirth index
                if (oldVersion.info.DateOfBirth == user.info.DateOfBirth)
                {
                    // just set
                    tableByBirth.Set(System.Text.Encoding.UTF8.GetBytes(user.info.DateOfBirth + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }
                else
                {
                    // delete old
                    tableByBirth.Delete(oldVersion.info.DateOfBirth + "|" + user.info.id.ToString());
                    // set new
                    tableByBirth.Set(System.Text.Encoding.UTF8.GetBytes(user.info.DateOfBirth + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }

                // set lastlogin index
                if (oldVersion.info.LastLogin == user.info.LastLogin)
                {
                    // just set
                    tableByLastLogin.Set(System.Text.Encoding.UTF8.GetBytes(user.info.LastLogin + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }
                else
                {
                    // delete old
                    tableByLastLogin.Delete(oldVersion.info.LastLogin + "|" + user.info.id.ToString());
                    // set new
                    tableByLastLogin.Set(System.Text.Encoding.UTF8.GetBytes(user.info.LastLogin + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                }
            }
            else
            {
                tableByNick.Set(System.Text.Encoding.UTF8.GetBytes(user.info.Nick + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                tableByBirth.Set(System.Text.Encoding.UTF8.GetBytes(user.info.DateOfBirth + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
                tableByLastLogin.Set(System.Text.Encoding.UTF8.GetBytes(user.info.LastLogin + "|" + user.info.id.ToString()), Utils.JsonSerialize(user.info));
            }
        }
Example #2
0
 public void DeleteUser(TestUser user)
 {
     table.Delete(user.info.id);
     tableByNick.Delete(user.info.Nick + "|" + user.info.id.ToString());
     tableByBirth.Delete(user.info.DateOfBirth + "|" + user.info.id.ToString());
     tableByLastLogin.Delete(user.info.LastLogin + "|" + user.info.id.ToString());
 }
Example #3
0
        public TestUser GetUser(string userID)
        {
            TestUser user = new TestUser();

            byte[] row = table.Get(System.Text.Encoding.UTF8.GetBytes(userID));
            if (row == null) return null;
            user.info = Utils.JsonDeserialize<TestUserInfo>(row);

            return user;
        }
Example #4
0
 public void AddUser()
 {
     // getID from Sequence
     using (TestUser user = new TestUser(userIDs.GetNext))
     {
         user.info.Nick = Utils.RandomString(12);
         SetUser(user);
     }
 }