317 lines
9.1 KiB
C#
317 lines
9.1 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="RSSModel.cs" company="BTU/IIT">
|
|
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
|
// </copyright>
|
|
// <author>fiedlchr</author>
|
|
// <date>15.10.2013</date>
|
|
// <summary>Implements the RSS model class</summary>
|
|
//-----------------------------------------------------------------------
|
|
namespace CampusAppWPortalLib8.Model.RSS
|
|
{
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Text;
|
|
using System.Xml.Serialization;
|
|
|
|
/// <summary> Contains the RSS feed information. </summary>
|
|
/// <remarks> fiedlchr, 15.10.2013. </remarks>
|
|
/// <seealso cref="T:System.ComponentModel.INotifyPropertyChanged"/>
|
|
public class RSSModel : INotifyPropertyChanged
|
|
{
|
|
#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;
|
|
|
|
/// <summary> true to show, false to hide the text. </summary>
|
|
private bool textVisible = true;
|
|
|
|
#endregion
|
|
|
|
#region event
|
|
|
|
/// <summary> Occurs when Property Changed. </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
#endregion
|
|
|
|
#region Property
|
|
|
|
/// <summary> Gets or sets the title of the feed. </summary>
|
|
/// <value> The title. </value>
|
|
[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>
|
|
/// <value> The text. </value>
|
|
[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>
|
|
/// <value> The timestamp. </value>
|
|
[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>
|
|
/// <value> The DateTime timestamp. </value>
|
|
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>
|
|
/// <value> The date. </value>
|
|
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>
|
|
/// <value> The short date. </value>
|
|
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>
|
|
/// <value> The time. </value>
|
|
public string Time
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0:h:mm} Uhr", this.timestamp);
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets or sets the link/url of the feed. </summary>
|
|
/// <value> The link. </value>
|
|
[XmlElement("link")]
|
|
public string Link
|
|
{
|
|
get
|
|
{
|
|
return this.link;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (this.link != value)
|
|
{
|
|
this.link = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets or sets the ListIndex. </summary>
|
|
/// <value> The index. </value>
|
|
public int Index
|
|
{
|
|
get
|
|
{
|
|
return this.index;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.index = value;
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets or sets a value indicating whether the text visibility. </summary>
|
|
/// <value> true if text visibility, false if not. </value>
|
|
public bool TextVisibility
|
|
{
|
|
get
|
|
{
|
|
return this.textVisible;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value != this.textVisible)
|
|
{
|
|
this.textVisible = value;
|
|
this.NotifyPropertyChanged("TextVisibility");
|
|
this.NotifyPropertyChanged("BrowserVisibility");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets a value indicating whether the browser visibility. </summary>
|
|
/// <value> true if browser visibility, false if not. </value>
|
|
public bool BrowserVisibility
|
|
{
|
|
get
|
|
{
|
|
return !this.textVisible;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
#region public
|
|
|
|
/// <summary> Comparing function for DateTime timestamps. (currently unused) </summary>
|
|
/// <remarks> fiedlchr, 15.10.2013. </remarks>
|
|
/// <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> Notifies a property changed. </summary>
|
|
/// <remarks> fiedlchr, 15.10.2013. </remarks>
|
|
/// <param name="info"> The information. </param>
|
|
private void NotifyPropertyChanged(string info)
|
|
{
|
|
if (this.PropertyChanged != null)
|
|
{
|
|
this.PropertyChanged(this, new PropertyChangedEventArgs(info));
|
|
}
|
|
}
|
|
|
|
/// <summary> Remove or transform html-unicode specific tags into ASCII. </summary>
|
|
/// <remarks> fiedlchr, 15.10.2013. </remarks>
|
|
/// <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
|
|
}
|
|
}
|