home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- using System.Net;
- using System.IO;
- using System.Diagnostics;
- using System.Threading;
- using System.Xml;
- using System.Xml.Serialization;
- using System.Reflection;
- using System.Runtime.CompilerServices;
-
- [assembly: AssemblyTitle("Newsfeed")]
- [assembly: AssemblyDescription("Generated newsfeed component for Codename: Dashboard")]
- [assembly: AssemblyConfiguration("")]
- [assembly: AssemblyCompany("SNP Software")]
- [assembly: AssemblyProduct("Codename: Dashboard")]
- [assembly: AssemblyCopyright("(c) 2002-2003 STOP Network Productions Ltd.")]
- [assembly: AssemblyTrademark("")]
- [assembly: AssemblyCulture("")]
- [assembly: AssemblyVersion("1.1.518.942")]
-
- namespace ***NAMESPACE***
- {
- public class ***CLASSNAME*** : STOPNetwork.Dashboard.Components.ComponentControl
- {
- private LinkLabel[] NewsLabels = new LinkLabel[6];
- private ToolTip[] NewsTips = new ToolTip[6];
- private bool bSuspend = false;
- private System.Windows.Forms.Timer timer1;
- private System.ComponentModel.IContainer components;
-
- public ***CLASSNAME***()
- {
- InitializeComponent();
- }
-
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if( components != null )
- components.Dispose();
- }
- base.Dispose( disposing );
- }
-
- public override void InitializeControl()
- {
- for (int nCounter = 0; nCounter < 6; nCounter++)
- {
- NewsLabels[nCounter] = new LinkLabel();
- NewsLabels[nCounter].Parent = this;
- NewsLabels[nCounter].Left = 5;
- NewsLabels[nCounter].Width = this.Width - 10;
- NewsLabels[nCounter].Top = (nCounter * 14) + 19;
- NewsLabels[nCounter].Height = 14;
- NewsLabels[nCounter].LinkColor = ComponentTextColor;
- NewsLabels[nCounter].VisitedLinkColor = ComponentTextColor;
- NewsLabels[nCounter].BackColor = Color.Transparent;
- NewsLabels[nCounter].Click += new System.EventHandler(NewsLabelClick);
- NewsLabels[nCounter].Show();
-
- NewsTips[nCounter] = new ToolTip();
- NewsTips[nCounter].ShowAlways = true;
- }
-
- this.Height = 108;
- this.LastHeight = 108;
-
- RetrieveNews();
- }
-
- public override void CheckThemeElements()
- {
- for (int nCounter = 0; nCounter < 6; nCounter++)
- {
- NewsLabels[nCounter].LinkColor = ComponentTextColor;
- NewsLabels[nCounter].VisitedLinkColor = ComponentTextColor;
- }
- }
-
- public override void SuspendComponent()
- {
- bSuspend = true;
- }
-
- public override void ResumeComponent()
- {
- bSuspend = false;
- }
-
- #region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.timer1 = new System.Windows.Forms.Timer(this.components);
- //
- // timer1
- //
- this.timer1.Enabled = true;
- this.timer1.Interval = 300000;
- this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
- //
- // TechCriticControl
- //
- this.Name = "TechCriticControl";
- this.Size = new System.Drawing.Size(156, 150);
-
- }
- #endregion
-
- private void RetrieveNews()
- {
- if (bSuspend == true) {return;}
-
- WebClient newClient = new WebClient();
-
- try
- {
- newClient.DownloadFile("***NEWSFEEDLOCATION***",Path.GetTempPath() + "***TEMPFILENAME***");
-
- if (this.Closed == false)
- {
- if (this.Height != 108)
- {
- this.Height = 108;
- ComponentResize();
- }
- }
- else
- {
- if (this.LastHeight != 108)
- {
- this.LastHeight = 108;
- }
- }
- }
- catch (System.Net.WebException)
- {
- NewsLabels[0].Text = "Download Error";
-
- for (int nCounter = 1; nCounter < 6; nCounter++)
- {
- NewsLabels[nCounter].Text = "";
- }
-
- if (this.Closed == false)
- {
- this.Height = 35;
- ComponentResize();
- }
- else
- {
- this.LastHeight = 35;
- }
-
- return;
- }
-
- RDFNewsFeed newFeed = new RDFNewsFeed();
- try
- {
- NewsFeedSerializer.Deserialize(ref newFeed,Path.GetTempPath() + "***TEMPFILENAME***");
- }
- catch (Exception)
- {
- NewsLabels[0].Text = "Read Error";
-
- for (int nCounter = 1; nCounter < 6; nCounter++)
- {
- NewsLabels[nCounter].Text = "";
- }
-
- return;
- }
-
- for (int nCounter = 0; nCounter < 6; nCounter++)
- {
- Object[] oArgs = {(Object)newFeed.Items[nCounter].Title,(Object)newFeed.Items[nCounter].URL,(Object)nCounter};
- SetNewsTextDelegate oDel = new SetNewsTextDelegate(this.SetNewsText);
- this.Invoke(oDel,oArgs);
- }
- }
-
- delegate void SetNewsTextDelegate(String strText, String strLink, int nIndex);
- private void SetNewsText(String strText,String strLink,int nIndex)
- {
- NewsLabels[nIndex].Text = strText;
- NewsLabels[nIndex].Tag = (Object)strLink;
- NewsTips[nIndex].ShowAlways = true;
- NewsTips[nIndex].SetToolTip(NewsLabels[nIndex],strText);
- }
-
- private void NewsLabelClick(object sender, System.EventArgs e)
- {
- Process.Start(this.BrowserLocation,((LinkLabel)sender).Tag.ToString());
- }
-
- private void timer1_Tick(object sender, System.EventArgs e)
- {
- new Thread(new ThreadStart(RetrieveNews)).Start();
- }
- }
-
- /// <summary>
- /// The NewsFeed class holds all the information from the feed
- /// </summary>
- public class RDFNewsFeed
- {
- /// <summary>
- /// Create an instance of NewsFeed
- /// </summary>
- public RDFNewsFeed() {}
-
- /// <summary>
- /// The Item group that holds the information
- /// </summary>
- public ItemClass[] Items;
-
- /// <summary>
- /// Clear the feed so it can be read in again
- /// </summary>
- public void Clear()
- {
- try
- {
- for (int nCounter = 0; nCounter < Items.Length; nCounter++)
- {
- GC.ReRegisterForFinalize((Object)Items[nCounter]);
- Items[nCounter] = null;
- }
- }
- catch (System.NullReferenceException) {;}
-
- Items = null;
- }
-
- /// <summary>
- /// Add an item to the collection
- /// </summary>
- /// <param name="Title">Title of the Article</param>
- /// <param name="URL">URL of the Article</param>
- public void AddItem(String Title, String URL)
- {
- ItemClass newItem = new ItemClass();
- ArrayList alItems = new ArrayList();
-
- newItem.Title = Title;
- newItem.URL = URL;
-
- try
- {
- for (int nCounter = 0; nCounter < Items.Length; nCounter++)
- {
- alItems.Add((Object)Items[nCounter]);
- }
- }
- catch (System.NullReferenceException) {;}
-
- alItems.Add((Object)newItem);
-
- Items = new ItemClass[alItems.Count];
-
- for (int nCounter = 0; nCounter < alItems.Count; nCounter++)
- {
- Items[nCounter] = (ItemClass)alItems[nCounter];
- }
- }
- }
-
- /// <summary>
- /// The ItemClass class holds the information for a single story
- /// </summary>
- public class ItemClass
- {
- /// <summary>
- /// Construct an instance of the ItemClass class
- /// </summary>
- public ItemClass() {}
-
- public String Title;
- public String URL;
- }
-
- /// <summary>
- /// The FlexBetaSerializer handles all File I/O for the component
- /// </summary>
- public class NewsFeedSerializer
- {
- /// <summary>
- /// Deserializes the news feed XML file from the disk
- /// </summary>
- /// <param name="thisNews">A reference to the FlexBetaNews object to deserialize</param>
- public static void Deserialize(ref RDFNewsFeed thisNews,String TempFilePath)
- {
- String strNextURL = "";
- String strNextTitle = "";
-
- thisNews.Clear();
-
- System.Xml.XmlTextReader newReader = new XmlTextReader(TempFilePath);
- while (newReader.Read() != false)
- {
- if ((newReader.Name == "item") & (newReader.NodeType != XmlNodeType.EndElement))
- {
- strNextURL = "";
- strNextTitle = "";
-
- while (newReader.Read() != false)
- {
- if ((newReader.Name == "title") & (newReader.NodeType != XmlNodeType.EndElement))
- {
- newReader.Read();
- strNextTitle = newReader.Value;
- }
- if ((newReader.Name == "link") & (newReader.NodeType != XmlNodeType.EndElement))
- {
- newReader.Read();
- strNextURL = newReader.Value;
- }
-
- if (strNextURL != "")
- {
- if (strNextTitle != "")
- {
- thisNews.AddItem(strNextTitle,strNextURL);
- break;
- }
- }
- }
- }
- }
- newReader.Close();
- }
- }
- }
-