public static void TPCMFrame(byte sa, byte[] payload)
        {
            if (payload[0] != (byte)ControlByte.BAM)
            {
                throw new ArgumentException(string.Format("Control byte {0}", (ControlByte)payload[0]));
            }

            TPMessage msg       = null;
            TPMessage tpMessage = new TPMessage(payload);

            lock (mTPMessages)
            {
                try
                {
                    if (mTPMessages.TryGetValue(sa, out msg))
                    {
                        mTPMessages.Remove(sa);
                    }
                    mTPMessages.Add(sa, tpMessage);
                    //Console.WriteLine(tpMessage);
                }
                catch (Exception e) { CNXLog.ErrorFormat("TPCMFrame {0}", e.ToString()); }
            }

            if (msg != null)
            {
                throw new IncompleteTPMessageException(string.Format("SA {0} PGN {1}", sa, msg.PGN));
            }
        }
        public static TPMessage TPDataFrame(byte sa, byte[] payload)
        {
            //Console.WriteLine("TPDataFrame SA {0} packet {1}", sa, payload[0]);

            TPMessage msg = null;

            lock (mTPMessages)
            {
                try
                {
                    if (!mTPMessages.TryGetValue(sa, out msg))
                    {
                        Console.WriteLine("Missing BAM for this SA {0}", sa);
                    }
                }
                catch (Exception e) { CNXLog.ErrorFormat("TPDataFrame {0}", e.ToString()); }
            }

            if (msg == null)
            {
                throw new ArgumentOutOfRangeException(string.Format("Missing BAM for this SA {0}", sa));
            }

            try
            {
                if (msg.NextSequence(payload))
                {
                    lock (mTPMessages)
                    {
                        try
                        {
                            mTPMessages.Remove(sa);
                        }
                        catch (Exception e) { CNXLog.ErrorFormat("TPDataFrame {0}", e.ToString()); }
                    }
                    return(msg);
                }
            }
            catch (Exception e)
            {
                lock (mTPMessages)
                {
                    try
                    {
                        mTPMessages.Remove(sa);
                    }
                    catch (Exception ee) { CNXLog.ErrorFormat("TPDataFrame {0}", ee.ToString()); }
                }
                throw e;
            }

            return(null);
        }
 internal IBroadcastMessage CreateSETMessage(string message)
 {
     IBroadcastMessage result;
     try
     {
         string text = message.Substring(0, 2);
         switch (text)
         {
         case "TP":
             result = new TPMessage(message);
             return result;
         case "L+":
             result = new LSAccumulate(message);
             return result;
         case "PO":
             result = new POMessage(message);
             return result;
         case "B+":
             result = new BCTextMessage(message);
             return result;
         case "IS":
             result = new ISMessage(message);
             return result;
         case "IE":
             result = new IEMessage(message);
             return result;
         case "LO":
             this.loMessage.Unpack(message);
             result = this.loMessage;
             return result;
         case "MT":
             result = new MarketInfo(message);
             return result;
         case "PD":
             this.pdMessage.Unpack(message);
             result = this.pdMessage;
             return result;
         case "SC":
             this.scMessage.Unpack(message);
             result = this.scMessage;
             return result;
         case "SS":
             result = new SSMessage(message);
             return result;
         case "AA":
             this.aaMessage.Unpack(message);
             result = this.aaMessage;
             return result;
         case "NH":
             this.nhMessage.Unpack(message);
             result = this.nhMessage;
             return result;
         case "BA":
             result = new BAMessage(message);
             return result;
         case "0I":
             result = new OrderInfoClient(message);
             return result;
         case "0B":
             this.broadcastMessageClient.Unpack(message);
             result = this.broadcastMessageClient;
             return result;
         case "0G":
             this.dgwOrderReply.Unpack(message);
             result = this.dgwOrderReply;
             return result;
         }
         result = null;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return result;
 }
        public void UpdateVolum(TPMessage msgLS, StockList.StockInformation realtimeStockInfo)
        {
            foreach (LocalAutoTradeItem item in this._itemList)
            {
                if (item.StockName == realtimeStockInfo.Symbol &&
                    item.Status == AutoTradeConstant.STATUS_WAIT)
                {
                    if (msgLS.Side == "B")
                    {
                        item.FirstBidVol = msgLS.Volume1;
                        item.SecondBidVol = msgLS.Volume2;
                    }
                    else if (msgLS.Side == "S")
                    {
                        item.FirstOfferVol = msgLS.Volume1;
                        item.SecondOfferVol = msgLS.Volume2;
                    }
                    else
                    {
                        //Don't know if there is any side
                    }

                }
            }
        }
 private void AddItem(TPMessage msgTP, string symbol)
 {
     if (this.IsMonitoring)
     {
         lock (((ICollection)this._bcMessages).SyncRoot)
         {
             this._bcMessages.Enqueue(new AlertManager.AlertBcItem(msgTP.MessageType, symbol, msgTP.Side, msgTP.Price1));
         }
     }
 }