Exemplo n.º 1
0
        public StocklistClient(
            string pushServerUrl,
            string forceT,
            DemoForm form,
            LightstreamerUpdateDelegate lsUpdateDelegate,
            LightstreamerStatusChangedDelegate lsStatusChangeDelegate)
        {
            demoForm             = form;
            updateDelegate       = lsUpdateDelegate;
            statusChangeDelegate = lsStatusChangeDelegate;

            LightstreamerClient.setLoggerProvider(new Log4NetLoggerProviderWrapper());

            client = new LightstreamerClient(pushServerUrl, "DEMO");

            client.connectionOptions.RetryDelay = 3500;
            switch (forceT)
            {
            case "websocket":
                client.connectionOptions.ForcedTransport = "WS";
                break;

            case "http":
                client.connectionOptions.ForcedTransport = "HTTP";
                break;

            case "polling":
                client.connectionOptions.ForcedTransport = "HTTP-POLLING";
                break;

            default:
                break;
            }
        }
        public void Connect()
        {
            bool noException = true;

            // Start a new attempt to connect to Lightstreamer server.

            if (ls != null)
            {
                ls.disconnect();

                Thread.Sleep(1500);
            }

            while (noException)
            {
                try
                {
                    ls = new LightstreamerClient(pushServerUrl, adapter);

                    ls.addListener(new TestConnectionListener(this));
                    ls.connect();

                    noException = false;
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Connection failure: " + e.Message + " - " + e.StackTrace);
                }
            }
            Debug.WriteLine("Connection ... ");
        }
Exemplo n.º 3
0
        public IgStreamingApiClient(AuthenticationResponse authenticationResponse)
        {
            Contract.Requires(authenticationResponse != null);

            _accountId = authenticationResponse.CurrentAccountId;
            _lsClient  = new LightstreamerClient(authenticationResponse.LightstreamerEndpoint, "DEFAULT");
            _lsClient.connectionDetails.AdapterSet    = "DEFAULT";
            _lsClient.connectionDetails.User          = authenticationResponse.CurrentAccountId;
            _lsClient.connectionDetails.Password      = $"CST-{authenticationResponse.Cst}|XST-{authenticationResponse.XSecurityToken}";
            _lsClient.connectionDetails.ServerAddress = authenticationResponse.LightstreamerEndpoint;
        }
 public static void Stop(SubscribedTableKey tableKey)
 {
     lock (mutex)
     {
         if (client != null)
         {
             client.Stop(tableKey);
         }
         client = null;
     }
 }
        public void Disconnect()
        {
            if (ls == null)
            {
                return;
            }

            ls.disconnect();

            ls = null;
        }
 public MyConnector(string host, string adapter_set)
 {
     try
     {
         this.client = new LightstreamerClient(host, adapter_set);
         var clientListener = new MyListener(client.connectionDetails.AdapterSet);
         client.connectionOptions.ForcedTransport = "WS-STREAMING";
         client.addListener(clientListener);
     }
     catch (Exception e)
     {
         System.Console.WriteLine("Errore Create. " + e.Message);
     }
 }
 public static SubscribedTableKey Startup(ILightstreamerListener listener, string[] items)
 {
     lock (mutex)
     {
         if (client == null)
         {
             Debug.Log("Loading Lightstreamer Singleton");
             client = new LightstreamerClient();
             client.Start(pushServerHost);
         }
         SubscribedTableKey tableKey = client.AppendListener(listener, items, fields);
         return(tableKey);
     }
 }
Exemplo n.º 8
0
        public void Test2()
        {
            
            var authenticatedClient = new CIAPI.Rpc.Client(new Uri(apiUrl));
            authenticatedClient.LogIn(userName, password);


            var client = new LightstreamerClient(streamingUrl, authenticatedClient.UserName, authenticatedClient.Session);

            client.StatusUpdate += AdapterStatusUpdate;

            var listener = client.BuildListener<PriceDTO>(dataAdapter, topic);
            listener.MessageReceived += ListenerMessageReceived;

            new ManualResetEvent(false).WaitOne(20000);

            client.TearDownListener(listener);

            client.Dispose();


        }
 void ClientListener.onListenStart(LightstreamerClient client)
 {
     // ...
 }
 void ClientListener.onListenEnd(LightstreamerClient client)
 {
     // ...
 }
