public static bool Exists(string subject, string senderEmail, DateTime receivedTime)
        {
            var result = false;

            var sqlEngine = new SqlEngine.Server(Constants.ConnectionString);

            using (var command = sqlEngine.Connection.CreateCommand())
            {
                string queryString = @"SELECT TOP 1 id FROM emails";
                queryString += @" WHERE sender_mail='" + senderEmail + "'";
                queryString += @" AND subject='" + subject + "'";
                queryString += @" AND received_at='" + sqlEngine.ConvertToSqlDateTimeFormat(receivedTime) + "'";

                command.CommandType = CommandType.Text;
                command.CommandText = queryString;

                try
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var value = reader.GetValue(0);
                            if (value != DBNull.Value)
                            {
                                result = true;
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
            }

            sqlEngine.Dispose();

            return(result);
        }
Beispiel #2
0
        public static DateTime LastEmailReceived()
        {
            var result = DateTime.MinValue;

            var sqlEngine = new SqlEngine.Server(Constants.ConnectionString);

            using (var command = sqlEngine.Connection.CreateCommand())
            {
                string queryString = @"SELECT TOP 1 option_value FROM options WHERE option_key='email_last_received'";

                command.CommandType = CommandType.Text;
                command.CommandText = queryString;

                try
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var value = reader.GetValue(0);
                            if (value != DBNull.Value)
                            {
                                result = DateTime.Parse(value.ToString());
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
            }

            sqlEngine.Dispose();

            return(result);
        }