Ejemplo n.º 1
0
        void IStreamingListener.Start(int phase)
        {
            var text = _groupOrItemName.ToUpper();

            if (_listener != null)
            {
                _listener.MessageReceived -= ListenerMessageReceived;
                ((IStreamingListener)this).Stop();
            }

            var fieldList = _messageConverter.GetFieldList();
            var text2     = _channel.ToUpper();

            _listener = new TableListener <TDto>(_logger, _adapterSet.ToUpper(), text2, text, phase, _serializer);
            _listener.MessageReceived += ListenerMessageReceived;

            _logger.Debug(string.Format("Subscribing to group:{0}, schema {1}, dataAdapter {2}, mode {3}, snapshot {4}",
                                        text,
                                        fieldList,
                                        text2,
                                        _mode.ToUpper(),
                                        _snapshot));

            var schema          = fieldList;
            var mode            = _mode.ToUpper();
            var snapshot        = _snapshot;
            var simpleTableInfo = new SimpleTableInfo(text, mode, schema, snapshot)
            {
                DataAdapter = text2
            };

            var       gate = new ManualResetEvent(false);
            Exception ex   = null;

            new Thread(delegate()
            {
                try
                {
                    _subscribedTableKey = _lightstreamer.SubscribeTable(simpleTableInfo, _listener, false);
                    _logger.Debug(string.Format("Subscribed to table with key: {0}", _subscribedTableKey));
                }
                catch (Exception e)
                {
                    ex = e;
                }
                gate.Set();
            }).Start();

            if (ex != null)
            {
                _logger.Error(ex);
                throw ex;
            }
            if (!gate.WaitOne(Settings.DefaultTimeoutMs + 1000))
            {
                _logger.Error(string.Format("Listener taking longer than {0}ms to start: {1}.", Settings.DefaultTimeoutMs, base.GetType().Name));
            }
        }
Ejemplo n.º 2
0
        void IStreamingListener.Start(int phase)
        {
            string groupOrItemName = _groupOrItemName.ToUpper();

            if (_listener != null)
            {
                _listener.MessageReceived -= ListenerMessageReceived;
                ((IStreamingListener)this).Stop();
            }

            string schema  = _messageConverter.GetFieldList();
            string channel = _channel.ToUpper();

            _listener = new TableListener <TDto>(_adapterSet.ToUpper(), channel, groupOrItemName, phase, _serializer);
            _listener.MessageReceived += ListenerMessageReceived;


            Logger.Debug(string.Format("Subscribing to group:{0}, schema {1}, dataAdapter {2}, mode {3}, snapshot {4}", groupOrItemName, schema, channel, _mode.ToUpper(), _snapshot));

            var simpleTableInfo = new SimpleTableInfo(
                groupOrItemName,
                schema: schema,
                mode: _mode.ToUpper(), snap: _snapshot)
            {
                DataAdapter = channel
            };
            var       gate = new ManualResetEvent(false);
            Exception ex   = null;

            new Thread(() =>
            {
                try
                {
                    _subscribedTableKey = _lsClient.SubscribeTable(simpleTableInfo, _listener, false);
                    Logger.Debug(string.Format("Subscribed to table with key: {0}", _subscribedTableKey));
                }
                catch (Exception exInner)
                {
                    ex = exInner;
                }
                gate.Set();
            }).Start();
            if (ex != null)
            {
                Logger.Error(ex);
                throw ex;
            }

            if (!gate.WaitOne(LightstreamerDefaults.DEFAULT_TIMEOUT_MS + 1000))
            {
                Logger.Error(string.Format("Listener taking longer than {0}ms to start: {1}.",
                                           LightstreamerDefaults.DEFAULT_TIMEOUT_MS, GetType().Name));
            }
        }
