private void NotifyBook(BookMessageSerialize book) { if (IsNotifyMessage(book) && messageListeners.TryGetValue(new CommandKey(book.Type, book.Id), out IEnumerable <IUserChannelNotification> listeners)) { foreach (var listener in listeners) { listener.Arrived(book); } } }
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)); } }
private bool IsNotifyMessage(BookMessageSerialize book) { return(book.IsEndLoad); }