ForumSurfer.Data.Feed.LoadAll C# (CSharp) Method

LoadAll() public static method

public static LoadAll ( ) : List
return List
        public static List<Feed> LoadAll()
        {
            List<Feed> results = new List<Feed>();

            String sqlFeeds = @"
                SELECT *
                FROM Feeds;
            ";

            using (SQLiteConnection m_dbConnection = new SQLiteConnection(Repository.ConnectionString))
            {
                m_dbConnection.Open();
                SQLiteCommand command = new SQLiteCommand(sqlFeeds, m_dbConnection);
                using (SQLiteDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Feed feed = new Feed();
                        feed.Location = new Uri(reader["uri"].ToString());
                        String lastUpd = reader["last_update"].ToString();
                        if (String.IsNullOrEmpty(lastUpd)) lastUpd = DateTime.Now.ToString("s");
                        feed.LastUpdate = DateTime.Parse(lastUpd);
                        feed.Host = feed.Location.Host;
                        feed.Title = reader["title"].ToString();
                        feed.Id = (long)reader["feed_id"];
                        results.Add(feed);
                    }
                }
            }

            foreach(Feed f in results)
            {
                f.Articles = new List<Model.Article>(Article.LoadByFeed(f));
            }

            return results.ToList();
        }

Usage Example

Beispiel #1
0
        public static List <Host> LoadAll()
        {
            List <Host> results = new List <Host>();

            List <Feed> feeds = Feed.LoadAll();

            foreach (Feed feed in feeds)
            {
                Host feedHost = results.FirstOrDefault(el => el.Location.Equals(new Uri("http://" + feed.Host)));
                if (feedHost == null)
                {
                    feedHost        = Load(feed.Host);
                    feed.ParentHost = feedHost;
                    results.Add(feedHost);
                }

                if (feedHost == null)
                {
                    feedHost          = new Host();
                    feedHost.Title    = feed.Host;
                    feedHost.Location = new Uri("http://" + feed.Host);
                    feedHost.Zoom     = 100;
                    feed.ParentHost   = feedHost;
                    results.Add(feedHost);
                }
                if (feed.ParentHost == null)
                {
                    feed.ParentHost = feedHost;
                }

                feedHost.Feeds.Add(feed);
            }

            return(results);
        }