using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Westwind.Web.Controls;
using System.Collections.Generic;

public partial class IFrame : System.Web.UI.Page
{
    List<FeedItem> List = null;

    string FeedTitle = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        this.RssFeed.DataFile = this.txtFeedUrl.Text;

        try
        {
            // *** Explicitly extract the Title out of the feed
            System.Xml.XmlDocument Dom = this.RssFeed.GetXmlDocument();
            this.FeedTitle = Dom.SelectSingleNode("rss/channel/title").InnerText;
            this.grdFeed.HeaderRow.Cells[0].Text = this.FeedTitle;
        }
        catch
        {
            this.ErrorDisplay.ShowError("Sorry, unable to read your feed.");
        }
        this.SaveFeedUrl();
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
    }

    protected void SaveFeedUrl()
    {
        List = this.Cache["IFrameFeedItems"] as List<FeedItem>;
        if (List == null)
        {
            List = new List<FeedItem>();
            List.Add(new FeedItem("Rick Strahl's Web Log","http://west-wind.com/weblog/rss.aspx"));
            List.Add(new FeedItem("West Wind News","http://www.west-wind.com/westwindnews.rss.xml"));            
            List.Add(new FeedItem("K. Scott Allen", "http://odetocode.com/Blogs/scott/Rss.aspx"));
            List.Add(new FeedItem("Coding Horror", "http://www.codinghorror.com/blog/index.xml"));
            List.Add(new FeedItem("you've been HAACKED", "http://haacked.com/Rss.aspx"));
            List.Add(new FeedItem("WebLogs @ ASP.NET", "http://weblogs.asp.net/MainFeed.aspx"));
        }

        if (this.FeedTitle != "")
        {

            // *** Add the current Url - first remove if it already exists
            string Url = this.txtFeedUrl.Text.ToLower();

            FeedItem Item = new FeedItem(this.FeedTitle, Url);

            if (List.Contains(Item))
                List.Remove(Item);

            List.Insert(0, Item);
        }

        this.Cache["IFrameFeedItems"] = List;
    }
    
}
