예제 #1
0
 internal virtual void OnTDSMessageReceived(BridgedConnection bc, Message.TDSMessage msg)
 {
     if (TDSMessageReceived != null)
     {
         TDSMessageReceived(this, bc, msg);
     }
 }
예제 #2
0
        static void b_TDSMessageReceived(object sender, BridgedConnection bc, Common.Message.TDSMessage msg)
        {
            Console.WriteLine(FormatDateTime() + "|" + msg);
            if (msg is Common.Message.SQLBatchMessage)
            {
                Console.Write("\tSQLBatch message ");
                Common.Message.SQLBatchMessage b = (Common.Message.SQLBatchMessage)msg;
                string strBatchText = b.GetBatchText();
                Console.Write("({0:N0} chars worth of {1:N0} bytes of data)[", strBatchText.Length, strBatchText.Length * 2);
                Console.Write(strBatchText);
                Console.WriteLine("]");
            }
            else if (msg is Common.Message.RPCRequestMessage)
            {
                try
                {
                    Common.Message.RPCRequestMessage rpc = (Common.Message.RPCRequestMessage)msg;
                    byte[] bPayload = rpc.AssemblePayload();

                    #if DEBUG
                    //using (System.IO.FileStream fs = new System.IO.FileStream(
                    //    "C:\\temp\\dev\\" + (iRPC++) + ".raw",
                    //    System.IO.FileMode.Create,
                    //    System.IO.FileAccess.Write,
                    //    System.IO.FileShare.Read))
                    //{
                    //    fs.Write(bPayload, 0, bPayload.Length);
                    //}
                    #endif
                }
                catch (Exception exce)
                {
                    Console.WriteLine("Exception: " + exce.ToString());
                }
            }
        }
예제 #3
0
        protected virtual void ClientBridgeThread()
        {
            try
            {
                byte[] bBuffer   = null;
                byte[] bHeader   = new byte[Header.TDSHeader.HEADER_SIZE];
                int    iReceived = 0;

                Message.TDSMessage tdsMessage = null;

                while ((iReceived = SocketCouple.ClientBridgeSocket.Receive(bHeader, Header.TDSHeader.HEADER_SIZE, SocketFlags.None)) > 0)
                //while ((iReceived = sc.InputSocket.Receive(bBuffer, SocketFlags.None)) > 0)
                {
                    Header.TDSHeader header = new Header.TDSHeader(bHeader);

                    int iMinBufferSize = Math.Max(0x1000, header.LengthIncludingHeader + 1);
                    if ((bBuffer == null) || (bBuffer.Length < iMinBufferSize))
                    {
                        bBuffer = new byte[iMinBufferSize];
                    }

                    //Console.WriteLine(header.Type);

                    if (header.Type == (HeaderType)23)
                    {
                        iReceived = SocketCouple.ClientBridgeSocket.Receive(bBuffer, 0, 0x1000 - Header.TDSHeader.HEADER_SIZE, SocketFlags.None);
                    }
                    else if (header.PayloadSize > 0)
                    {
                        //Console.WriteLine("\t{0:N0} bytes package", header.LengthIncludingHeader);
                        SocketCouple.ClientBridgeSocket.Receive(bBuffer, 0, header.PayloadSize, SocketFlags.None);
                    }
                    TDSPacket tdsPacket = new TDSPacket(bHeader, bBuffer, header.PayloadSize);
                    OnTDSPacketReceived(tdsPacket);

                    if (tdsMessage == null)
                    {
                        tdsMessage = Message.TDSMessage.CreateFromFirstPacket(tdsPacket);
                    }
                    else
                    {
                        tdsMessage.Packets.Add(tdsPacket);
                    }

                    if ((header.StatusBitMask & StatusBitMask.END_OF_MESSAGE) == StatusBitMask.END_OF_MESSAGE)
                    {
                        OnTDSMessageReceived(tdsMessage);
                        tdsMessage = null;
                    }

                    SocketCouple.BridgeSQLSocket.Send(bHeader, bHeader.Length, SocketFlags.None);

                    if (header.Type == (HeaderType)23)
                    {
                        SocketCouple.BridgeSQLSocket.Send(bBuffer, iReceived, SocketFlags.None);
                    }
                    else
                    {
                        // METHOD: Converts unicode bytestream to string, modifies the DBName from the query, & converts it back
                        // Doesn't work probably due to off-by-one errors during conversions

                        // string temp = Encoding.Unicode.GetString(bBuffer);
                        // bBuffer = Encoding.Unicode.GetBytes(temp.Replace("alpha", "bravo"));

                        // Unicode representation
                        // Console.WriteLine("BYTES: " + BitConverter.ToString(bBuffer));

                        // Unicode - String conversion
                        // Console.WriteLine("BYTES TO STRING: " + Encoding.Unicode.GetString(bBuffer));

                        SocketCouple.BridgeSQLSocket.Send(bBuffer, header.PayloadSize, SocketFlags.None);
                    }

                    //sc.OutputSocket.Send(bBuffer, header.LengthIncludingHeader, SocketFlags.None);
                    //sc.OutputSocket.Send(bBuffer, iReceived, SocketFlags.None);
                }
            }
            catch (Exception e)
            {
                OnBridgeException(ConnectionType.ClientBridge, e);
            }

            OnConnectionDisconnected(ConnectionType.ClientBridge);
            //Console.WriteLine("Closing InputThread");
        }
