using System.Xml; using TradeIdeas.ServerConnection; using TradeIdeas.TIProData.Interfaces; using TradeIdeas.XML; namespace TradeIdeas.TIProData { /// /// This ia a container class /// public class CompanyProfileInfo { public CompanyProfileInfo(string symbol, string summary, string country, string website) { Symbol = symbol; Summary = summary; Country = country; Website = website; } public string Symbol { get; } public string Summary { get; } public string Country { get; } public string Website { get; } } /// /// This is a notification when the server sends us data to populate the object. /// /// The object which now has data. public delegate void CompanyProfileReceived(CompanyProfileInfo companyProfileInfo); /// /// This class provides access to company profile text for a given symbol /// public class CompanyProfileManager { private ISendManager _sendManager; /// /// This is the event-driven way to know when data is available. /// public event CompanyProfileReceived ProfileReceived; /// A pointer to (the relevant part of) the server connection. public CompanyProfileManager(ISendManager sendManager) { _sendManager = sendManager; } public void RequestNow(string symbol) { _sendManager.SendMessage(TalkWithServer.CreateMessage("command", "get_profile", "symbol", symbol), Response); } private void Response(byte[] body, object clientId) { if (null == body) { return; } XmlDocument wholeMessage = XmlHelper.Get(body); XmlNode profileNode = wholeMessage.Node(0).Node("PROFILE"); if (profileNode != null) { string symbol = profileNode.Property("SYMBOL"); string summary = profileNode.Text(); string country = profileNode.Property("COUNTRY"); string website = profileNode.Property("WEBSITE"); CompanyProfileInfo companyProfileInfo = new CompanyProfileInfo(symbol, summary, country, website ); CompanyProfileReceived callback = ProfileReceived; if (null != callback) try { callback(companyProfileInfo); } catch { } } } } }