Ejemplo n.º 1
0
        public List <SimpleMailTask> GetEmailsList(bool showAll)
        {
            string query = "select Id,Username,email,MsgId from emails";

            if (!showAll)
            {
                query += " where State is NULL";
            }
            List <SimpleMailTask> list      = new List <SimpleMailTask>();
            MySqlDataReader       sqlReader = GetQueryReader(query);

            while (sqlReader.Read())
            {
                SimpleMailTask task;

                int    id       = sqlReader.GetInt32(0);
                string username = sqlReader.GetString(1);
                string email    = sqlReader.GetString(2);
                int    msgid    = sqlReader.GetInt32(3);

                if (sqlReader.IsDBNull(1))
                {
                    task = new SimpleMailTask(id, email, msgid);
                }
                else
                {
                    task = new SimpleMailTask(id, email, username, msgid);
                }

                list.Add(task);
            }
            sqlReader.Close();

            return(list);
        }
Ejemplo n.º 2
0
        public void UpdateTask(int id, SimpleMailTask task)
        {
            string strFUsername =
                (task.Address.DisplayName != null) &&
                (task.Address.DisplayName != "") ?
                "'{0}'" : "NULL";

            string username = string.Join("\\'",
                                          task.Address.DisplayName.Split('\''));

            SendQuery(string.Format(
                          @"UPDATE emails
SET Username="******",Email='{1}',MsgID={2}
WHERE Id={3}", username, task.Address.Address, task.MessageID, id));
        }
Ejemplo n.º 3
0
        public IEnumerable <SimpleMailTask> GetTasks(int CountLimit, int ClientID)
        {
            string sqlQuery;

            if (!IsConnectionOpened)
            {
                throw new Exception("Connection must to be opened first");
            }

            sqlQuery =
                @"UPDATE emails SET State=" + DbClient.TokenSelected(ClientID) + @"
WHERE (State IS NULL)AND(MsgID>0)
ORDER BY RAND() LIMIT " + CountLimit.ToString();

            if (SendQuery(sqlQuery) < 1)
            {
                yield break;
            }

            sqlQuery =
                @"SELECT Id,Email,Username,MsgID
FROM emails
WHERE State=" + DbClient.TokenSelected(ClientID);

            MySqlDataReader sqlReader = GetQueryReader(sqlQuery);

            if (sqlReader != null)
            {
                while (sqlReader.Read())
                {
                    SimpleMailTask task;
                    if (sqlReader.IsDBNull(2))
                    {
                        task = new SimpleMailTask(
                            sqlReader.GetInt32(0),                            // id
                            sqlReader.GetString(1),                           // address
                            sqlReader.GetInt32(3));                           // msgid
                    }
                    else
                    {
                        task = new SimpleMailTask(
                            sqlReader.GetInt32(0),                            // id
                            sqlReader.GetString(1),                           // address
                            sqlReader.GetString(2),                           // display name
                            sqlReader.GetInt32(3));                           // msgid
                    }
                    yield return(task);
                }

                sqlReader.Close();
            }

            sqlQuery =
                @"UPDATE emails
SET State=" + DbClient.TokenTaken(ClientID) + @"
WHERE State=" + DbClient.TokenSelected(ClientID);

            SendQuery(sqlQuery);

            yield break;
        }