public List <Stock> GetDataUsingDataContract() { string host = "localhost"; int reqrepPort = 6661; int notifPort = 6662; try { DataProviderServer server = new DataProviderServer(); server.Adapter = new StockAdapter(); TcpClient reqrepSocket = new TcpClient(host, reqrepPort); server.RequestStream = reqrepSocket.GetStream(); server.ReplyStream = reqrepSocket.GetStream(); TcpClient notifSocket = new TcpClient(host, notifPort); server.NotifyStream = notifSocket.GetStream(); server.Start(); System.Console.WriteLine("Remote Adapter connected to Lightstreamer Server."); System.Console.WriteLine("Ready to publish data..."); } catch (Exception e) { System.Console.WriteLine("Could not connect to Lightstreamer Server."); System.Console.WriteLine("Make sure Lightstreamer Server is started before this Adapter."); System.Console.WriteLine(e); } return(new List <Stock>()); }
public static void Main(string[] args) { try { // Startup Provider and Connect to LightStreamer Server. string host = System.Configuration.ConfigurationManager.AppSettings.Get("LsServerIP"); int reqrepPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get("LsRequestPort")); int notifPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get("LsNotifyPort")); DataAadapter feedDataAdapter = new DataAadapter(); feedDataAdapter.Initialize(); feedDataAdapter.ConnectToFeedProvider(); DataProviderServer server = new DataProviderServer(); server.Adapter = feedDataAdapter; TcpClient reqrepSocket = new TcpClient(host, reqrepPort); server.RequestStream = reqrepSocket.GetStream(); server.ReplyStream = reqrepSocket.GetStream(); TcpClient notifSocket = new TcpClient(host, notifPort); server.NotifyStream = notifSocket.GetStream(); server.Start(); m_NLog.Info("Remote DataAdapter connected succssfully to LS on IP {0} and Port {1}", host, reqrepPort); Console.ReadLine(); } catch (Exception exp) { m_NLog.Warn("Make sure Lightstreamer Server is started before this Adapter."); m_NLog.Error("Error : Could not connect to Lightstreamer Server. Error Details : {0}", exp.ToString()); Console.ReadLine(); } }
public static void Main(string[] args) { var config = new NLog.Config.LoggingConfiguration(); var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "TestAdapter.log" }; var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile); NLog.LogManager.Configuration = config; if (args.Length == 0) { Help(); } _log.Info("Lightstreamer PortfolioDemo .NET Adapter Custom Server starting..."); Server.SetLoggerProvider(new Log4NetLoggerProviderWrapper()); IDictionary parameters = new Hashtable(); string host = null; int rrPortMD = -1; int rrPortD = -1; int notifPortD = -1; string name = null; for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.StartsWith(PREFIX1) || arg.StartsWith(PREFIX2)) { arg = arg.Substring(1).ToLower(); if (arg.Equals(ARG_HELP_SHORT) || arg.Equals(ARG_HELP_LONG)) { Help(); } else if (arg.Equals(ARG_HOST)) { i++; host = args[i]; _log.Debug("Found argument: '" + ARG_HOST + "' with value: '" + host + "'"); } else if (arg.Equals(ARG_METADATA_RR_PORT)) { i++; rrPortMD = Int32.Parse(args[i]); _log.Debug("Found argument: '" + ARG_METADATA_RR_PORT + "' with value: '" + rrPortMD + "'"); } else if (arg.Equals(ARG_DATA_RR_PORT)) { i++; rrPortD = Int32.Parse(args[i]); _log.Debug("Found argument: '" + ARG_DATA_RR_PORT + "' with value: '" + rrPortD + "'"); } else if (arg.Equals(ARG_DATA_NOTIF_PORT)) { i++; notifPortD = Int32.Parse(args[i]); _log.Debug("Found argument: '" + ARG_DATA_NOTIF_PORT + "' with value: '" + notifPortD + "'"); } else if (arg.Equals(ARG_NAME)) { i++; name = args[i]; _log.Debug("Found argument: '" + ARG_NAME + "' with value: '" + name + "'"); } } else { int sep = arg.IndexOf(SEP); if (sep < 1) { _log.Warn("Skipping unrecognizable argument: '" + arg + "'"); } else { string par = arg.Substring(0, sep).Trim(); string val = arg.Substring(sep + 1).Trim(); parameters[par] = val; _log.Debug("Found parameter: '" + par + "' with value: '" + val + "'"); } } } PortfolioFeedSimulator feed = new PortfolioFeedSimulator(); // A reference to the feed simulator will be supplied // to both the Data and the Matedata Adapters. try { { MetadataProviderServer server = new MetadataProviderServer(); Lightstreamer.Adapters.PortfolioDemo.Metadata.PortfolioMetadataAdapter adapter = new Lightstreamer.Adapters.PortfolioDemo.Metadata.PortfolioMetadataAdapter(); // We complete the Metadata Adapter initialization by supplying // a reference to the feed simulator through a custom method; // for this reason, the Portfolio Demo Metadata Adapter // does not support the basic DotNetServer.exe launcher // provided by LS library, adapter.SetFeed(feed); server.Adapter = adapter; server.AdapterParams = parameters; // server.AdapterConfig not needed by PortfolioMetadataAdapter if (name != null) { server.Name = name; } _log.Debug("Remote Metadata Adapter initialized"); ServerStarter starter = new ServerStarter(host, rrPortMD, -1); starter.Launch(server); } { DataProviderServer server = new DataProviderServer(); Lightstreamer.Adapters.PortfolioDemo.Data.PortfolioAdapter adapter = new Lightstreamer.Adapters.PortfolioDemo.Data.PortfolioAdapter(); // We complete the Data Adapter initialization by supplying // a reference to the feed simulator through a custom method; // for this reason, the Portfolio Demo Data Adapter // does not support the basic DotNetServer.exe launcher // provided by LS library, adapter.SetFeed(feed); server.Adapter = adapter; // server.AdapterParams not needed by PortfolioAdapter // server.AdapterConfig not needed by PortfolioAdapter if (name != null) { server.Name = name; } _log.Debug("Remote Data Adapter initialized"); ServerStarter starter = new ServerStarter(host, rrPortD, notifPortD); starter.Launch(server); } } catch (Exception e) { _log.Fatal("Exception caught while starting the server: " + e.Message + ", aborting...", e); } _log.Info("Lightstreamer PortfolioDemo .NET Adapter Custom Server running"); }
public static void Main(string[] args) { var config = new NLog.Config.LoggingConfiguration(); var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "TestAdapter.log" }; var logconsole = new NLog.Targets.ConsoleTarget("logconsole"); config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole); config.AddRule(LogLevel.Info, LogLevel.Fatal, logfile); NLog.LogManager.Configuration = config; if (args.Length == 0) { Help(); } nLog.Info("Lightstreamer StockListDemo .NET Adapter Standalone Server starting ..."); Server.SetLoggerProvider(new Log4NetLoggerProviderWrapper()); IDictionary parameters = new Hashtable(); string host = null; bool isTls = false; int rrPortMD = -1; int rrPortD = -1; int notifPortD = -1; string username = null; string password = null; string name = null; for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.StartsWith(PREFIX1) || arg.StartsWith(PREFIX2)) { arg = arg.Substring(1).ToLower(); if (arg.Equals(ARG_HELP_SHORT) || arg.Equals(ARG_HELP_LONG)) { Help(); } else if (arg.Equals(ARG_HOST)) { i++; host = args[i]; nLog.Debug("Found argument: '" + ARG_HOST + "' with value: '" + host + "'"); } else if (arg.Equals(ARG_TLS)) { isTls = true; nLog.Debug("Found argument: '" + ARG_TLS + "'"); } else if (arg.Equals(ARG_METADATA_RR_PORT)) { i++; rrPortMD = Int32.Parse(args[i]); nLog.Debug("Found argument: '" + ARG_METADATA_RR_PORT + "' with value: '" + rrPortMD + "'"); } else if (arg.Equals(ARG_DATA_RR_PORT)) { i++; rrPortD = Int32.Parse(args[i]); nLog.Debug("Found argument: '" + ARG_DATA_RR_PORT + "' with value: '" + rrPortD + "'"); } else if (arg.Equals(ARG_DATA_NOTIF_PORT)) { i++; notifPortD = Int32.Parse(args[i]); nLog.Debug("Found argument: '" + ARG_DATA_NOTIF_PORT + "' with value: '" + notifPortD + "'"); } else if (arg.Equals(ARG_USER)) { i++; username = args[i]; nLog.Debug("Found argument: '" + ARG_USER + "' with value: '" + username + "'"); } else if (arg.Equals(ARG_PASSWORD)) { i++; password = args[i]; nLog.Debug("Found argument: '" + ARG_PASSWORD + "' with value: '" + password + "'"); } else if (arg.Equals(ARG_NAME)) { i++; name = args[i]; nLog.Debug("Found argument: '" + ARG_NAME + "' with value: '" + name + "'"); } } else { int sep = arg.IndexOf(SEP); if (sep < 1) { nLog.Warn("Skipping unrecognizable argument: '" + arg + "'"); } else { string par = arg.Substring(0, sep).Trim(); string val = arg.Substring(sep + 1).Trim(); parameters[par] = val; nLog.Debug("Found parameter: '" + par + "' with value: '" + val + "'"); } } } try { if ((username != null) != (password != null)) { throw new Exception("Incomplete setting of /user and /password arguments"); } { MetadataProviderServer server = new MetadataProviderServer(); server.Adapter = new Lightstreamer.Adapters.Metadata.LiteralBasedProvider(); server.AdapterParams = parameters; // server.AdapterConfig not needed by LiteralBasedProvider if (parameters["name"] != null) { server.Name = "Test:LBP"; } if (username != null) { server.RemoteUser = username; server.RemotePassword = password; } nLog.Debug("Remote Metadata Adapter initialized"); ServerStarter starter = new ServerStarter(host, isTls, rrPortMD, -1); starter.Launch(server); } { DataProviderServer server = new DataProviderServer(); server.Adapter = new Lightstreamer.Adapters.StockListDemo.Data.StockListDemoAdapter(); // server.AdapterParams not needed by StockListDemoAdapter // server.AdapterConfig not needed by StockListDemoAdapter if (name != null) { server.Name = name; } if (username != null) { server.RemoteUser = username; server.RemotePassword = password; } nLog.Debug("Remote Data Adapter initialized"); ServerStarter starter = new ServerStarter(host, isTls, rrPortD, notifPortD); starter.Launch(server); } } catch (Exception e) { nLog.Fatal("Exception caught while starting the server: " + e.Message + ", aborting...", e); } nLog.Info("Lightstreamer StockListDemo .NET Adapter Standalone Server running"); }