Exemplo n.º 1
0
        private void connect()
        {
            lock (this) {
                bool connected = false;
                //this method will not exit until the openConnection returns without throwing an exception
                while (!connected)
                {
                    demoForm.Invoke(statusChangeDelegate, new Object[] { StocklistConnectionListener.VOID, "Connecting to Lightstreamer Server @ " + cInfo.PushServerUrl });
                    try {
                        this.phase++;
                        client.OpenConnection(this.cInfo, new StocklistConnectionListener(this, this.phase));
                        connected = true;
                    } catch (PushConnException e) {
                        demoForm.Invoke(statusChangeDelegate, new Object[] { StocklistConnectionListener.VOID, e.Message });
                    } catch (PushServerException e) {
                        demoForm.Invoke(statusChangeDelegate, new Object[] { StocklistConnectionListener.VOID, e.Message });
                    } catch (PushUserException e) {
                        demoForm.Invoke(statusChangeDelegate, new Object[] { StocklistConnectionListener.VOID, e.Message });
                    }

                    if (!connected)
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
        }
Exemplo n.º 2
0
        void ILightstreamerAdapter.OpenConnection(int ph)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                PauseAndRetryStartClient(ph);
                return;
            }
            try
            {
                if (!CheckPhase(ph))
                {
                    return;
                }

                _logger.Info("Connecting to " + _streamingUri);
                OnStatusUpdate(ph, ConnectionStatus.Connecting, "Connecting to " + _streamingUri);
                var info = new ConnectionInfo
                {
                    PushServerUrl = _streamingUri.TrimEnd('/'),
                    Adapter       = _adapterSet,
                    User          = _userName,
                    Password      = _password,
                    Constraints   =
                    {
                        MaxBandwidth = 999999.0
                    },
                    Polling = _usePolling
                };
                try
                {
                    _client.OpenConnection(info, this);
                    Connected = true;
                }
                catch (PushUserException ex)
                {
                    if (ex.Message == "Requested Adapter Set not available")
                    {
                        throw new Exception(string.Format("Adapter set {0} is not available", _adapterSet), ex);
                    }

                    throw;
                }

                foreach (var current in _currentListeners)
                {
                    current.Value.Start(_phase);
                }

                Connected  = true;
                _lastDelay = 1;
            }
            catch (PushConnException e)
            {
                PauseAndRetryStartClient(ph);
            }
            catch (SubscrException e)
            {
                PauseAndRetryStartClient(ph);
            }
        }
