Пример #1
0
        /// <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);
            }
        }