/// <summary> /// Process a message and enqueues in another message queue /// </summary> /// <param name="message"></param> public void ProcessMessage(string message) { StockMessage messageObject = JsonConvert.DeserializeObject <StockMessage>(message); var quote = GetQuoteForStock(messageObject.Text); messageObject.Text = quote; MQClient.Send("stockResponse", JsonConvert.SerializeObject(messageObject)); }
/// <summary> /// Publish a message coming from the queue /// </summary> /// <param name="message"></param> /// <returns></returns> public static void PublishMessageFromQueue(string message) { StockMessage messageObject = JsonConvert.DeserializeObject <StockMessage>(message); var time = DateTime.Now.ToString("yyyy-MM-dd, hh:mm:ss"); var context = GlobalHost.ConnectionManager.GetHubContext <ChatRoom>(); var onlineClient = context.Clients.Client(messageObject.UserId); onlineClient.printMessage("ChatBot", messageObject.Text, "result", time); }
public StockMessage Deserialize(byte[] messageBytes) { StockMessage message = null; //using (var stream = new MemoryStream(messageBytes)) //{ //using (var output = new CodedOutputStream(stream)) //{ message = StockMessage.Parser.ParseFrom(messageBytes); // message.WriteTo(stream); //} //} return(message); }
public byte[] Serialize(StockMessage message) { byte[] messageBytes = null; using (var stream = new MemoryStream()) { //using (var output = new CodedOutputStream(stream)) //{ message.WriteTo(stream); messageBytes = stream.ToArray(); //} } return(messageBytes); }
/// <summary> /// Receives a message to be sent to all the audience or a command for the bot /// </summary> /// <param name="userName">The user initiating the action</param> /// <param name="message">The message to be delivered or the command</param> /// <param name="time">String representation of the time when the message was submitted</param> public void ProcessInput(string userName, string message) { var time = DateTime.Now.ToString("yyyy-MM-dd, hh:mm:ss"); var userId = Context.ConnectionId; if (CommandParser.IsCommand(message)) { // This is a command for the bot var stockValue = CommandParser.GetStockFromCommand(message); // Build the message for the queue StockMessage messageObject = new StockMessage { Text = stockValue, UserId = userId, UserName = userName }; // Write the request in the outgoing message queue MQClient.Send("stockRequest", JsonConvert.SerializeObject(messageObject)); var onlineClient = Clients.Client(userId); onlineClient.printMessage(userName, message, "command", time); } else { // This is a message for the audience // Add new message to the cache MessagesCache.Add(new Message { Owner = userName, TextMessage = message, Time = time }); // Controls the messages cache not growing over 50 elements if (MessagesCache.Count > 50) { MessagesCache.RemoveAt(0); } // Persist message to DB? // Broad cast message Clients.All.printMessage(userName, message, "normal", time); } }
public StockMessage GetMessage(string symbol, string city, string marketSymbol) { var message = new StockMessage { Symbol = symbol, Id = Guid.NewGuid().ToString(), Change = new StockChange { Price = 114.55, PriceChange = -1.08, PercentageChange = 0.05, DateTime = DateTime.UtcNow.ToString() }, Market = new Market { City = city, Symbol = marketSymbol, Status = MarketStatus.Closed } }; message.Comments.Add( new Comment { Id = 1, Title = "Fixed Item", Content = "Item has been fixed before", DateTime = DateTime.UtcNow.ToString() }); message.Comments.Add( new Comment { Id = 2, Title = "Fixed Item", Content = "Item has been fixed again", DateTime = DateTime.UtcNow.ToString() }); return(message); }