Beispiel #1
0
        public bool GetAvatarNotes(ref UserProfileNotes notes)
        {
            IDataReader reader = null;
            string      query  = string.Empty;

            query += "SELECT `notes` FROM usernotes WHERE ";
            query += "useruuid = :Id AND ";
            query += "targetuuid = :TargetId";
            OSDArray data = new OSDArray();

            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue(":Id", notes.UserId.ToString());
                    cmd.Parameters.AddWithValue(":TargetId", notes.TargetId.ToString());

                    using (reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        while (reader.Read())
                        {
                            notes.Notes = OSD.FromString((string)reader["notes"]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": GetAvatarNotes exception {0}", e.Message);
            }
            return(true);
        }
Beispiel #2
0
        public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Params missing";
                m_log.DebugFormat("Avatar Notes Request");
                return(false);
            }

            string           result = string.Empty;
            UserProfileNotes note   = new UserProfileNotes();
            object           Note   = (object)note;

            OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
            if (Service.AvatarNotesRequest(ref note))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = "Error reading notes";
            return(false);
        }
        /// <summary>
        /// Handles the avatar notes request.
        /// </summary>
        /// <param name='sender'>
        /// Sender.
        /// </param>
        /// <param name='method'>
        /// Method.
        /// </param>
        /// <param name='args'>
        /// Arguments.
        /// </param>
        public void NotesRequest(Object sender, string method, List <String> args)
        {
            UserProfileNotes note = new UserProfileNotes();

            if (!(sender is IClientAPI))
            {
                return;
            }

            IClientAPI remoteClient = (IClientAPI)sender;
            string     serverURI    = string.Empty;

            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
            note.UserId = remoteClient.AgentId;
            UUID.TryParse(args[0], out note.TargetId);

            object Note = (object)note;

            if (!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
            {
                remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
                return;
            }
            note = (UserProfileNotes)Note;

            remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
        }
        public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Params missing";
                m_log.DebugFormat("Avatar Notes Request");
                return(false);
            }

            UserProfileNotes note = new UserProfileNotes();
            object           Note = (object)note;

            OSD.DeserializeMembers(ref Note, (OSDMap)tmpParams);
            if (Service.AvatarNotesRequest(ref note))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = "Error reading notes";
            return(false);
        }
        public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
        {
            string query = string.Empty;
            bool   remove;

            if (string.IsNullOrEmpty(note.Notes))
            {
                remove = true;
                query += "DELETE FROM usernotes WHERE ";
                query += "useruuid=:UserId AND ";
                query += "targetuuid=:TargetId";
            }
            else
            {
                remove = false;

                query = @"WITH upsert AS (
                          UPDATE usernotes SET notes = :Notes, useruuid = :UserId, targetuuid = :TargetId RETURNING * )
                          INSERT INTO usernotes (notes,useruuid,targetuuid)
                          SELECT :Notes,:UserId,:TargetId
                            WHERE NOT EXISTS (
                              SELECT * FROM upsert
                            )";
            }

            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        if (!remove)
                        {
                            cmd.Parameters.Add(m_database.CreateParameter("Notes", note.Notes));
                        }

                        cmd.Parameters.Add(m_database.CreateParameter("TargetId", note.TargetId));
                        cmd.Parameters.Add(m_database.CreateParameter("UserId", note.UserId));

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
        {
            string query = string.Empty;
            bool   remove;

            if (string.IsNullOrEmpty(note.Notes))
            {
                remove = true;
                query += "DELETE FROM usernotes WHERE ";
                query += "useruuid=:UserId AND ";
                query += "targetuuid=:TargetId";
            }
            else
            {
                remove = false;
                query  = @"INSERT INTO usernotes VALUES ( :UserId, :TargetId, :Notes )
                            where not exists ( Select useruuid from usernotes where useruuid = :UserId and targetuuid = :TargetId );

                           update usernotes
                              set notes = :Notes
                            where useruuid = :UserId 
                              and targetuuid = :TargetId;
                        ";
            }

            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        if (!remove)
                        {
                            cmd.Parameters.AddWithValue("Notes", note.Notes);
                        }
                        cmd.Parameters.AddWithValue("TargetId", note.TargetId.ToString());
                        cmd.Parameters.AddWithValue("UserId", note.UserId.ToString());

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": UpdateAvatarNotes exception {0}", e.Message);
                return(false);
            }
            return(true);
        }
        public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
        {
            string query = string.Empty;
            bool   remove;

            if (string.IsNullOrEmpty(note.Notes))
            {
                remove = true;
                query += "DELETE FROM usernotes WHERE ";
                query += "useruuid=?UserId AND ";
                query += "targetuuid=?TargetId";
            }
            else
            {
                remove = false;
                query += "INSERT INTO usernotes VALUES ( ";
                query += "?UserId,";
                query += "?TargetId,";
                query += "?Notes )";
                query += "ON DUPLICATE KEY ";
                query += "UPDATE ";
                query += "notes=?Notes";
            }

            try
            {
                using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
                    {
                        if (!remove)
                        {
                            cmd.Parameters.AddWithValue("?Notes", note.Notes);
                        }
                        cmd.Parameters.AddWithValue("?TargetId", note.TargetId.ToString());
                        cmd.Parameters.AddWithValue("?UserId", note.UserId.ToString());

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": UpdateAvatarNotes exception {0}", e.Message);
                return(false);
            }
            return(true);
        }
