using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Xml; using System.Windows.Forms; using TradeIdeas.TIProData; using TradeIdeas.TIProData.Configuration; using TradeIdeas.XML; using TradeIdeas.TIProGUI; namespace SimpleTIPro { public partial class Form1 : Form { private static ConnectionMaster _connectionMaster; //static public ConnectionMaster Connection { get { return _connectionMaster; } } public Form1() { InitializeComponent(); // It's best to create this at the very beginning, rather than waiting until // you log in. If this is null, other windows will have trouble and could // cause null pointer exceptions. If we are not logged in and not connected, // but this object exists, most messages will be safely ignored. _connectionMaster = new ConnectionMaster(); XmlDocument config = new XmlDocument(); config.Load("Config.xml"); Text = config.Node("CONFIG").Node("TITLE").Text("Trade-Ideas"); foreach (XmlNode windowNode in config.Node("CONFIG").Node("WINDOWS").Enum()) { if (windowNode.Property("TYPE") == "toplist") { newWindowListBox.Items.Add(new WindowDescription(windowNode)); } } //FormCollection fc = Application.OpenForms; _connectionMaster.PingManager.PingUpdate += new PingUpdate(PingManager_PingUpdate); _connectionMaster.LoginManager.AccountStatusUpdate += new AccountStatusUpdate(LoginManager_AccountStatusUpdate); _connectionMaster.ConnectionBase.ConnectionStatusUpdate += new ConnectionStatusUpdate(ConnectionBase_ConnectionStatusUpdate); } void ConnectionBase_ConnectionStatusUpdate(ConnectionBase source, ConnectionStatusCallbackArgs args) { if (InvokeRequired) BeginInvoke((MethodInvoker)delegate { ConnectionBase_ConnectionStatusUpdate(source, args); }); else connectionStatusLabel.Text = "Connection status: " + args.message; } void LoginManager_AccountStatusUpdate(LoginManager source, AccountStatusArgs args) { if (InvokeRequired) BeginInvoke((MethodInvoker)delegate { LoginManager_AccountStatusUpdate(source, args); }); else { accountStatusLabel.Text = "Account status: " + args.accountStatus.English(); if (null != args.nextPayment) nextPaymentLabel.Text = "Next payment due: " + args.nextPayment.ToString(); else nextPaymentLabel.Text = ""; } } void PingManager_PingUpdate(TimeSpan pingTime) { if (InvokeRequired) BeginInvoke((MethodInvoker)delegate { PingManager_PingUpdate(pingTime); }); else latencyLabel.Text = "Latency: " + pingTime.TotalMilliseconds.ToString() + " ms"; } private void loginButton_Click(object sender, EventArgs e) { _connectionMaster.LoginManager.Username = usernameTextBox.Text; _connectionMaster.LoginManager.Password = passwordTextBox.Text; } private class WindowDescription { public WindowDescription(XmlNode windowNode) { Name = windowNode.Property("NAME"); Config = windowNode.Property("CONFIG"); } public Form Form; public String Name; public override string ToString() { return Name; } public String Config; public void Requested() { if ((null == Form) || (Form.IsDisposed)) { Form = new TopListForm(_connectionMaster, Config); Form.Show(); } else { Form.WindowState = FormWindowState.Normal; Form.BringToFront(); } } } private void newWindowListBox_DoubleClick(object sender, EventArgs e) { WindowDescription target = (WindowDescription)newWindowListBox.SelectedItem; if (null != target) target.Requested(); } } }