Ejemplo n.º 3
0
        private void btnSubscribeToLs_Click(object sender, EventArgs e)
        {
            try
            {
                SubscribedTableKey[] tableRefs;


                string items = txtBoxSubsciptionItems.Text;
                subsciptionmdoe = comboBoxSubscriptionMode.Text;
                schecmName      = textboxSchema.Text;



                DialogResult dialogresult = MessageBox.Show("Subscribe to items : " + items, "Subscription", MessageBoxButtons.YesNo);

                if (dialogresult == DialogResult.No)
                {
                    return;
                }

                SimpleTableInfo tableInfo = new SimpleTableInfo(
                    items,
                    subsciptionmdoe,
                    schecmName,
                    false
                    );

                tableInfo.DataAdapter = txtboxFeedAdatperName.Text;



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


                tableRefs = new SubscribedTableKey[] { tableRef };
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }
Ejemplo n.º 4
0
        private void subscribe()
        {
            lock (this)
            {
                //this method will try just one subscription.
                //we know that when this method executes we should be already connected
                //If we're not or we disconnect while subscribing we don't have to do anything here as an
                //event will be (or was) sent to the ConnectionListener that will handle the case.
                //If we're connected but the subscription fails we can't do anything as the same subscription
                //would fail again and again (btw this should never happen)

                try
                {
                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        "item1 item2 item3 item4 item5 item6 item7 item8 item9 item10 item11 item12 item13 item14 item15 item16 item17 item18 item19 item20 item21 item22 item23 item24 item25 item26 item27 item28 item29 item30",
                        "MERGE",
                        "stock_name last_price time pct_change bid_quantity bid ask ask_quantity min max ref_price open_price",
                        true);
                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    client.SubscribeTable(
                        tableInfo,
                        new StocklistHandyTableListener(this, this.phase),
                        false);
                }
                catch (SubscrException)
                {
                }
                catch (PushServerException)
                {
                }
                catch (PushUserException)
                {
                }
                catch (PushConnException)
                {
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TDto"></typeparam>
        /// <param name="simpleTableInfo"></param>
        /// <param name="listener"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public SubscribedTableKey SubscribeTable <TDto>(SimpleTableInfo simpleTableInfo, ITableListener <TDto> listener, bool b) where TDto : class, new()
        {
            SubscribedTableKey key = _client.SubscribeTable(simpleTableInfo, listener, b);

            return(key);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                SubscribedTableKey[] tableRefs;


                string items = txtBoxSubsciptionItems.Text;
                subsciptionmdoe = comboBoxSubscriptionMode.Text;
                schecmName      = textboxSchema.Text;



                DialogResult dialogresult = MessageBox.Show("Subscribe to items : " + items, "Subscription", MessageBoxButtons.YesNo);

                if (dialogresult == DialogResult.No)
                {
                    return;
                }

                SimpleTableInfo tableInfo = new SimpleTableInfo(
                    items,
                    subsciptionmdoe,
                    schecmName,
                    true
                    );

                tableInfo.DataAdapter = txtboxFeedAdatperName.Text;



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


                tableRefs = new SubscribedTableKey[] { tableRef };
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }

            //try
            //{
            //    SubscribedTableKey[] tableRefs;


            //    string items = txtBoxSubsciptionItems.Text;
            //    subsciptionmdoe = comboBoxSubscriptionMode.Text;
            //    schecmName = textboxSchema.Text;



            //    string[] itemsArr = items.Split(new char[] {' '});

            //    string[] itemscodes = new string[] { "mpEGS700" };
            //    string[] schema = new string[] { "Code", "SubscriptionCode", "LastPrice", "Quantity", "RecSerial" };

            //    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
            //          itemscodes,
            //           subsciptionmdoe,
            //           schema,
            //           false
            //           );

            //    tableInfo.DataAdapter = txtboxFeedAdatperName.Text;



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


            //    tableRefs = new SubscribedTableKey[] { tableRef };
            //}
            //catch (Exception exp)
            //{
            //    MessageBox.Show(exp.ToString());
            //}
        }
Ejemplo n.º 8
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);
        }