289 lines
7.2 KiB
C#
289 lines
7.2 KiB
C#
//-----------------------------------------------------------------------------
|
|
// <copyright file="RSSModel.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>fiedlchr</author>
|
|
// <sience>24.06.2013</sience>
|
|
//-----------------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Model.RSS
|
|
{
|
|
using System;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
|
|
/// <summary>
|
|
/// Contains the RSS feed information.
|
|
/// </summary>
|
|
public class RSSModel
|
|
{
|
|
#region Member
|
|
|
|
/// <summary>
|
|
/// Index of this object.
|
|
/// </summary>
|
|
private int index = -1;
|
|
|
|
/// <summary>
|
|
/// Title of the fees
|
|
/// </summary>
|
|
private string title;
|
|
|
|
/// <summary>
|
|
/// Description text of the feed.
|
|
/// </summary>
|
|
private string text;
|
|
|
|
/// <summary>
|
|
/// Timestamp (publication date) of the event or news.
|
|
/// </summary>
|
|
private DateTime timestamp;
|
|
|
|
/// <summary>
|
|
/// Url of the feed.
|
|
/// </summary>
|
|
private string link;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary>
|
|
/// Gets or sets the title of the feed.
|
|
/// </summary>
|
|
[XmlElement("title")]
|
|
public string Title
|
|
{
|
|
get
|
|
{
|
|
return this.title;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (this.title != value)
|
|
{
|
|
this.title = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the text of the feed.
|
|
/// </summary>
|
|
[XmlElement("description")]
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
return this.text;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (this.text != this.HTMLUnicodeToString(value))
|
|
{
|
|
this.text = this.HTMLUnicodeToString(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the timestamp of the feed as string.
|
|
/// </summary>
|
|
[XmlElement("pubDate")]
|
|
public string Timestamp
|
|
{
|
|
get
|
|
{
|
|
return this.timestamp.ToString("R");
|
|
}
|
|
|
|
set
|
|
{
|
|
if (this.timestamp != DateTime.Parse(value))
|
|
{
|
|
this.timestamp = DateTime.Parse(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the timestamp of the feed as DateTime object.
|
|
/// </summary>
|
|
public DateTime DTTimestamp
|
|
{
|
|
get
|
|
{
|
|
return this.timestamp;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.timestamp = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the date of the timestamp as string.
|
|
/// example: Mon, 25.06.2013.
|
|
/// </summary>
|
|
public string Date
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0:ddd, dd.MM.yyyy}", this.timestamp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the date of the timestamp as string.
|
|
/// example: 25.06.
|
|
/// </summary>
|
|
public string ShortDate
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0:dd.MM.}", this.timestamp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the time of the timestamp as string.
|
|
/// example: 12:56.
|
|
/// </summary>
|
|
public string Time
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0:h:mm} Uhr", this.timestamp);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the link/url of the feed.
|
|
/// </summary>
|
|
[XmlElement("link")]
|
|
public string Link
|
|
{
|
|
get
|
|
{
|
|
return this.link;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (this.link != value)
|
|
{
|
|
this.link = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the ListIndex.
|
|
/// </summary>
|
|
public int Index
|
|
{
|
|
get
|
|
{
|
|
return this.index;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.index = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#region public
|
|
|
|
/// <summary>
|
|
/// Comparing function for DateTime timestamps.
|
|
/// (currently unused)
|
|
/// </summary>
|
|
/// <param name="item1">first item</param>
|
|
/// <param name="item2">second item</param>
|
|
/// <returns>-1 if item2 is older then item1, otherwise 0</returns>
|
|
public static int CompareTimeStamp(RSSModel item1, RSSModel item2)
|
|
{
|
|
if (item1.DTTimestamp > item2.DTTimestamp)
|
|
{
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private
|
|
|
|
/// <summary>
|
|
/// Remove or transform html-unicode specific tags into ASCII.
|
|
/// </summary>
|
|
/// <param name="htmluni">html string</param>
|
|
/// <returns>ASCII string</returns>
|
|
private string HTMLUnicodeToString(string htmluni)
|
|
{
|
|
StringBuilder retValue = new StringBuilder();
|
|
|
|
for (int i = 0; i < htmluni.Length; i++)
|
|
{
|
|
switch (htmluni[i])
|
|
{
|
|
// beginning tag of the unicode
|
|
case '&':
|
|
int startOff = i + 2;
|
|
//// sear closing tag of the unicode
|
|
int endOff = htmluni.IndexOf(';', startOff);
|
|
//// get and parse value inbetween
|
|
string sub = htmluni.Substring(startOff, endOff - startOff);
|
|
int charVal = int.Parse(sub);
|
|
|
|
switch (charVal)
|
|
{
|
|
// if the unicode value is 128 (€)
|
|
case 128:
|
|
retValue.Append('€');
|
|
break;
|
|
|
|
default:
|
|
retValue.Append((char)charVal);
|
|
break;
|
|
}
|
|
|
|
// set the current index to the end of the unicode tag
|
|
i = endOff;
|
|
break;
|
|
|
|
case '<':
|
|
// ignoring <..> html tags
|
|
i = htmluni.IndexOf('>', i);
|
|
break;
|
|
|
|
case '\t':
|
|
// removing tabs
|
|
break;
|
|
|
|
default:
|
|
// adding other characters to the return string
|
|
retValue.Append(htmluni[i]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return retValue.ToString();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|