示例#1
0
        private object DecodeScalar(byte[] content)
        {
            DictNode rootNode = (DictNode)BEncode.Decode(content);
            IntNode  codeNode = (IntNode)rootNode["code"];

            switch (codeNode.Value)
            {
            case 1:
            case 2:
                throw new DbProxyException("数据集收到的数据包出错!");

            case 3:
                DictNode itemNode = (DictNode)rootNode["item"];
                string   typeName = ((BytesNode)itemNode["type"]).StringText;
                string   value    = ((BytesNode)itemNode["value"]).StringText;
                if (rootNode.ContainsKey("parmlist"))
                {
                    HandleParmsNode((rootNode)["parmlist"]);
                }
                return(NodeEncoder.GetObject(typeName, value));

            case 4:
                BytesNode messageNode = (BytesNode)rootNode["message"];
                throw new DbProxyException(messageNode.StringText);

            case 5:
                throw new DbProxyException("校验出错!");

            default:
                throw new DbProxyException(string.Format("无效消息代码:{0}!", codeNode.Value));
            }
        }
示例#2
0
        private void HandleParmsNode(BEncodedNode parmlistNode)
        {
            ListNode parmsNode = (ListNode)parmlistNode;

            foreach (BEncodedNode node in parmsNode)
            {
                DictNode parmNode = (DictNode)node;
                string   name     = ((BytesNode)parmNode["name"]).StringText;
                string   typeName = ((BytesNode)parmNode["type"]).StringText;
                parameters[name].Value = NodeEncoder.GetObject(typeName, (BytesNode)parmNode["value"]);
            }
        }
示例#3
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));
        }