Example #1
0
        /// <summary>
        /// 新建握手数据包
        /// </summary>
        /// <param name="key">密钥</param>
        /// <param name="iv">初始化向量</param>
        /// <returns>返回握手数据包</returns>
        public static byte[] BuildHandshake(byte[] key, byte[] iv)
        {
            DictNode node = new DictNode();

            node.Add("key", key);
            node.Add("iv", iv);
            return(BEncode.ByteArrayEncode(node));
        }
Example #2
0
        /// <summary>
        /// 建立失败打开数据包
        /// </summary>
        /// <param name="message">失败消息</param>
        /// <returns>返回数据包</returns>
        private byte[] BuildFailOpenPacket(string message)
        {
            DictNode result = new DictNode();

            result.Add("code", 6);
            result.Add("message", message);
            return(BEncode.ByteArrayEncode(result));
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="iv"></param>
        /// <returns></returns>
        private byte[] BuildAckMessage(byte[] key, byte[] iv)
        {
            DictNode node = new DictNode();

            node.Add("key", key);
            node.Add("iv", iv);
            return(BEncode.ByteArrayEncode(node));
        }
Example #4
0
        /// <summary>
        /// 建立打开DB Proxy Server包
        /// </summary>
        /// <returns>返回数据包</returns>
        private byte[] BuildOpenPacket()
        {
            DictNode rootNode = new DictNode();

            rootNode.Add("action", 1);
            rootNode.Add("deviceid", deviceId);
            rootNode.Add("priority", priority);
            return(BEncode.ByteArrayEncode(rootNode));
        }
Example #5
0
        /// <summary>
        /// 记录数据包
        /// </summary>
        /// <param name="buffer">待记录的数据包</param>
        /// <param name="endPoint">IP端点</param>
        public override void Write(byte[] buffer, IPEndPoint endPoint)
        {
            DictNode node = new DictNode();

            node.Add("buffer", buffer);
            node.Add("endpoint", endPoint.ToString());
            byte[] sndMsg = BEncode.ByteArrayEncode(node);
            handler.SendNormalPacket(sndMsg);
        }
Example #6
0
        /// <summary>
        /// 建立成功打开数据包
        /// </summary>
        /// <param name="key">密钥</param>
        /// <param name="iv">初始化向量</param>
        /// <returns>返回数据包</returns>
        private byte[] BuildSuccessOpenPacket(byte[] key, byte[] iv)
        {
            DictNode result = new DictNode();

            result.Add("code", 1);
            result.Add("key", key);
            result.Add("iv", iv);
            return(BEncode.ByteArrayEncode(result));
        }
Example #7
0
        /// <summary>
        /// 建立连接包
        /// </summary>
        /// <returns></returns>
        private byte[] BuildHandshakeMessage()
        {
            DictNode node = new DictNode();

            node.Add("port", clientPort);
            node.Add("key", key);
            node.Add("iv", iv);
            return(BEncode.ByteArrayEncode(node));
        }
Example #8
0
        /// <summary>
        /// 交互函数
        /// </summary>
        /// <param name="stateInfo"></param>
        internal void Exchange(object stateInfo)
        {
            try
            {
                isClose = false;
                do
                {
                    byte[]   rcvMsg       = handler.ReceiveSealedPacket();
                    DictNode responseNode = HandlePacket(rcvMsg);
                    byte[]   sndMsg       = BEncode.ByteArrayEncode(responseNode);
                    handler.SendSealedPacket(sndMsg);
                    if (isClose)
                    {
                        return;
                    }
                } while (true);
            }

            catch (TdsException te)
            {
                Console.WriteLine("Tds Exception:{0}", te.Message);
            }

            catch (PacketException pe)
            {
                Console.WriteLine("Packet Exception:{0}", pe.Message);
            }

            catch (IOException ioe)
            {
                Console.WriteLine("IO Exception:{0}", ioe.Message);
            }

            catch (SocketException se)
            {
                Console.WriteLine("Socket Exception:{0}", se.Message);
            }

            catch (BEncodingException bee)
            {
                Console.WriteLine("BEncoding Exception:{0}", bee.Message);
            }

            finally
            {
                monitor.Unregister(handler);
                handler.Close();
            }
        }
Example #9
0
        /// <summary>
        /// 生成存储过程发送的字节流
        /// </summary>
        /// <returns>返回发送的字节流</returns>
        private byte[] BuildProcMessage(DictNode contentNode)
        {
            contentNode.Add("text", commandText);

            //建立参数列表
            if (parameters.Count != 0)
            {
                ListNode parmsNode = new ListNode();
                foreach (DbProxyParameter para in parameters)
                {
                    DictNode parmNode = new DictNode();
                    parmNode.Add("name", para.ParameterName);
                    parmNode.Add("type", (int)para.DbType);

                    switch (para.Direction)
                    {
                    case ParameterDirection.Input:
                        parmNode.Add("value", NodeEncoder.GetValueNode(para));
                        break;

                    case ParameterDirection.Output:
                        parmNode.Add("direction", OutputNum);
                        break;

                    case ParameterDirection.InputOutput:
                        parmNode.Add("direction", InputOutputNum);
                        parmNode.Add("value", NodeEncoder.GetValueNode(para));
                        break;

                    case ParameterDirection.ReturnValue:
                        parmNode.Add("direction", ReturnValueNum);
                        break;
                    }


                    if (para.Size != 0)
                    {
                        parmNode.Add("size", para.Size);
                    }

                    parmsNode.Add(parmNode);
                }

                contentNode.Add("parms", parmsNode);
            }

            return(BEncode.ByteArrayEncode(contentNode));
        }
Example #10
0
 /// <summary>
 /// 生成SQL文本发送的字节流
 /// </summary>
 /// <returns>返回发送的字节流</returns>
 private byte[] BuildTextMessage(DictNode contentNode)
 {
     contentNode.Add("text", commandText);
     return(BEncode.ByteArrayEncode(contentNode));
 }