Exemplo n.º 3
0
        private void btnConnectToLs_Click(object sender, EventArgs e)
        {
            try
            {
                lblConnecionStatus.Text = "";
                LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

                string pushServerHost = txtboxLsServer.Text;
                int    pushServerPort = Convert.ToInt32(txtLsPort.Text);

                ConnectionInfo connInfo = new ConnectionInfo();
                connInfo.PushServerUrl = "http://" + pushServerHost + ":" + pushServerPort;
                connInfo.Adapter       = txtboxAdapterSetName.Text;

                connInfo.User     = txtboxUserName.Text;
                connInfo.Password = txtboxPassword.Text;


                myClient = new LSClient();

                myClient.OpenConnection(connInfo, new LsConnectionListener(lblConnecionStatus));
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
    public void Start(string pushServerUrl)
    {
        ConnectionInfo connInfo = new ConnectionInfo();

        connInfo.PushServerUrl = pushServerUrl;
        connInfo.Adapter       = "DEMO";
        ls = new StocklistConnectionListener();
        client.OpenConnection(connInfo, ls);
        hl = new StocklistHandyTableListener();
    }
Exemplo n.º 5
0
        public void Start(string pushServerUrl, int phase, ILightstreamerListener listener)
        {
            StocklistConnectionListener ls = new StocklistConnectionListener(listener, phase);

            ConnectionInfo connInfo = new ConnectionInfo();

            connInfo.PushServerUrl = pushServerUrl;
            connInfo.Adapter       = "DEMO";
            client.OpenConnection(connInfo, ls);
        }
Exemplo n.º 6
0
        public IGMarketDataStreamer(AccountDetails accountDetails, IGApiAccount account)
        {
            Client = new LSClient();
            ConnectionInfo connectionInfo = new ConnectionInfo();

            connectionInfo.User          = accountDetails.Accounts[0].AccountId;
            connectionInfo.Password      = $"CST-{account.CST}|XST-{account.XSecurityToken}";
            connectionInfo.PushServerUrl = accountDetails.LightstreamerEndpoint;

            Client.OpenConnection(connectionInfo, new ClientConnectionEvents());

            CreateSubscription("IX.D.OMX.IFM.IP");
        }
        /// <summary>
        /// Establish Connecion with
        /// LighStreamer
        /// </summary>
        /// <returns></returns>
        public bool ConnectToLs()
        {
            // LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = PushServer;
            int    pushServerPort = Port;

            ConnectionInfo connInfo = new ConnectionInfo();

            connInfo.PushServerUrl = "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter       = AdapterSetName;

            connInfo.User     = UserName;
            connInfo.Password = Password;


            m_lsClient.OpenConnection(connInfo, new LsConnectionListener());
            return(true);
        }
Exemplo n.º 8
0
        private void Connect()
        {
            lock (this)
            {
                bool connected = false;
                while (!connected)
                {
                    this.StatusChanged(this.phase, "Connecting to Lightstreamer Server @ " + connInfo.PushServerUrl, DISCONNECTED);

                    /// <exception cref="PushConnException">in case of connection problems.</exception>
                    /// <exception cref="PushServerException">in case of errors in the supplied
                    /// parameters or in Server answer.
                    /// In normal operation, this should not happen.</exception>
                    /// <exception cref="PushUserException">in case the connection was refused
                    /// after the checks in Lightstreamer Server Metadata Adapter.</exception>
                    try
                    {
                        this.phase++;
                        client.OpenConnection(this.connInfo, new StocklistConnectionListener(this, this.phase));
                        connected = true;
                    }
                    catch (PushConnException e)
                    {
                        this.StatusChanged(this.phase, "Connection to Server failed: " + e.Message, null);
                    }
                    catch (PushServerException e)
                    {
                        this.StatusChanged(this.phase, "Unexpected error: " + e.Message, null);
                    }
                    catch (PushUserException e)
                    {
                        this.StatusChanged(this.phase, "Request refused: " + e.Message, null);
                    }

                    if (!connected)
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
        }
    private void LightStreanerConnect()
    {
        cInfo = new ConnectionInfo()
        {
            PushServerUrl          = Hostname,
            Adapter                = AdapterSet,
            StreamingTimeoutMillis = 10000,
            EnableStreamSense      = false
        };
        try
        {
            Debug.Log("Let's go!  -> " + System.Environment.TickCount);

            client.OpenConnection(cInfo, new StocklistConnectionListener(this));
        }
        catch (PushConnException pfe)
        {
            Debug.LogError("Error: " + pfe.Message);
            this.StateMachine = 0;
        }
    }
Exemplo n.º 10
0
        public void CreateConnection()
        {
            try
            {
                lsClient = new LSClient();

                connectionInfo               = new ConnectionInfo();
                connectionInfo.Adapter       = "DEFAULT";
                connectionInfo.User          = Session.Username;
                connectionInfo.Password      = string.Format("CST-{0}|XST-{1}", Session.CST, Session.X_SECURITY_TOKEN);
                connectionInfo.PushServerUrl = Session.Response.Response.LightstreamerEndpoint;

                lsClient.OpenConnection(connectionInfo, this);

                ConnectionEstablished = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("LS Connection Failed");
                ConnectionEstablished = false;
            }
        }
        public bool Connect(string username, string cstToken, string xSecurityToken, string apiKey, string lsHost)
        {
            bool connectionEstablished = false;

            ConnectionInfo connectionInfo = new ConnectionInfo();

            connectionInfo.Adapter       = "DEFAULT";
            connectionInfo.User          = username;
            connectionInfo.Password      = string.Format("CST-{0}|XST-{1}", cstToken, xSecurityToken);
            connectionInfo.PushServerUrl = lsHost;
            try
            {
                if (lsClient != null)
                {
                    lsClient.OpenConnection(connectionInfo, this);
                    connectionEstablished = true;
                }
            }
            catch (Exception)
            {
                connectionEstablished = false;
            }
            return(connectionEstablished);
        }
Exemplo n.º 12
0
        void IFaultTolerantLsClientAdapter.OpenConnection(int ph)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                PauseAndRetryStartClient(ph, null);
                return;
            }

            try
            {
                if (!CheckPhase(ph))
                {
                    return;
                }

                OnStatusUpdate(ph, ConnectionStatus.Connecting, "Connecting to " + _streamingUri);


                var connection = new ConnectionInfo
                {
                    PushServerUrl = _streamingUri.TrimEnd('/'),
                    Adapter       = _adapterSet,
                    User          = _userName,
                    Password      = _sessionId,
                    Constraints   = { MaxBandwidth = 999999 },
                    Polling       = _usePolling //,PollingIdleMillis = 250,PollingMillis = 250
                };

                try
                {
                    //#TODO find out why it is still trying to connect after shutdown
                    Debug.WriteLine("connecting streaming client to adapter " + _adapterSet);
                    _client.OpenConnection(connection, this);
                    Debug.WriteLine("connected streaming client to adapter " + _adapterSet);
                    Connected = true;
                }
                catch (PushUserException ex)
                {
                    if (ex.Message == "Requested Adapter Set not available")
                    {
                        throw new Exception(string.Format("Adapter set {0} is not available", _adapterSet), ex);
                    }
                    throw;
                }

                // rebuild up any existing listeners
                foreach (KeyValuePair <string, IStreamingListener> kvp in _currentListeners)
                {
                    kvp.Value.Start(_phase);
                }

                Connected = true;
                Debug.WriteLine("Lightstreamer Client Started");
                _lastDelay = 1;
            }

            catch (PushConnException pce)
            {
                PauseAndRetryStartClient(ph, pce);
            }
            catch (SubscrException se)
            {
                PauseAndRetryStartClient(ph, se);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Opens a connection, performs a table subscription and unsubscription
        /// and closes the connection after some time.
        /// </summary>
        /// <param name="args">Should specify the host name of the Server, the port number
        /// and optionally the "extended", "multiple" and "command" flags.
        /// </param>
        /// <throws>Exception Thrown in case of any error.</throws>
        public static void Main(string[] args)
        {
            LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = args[0];
            int    pushServerPort = Int32.Parse(args[1]);

            ArrayList opts = new ArrayList();

            for (int i = 2; i < args.Length; i++)
            {
                opts.Add(args[i]);
            }
            bool extended = opts.Contains("extended");
            bool multiple = opts.Contains("multiple");
            bool command  = opts.Contains("command");

            Thread.Sleep(2000);

            ConnectionInfo connInfo = new ConnectionInfo();

            connInfo.PushServerUrl = "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter       = "DEMO";

            LSClient myClient = new LSClient();

            myClient.OpenConnection(connInfo, new TestConnectionListener());

            Thread.Sleep(5000);

            ArrayList refs = new ArrayList();

            SubscribedTableKey[] tableRefs;

            if (!command)
            {
                if (extended)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForExtended(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
                else if (multiple)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    tableRefs = myClient.SubscribeItems(
                        tableInfo,
                        new TestTableListenerForMultiple()
                        );
                }
                else
                {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    string groupName  = "item1 item2 item3";
                    string schemaName = "last_price time pct_change";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "MERGE",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForSimple(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }
            else
            {
                if (extended)
                {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new String[] { "portfolio1" },
                        "COMMAND",
                        new String[] { "key", "command", "qty" },
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForExtended(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
                else
                {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    String groupName  = "portfolio1";
                    String schemaName = "key command qty";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "COMMAND",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForSimple(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }

            for (int j = 0; j < tableRefs.Length; j++)
            {
                refs.Add(tableRefs[j]);
            }

            Thread.Sleep(20000);

            SubscribedTableKey[] allTableRefs = new SubscribedTableKey[refs.Count];
            for (int i = 0; i < refs.Count; i++)
            {
                allTableRefs[i] = (SubscribedTableKey)refs[i];
            }
            myClient.UnsubscribeTables(allTableRefs);

            Thread.Sleep(5000);

            myClient.CloseConnection();

            Thread.Sleep(2000);
            Environment.Exit(0);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Opens a connection, performs a table subscription and unsubscription
        /// and closes the connection after some time.
        /// </summary>
        /// <param name="args">Should specify the host name of the Server, the port number
        /// and optionally the "extended", "multiple" and "command" flags.
        /// </param>
        /// <throws>Exception Thrown in case of any error.</throws>
        public static void Main(string[] args) {

            LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = args[0];
            int pushServerPort = Int32.Parse(args[1]);

            ArrayList opts = new ArrayList();
            for (int i = 2; i < args.Length; i++) {
                opts.Add(args[i]);
            }
            bool extended = opts.Contains("extended");
            bool multiple = opts.Contains("multiple");
            bool command = opts.Contains("command");

            Thread.Sleep(2000);

            ConnectionInfo connInfo= new ConnectionInfo();
            connInfo.PushServerUrl= "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter= "DEMO";

            LSClient myClient = new LSClient();
            myClient.OpenConnection(connInfo, new TestConnectionListener());
        
            Thread.Sleep(5000);

            ArrayList refs = new ArrayList();
            SubscribedTableKey[] tableRefs;

            if (!command) {
                if (extended) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";
                
                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForExtended(),
                        false
                        );
                
                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else if (multiple) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    tableRefs = myClient.SubscribeItems(
                        tableInfo,
                        new TestTableListenerForMultiple()
                        );

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    string groupName = "item1 item2 item3";
                    string schemaName = "last_price time pct_change";

                    SimpleTableInfo tableInfo= new SimpleTableInfo(
                        groupName, 
                        "MERGE", 
                        schemaName, 
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForSimple(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            } else {
                if (extended) {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new String[] { "portfolio1" },
                        "COMMAND",
                        new String[] { "key", "command", "qty" },
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForExtended(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    String groupName = "portfolio1";
                    String schemaName = "key command qty";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "COMMAND",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForSimple(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }

            for (int j = 0; j < tableRefs.Length; j++) {
                refs.Add(tableRefs[j]);
            }

            Thread.Sleep(20000);

            SubscribedTableKey[] allTableRefs = new SubscribedTableKey[refs.Count];
            for (int i= 0; i < refs.Count; i++) allTableRefs[i]= (SubscribedTableKey) refs[i];
            myClient.UnsubscribeTables(allTableRefs);

            Thread.Sleep(5000);
        
            myClient.CloseConnection();
        
            Thread.Sleep(2000);
            Environment.Exit(0);
        }