using System; using System.Xml; using System.Xml.Serialization; using System.Collections.Generic; using RightEdge.Common; using RightEdge.Properties; namespace RightEdge.Objects { public class WatchListItem { private bool isFolder = false; private WatchListFolder folder = null; private Symbol symbol = null; private WatchListItem parent = null; private AssetClass assetType = AssetClass.Stock; //private double pipSize = -1; private BarConstructionType barConstruction = BarConstructionType.Default; private int frequency = -1; public WatchListItem() { } public WatchListItem(bool isFolder) { this.isFolder = isFolder; } public WatchListItem(WatchListItem other) { isFolder = other.isFolder; if (other.folder != null) { folder = new WatchListFolder(other.folder); foreach (WatchListItem item in folder.Contents) { item.Parent = this; } } symbol = other.symbol; parent = other.parent; assetType = other.assetType; //pipSize = other.pipSize; barConstruction = other.barConstruction; frequency = other.frequency; } public override string ToString() { if (isFolder) { return folder.FolderName; } else { return symbol.Name; } } public bool IsFolder { get { return isFolder; } set { isFolder = value; } } //public BarConstructionType BarConstruction //{ // get // { // if (InheritsBarConstruction && parent != null) // { // return parent.BarConstruction; // } // else // { // return barConstruction; // } // } // set // { // barConstruction = value; // } //} public BarConstructionType BarConstruction { get { return barConstruction; } set { barConstruction = value; } } //public bool InheritsBarConstruction //{ // get // { // if (IsFolder) // { // return false; // } // else // { // return true; // } // } //} public WatchListFolder Folder { get { if (isFolder) { if (folder == null) { folder = new WatchListFolder(); } return folder; } return null; } set { folder = value; } } public Symbol Symbol { get { if (!isFolder) { if (symbol == null) { symbol = new Symbol(""); } return symbol; } return null; } set { symbol = value; } } public int Frequency { get { if (IsFolder && !Folder.InheritsFrequency) { return Folder.Frequency; } else { if (parent == null) { return (int) BarFrequency.Daily; } else { return parent.Frequency; } } } } public string HistService { get { if (IsFolder && !Folder.InheritsHistService) { return Folder.HistService; } else { if (parent == null) { return ""; } else { return parent.HistService; } } } } public string RealtimeService { get { if (IsFolder && !Folder.InheritsRealtimeService) { return Folder.RealtimeService; } else { if (parent == null) { return ""; } else { return parent.RealtimeService; } } } } public string BrokerService { get { if (IsFolder && !Folder.InheritsBrokerService) { return Folder.BrokerService; } else { if (parent == null) { return ""; } else { return parent.BrokerService; } } } } public bool SaveTicks { get { if (IsFolder && (parent == null || !Folder.InheritsSaveTicks)) { return Folder.SaveTicks; } else { if (parent == null) { return false; } else { return parent.SaveTicks; } } } } public bool SaveBars { get { if (IsFolder && (parent == null || !Folder.InheritsSaveBars)) { return Folder.SaveBars; } else { if (parent == null) { return false; } else { return parent.SaveBars; } } } } public DateTime DownloadStartDate { get { if (IsFolder && (parent == null || !Folder.InheritsDownloadStartDate)) { return Folder.DownloadStartDate; } else { if (parent == null) { return DateTime.MinValue; } else { return parent.DownloadStartDate; } } } } [XmlIgnore] public WatchListItem Parent { get { return parent; } set { parent = value; } } public void SetFromSymbolSetup(SymbolSetup symbolSetup) { //this.AssetType = symbolSetup.AssetType; this.BarConstruction = symbolSetup.BarConstruction; this.Symbol = symbolSetup.Symbol; } public SymbolSetup GetSymbolSetup() { SymbolSetup ret = new SymbolSetup(Symbol, Frequency); ret.HistService = HistService; ret.RealtimeService = RealtimeService; ret.BrokerService = BrokerService; ret.SaveLiveBars = SaveBars; ret.SaveLiveTicks = SaveTicks; ret.DownloadStartDate = DownloadStartDate; ret.BarConstruction = BarConstruction; //ret.AssetType = AssetType; ret.Frequency = Frequency; return ret; } } public class WatchListFolder { public string FolderName = ""; public List Contents = new List(); //public int Frequency = (int) BarFrequency.Daily; public int Frequency = -1; public bool InheritsHistService = true; public string HistService = ""; public bool InheritsRealtimeService = true; public string RealtimeService = ""; public bool InheritsBrokerService = true; public string BrokerService = ""; public bool InheritsSaveTicks = true; public bool SaveTicks = false; public bool InheritsSaveBars = true; public bool SaveBars = true; public DateTime DownloadStartDate = DateTime.MinValue; public bool InheritsDownloadStartDate = true; public WatchListFolder() { } public WatchListFolder(WatchListFolder other) { FolderName = other.FolderName; foreach (WatchListItem item in other.Contents) { Contents.Add(new WatchListItem(item)); } Frequency = other.Frequency; InheritsHistService = other.InheritsHistService; HistService = other.HistService; InheritsRealtimeService = other.InheritsRealtimeService; RealtimeService = other.RealtimeService; InheritsBrokerService = other.InheritsBrokerService; BrokerService = other.BrokerService; InheritsSaveBars = other.InheritsSaveBars; SaveBars = other.SaveBars; InheritsSaveTicks = other.InheritsSaveTicks; SaveTicks = other.SaveTicks; DownloadStartDate = other.DownloadStartDate; InheritsDownloadStartDate = other.InheritsDownloadStartDate; foreach (WatchListItem item in Contents) { item.Parent = null; } } public bool InheritsFrequency { get { if (Frequency == -1) { return true; } else { return false; } } set { if (value == true) { Frequency = -1; } else { if (Frequency == -1) { Frequency = (int) BarFrequency.Daily; } } } } } public class WatchListItemComparer : IComparer { public int Compare(WatchListItem x, WatchListItem y) { if (x == null && y == null) { return 0; } else if (x == null) { return -1; } else if (y == null) { return 1; } if (x.IsFolder && !y.IsFolder) { return -1; } else if (!x.IsFolder && y.IsFolder) { return 1; } else if (x.IsFolder) { return x.Folder.FolderName.CompareTo(y.Folder.FolderName); } else { return x.Symbol.ToString().CompareTo(y.Symbol.ToString()); } } } }