//----------------------------------------------------------------------- // // The MIT License (MIT). Copyright (c) 2013 BTU/IIT. // // fiedlchr // 15.10.2013 // Implements the RSS channel model class //----------------------------------------------------------------------- namespace CampusAppWPortalLib8.Model.RSS { using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using System.Xml.Serialization; /// Channel Model, which contains the RSS feed item list. /// fiedlchr, 15.10.2013. public class RSSChannelModel { /// RSS feed information item list. private ObservableCollection item; #region Constructor /// Initializes a new instance of the class. /// fiedlchr, 15.10.2013. public RSSChannelModel() { this.item = new ObservableCollection(); this.item.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged); } #endregion #region Property /// Gets or sets the RSS feed item list. /// The item. [XmlElement("item")] public ObservableCollection Item { get { return this.item; } set { if (value != this.item) { this.item = value; } } } #endregion #region Method /// Order by date. /// fiedlchr, 15.10.2013. /// (Optional) the ascending. public void OrderByDate(bool asc = false) { this.item.CollectionChanged -= this.OnListChanged; if (asc == false) { var sortedOC = from elem in this.item orderby elem.DTTimestamp descending select elem; this.item = new ObservableCollection(sortedOC); this.FixIndex(); this.item.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged); } else { var sortedOC = from elem in this.item orderby elem.DTTimestamp ascending select elem; this.item = new ObservableCollection(sortedOC); this.FixIndex(); this.item.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged); } } /// /// Is called when the item list has changed. Here used for the add event. Set the index of /// the last list element. /// /// fiedlchr, 15.10.2013. /// item list. /// event args. private void OnListChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { ObservableCollection list = sender as ObservableCollection; list[list.Count - 1].Index = list.Count - 1; } } /// Fixes the index property of the items. /// Fiedler, 15.10.2013. private void FixIndex() { for (int i = 0; i < this.item.Count(); i++) { this.item[i].Index = i; } } #endregion } }