210 lines
6.1 KiB
C#
210 lines
6.1 KiB
C#
using CampusAppWP8.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace CampusAppWP8.Model.events_news
|
|
{
|
|
/// <summary>
|
|
/// Contains the rss feed informations.
|
|
/// </summary>
|
|
public class RSSModel : BaseModel
|
|
{
|
|
/// <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>
|
|
/// Set/Get the title of the feed.
|
|
/// </summary>
|
|
[XmlElement("title")]
|
|
public string Title
|
|
{
|
|
get { return this.title; }
|
|
set
|
|
{
|
|
if (this.title != value)
|
|
{
|
|
this.title = value;
|
|
NotifyPropertyChanged("rss");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/Get the text of the feed.
|
|
/// </summary>
|
|
[XmlElement("description")]
|
|
public string Text
|
|
{
|
|
get { return this.text; }
|
|
set
|
|
{
|
|
if (this.text != HTMLUnicodeToString(value))
|
|
{
|
|
this.text = HTMLUnicodeToString(value);
|
|
NotifyPropertyChanged("rss");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/Get 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);
|
|
NotifyPropertyChanged("rss");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/Get the timestamp of the feed as DateTime object.
|
|
/// </summary>
|
|
public DateTime DTTimestamp
|
|
{
|
|
get { return this.timestamp; }
|
|
set { this.timestamp = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return 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>
|
|
/// Return the time of the timestamp as string.
|
|
/// example: 12:56 Uhr.
|
|
/// </summary>
|
|
public string Time
|
|
{
|
|
get { return String.Format("{0:h:mm} Uhr", this.timestamp); }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets the ListIndex
|
|
/// </summary>
|
|
public int Index { get; set; }
|
|
|
|
/// <summary>
|
|
/// Set/Get the link/url of the feed.
|
|
/// </summary>
|
|
[XmlElement("link")]
|
|
public string Link
|
|
{
|
|
get { return this.link; }
|
|
set
|
|
{
|
|
if (this.link != value)
|
|
{
|
|
this.link = value;
|
|
NotifyPropertyChanged("rss");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <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 cVal = int.Parse(sub);
|
|
|
|
switch (cVal)
|
|
{
|
|
// if the unicode value is 128 (€)
|
|
case 128:
|
|
retValue.Append('€');
|
|
break;
|
|
|
|
default:
|
|
retValue.Append((char)cVal);
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Comparing function for Datetime-Timestamps.
|
|
/// (currently unused)
|
|
/// </summary>
|
|
/// <param name="item1">first item</param>
|
|
/// <param name="item2">secound item</param>
|
|
/// <returns></returns>
|
|
public static int CompareTimeStamp(RSSModel item1, RSSModel item2)
|
|
{
|
|
if (item1.DTTimestamp > item2.DTTimestamp)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
}
|
|
}
|