Exemplo n.º 1
0
        internal Message GetLockMessage(int messageId)
        {
            // TODO: lock the message so that one message can't be processed twice
            string query = "SELECT * FROM queuemessage WHERE id = ?id";

            MySqlCommand command = new MySqlCommand(query, connection);

            command.Parameters.AddWithValue("?id", messageId);

            Message result;

            using (MySqlDataReader reader = command.ExecuteReader())
            {

                if (reader.Read())
                {
                    result = new Message();
                    result.FillFromReader(reader);
                }
                else
                {
                    // No more messages to process
                    result = null;
                }
            }

            return result;
        }
Exemplo n.º 2
0
        public static int SaveMessage(Message message)
        {
            int result;
            using (QueueDBWriteInterface db = new QueueDBWriteInterface())
            {
                result = db.SaveMessage(message);
            }

            return result;
        }
Exemplo n.º 3
0
        internal Message GetLockTopMessage()
        {
            MySqlCommand command = new MySqlCommand("queue_getLockMessage", connection);

            command.CommandType = System.Data.CommandType.StoredProcedure;

            Message result;

            using (MySqlDataReader reader = command.ExecuteReader())
            {

                if (reader.Read())
                {
                    result = new Message();
                    result.FillFromReader(reader);
                }
                else
                {
                    // No more messages to process
                    result = null;
                }
            }

            return result;
        }
Exemplo n.º 4
0
        internal int SaveMessage(Message message)
        {
            // Verify that the message doesn't already exist
            string query;

            if (message.ValidDate != null)
            {
                query = "SELECT id FROM queuemessage WHERE action = ?action AND mainId = ?mainId AND secondaryId = ?secondaryId AND validDate=?validDate";
            }
            else
            {
                query = "SELECT id FROM queuemessage WHERE action = ?action AND mainId = ?mainId AND secondaryId = ?secondaryId AND validDate IS NULL";
            }

            var command = new MySqlCommand(query, connection);
            command.Parameters.AddWithValue("?action", message.Action);
            command.Parameters.AddWithValue("?mainId", message.MainId);
            command.Parameters.AddWithValue("?secondaryId", message.SecondaryId);
            command.Parameters.AddWithValue("?validDate", message.ValidDate);

            using( MySqlDataReader reader = command.ExecuteReader() )
            {
                if( reader.HasRows )
                {
                    throw new Exception( String.Format("Message with action '{0}', main id {1} secondary Id {2} already exists", message.Action, message.MainId, message.SecondaryId ) );
                }
            }

            query = "INSERT INTO queuemessage (Action, MainId, SecondaryId, DateAdded, Priority, ValidDate ) VALUES( ?Action, ?MainId, ?SecondaryId, ?DateAdded, ?Priority, ?ValidDate )";

            command = new MySqlCommand(query, connection);

            message.FillCommandParameters(command);
               // command.Parameters.AddWithValue("?tableName", Config.TableName);
            command.Parameters.AddWithValue("?dateAdded", DateTime.Now);

            command.ExecuteNonQuery();

            query = "SELECT LAST_INSERT_ID() FROM queuemessage LIMIT 0, 1";

            command = new MySqlCommand(query, connection);

            int messageId = Convert.ToInt32(command.ExecuteScalar());

            return messageId;
        }