using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Windows.Media; using MarketData.Utils; using Ticker.Helper; namespace Ticker.Models { public class FeedBrushes { public enum BrushColor{Normal=0,Red=1,Green=2}; public static Brush[] ContextBrushes={ new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00ABA9")), new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF0000")), new SolidColorBrush((Color)ColorConverter.ConvertFromString("#008000")) }; private FeedBrushes() { } public static Brush GetContextBrush(BrushColor brushColor) { return ContextBrushes[(int)brushColor]; } } // public class FeedItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private string title; private string pubDate; private string link; private string description; private string guid; private string source; private bool read; private FeedBrushes.BrushColor brushAssignment; public FeedItem() { brushAssignment=FeedBrushes.BrushColor.Normal; } // Don't save the link. Firstly, we don't need it, secondly, it contains '=' which are a keyword for NVP public NVPCollection ToNVPCollection() { NVPCollection nvpCollection=new NVPCollection(); nvpCollection.Add(new NVP("Title",title)); nvpCollection.Add(new NVP("PubDate",pubDate)); String fixupLink=link.Replace("=","^"); nvpCollection.Add(new NVP("Link",fixupLink)); nvpCollection.Add(new NVP("Description",description)); nvpCollection.Add(new NVP("Guid",guid)); nvpCollection.Add(new NVP("Source",source)); nvpCollection.Add(new NVP("Read",read.ToString())); return nvpCollection; } public static FeedItem FromString(String strFeedItem) { try { FeedItem feedItem=new FeedItem(); NVPCollection nvpCollection=new NVPCollection(strFeedItem); NVPDictionary nvpDictionary=nvpCollection.ToDictionary(); feedItem.Title=nvpDictionary["Title"].Get(); feedItem.PubDate=nvpDictionary["PubDate"].Get(); String fixupLink=nvpDictionary["Link"].Get(); feedItem.Link=fixupLink.Replace("^","="); feedItem.Description=nvpDictionary["Description"].Get(); feedItem.Guid=nvpDictionary["Guid"].Get(); feedItem.Source=nvpDictionary["Source"].Get(); feedItem.Read=nvpDictionary["Read"].Get(); return feedItem; } catch(Exception) { return null; } } public Brush ForegroundBrush { get{return FeedBrushes.GetContextBrush(brushAssignment);} } public FeedBrushes.BrushColor BrushAssigment { get{return brushAssignment;} set{brushAssignment=value;if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("BrushAssigment"));} } public bool Read { get { return read; } set { read = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Read")); } } public string Source { get { return source; } set { source = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Source")); } } public string Guid { get { return guid; } set { guid = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Guid")); } } public string Description { get { return description; } set { description = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Description")); } } public string Link { get { return link; } set { link = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Link")); } } public string PubDate { get { return pubDate; } set { pubDate = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("PubDate")); } } public string Title { get { return title; } set { title = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Title")); } } } }