Ejemplo n.º 1
0
        public override bool TryGetValue(UUID sessionID, string assoc, string varname, out UserSessionInfo.Entry value)
        {
            value = default(UserSessionInfo.Entry);
            using (var conn = new NpgsqlConnection(m_ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand("SELECT * FROM usersessiondata WHERE sessionid=@sessionid AND \"assoc\"=@assoc AND \"varname\"=@varname AND (NOT isexpiring OR expirydate >= @now)", conn))
                {
                    cmd.Parameters.AddParameter("@sessionid", sessionID);
                    cmd.Parameters.AddParameter("@assoc", assoc);
                    cmd.Parameters.AddParameter("@varname", varname);
                    cmd.Parameters.AddParameter("@now", Date.Now);
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (!reader.Read())
                        {
                            return(false);
                        }
                        Date expirydate = null;
                        if ((bool)reader["isexpiring"])
                        {
                            expirydate = reader.GetDate("expirydate");
                        }

                        value = new UserSessionInfo.Entry
                        {
                            Value      = (string)reader["value"],
                            ExpiryDate = expirydate
                        };
                        return(true);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override bool TryGetValueExtendLifetime(UUID sessionID, string assoc, string varname, TimeSpan span, out UserSessionInfo.Entry value)
        {
            UserSessionInfo.Entry val = default(UserSessionInfo.Entry);
            bool success;

            value = val;
            using (var conn = new NpgsqlConnection(m_ConnectionString))
            {
                conn.Open();
                success = conn.InsideTransaction((transaction) =>
                {
                    using (var cmd = new NpgsqlCommand("SELECT * FROM usersessiondata WHERE sessionid = @sessionid AND \"assoc\" = @assoc AND \"varname\" = @varname AND (NOT isexpiring OR expirydate >= @now)", conn)
                    {
                        Transaction = transaction
                    })
                    {
                        cmd.Parameters.AddParameter("@sessionid", sessionID);
                        cmd.Parameters.AddParameter("@assoc", assoc);
                        cmd.Parameters.AddParameter("@varname", varname);
                        cmd.Parameters.AddParameter("@now", Date.Now);
                        using (var reader = cmd.ExecuteReader())
                        {
                            if (!reader.Read())
                            {
                                return(false);
                            }
                            val = new UserSessionInfo.Entry
                            {
                                Value = (string)reader["value"]
                            };

                            if ((bool)reader["isexpiring"])
                            {
                                val.ExpiryDate = reader.GetDate("expirydate");
                            }
                        }
                    }

                    if (val.ExpiryDate != null)
                    {
                        val.ExpiryDate = val.ExpiryDate.Add(span);
                        using (var cmd = new NpgsqlCommand("UPDATE usersessiondata SET expirydate = @expirydate WHERE sessionid = @sessionid AND \"assoc\" = @assoc AND \"varname\" = @varname", conn)
                        {
                            Transaction = transaction
                        })
                        {
                            cmd.Parameters.AddParameter("@expirydate", val.ExpiryDate);
                            cmd.Parameters.AddParameter("@sessionid", sessionID);
                            cmd.Parameters.AddParameter("@assoc", assoc);
                            cmd.Parameters.AddParameter("@varname", varname);
                            cmd.ExecuteNonQuery();
                        }
                    }
                    return(true);
                });
            }
            value = val;
            return(success);
        }
        public bool TryGetValue(UUID sessionID, KnownUserSessionInfoVariables varid, out UserSessionInfo.Entry value)
        {
            value = default(UserSessionInfo.Entry);
            string assoc;
            string varname;

            return(UserSessionInfo.TryGetVarInfo(varid, out assoc, out varname) && TryGetValue(sessionID, assoc, varname, out value));
        }
 public override bool TryGetValue(UUID sessionID, string assoc, string varname, out UserSessionInfo.Entry value)
 {
     value = default(UserSessionInfo.Entry);
     lock (m_UserSessionLock)
     {
         UserSessionInfo info;
         bool            f = m_UserSessions.TryGetValue(sessionID, out info) && info.TryGetValue(assoc, varname, out value);
         if (f)
         {
             value = new UserSessionInfo.Entry(value);
         }
         return(f);
     }
 }
 public override bool TryCompareValueExtendLifetime(UUID sessionID, string assoc, string varname, string oldvalue, TimeSpan span, out UserSessionInfo.Entry value)
 {
     value = default(UserSessionInfo.Entry);
     lock (m_UserSessionLock)
     {
         UserSessionInfo info;
         if (!m_UserSessions.TryGetValue(sessionID, out info))
         {
             return(false);
         }
         if (info.TryGetValue(assoc, varname, out value) && value.Value == oldvalue)
         {
             if (value.ExpiryDate != null)
             {
                 value.ExpiryDate = value.ExpiryDate.Add(span);
             }
             value = new UserSessionInfo.Entry(value);
             return(true);
         }
         return(false);
     }
 }
        public override bool TryCompareAndChangeValueExtendLifetime(UUID sessionID, string assoc, string varname, string oldvalue, string newvalue, TimeSpan span, out UserSessionInfo.Entry value)
        {
            UserSessionInfo.Entry val = default(UserSessionInfo.Entry);
            bool success;

            value = val;
            using (var conn = new MySqlConnection(m_ConnectionString))
            {
                conn.Open();
                success = conn.InsideTransaction((transaction) =>
                {
                    using (var cmd = new MySqlCommand("SELECT * FROM usersessiondata WHERE sessionid = @sessionid AND assoc = @assoc AND varname = @varname AND `value`=@value AND (NOT isexpiring OR expirydate >= @now)", conn)
                    {
                        Transaction = transaction
                    })
                    {
                        cmd.Parameters.AddParameter("@sessionid", sessionID);
                        cmd.Parameters.AddParameter("@assoc", assoc);
                        cmd.Parameters.AddParameter("@varname", varname);
                        cmd.Parameters.AddParameter("@value", oldvalue);
                        cmd.Parameters.AddParameter("@now", Date.Now);
                        using (var reader = cmd.ExecuteReader())
                        {
                            if (!reader.Read())
                            {
                                return(false);
                            }
                            val = new UserSessionInfo.Entry
                            {
                                Value = reader.GetString("value")
                            };

                            if (reader.GetBool("isexpiring"))
                            {
                                val.ExpiryDate = reader.GetDate("expirydate");
                            }
                        }
                    }

                    val.Value = newvalue;
                    if (val.ExpiryDate != null)
                    {
                        val.ExpiryDate = val.ExpiryDate.Add(span);
                        using (var cmd = new MySqlCommand("UPDATE usersessiondata SET expirydate = @expirydate, `value`=@newvalue WHERE sessionid = @sessionid AND assoc = @assoc AND varname = @varname AND `value` = @value", conn)
                        {
                            Transaction = transaction
                        })
                        {
                            cmd.Parameters.AddParameter("@expirydate", val.ExpiryDate);
                            cmd.Parameters.AddParameter("@sessionid", sessionID);
                            cmd.Parameters.AddParameter("@assoc", assoc);
                            cmd.Parameters.AddParameter("@varname", varname);
                            cmd.Parameters.AddParameter("@value", oldvalue);
                            cmd.Parameters.AddParameter("@newvalue", newvalue);
                            return(cmd.ExecuteNonQuery() > 0);
                        }
                    }
                    else
                    {
                        using (var cmd = new MySqlCommand("UPDATE usersessiondata SET `value`=@newvalue WHERE sessionid = @sessionid AND assoc = @assoc AND varname = @varname AND `value` = @value", conn)
                        {
                            Transaction = transaction
                        })
                        {
                            cmd.Parameters.AddParameter("@sessionid", sessionID);
                            cmd.Parameters.AddParameter("@assoc", assoc);
                            cmd.Parameters.AddParameter("@varname", varname);
                            cmd.Parameters.AddParameter("@value", oldvalue);
                            cmd.Parameters.AddParameter("@newvalue", newvalue);
                            return(cmd.ExecuteNonQuery() > 0);
                        }
                    }
                });
            }
            value = val;
            return(success);
        }
 public abstract bool TryGetValue(UUID sessionID, string assoc, string varname, out UserSessionInfo.Entry value);
 public abstract bool TryCompareAndChangeValueExtendLifetime(UUID sessionID, string assoc, string varname, string oldvalue, string newvalue, TimeSpan span, out UserSessionInfo.Entry value);
 public abstract bool TryGetValueExtendLifetime(UUID sessionID, string assoc, string varname, TimeSpan span, out UserSessionInfo.Entry value);
        public bool TryGetValueExtendLifetime(UUID sessionID, KnownUserSessionInfoVariables varid, TimeSpan span, out UserSessionInfo.Entry value)
        {
            string assoc;
            string varname;

            value = default(UserSessionInfo.Entry);
            return(UserSessionInfo.TryGetVarInfo(varid, out assoc, out varname) && TryGetValueExtendLifetime(sessionID, assoc, varname, span, out value));
        }