public void SendDataToClients(object ob, enmTradingEvent ev, int connId = cnstBroadCast)
        {
            byte[] arrHeader = /*CMessenger*/ _messenger.GenBinaryMessageHeader((byte)ev);

            byte[] arrBody = CUtilProto.SerializeProto(ob);

            byte[] arrMsg = new byte[arrHeader.Length + arrBody.Length];


            Buffer.BlockCopy(arrHeader, 0, arrMsg, 0, arrHeader.Length);


            Buffer.BlockCopy(arrBody, 0, arrMsg, arrHeader.Length, arrBody.Length);
            if (connId == cnstBroadCast)
            {
                foreach (KeyValuePair <int, CTradeManagerLink> kvp in _dictConIdTradeMgrLink)
                {
                    if (kvp.Value.IsLoggedOn)
                    {
                        _tcpServer.SendMessage(kvp.Key, arrMsg);
                    }
                }
            }
            else
            {
                _tcpServer.SendMessage(connId, arrMsg);
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates message of specificated format (header, body) and writes message to tcpClient.
        ///
        ///
        ///
        /// Call from:
        /// 1) Internal class methods
        /// 2) From MarketViewModel
        /// </summary>
        /// <param name="conId"></param>
        /// <param name="ob"></param>
        /// <param name="ev"></param>
        public void SendDataToServer(int conId, object ob, enmTradingEvent ev)
        {
            CTCPClient tcpClient = null;

            if (GetTCPClient(conId, out tcpClient))
            {
                byte[] arrHeader = _messenger.GenBinaryMessageHeader((byte)ev);
                byte[] arrBody   = CUtilProto.SerializeProto(ob);

                byte[] arrMsg = new byte[arrHeader.Length + arrBody.Length];

                Buffer.BlockCopy(arrHeader, 0, arrMsg, 0, arrHeader.Length);
                Buffer.BlockCopy(arrBody, 0, arrMsg, arrHeader.Length, arrBody.Length);

                tcpClient.WriteMessage(arrMsg);
            }
        }
        // connId == -1 for all else for specific connId

        public void SendDataToClients(object ob, enmTradingEvent ev, string isin, int connId = cnstBroadCast)
        {
            try
            {
                Stopwatch sw2_1 = new Stopwatch();
                Stopwatch sw2_2 = new Stopwatch();
                Stopwatch sw2_3 = new Stopwatch();
                //Stopwatch sw2_4 = new Stopwatch();
                //Stopwatch sw2_5 = new Stopwatch();
                //Stopwatch sw2_6 = new Stopwatch();



                sw2_1.Reset(); sw2_1.Start();
                sw2_2.Reset(); sw2_2.Start();
                sw2_3.Reset(); sw2_3.Start();
                //  sw2_4.Reset(); sw2_4.Start();
                //  sw2_5.Reset(); sw2_5.Start();
                //  sw2_6.Reset(); sw2_6.Start();

                byte[] arrHeader = /*CMessenger*/ _messenger.GenBinaryMessageHeader((byte)ev);
                //  sw2_6.Stop();
                // byte[] arrBody = CUtil.SerializeBinary(ob).ToArray();


                byte[] arrBody = CUtilProto.SerializeProto(ob);

                //  byte[] arrBody = (CUtil.SerializeBinaryExt(ob, ref ms, ref formatter)).ToArray();

                //sw2_5.Stop();
                byte[] arrMsg = new byte[arrHeader.Length + arrBody.Length];

                //sw2_4.Stop();
                Buffer.BlockCopy(arrHeader, 0, arrMsg, 0, arrHeader.Length);

                sw2_3.Stop();
                Buffer.BlockCopy(arrBody, 0, arrMsg, arrHeader.Length, arrBody.Length);

                sw2_2.Stop();



                //TO DO send olny subscribers that are subscribed

                if (connId == cnstBroadCast)
                {
                    foreach (KeyValuePair <int, CTrader> kvp in _dictConnIdTrader)
                    {
                        if (kvp.Value.IsLoggedOn)
                        {
                            if (ev == enmTradingEvent.SynchroniseTime || kvp.Value.SubscribedIsins.Contains(isin))
                            {
                                _tcpServer.SendMessage(kvp.Key, arrMsg);
                            }
                        }
                    }

                    sw2_1.Stop();

                    LogIsin(isin, ev + " sw2_1.Milliseconds= " + sw2_1.ElapsedMilliseconds + " s2_1.Ticks=" + sw2_1.ElapsedTicks);

                    _perfAnlzr.CheckLim(sw2_1.ElapsedMilliseconds, _perfSendDataToClient, "CTradersDispatcher.SendDataToClients sw2_1");
                    _perfAnlzr.CheckLim(sw2_2.ElapsedMilliseconds, _perfSendDataToClient, "CTradersDispatcher.SendDataToClients sw2_2");
                    _perfAnlzr.CheckLim(sw2_3.ElapsedMilliseconds, _perfSendDataToClient, "CTradersDispatcher.SendDataToClients sw2_3");
                }
                else
                {
                    _tcpServer.SendMessage(connId, arrMsg);
                }
            }
            catch (Exception e)
            {
                Error("CTradersDispatcher. Serialization", e);
            }
        }