예제 #4
0
 protected virtual void OnTDSMessageReceived(Message.TDSMessage msg)
 {
     BridgeAcceptor.OnTDSMessageReceived(this, msg);
 }
예제 #5
0
        protected virtual void ClientBridgeThread()
        {
            try
            {
                byte[] bBuffer   = null;
                byte[] bHeader   = new byte[Header.TDSHeader.HEADER_SIZE];
                int    iReceived = 0;

                Message.TDSMessage tdsMessage = null;

                while ((iReceived = SocketCouple.ClientBridgeSocket.Receive(bHeader, Header.TDSHeader.HEADER_SIZE, SocketFlags.None)) > 0)
                //while ((iReceived = sc.InputSocket.Receive(bBuffer, SocketFlags.None)) > 0)
                {
                    Header.TDSHeader header = new Header.TDSHeader(bHeader);

                    int iMinBufferSize = Math.Max(0x1000, header.LengthIncludingHeader + 1);
                    if ((bBuffer == null) || (bBuffer.Length < iMinBufferSize))
                    {
                        bBuffer = new byte[iMinBufferSize];
                    }

                    //Console.WriteLine(header.Type);

                    if (header.Type == (HeaderType)23)
                    {
                        iReceived = SocketCouple.ClientBridgeSocket.Receive(bBuffer, 0, 0x1000 - Header.TDSHeader.HEADER_SIZE, SocketFlags.None);
                    }
                    else if (header.PayloadSize > 0)
                    {
                        //Console.WriteLine("\t{0:N0} bytes package", header.LengthIncludingHeader);
                        SocketCouple.ClientBridgeSocket.Receive(bBuffer, 0, header.PayloadSize, SocketFlags.None);
                    }
                    TDSPacket tdsPacket = new TDSPacket(bHeader, bBuffer, header.PayloadSize);
                    OnTDSPacketReceived(tdsPacket);

                    if (tdsMessage == null)
                    {
                        tdsMessage = Message.TDSMessage.CreateFromFirstPacket(tdsPacket);
                    }
                    else
                    {
                        tdsMessage.Packets.Add(tdsPacket);
                    }

                    if ((header.StatusBitMask & StatusBitMask.END_OF_MESSAGE) == StatusBitMask.END_OF_MESSAGE)
                    {
                        OnTDSMessageReceived(tdsMessage);
                        tdsMessage = null;
                    }

                    SocketCouple.BridgeSQLSocket.Send(bHeader, bHeader.Length, SocketFlags.None);

                    if (header.Type == (HeaderType)23)
                    {
                        SocketCouple.BridgeSQLSocket.Send(bBuffer, iReceived, SocketFlags.None);
                    }
                    else
                    {
                        SocketCouple.BridgeSQLSocket.Send(bBuffer, header.PayloadSize, SocketFlags.None);
                    }

                    //sc.OutputSocket.Send(bBuffer, header.LengthIncludingHeader, SocketFlags.None);
                    //sc.OutputSocket.Send(bBuffer, iReceived, SocketFlags.None);
                }
            }
            catch (Exception e)
            {
                OnBridgeException(ConnectionType.ClientBridge, e);
            }

            OnConnectionDisconnected(ConnectionType.ClientBridge);
            //Console.WriteLine("Closing InputThread");
        }