예제 #1
0
        public int addMessageToThread(VerseMessageThread vmt, String message_text)
        {
            DateTime datetime = DateTime.Now;
            VerseMessage vm = new VerseMessage(-1, vmt.thread_id, datetime, message_text, us.user_profile.id);
            //dont do this in a seperate thread now, because we need to know if it's succesful.
            int code = AddMessageToThreadDB(message_text,datetime,vmt,vm);
            if(code == MESSAGE_SENT_CODE_SUCCESSFUL)
            {
                //this is a little messy. we should be consistent in the way we update memory and db.

                vmt.addMessage(vm);

                updateThreadLastModifiedTime(vmt, vm);
                VerseMessageParticipant vmp = vmt.getParticipant(us.user_profile.id);
                updateParticipantThreadLastAccessedTime (vmp);

                return MESSAGE_SENT_CODE_SUCCESSFUL;
            }
            else
            {
                return MESSAGE_SENT_CODE_ERROR;
            }
        }
예제 #2
0
        private void loadMessagesByThreadID()
        {
            string sqlQuery = "SELECT message_id, thread_id, datetime_sent, message_text, sender_id " +
            " FROM versemessages" +
            " WHERE thread_id = " +thread_id +" ORDER BY datetime_sent";

            MySqlConnection conn = DBManager.getConnection();
            MySqlDataReader rdr = null;
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                rdr = cmd.ExecuteReader();
                long message_id = -1;
                long sender_id = -1;
                String message_text = "";
                DateTime datetime_sent;
                VerseMessage tmp_vm = null;
                while (rdr.Read())
                {
                    message_id = long.Parse((rdr[0]).ToString());
                    datetime_sent = DateTime.Parse((rdr[2]).ToString());
                    message_text = (rdr[3].ToString());
                    sender_id = long.Parse(rdr[4].ToString());
                    tmp_vm = new VerseMessage(
                        message_id,
                        thread_id,
                        datetime_sent,
                        message_text,
                        sender_id);
                    messages.Add(tmp_vm);
                }
                rdr.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (rdr != null)
                    rdr.Close();
                conn.Close();
            }
        }
예제 #3
0
 public void addMessage(VerseMessage vm)
 {
     lock (thisLock)
     {
         if (!isLoaded)
         {
             loadMessagesAndParticipantsFromDB();
         }
         else
         {
             messages.Add(vm);
         }
         //TODO: this message at the moment is always added in DB first, check this because we might change it to threaded task later on then it might be buggy
     }
 }
예제 #4
0
        private int AddMessageToThreadDB(String message_text, DateTime datetime_sent, VerseMessageThread vmt, VerseMessage vm)
        {
            MySqlConnection conn = DBManager.getConnection();
            try
            {
                conn.Open();
                //later on we will do db updates in seperate thread.
                string sqlQuery =
                    "INSERT INTO versemessages VALUES (NULL, " + vmt.thread_id + ",'" + datetime_sent.ToString("yyyy-MM-dd HH:mm:ss") + "',@message_text," + us.user_profile.id + ")";
                MySqlCommand cmd = new MySqlCommand(sqlQuery, conn);
                cmd.Parameters.Add("@message_text", MySql.Data.MySqlClient.MySqlDbType.Text);
                cmd.Parameters["@message_text"].Value = message_text;

                int output = cmd.ExecuteNonQuery();
                long row_id = cmd.LastInsertedId;
                vm.message_id = row_id; //TODO: Check if this actually works.
                return MESSAGE_SENT_CODE_SUCCESSFUL;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return MESSAGE_SENT_CODE_ERROR;
            }
            finally
            {
                conn.Close();
            }
        }
예제 #5
0
 public void updateThreadLastModifiedTime(VerseMessageThread vmt, VerseMessage vm)
 {
     if (vmt != null)
      {
          DateTime datetime = DateTime.Now;
          vmt.datetime_last_modified = datetime;
          MessageTask mt = new MessageTask(us, vm);
          mt.UpdateLastAccessedTime();
      }
 }