예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        GenericRssChannel c = GenericRssChannel.LoadChannel("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml");

        Image1.ImageUrl = c.Image["url"];

        GridView1.DataSource = c.SelectItems();
        GridView1.DataBind();
    }
예제 #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                GenericRssChannel c = GenericRssChannel.LoadChannel(feedLocation);
                int recordCount     = c.Items.Count;
                if (recordCount == 0)
                {
                    //if we didn't find anything, add a message literal and drop out.
                    Literal messageLiteral = new Literal();
                    messageLiteral.Text = NoItemsFoundText;
                    this.Controls.Add(messageLiteral);
                    return;
                }
                //limit the number of records to show if needed.
                if (MaxRecords > 0 && MaxRecords < recordCount)
                {
                    recordCount = MaxRecords;
                }

                HtmlTable table = new HtmlTable();
                table.CellPadding = 2;
                table.CellSpacing = 2;
                table.Border      = 0;

                for (int i = 0; i < recordCount; i++)
                {
                    HtmlTableRow  row  = new HtmlTableRow();
                    HtmlTableCell cell = new HtmlTableCell();
                    HyperLink     link = new HyperLink();
                    link.NavigateUrl = c.Items[i]["link"];
                    link.Text        = c.Items[i]["title"];
                    if (separateItems)
                    {
                        link.Font.Bold = true;
                    }

                    if (Target.Trim().Length > 0)
                    {
                        link.Target = Target;
                    }

                    cell.Controls.Add(link);
                    if (showDate)
                    {
                        try
                        {
                            Literal dateLiteral = new Literal();
                            dateLiteral.Text = " - Posted: " + DateTime.Parse(c.Items[i]["pubDate"]).ToShortDateString();
                            cell.Controls.Add(dateLiteral);
                        }
                        catch
                        {
                        }
                    }
                    if (ShowDescription)
                    {
                        HtmlGenericControl div = new HtmlGenericControl("div");
                        //div.InnerHtml = Server.HtmlEncode(c.Items[i]["description"]);
                        div.InnerHtml = c.Items[i]["description"];
                        cell.Controls.Add(div);
                    }
                    row.Cells.Add(cell);
                    table.Rows.Add(row);
                    if (separateItems && recordCount > 1 && i < recordCount - 1)
                    {
                        HtmlTableRow       ruleRow  = new HtmlTableRow();
                        HtmlTableCell      ruleCell = new HtmlTableCell();
                        HtmlGenericControl rule     = new HtmlGenericControl("hr");
                        rule.Style.Add("width", "99%");
                        ruleCell.Controls.Add(rule);
                        ruleRow.Cells.Add(ruleCell);
                        table.Rows.Add(ruleRow);
                    }
                }
                this.Controls.Add(table);
            }
            catch (Exception ex)
            {
                Literal messageLiteral = new Literal();
                if (DebugUtility.IsDebugMode(Response, Request))
                {
                    messageLiteral.Text  = "The following error occurred while checking the rss feed:<br /><br />";
                    messageLiteral.Text += "<b>Message:</b> " + ex.Message + "<br /><br />" +
                                           "<b>Stack Trace:</b> " + ex.StackTrace.Replace("\n", "<br />");
                }
                else
                {
                    messageLiteral.Text = NoItemsFoundText;
                }
                this.Controls.Add(messageLiteral);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Simple RSS Compiler v1.0");
            Console.WriteLine();

            // Process command line
            if (args.Length != 2)
            {
                Console.WriteLine("usage: rssdl.exe url-or-file outputcode.cs");
                return;
            }

            string url             = args[0];
            string codeFilename    = args[1];
            string classNamePrefix = Path.GetFileNameWithoutExtension(codeFilename);

            // Load the channel data from supplied url
            GenericRssChannel channel;

            try {
                // try to interpret as file first
                bool isFile = false;

                try {
                    if (File.Exists(url))
                    {
                        isFile = true;
                    }
                }
                catch {
                }

                if (isFile)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(url);
                    channel = GenericRssChannel.LoadChannel(doc);
                }
                else
                {
                    channel = GenericRssChannel.LoadChannel(url);
                }
            }
            catch (Exception e) {
                Console.WriteLine("*** Failed to load '{0}' *** {1}: {2}", url, e.GetType().Name, e.Message);
                return;
            }

            // Open the output code file
            TextWriter codeWriter;

            try {
                codeWriter = new StreamWriter(codeFilename, false);
            }
            catch (Exception e) {
                Console.WriteLine("*** Failed to open '{0}' for writing *** {1}: {2}", codeFilename, e.GetType().Name, e.Message);
                return;
            }

            // Get the language from file extension
            string lang = Path.GetExtension(codeFilename);

            if (lang != null && lang.Length > 1 && lang.StartsWith("."))
            {
                lang = lang.Substring(1).ToUpperInvariant();
            }
            else
            {
                lang = "CS";
            }

            // Generate source
            try {
                RssCodeGenerator.GenerateCode(channel, lang, "", classNamePrefix, codeWriter);
            }
            catch (Exception e) {
                codeWriter.Dispose();
                File.Delete(codeFilename);

                Console.WriteLine("*** Error generating '{0}' *** {1}: {2}", codeFilename, e.GetType().Name, e.Message);
                return;
            }

            // Done
            codeWriter.Dispose();

            Console.WriteLine("Done -- generated '{0}'.", codeFilename);
        }