- public partial class Aggregation : Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //configuration
- Dictionary<string, string> bloggers = new Dictionary<string, string>();
-
- bloggers.Add("Florent Santin", "http://blogs.developpeur.org/azra/rss.aspx");
- bloggers.Add("Christian Robert", "http://blogs.developpeur.org/christian/rss.aspx");
- bloggers.Add("Nixounet", "http://blogs.developpeur.org/nix");
- bloggers.Add("JavaScript warrior", "http://blogs.developpeur.org/cyril");
-
- int NbMessageAffiche = 10;
-
-
- List<BlogMessage> elem;
-
- //gestion du cache
- if (Cache["LastData"] == null)
- {
- //algo, on va creer la liste
- elem = new List<BlogMessage>();
-
- //récupération des derniers messages
- foreach (KeyValuePair<string, string> pair in bloggers)
- {
- GenericRssChannel c = GenericRssChannel.LoadChannel(pair.Value);
-
- IEnumerator Ienum = c.Items.GetEnumerator();
- while (Ienum.MoveNext())
- {
- GenericRssElement curr = (GenericRssElement)Ienum.Current;
- elem.Add(
- new BlogMessage(pair.Key, curr.Attributes["title"], curr.Attributes["link"],
- DateTime.Parse(curr.Attributes["pubDate"])));
- }
- }
- elem.Sort();
-
- //mise en cache de liste pour une heure
- Cache.Insert("LastData", elem, null, Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0),
- CacheItemPriority.Default, null);
- }
- else
- {
- //l object est deja en cache, on le récupére
- elem = Cache["LastData"] as List<BlogMessage>;
- }
-
- GridView1.DataSource = elem.GetRange(0, NbMessageAffiche);
- GridView1.DataBind();
- }
- }
-
- public class BlogMessage : IComparable<BlogMessage>
- {
- private string _nom;
-
- public string Nom
- {
- get { return _nom; }
- set { _nom = value; }
- }
-
- private string _title;
-
- public string Title
- {
- get { return _title; }
- set { _title = value; }
- }
-
- private DateTime _pubdate;
-
- public DateTime PubDate
- {
- get { return _pubdate; }
- set { _pubdate = value; }
- }
-
- private string _link;
-
- public string Link
- {
- get { return _link; }
- set { _link = value; }
- }
-
- public BlogMessage(string nom, string title, string link, DateTime pubdate)
- {
- _nom = nom;
- _title = title;
- _link = link;
- _pubdate = pubdate;
- }
-
- #region IComparable<BlogMessage> Members
-
- public int CompareTo(BlogMessage other)
- {
- if (this.PubDate > other.PubDate)
- return -1;
- else if (this.PubDate < other.PubDate)
- return 1;
- else
- return 0;
- }
-
- #endregion
- }
public partial class Aggregation : Page
{
protected void Page_Load(object sender, EventArgs e)
{
//configuration
Dictionary<string, string> bloggers = new Dictionary<string, string>();
bloggers.Add("Florent Santin", "http://blogs.developpeur.org/azra/rss.aspx");
bloggers.Add("Christian Robert", "http://blogs.developpeur.org/christian/rss.aspx");
bloggers.Add("Nixounet", "http://blogs.developpeur.org/nix");
bloggers.Add("JavaScript warrior", "http://blogs.developpeur.org/cyril");
int NbMessageAffiche = 10;
List<BlogMessage> elem;
//gestion du cache
if (Cache["LastData"] == null)
{
//algo, on va creer la liste
elem = new List<BlogMessage>();
//récupération des derniers messages
foreach (KeyValuePair<string, string> pair in bloggers)
{
GenericRssChannel c = GenericRssChannel.LoadChannel(pair.Value);
IEnumerator Ienum = c.Items.GetEnumerator();
while (Ienum.MoveNext())
{
GenericRssElement curr = (GenericRssElement)Ienum.Current;
elem.Add(
new BlogMessage(pair.Key, curr.Attributes["title"], curr.Attributes["link"],
DateTime.Parse(curr.Attributes["pubDate"])));
}
}
elem.Sort();
//mise en cache de liste pour une heure
Cache.Insert("LastData", elem, null, Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0),
CacheItemPriority.Default, null);
}
else
{
//l object est deja en cache, on le récupére
elem = Cache["LastData"] as List<BlogMessage>;
}
GridView1.DataSource = elem.GetRange(0, NbMessageAffiche);
GridView1.DataBind();
}
}
public class BlogMessage : IComparable<BlogMessage>
{
private string _nom;
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
private string _title;
public string Title
{
get { return _title; }
set { _title = value; }
}
private DateTime _pubdate;
public DateTime PubDate
{
get { return _pubdate; }
set { _pubdate = value; }
}
private string _link;
public string Link
{
get { return _link; }
set { _link = value; }
}
public BlogMessage(string nom, string title, string link, DateTime pubdate)
{
_nom = nom;
_title = title;
_link = link;
_pubdate = pubdate;
}
#region IComparable<BlogMessage> Members
public int CompareTo(BlogMessage other)
{
if (this.PubDate > other.PubDate)
return -1;
else if (this.PubDate < other.PubDate)
return 1;
else
return 0;
}
#endregion
}