//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Xml; using System.Windows.Forms; using DarkWynter.Engine.Networking; namespace DarkWynter.App { public partial class InputOutputControl : UserControl { // The RssFeed to display articles from private static RssFeed rssFeed; private static List fileLocation = new List(); private static String fileName = "reuters"; private static ListBox head; public InputOutputControl() { InitializeComponent(); this.Dock = DockStyle.Fill; head = Head_listBox; fileLocation.Add("http://feeds.reuters.com/reuters/worldNews?format=xml"); } private void addToolStripMenuItem_Click(object sender, EventArgs e) { fileLocation.Add("http://feeds.reuters.com/reuters/worldNews?format=xml"); } private void updateToolStripMenuItem_Click(object sender, EventArgs e) { LoadRssFeed(); } private void LoadRssFeed() { try { // Try to get it from the users settings RssFeed.FromUriInBackground(fileLocation[0], fileName, DownloadFileCallback); } catch { // If there is any problem loading the RSS load an error message RSS feed rssFeed = RssFeed.FromText("Error loading RSS Data"); } } private static void DownloadFileCallback(object sender, AsyncCompletedEventArgs e) { XmlDocument reader = new XmlDocument(); try { reader.Load(fileName); rssFeed = new RssFeed(reader); head.Items.Clear(); // Add Header //Head_listBox.Items.Add(rssFeed.MainChannel.Title); // Add Child Nodes for (int i = 0; i < rssFeed.MainChannel.Items.Count; i++) { //Headings_listBox.Items.Add(""); head.Items.Add(rssFeed.MainChannel.Items[i].Title); //Headings_listBox.Items.Add(rssFeed.MainChannel.Items[i].Description); //Headings_listBox.Items.Add(rssFeed.MainChannel.Items[i].Link); } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml: " + fileName); // throw new Exception("Error reading XML"); } //return new RssFeed(reader); } private void Headings_listBox_SelectedIndexChanged(object sender, EventArgs e) { ListBox listBox = sender as ListBox; int selectedIndex = listBox.SelectedIndex; if (selectedIndex < rssFeed.MainChannel.Items.Count && selectedIndex != -1) { // Update to the Selected Node Body_richTextBox.Text = rssFeed.MainChannel.Items[selectedIndex].Description; Body_richTextBox.WordWrap = true; } else{Console.WriteLine("Invalid RSS Index Selection");} } } }