Beispiel #8
0
        public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
        {
            string query = string.Empty;
            bool   remove;

            if (string.IsNullOrEmpty(note.Notes))
            {
                remove = true;
                query += "DELETE FROM usernotes WHERE ";
                query += "useruuid=:UserId AND ";
                query += "targetuuid=:TargetId";
            }
            else
            {
                remove = false;
                query += "INSERT OR REPLACE INTO usernotes VALUES ( ";
                query += ":UserId,";
                query += ":TargetId,";
                query += ":Notes )";
            }

            try
            {
                using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
                {
                    cmd.CommandText = query;

                    if (!remove)
                    {
                        cmd.Parameters.AddWithValue(":Notes", note.Notes);
                    }
                    cmd.Parameters.AddWithValue(":TargetId", note.TargetId.ToString());
                    cmd.Parameters.AddWithValue(":UserId", note.UserId.ToString());

                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[PROFILES_DATA]" +
                                  ": UpdateAvatarNotes exception {0}", e.Message);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Avatars the notes update.
        /// </summary>
        /// <param name='remoteClient'>
        /// Remote client.
        /// </param>
        /// <param name='queryTargetID'>
        /// Query target I.
        /// </param>
        /// <param name='queryNotes'>
        /// Query notes.
        /// </param>
        public void NotesUpdate(IClientAPI remoteClient, UUID queryTargetID, string queryNotes)
        {
            UserProfileNotes note = new UserProfileNotes();

            note.UserId   = remoteClient.AgentId;
            note.TargetId = queryTargetID;
            note.Notes    = queryNotes;

            string serverURI = string.Empty;

            GetUserProfileServerURI(remoteClient.AgentId, out serverURI);

            object Note = note;

            if (!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
            {
                return;
            }
        }
 public bool GetAvatarNotes(ref UserProfileNotes notes)
 {  // WIP
     string query = string.Empty;
     
     query += "SELECT `notes` FROM usernotes WHERE ";
     query += "useruuid = ?Id AND ";
     query += "targetuuid = ?TargetId";
     OSDArray data = new OSDArray();
     
     try
     {
         using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
         {
             dbcon.Open();
             using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
             {
                 cmd.Parameters.AddWithValue("?Id", notes.UserId.ToString());
                 cmd.Parameters.AddWithValue("?TargetId", notes.TargetId.ToString());
                 
                 using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                 {
                     if(reader.HasRows)
                     {
                         reader.Read();
                         notes.Notes = OSD.FromString((string)reader["notes"]);
                     }
                     else
                     {
                         notes.Notes = OSD.FromString("");
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         m_log.DebugFormat("[PROFILES_DATA]" +
                          ": GetAvatarNotes exception {0}", e.Message);
     }
     return true;
 }
 public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
 {
     if(!json.ContainsKey("params"))
     {
         response.Error.Code = ErrorCode.ParseError;
         response.Error.Message = "No parameters";
         m_log.DebugFormat ("Avatar Notes Update Request");
         return false;
     }
     
     string result = string.Empty;
     UserProfileNotes note = new UserProfileNotes();
     object Notes = (object) note;
     OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
     if(Service.NotesUpdate(ref note, ref result))
     {
         response.Result = OSD.SerializeMembers(note);
         return true;
     }
     return true;
 }
        public bool GetAvatarNotes(ref UserProfileNotes notes)
        {  // WIP
            string query = string.Empty;

            query += "SELECT notes FROM usernotes WHERE ";
            query += "useruuid = :Id AND ";
            query += "targetuuid = :TargetId";
            OSDArray data = new OSDArray();

            try
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
                {
                    dbcon.Open();
                    using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
                    {
                        cmd.Parameters.Add(m_database.CreateParameter("Id", notes.UserId));
                        cmd.Parameters.Add(m_database.CreateParameter("TargetId", notes.TargetId));

                        using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                notes.Notes = OSD.FromString((string)reader["notes"]);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error("[PROFILES_DATA]: GetAvatarNotes exception ", e);
            }

            return(true);
        }
        public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "No parameters";
                m_log.DebugFormat("Avatar Notes Update Request");
                return(false);
            }

            string           result = string.Empty;
            UserProfileNotes note   = new UserProfileNotes();
            object           Notes  = (object)note;

            OSD.DeserializeMembers(ref Notes, (OSDMap)tmpParams);
            if (Service.NotesUpdate(ref note, ref result))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }
            return(true);
        }
Beispiel #14
0
 public bool NotesUpdate(ref UserProfileNotes note, ref string result)
 {
     return(ProfilesData.UpdateAvatarNotes(ref note, ref result));
 }
Beispiel #15
0
 public bool AvatarNotesRequest(ref UserProfileNotes note)
 {
     return(ProfilesData.GetAvatarNotes(ref note));
 }