home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 October
/
PCWorld_2003-10_cd.bin
/
Software
/
Vyzkuste
/
windowsxxl
/
windowsxxl.exe
/
DashboardSetup-V11-Framework11.exe
/
Source
/
TemplateRSSControl.cs
< prev
next >
Wrap
Text File
|
2003-06-28
|
7KB
|
269 lines
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;
}
if (this.Closed == false)
{
this.Height = 108;
this.LastHeight = 108;
ComponentResize();
}
else
{
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;
}
RSSNewsFeed newFeed = new RSSNewsFeed();
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.ccChannel.niItem[nCounter].strTitle,(Object)newFeed.ccChannel.niItem[nCounter].strLink,(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>
/// Class to hold the data from the news feed
/// </summary>
[XmlRoot("rss")]
public class RSSNewsFeed
{
public RSSNewsFeed() {}
[XmlAttribute("version")] public String strVersion;
[XmlElement("channel")] public ChannelClass ccChannel;
}
/// <summary>
/// Class to hold a set of stories
/// </summary>
public class ChannelClass
{
[XmlElement("item")] public ItemClass[] niItem;
}
/// <summary>
/// Class to hold a single story
/// </summary>
public class ItemClass
{
[XmlElement("title")] public String strTitle;
[XmlElement("link")] public String strLink;
}
/// <summary>
/// The NewsSerializer handles all File I/O for the component
/// </summary>
public class NewsFeedSerializer
{
/// <summary>
/// Deserializes the news feed from the disk and populates the NewsFeed class
/// </summary>
/// <param name="theFeed">Reference to the news feed object to deserialize</param>
/// <param name="strPath">Path to the temporary XML file</param>
public static void Deserialize(ref RSSNewsFeed theFeed,String strPath)
{
XmlSerializer newSerial = new XmlSerializer(typeof(RSSNewsFeed));
StreamReader newReader = new StreamReader(strPath);
theFeed = (RSSNewsFeed)newSerial.Deserialize(newReader);
newReader.Close();
}
}
}