Ejemplo n.º 1
0
        public feedimport.Rss.RssFeed GetRssFeed(int feedID, int? feedItemID)
        {
            feedimport.Rss.RssFeed ret = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssFeed();

            try
            {
                using(SqliteConnection conn = GetConnection())
                {
                    using(SqliteCommand sqlCmd = new SqliteCommand("SELECT FeedID, Title, Link, Description, LastBuildDate FROM rssfeeds WHERE FeedID=@FeedID LIMIT 1;", conn))
                    {
                        sqlCmd.Parameters.AddWithValue("@FeedID", feedID);

                        conn.Open();

                        using (DbDataReader reader = sqlCmd.ExecuteReader())
                        {
                            reader.Read();

                            if (reader.HasRows)
                            {
                                feedimport.Rss.RssHeader rssHeader = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssHeader();
                                rssHeader.FeedID = reader.GetInt32(0);

                                if (!reader.IsDBNull(1))
                                    rssHeader.Title = reader.GetString(1);

                                if (!reader.IsDBNull(2))
                                    rssHeader.Link = reader.GetString(2);

                                if (!reader.IsDBNull(3))
                                    rssHeader.Description = reader.GetString(3);

                                if (!reader.IsDBNull(4))
                                    rssHeader.LastBuildDate = reader.GetDateTime(4);

                                ret.Header = rssHeader;
                            }
                        }

                        conn.Close();
                    }

                    if (ret.Header != null)
                    {
                        using(SqliteCommand sqlCmd2 = new SqliteCommand("SELECT ItemID, FeedID, Title, Link, Description, Category, PubDate, IsRead FROM rssfeeditem WHERE FeedID=@FeedID " +
                                                                        (feedItemID.HasValue? "AND ItemID=@FeedItemID " : "") +
                                                                        "ORDER BY PubDate DESC;", conn))
                        {
                            sqlCmd2.Parameters.AddWithValue("@FeedID", feedID);

                            if (feedItemID.HasValue)
                                sqlCmd2.Parameters.AddWithValue("@FeedItemID", feedItemID);

                            conn.Open();

                            using (DbDataReader reader = sqlCmd2.ExecuteReader())
                            {
                                List<feedimport.Rss.RssItem> rssItems = new List<de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssItem>();

                                while(reader.Read())
                                {
                                    feedimport.Rss.RssItem rssItem = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssItem();

                                    if (reader.HasRows)
                                    {
                                        rssItem.ItemID = reader.GetInt32(0);
                                        rssItem.FeedID = reader.GetInt32(1);

                                        if (!reader.IsDBNull(2))
                                            rssItem.Title = reader.GetString(2);

                                        if (!reader.IsDBNull(3))
                                            rssItem.Link = reader.GetString(3);

                                        if (!reader.IsDBNull(4))
                                            rssItem.Description = reader.GetString(4);

                                        if (!reader.IsDBNull(5))
                                            rssItem.Category = reader.GetString(5);

                                        if (!reader.IsDBNull(6))
                                            rssItem.PubDate = reader.GetDateTime(6);

                                        rssItem.IsRead = reader.GetBoolean(7);
                                    }

                                    rssItems.Add(rssItem);
                                }

                                ret.Items = rssItems;
                            }

                            conn.Close();
                        }
                    }
                }
            }
            catch(SqliteException ex)
            {
                System.Diagnostics.Debug.WriteLine(this.GetType() + ".GetRssFee() - ex: " + ex.ToString());
            }

            return ret;
        }
Ejemplo n.º 2
0
        public feedimport.Rss.RssFeed GetRssFeed(int feedID, int?feedItemID)
        {
            feedimport.Rss.RssFeed ret = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssFeed();

            try
            {
                using (SqliteConnection conn = GetConnection())
                {
                    using (SqliteCommand sqlCmd = new SqliteCommand("SELECT FeedID, Title, Link, Description, LastBuildDate FROM rssfeeds WHERE FeedID=@FeedID LIMIT 1;", conn))
                    {
                        sqlCmd.Parameters.AddWithValue("@FeedID", feedID);

                        conn.Open();

                        using (DbDataReader reader = sqlCmd.ExecuteReader())
                        {
                            reader.Read();

                            if (reader.HasRows)
                            {
                                feedimport.Rss.RssHeader rssHeader = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssHeader();
                                rssHeader.FeedID = reader.GetInt32(0);

                                if (!reader.IsDBNull(1))
                                {
                                    rssHeader.Title = reader.GetString(1);
                                }

                                if (!reader.IsDBNull(2))
                                {
                                    rssHeader.Link = reader.GetString(2);
                                }

                                if (!reader.IsDBNull(3))
                                {
                                    rssHeader.Description = reader.GetString(3);
                                }

                                if (!reader.IsDBNull(4))
                                {
                                    rssHeader.LastBuildDate = reader.GetDateTime(4);
                                }

                                ret.Header = rssHeader;
                            }
                        }

                        conn.Close();
                    }


                    if (ret.Header != null)
                    {
                        using (SqliteCommand sqlCmd2 = new SqliteCommand("SELECT ItemID, FeedID, Title, Link, Description, Category, PubDate, IsRead FROM rssfeeditem WHERE FeedID=@FeedID " +
                                                                         (feedItemID.HasValue? "AND ItemID=@FeedItemID " : "") +
                                                                         "ORDER BY PubDate DESC;", conn))
                        {
                            sqlCmd2.Parameters.AddWithValue("@FeedID", feedID);

                            if (feedItemID.HasValue)
                            {
                                sqlCmd2.Parameters.AddWithValue("@FeedItemID", feedItemID);
                            }

                            conn.Open();

                            using (DbDataReader reader = sqlCmd2.ExecuteReader())
                            {
                                List <feedimport.Rss.RssItem> rssItems = new List <de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssItem>();

                                while (reader.Read())
                                {
                                    feedimport.Rss.RssItem rssItem = new de.dhoffmann.mono.adfcnewsapp.buslog.feedimport.Rss.RssItem();

                                    if (reader.HasRows)
                                    {
                                        rssItem.ItemID = reader.GetInt32(0);
                                        rssItem.FeedID = reader.GetInt32(1);

                                        if (!reader.IsDBNull(2))
                                        {
                                            rssItem.Title = reader.GetString(2);
                                        }

                                        if (!reader.IsDBNull(3))
                                        {
                                            rssItem.Link = reader.GetString(3);
                                        }

                                        if (!reader.IsDBNull(4))
                                        {
                                            rssItem.Description = reader.GetString(4);
                                        }

                                        if (!reader.IsDBNull(5))
                                        {
                                            rssItem.Category = reader.GetString(5);
                                        }

                                        if (!reader.IsDBNull(6))
                                        {
                                            rssItem.PubDate = reader.GetDateTime(6);
                                        }

                                        rssItem.IsRead = reader.GetBoolean(7);
                                    }

                                    rssItems.Add(rssItem);
                                }

                                ret.Items = rssItems;
                            }

                            conn.Close();
                        }
                    }
                }
            }
            catch (SqliteException ex)
            {
                System.Diagnostics.Debug.WriteLine(this.GetType() + ".GetRssFee() - ex: " + ex.ToString());
            }

            return(ret);
        }