Exemplo n.º 11
0
 public virtual void onListenEnd(LightstreamerClient client)
 {
 }
 void ClientListener.onListenStart(LightstreamerClient client)
 {
     //OnClientUpdateHandler(new ClientListenerEventArgs(DateTime.Now, $"Listen start"));
 }
 public ClientListenerStartEvent(LightstreamerClient client)
 {
     this.client = client;
 }
 public void onListenStart(LightstreamerClient client)
 {
     Debug.WriteLine("Listen Start - " + client.Status + " - ");
 }
Exemplo n.º 15
0
 public virtual void onListenStart(LightstreamerClient client)
 {
 }
Exemplo n.º 16
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            Console.WriteLine("Start same three ls ... " + args[0]);

            var config  = new NLog.Config.LoggingConfiguration();
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = "Test.log"
            };
            var logconsole = new NLog.Targets.ConsoleTarget("logconsole");

            // config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Warn, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile);

            NLog.LogManager.Configuration = config;

            // InternalLoggerFactory.DefaultFactory.AddProvider(new ConsoleLoggerProvider((s, level) => true, false));

            LightstreamerClient.setLoggerProvider(new Log4NetLoggerProviderWrapper());

            var ls1 = new MyConnector("https://push.lightstreamer.com", "DEMO");
            var ls2 = new MyConnector("https://push.lightstreamer.com", "WELCOME");
            var ls3 = new MyConnector("http://push.lightstreamer.com", "MARKETDEPTH");
            var ls4 = new MyConnector("http://localhost:8080", "ROUNDTRIPDEMO");
            var ls5 = new MyConnector("http://localhost:8080", "WELCOME");

            if (args[0].StartsWith("yes"))
            {
                Environment.SetEnvironmentVariable("io.netty.allocator.maxOrder", "1");
                Environment.SetEnvironmentVariable("io.netty.allocator.type", "unpooled");

                System.Console.WriteLine("Tuned DotNetty.");
            }

            while (true)
            {
                //var ls1 = new MyConnector("https://push.lightstreamer.com", "DEMO");
                //var ls2 = new MyConnector("https://push.lightstreamer.com", "WELCOME");
                //var ls3 = new MyConnector("http://push.lightstreamer.com", "MARKETDEPTH");
                //var ls4 = new MyConnector("http://localhost:8080", "ROUNDTRIPDEMO");
                //var ls5 = new MyConnector("http://localhost:8080", "PORTFOLIODEMO");

                var connectTasks = new List <Task>();
                var subTasks     = new List <Task>();

                connectTasks.Add(ls1.Connect(new CancellationTokenSource(7000).Token));
                connectTasks.Add(ls2.Connect(new CancellationTokenSource(7000).Token));
                connectTasks.Add(ls3.Connect(new CancellationTokenSource(7000).Token));
                connectTasks.Add(ls4.Connect(new CancellationTokenSource(7000).Token));
                connectTasks.Add(ls5.Connect(new CancellationTokenSource(7000).Token));

                var allTasksAwaiter = Task.WhenAll(connectTasks);

                try
                {
                    allTasksAwaiter.Wait();
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("ERRORE ********** " + e.Message);
                }

                subTasks.Add(ls1.Subscribe("MERGE", "QUOTE_ADAPTER", new string[2] {
                    "item2", "item16"
                }, new string[2] {
                    "last_price", "time"
                }, new CancellationTokenSource(5000).Token));
                subTasks.Add(ls2.Subscribe("MERGE", "STOCKS", new string[2] {
                    "item1", "item5"
                }, new string[1] {
                    "stock_name"
                }, new CancellationTokenSource(5000).Token));
                subTasks.Add(ls3.Subscribe("MERGE", null, new string[1] {
                    "AXY_COMP"
                }, new string[1] {
                    "trading_phase"
                }, new CancellationTokenSource(5000).Token));
                subTasks.Add(ls4.Subscribe("MERGE", "ROUNDTRIP_ADAPTER", new string[1] {
                    "roundtrip3"
                }, new string[2] {
                    "message", "IP"
                }, new CancellationTokenSource(5000).Token));
                subTasks.Add(ls5.Subscribe("MERGE", "STOCKS", new string[2] {
                    "item2", "item4"
                }, new string[1] {
                    "stock_name"
                }, new CancellationTokenSource(5000).Token));

                var allSubTasksAwaiter = Task.WhenAll(subTasks);

                try
                {
                    allSubTasksAwaiter.Wait();
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("ERRORE ********** " + e.Message);
                }

                ls1.disconnectAsync(false);
                ls2.disconnectAsync(false);
                ls3.disconnectAsync(false);
                ls4.disconnectAsync(false);
                await ls5.disconnectAsync(true);

                Thread.Sleep(5000);

                System.Console.WriteLine("Memory usage :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" + GC.GetTotalMemory(true));

                Thread.Sleep(5000);
            }
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start TwoLevel Push example");

            if (args.Length < 2)
            {
                Console.WriteLine("Arguments missing. Exit.");

                Thread.Sleep(7000);

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

            Thread.Sleep(2000);
            if (pushServerPort > 0)
            {
                Console.WriteLine("Opening Lightstreamer connection (" + pushServerHost + ":" + pushServerPort + ")");
                myClient = new LightstreamerClient("http://" + pushServerHost + ":" + pushServerPort, "DEMO");
            }
            else
            {
                Console.WriteLine("Opening Lightstreamer connection (" + pushServerHost + ")");
                myClient = new LightstreamerClient("https://" + pushServerHost, "DEMO");
            }

            TestConnectionListener myConnectionListener = new TestConnectionListener();

            myClient.addListener(myConnectionListener);

            try
            {
                myClient.connect();
            }
            catch (Exception eu)
            {
                Console.WriteLine("Error: " + eu.Message + ". Exit.");

                Thread.Sleep(7000);

                return;
            }

            while (!myConnectionListener.isSessionStarted())
            {
                Thread.Sleep(70);
            }

            Console.WriteLine("Go for the subscribe.");

            Subscription sub = new Subscription("COMMAND", "portfolio1", new String[] { "key", "command", "qty" });

            sub.DataAdapter                   = "PORTFOLIO_ADAPTER";
            sub.RequestedSnapshot             = "yes";
            sub.CommandSecondLevelDataAdapter = "QUOTE_ADAPTER";
            sub.CommandSecondLevelFields      = new String[] { "stock_name", "last_price", "time" }; //the key values from the 1st level are used as item names for the second level

            sub.addListener(new SystemOutSubscriptionListener(myClient, "portfolio1"));

            myClient.subscribe(sub);


            Thread.Sleep(5000);

            while (true)
            {
                Thread.Sleep(20);
            }
        }
 public SystemOutSubscriptionListener(LightstreamerClient myClient, string v)
 {
     this.myClient = myClient;
     this.v        = v;
 }
 public void onListenStart(LightstreamerClient client)
 {
     // throw new NotImplementedException();
 }
Exemplo n.º 20
0
 public void onListenStart(LightstreamerClient client)
 {
     M(enmMessageType.Debug, $"IGClientListener.onListenStart date={DateTime.Now}, status={client.Status}, listeners={client.Listeners.Count}, subscriptions={client.Subscriptions.Count}");
 }
Exemplo n.º 21
0
 public void SetUp()
 {
     _lightstreamerClient = new PartialLightstreamerClient(new Uri("http://some.sever.com/"), "", "");
 }
Exemplo n.º 22
0
 public IGStreamingApiClient(string endpoint)
 {
     _client = new LightstreamerClient(endpoint, null);
 }