Пример #1
0
        public IEnumerable <SavedEntry> Get(int count)
        {
            List <SavedEntry> result = new List <SavedEntry>();

            using (var connection = this.MemoryConnection()) {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                    using (var command = connection.CreateCommand()) {
                        command.CommandText = "SELECT"
                                              + "post_id, name, message, timestamp, ip_address"
                                              + "FROM entry ORDER BY post_id DESC";
                        try {
                            using (var reader = command.ExecuteReader()) {
                                while (reader.Read())
                                {
                                    var postId    = new PostId((int)reader["post_id"]);
                                    var name      = new Name((string)reader["name"]);
                                    var message   = new Message((string)reader["message"]);
                                    var timestamp = Timestamp.FromUnixTime((double)reader["timestamp"]);
                                    var ipAddress = IPAddress.FromString((string)reader["ip_address"]);
                                    result.Add(new SavedEntry(postId, name, message, timestamp, ipAddress));
                                }
                            }
                        }
                        catch (Exception) {
                        }
                    }
            }
            return(result);
        }