Beispiel #1
0
        public static void TestPostmanThread()
        {
            ILoggerFactory loggerFactory = new LoggerFactory()
                                           .AddConsole()
                                           .AddDebug();

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            IConfigurationRoot config = builder.Build();

            ILogger <PostmanThread> logger = loggerFactory.CreateLogger <PostmanThread>();

            PostmanThread postmanThread = new PostmanThread(logger);
            var           stock         = "PETR4";

            postmanThread.AddChannelHandle(stock, Streaming.Crystal.Model.Type.MarketMessageType.MINI_BOOK,
                                           new FakeUserChannelNotification(delegate(MessageBase msg)
            {
                BookMessageSerialize book = msg as BookMessageSerialize;
                //logger.LogInformation($"book.id = {book.Id}");
                //logger.LogInformation($"buy.count = {book.Buy.Count}");
                //logger.LogInformation($"sell.count = {book.Sell.Count}");

                for (int i = 0; i < 5; i++)
                {
                    var buy  = book.Buy[i];
                    var sell = book.Sell[i];
                    logger.LogInformation($"buy price: {buy.Price} - qtd: {buy.Qtd} - date: {buy.DateAndTime}::::::" +
                                          $"sell price: {sell.Price} - qtd: {sell.Qtd} - date: {sell.DateAndTime}");
                }

                return(true);
            }));

            IConnectionManager manager = new ConnectionManager(loggerFactory, config, new DirectNoficationMessage(postmanThread));

            ICrystalConnection conn = manager.NextConnection(); //CreateCrystalConnection(loggerFactory, postmanThread);

            conn.Connected += delegate(bool connected, EventArgs e)
            {
                if (connected)
                {
                    conn.Write(MessageFactoryCMP.SubscribeMiniBook(stock));
                }
            };

            if (conn.IsConnected())
            {
                conn.Write(MessageFactoryCMP.SubscribeMiniBook(stock));
            }
        }
Beispiel #2
0
        private void AddDependencyInjectionServicesMkt(IServiceCollection services)
        {
            var serviceProvider            = services.BuildServiceProvider();
            ILogger <PostmanThread> logger = serviceProvider.GetService <ILogger <PostmanThread> >();

            PostmanThread instance = new PostmanThread(logger);

            services.AddSingleton <IQueueMessageBox, PostmanThread>(provider => instance);
            services.AddSingleton <IRegisterChannelHandle, PostmanThread>(provider => instance);
            services.AddSingleton <CrystalConnectionMessageHandle, DirectNoficationMessage>();
            services.AddSingleton <IConnectionManager, ConnectionManager>();
            services.AddSingleton <IMarketStreamingFaced, MarketStreamingFaced>();
        }
Beispiel #3
0
        public static ICrystalDifusionConnectionBase CreateCrystalConnection(ILoggerFactory loggerFactory, PostmanThread postmanThread)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            IConfigurationRoot config = builder.Build();

            string user = config.GetSection("CrystalUserName").Value;
            string pass = config.GetSection("CrystalPassword").Value;

            IEnumerable <string> hosts = config.GetSection("CrystalHosts")
                                         .GetChildren()
                                         .Select(x => x.Value)
                                         .ToArray();

            string host = hosts.FirstOrDefault();
            int    port = config.GetSection("CrystalPort").Value != null?Convert.ToInt16(config.GetSection("CrystalPort").Value) : 81;

            DifusionCredential credential = new DifusionCredential(user, pass, "");

            ILogger <ICrystalDifusionConnectionBase>  logger     = loggerFactory.CreateLogger <ICrystalDifusionConnectionBase>();
            ILogger <CrystalDifusionConnectionEvents> loggerConn = loggerFactory.CreateLogger <CrystalDifusionConnectionEvents>();

            ListCircular <string> listCircular = new ListCircular <string>();

            listCircular.Add(host);

            ICrystalDifusionConnectionBase conn = new CrystalDifusionConnectionBase(new Streaming.Crystal.Connection.Manager.CrystalAddress(listCircular, port), logger);

            connEvent = new CrystalDifusionConnectionEvents(conn, new DirectNoficationMessage(postmanThread), loggerConn, "1", credential, new CrystalConnectionStatistics());

            return(conn);
        }