//----------------------------------------------------------------------------- // // Company copyright tag. // // fiedlchr // 24.06.2013 //----------------------------------------------------------------------------- namespace CampusAppWPortalLib8.Model.RSS { using System; using System.Text; using System.Xml.Serialization; /// /// Contains the RSS feed information. /// public class RSSModel { #region Member /// /// Index of this object. /// private int index = -1; /// /// Title of the fees /// private string title; /// /// Description text of the feed. /// private string text; /// /// Timestamp (publication date) of the event or news. /// private DateTime timestamp; /// /// Url of the feed. /// private string link; #endregion #region Property /// /// Gets or sets the title of the feed. /// [XmlElement("title")] public string Title { get { return this.title; } set { if (this.title != value) { this.title = value; } } } /// /// Gets or sets the text of the feed. /// [XmlElement("description")] public string Text { get { return this.text; } set { if (this.text != this.HTMLUnicodeToString(value)) { this.text = this.HTMLUnicodeToString(value); } } } /// /// Gets or sets the timestamp of the feed as string. /// [XmlElement("pubDate")] public string Timestamp { get { return this.timestamp.ToString("R"); } set { if (this.timestamp != DateTime.Parse(value)) { this.timestamp = DateTime.Parse(value); } } } /// /// Gets or sets the timestamp of the feed as DateTime object. /// public DateTime DTTimestamp { get { return this.timestamp; } set { this.timestamp = value; } } /// /// Gets the date of the timestamp as string. /// example: Mon, 25.06.2013. /// public string Date { get { return string.Format("{0:ddd, dd.MM.yyyy}", this.timestamp); } } /// /// Gets the time of the timestamp as string. /// example: 12:56. /// public string Time { get { return string.Format("{0:h:mm} Uhr", this.timestamp); } } /// /// Gets or sets the link/url of the feed. /// [XmlElement("link")] public string Link { get { return this.link; } set { if (this.link != value) { this.link = value; } } } /// /// Gets or sets the ListIndex. /// public int Index { get { return this.index; } set { this.index = value; } } #endregion #region Method #region public /// /// Comparing function for DateTime timestamps. /// (currently unused) /// /// first item /// second item /// -1 if item2 is older then item1, otherwise 0 public static int CompareTimeStamp(RSSModel item1, RSSModel item2) { if (item1.DTTimestamp > item2.DTTimestamp) { return -1; } else { return 0; } } #endregion #region private /// /// Remove or transform html-unicode specific tags into ASCII. /// /// html string /// ASCII string 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 } }