using MuchInfo.Chart.WPF.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System.Collections.Generic; using System.Xml.Linq; namespace MuchInfo.Chart.WPF.Primitives.Drawing { public class DrawingToolSpec : IXmlSavable, IDrawingToolSpec { #region Fields private string _drawingXElementString; private bool _plotOnAllSymbols; private string _uniqueId; #endregion Fields #region Constructors public DrawingToolSpec() { this._uniqueId = string.Empty; this._plotOnAllSymbols = false; } public DrawingToolSpec(string symbol, IDrawingTool drawingTool) { this._plotOnAllSymbols = false; this._uniqueId = symbol; this._drawingXElementString = drawingTool.ToXml(null).ToString(); } #endregion Constructors #region Properties #region Public Properties public string RootName { get { return "DTSPEC"; } } #endregion Public Properties #region Internal Properties internal DrawingToolContainer DrawingToolContainer { get; set; } #endregion Internal Properties #endregion Properties #region Methods #region Public Methods public bool AppliesToSymbol(string symbolUniqueId) { if (_plotOnAllSymbols) { return true; } else { if (string.IsNullOrWhiteSpace(this._uniqueId) || string.IsNullOrWhiteSpace(symbolUniqueId)) { return false; } else { return string.CompareOrdinal(this._uniqueId, symbolUniqueId) == 0; } } } public void DeleteTool() { bool flag = this.DrawingToolContainer != null; if (flag) { this.DrawingToolContainer.DrawingToolContainer_3724(this); } } public void FromXml(XElement node) { } public IDrawingTool GetTool() { var xElement = XElement.Parse(this._drawingXElementString); var xmlSavable = XmlTypeCreator.MakeElement(xElement); var drawingTool = xmlSavable as IDrawingTool; if (drawingTool == null) return null; drawingTool.OwnerSpec = this; return drawingTool; } public ScaleLayer ScaleLayer() { return this.DrawingToolContainer.ScaleLayer(); } public string SymbolUniqueId() { return this._uniqueId; } public void ToolChanged(IDrawingTool aTool) { this._drawingXElementString = aTool.ToXml(null).ToString(); this._plotOnAllSymbols = aTool.PlotOnAllSymbols; } public XElement ToXml(List args) { var xElement = new XElement(this.RootName); xElement.Add(new XAttribute("BID", this._uniqueId)); xElement.Add(new XAttribute("Xml", this._drawingXElementString)); xElement.Add(new XAttribute("ALLS", this._plotOnAllSymbols.ToString())); return xElement; } #endregion Public Methods #region Internal Methods internal void DrawingToolSpec_3741(XElement el) { bool flag = el.Attribute("BID") != null; if (flag) { this._uniqueId = el.Attribute("BID").Value; } else { flag = (el.Attribute("UID") != null); if (flag) { string value = el.Attribute("UID").Value; if (!string.IsNullOrWhiteSpace(value)) { this._uniqueId = value; } } } flag = (el.Attribute("Xml") != null); if (flag) { this._drawingXElementString = el.Attribute("Xml").Value; } flag = (el.Attribute("ALLS") != null); if (flag) { this._plotOnAllSymbols = bool.Parse(el.Attribute("ALLS").Value); } } #endregion Internal Methods #endregion Methods } }