|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Linq;
namespace RSSVideoPlayer.Model
{
public class FeedItem : INotifyPropertyChanged
{
private XElement _Feed;
private List<MediaItem> _MediaLinks;
private bool _selected;
public FeedItem(XElement element)
{
if (element == null) {
throw new NullReferenceException("New feed element is null");
}
_Feed = element;
_MediaLinks = new List<MediaItem>();
foreach (XElement m in element.Descendants())
{
try {
if (m != null) {
if (m.Name.LocalName == "content" | m.Name.LocalName == "enclosure") {
MediaItem mediaitem = new MediaItem(m.Attribute("url").Value.ToString());
if (mediaitem.Filename.Substring(mediaitem.Filename.LastIndexOf(".")).ToLower() == ".wmv" || mediaitem.Filename.Substring(mediaitem.Filename.LastIndexOf(".")).ToLower() == ".mp4") {
_MediaLinks.Add(mediaitem);
}
}
}
}
catch { throw new NullReferenceException("Error loading feed media"); }
}
}
public bool IsSelected {
get { return _selected; }
set {
if (_selected != value) {
_selected = value;
OnPropertyChanged("IsSelected");
OnPropertyChanged("MediaItems");
}
}
}
public List<MediaItem> MediaItems {
get { return _MediaLinks; }
}
public string Title {
get {
var t = from e in _Feed.Descendants("title") select e;
if (t.Count() > 0) {
return t.ElementAt<XElement>(0).Value.ToString();
}
else {
return null;
}
}
}
public string Description {
get {
var t = from e in _Feed.Descendants("title") select e;
if (t.Count() > 0) {
return t.ElementAt<XElement>(0).Value.ToString();
}
else {
return null;
}
}
}
public string Link {
get {
var t = from e in _Feed.Descendants("title") select e;
if (t.Count() > 0) {
return t.ElementAt<XElement>(0).Value.ToString();
}
else {
return null;
}
}
}
#region INotifyPropertyChanged Members
private void OnPropertyChanged(string Propname)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(Propname));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.