/// <summary> /// Process inbound messages. /// /// Take the message and turn them into Orders. Ensure that our local Order cache is updated /// with the latest status. /// /// </summary> /// <param name="message"></param> public void InboundApp(IMessage message) { try { var textMessage = message as ITextMessage; if (textMessage != null) { var appMessage = MessageUtil.ExtractRecord(textMessage.Text); MessageUtil.AddOriginalMessageID(textMessage.Properties["JmsOriginalMessageID"] as string, appMessage); MessageUtil.AddMessageID(textMessage.NMSMessageId, appMessage); // TODO We need to purge these at some time lock (receivedMessages) { receivedMessages.Add(appMessage); Console.WriteLine("Stored response for " + textMessage.Properties["JmsOriginalMessageID"]); } lock (this) { var receivedOrder = new Order(appMessage); var cacheKey = receivedOrder.CacheKey.ToUpper(CultureInfo.InvariantCulture); var cachedOrder = GetOrderByKey(cacheKey); // We already sent the order and it was accepted (persisted) if (cachedOrder != null) { if (cachedOrder.Status == "NEW" && receivedOrder.Status == "INVALID") { //RemoveOrder(cachedOrder); AddOrder(cachedOrder.MergeWith(receivedOrder)); } else { AddOrder(cachedOrder.MergeWith(receivedOrder)); } } else { AddOrder(receivedOrder); } if (UpdatedOrder != null && cacheKey != null) { UpdatedOrder(cacheKey); } log.Info("Updating order:" + cacheKey + " to " + receivedOrder.Status); } } } catch (Exception e) { log.Error("Problem processing inbound message", e); } }
/// <summary> /// Process inbound messages. /// /// Take the message and turn them into Orders. Ensure that our local Order cache is updated /// with the latest status. /// /// </summary> /// <param name="message"></param> public void InboundApp(IMessage message) { try { var textMessage = message as ITextMessage; if (textMessage != null) { var appMessage = MessageUtil.ExtractRecord(textMessage.Text); MessageUtil.AddOriginalMessageID(textMessage.Properties["JmsOriginalMessageID"] as string, appMessage); MessageUtil.AddMessageID(textMessage.NMSMessageId, appMessage); // TODO We need to purge these at some time lock (receivedMessages) { receivedMessages.Add(appMessage); //Console.WriteLine("Stored response for " + textMessage.Properties["JmsOriginalMessageID"]); } lock (orders) { var receivedOrder = new Order(appMessage); var clientOrderID = receivedOrder.ClientOrderID.ToUpper(); var cachedOrder = GetOrderByClientOrderID(clientOrderID); // We already sent the order and it was accepted (persisted) if (cachedOrder != null) { if (cachedOrder.Status == "NEW" && receivedOrder.Status == "INVALID") { //RemoveOrder(cachedOrder); AddOrder(cachedOrder.MergeWith(receivedOrder)); } else { AddOrder(cachedOrder.MergeWith(receivedOrder)); } } else { AddOrder(receivedOrder); } if (UpdatedOrder != null) { UpdatedOrder(clientOrderID); } } } } catch (Exception e) { Console.WriteLine(e); } }