Exemple #1
0
        private void NodeTagSet_Load(object sender, EventArgs e)
        {
            if (BindInstance == null)
            {
                return;
            }

            tbxNodeType.Text    = BindInstance.NodeType.AssemblyQualifiedName;
            tbxNodeSubType.Text = BindInstance.SubType != null ? BindInstance.SubType.AssemblyQualifiedName : "";

            tbxStartIndex.Text  = BindInstance.StoreIndex.ToString();
            tbxStoreLength.Text = BindInstance.StoreLength.ToString();

            cbxIsESPData.Checked = BindInstance.IsESPData;
            if (BindInstance.NodeType.IsSubclassOf(typeof(ESPDataBase)))
            {
                ESPDataBase instance = BindInstance.NodeItem as ESPDataBase;
                if (instance != null)
                {
                    tbxNodeItem.Text = SpecUtil.ByteArrayToHexString(instance.GetNetworkBytes());
                }
            }
            else if (BindInstance.NodeType.Equals(typeof(byte[])))
            {
                byte[] targetBytes = BindInstance.NodeItem as byte[];
                if (targetBytes != null && targetBytes.Length > 0)
                {
                    tbxNodeItem.Text = SpecUtil.ByteArrayToHexString(targetBytes);
                }
            }
            else
            {
                tbxNodeItem.Text = BindInstance.NodeItem.ToString();
            }
        }
Exemple #2
0
        private void espMItemExtract_Click(object sender, EventArgs e)
        {
            TreeView             tv   = GetCurrentTreeView();
            TreeNode             node = tv.SelectedNode;
            TreeNodeInstanceBind bind = node.Tag as TreeNodeInstanceBind;

            if (bind == null)
            {
                ShowEror("节点绑定Tag对象类型不为{0},操作不支持!", typeof(TreeNodeInstanceBind).FullName);
            }
            else
            {
                byte[] fileBytes = new byte[0];

                if (bind.NodeType.IsSubclassOf(typeof(ESPDataBase)))
                {
                    ESPDataBase instance = bind.NodeItem as ESPDataBase;
                    if (instance != null)
                    {
                        fileBytes = instance.GetNetworkBytes();
                    }
                }
                else if (bind.NodeType.Equals(typeof(byte[])))
                {
                    fileBytes = bind.NodeItem as byte[];
                }
                if (fileBytes.Length > 0)
                {
                    SaveBinDataToFileDialog(this, fileBytes);
                }
            }
        }
Exemple #3
0
        public void DoTest()
        {
            ApplicationRequest instance = new ApplicationRequest();

            instance.ESP_Header        = RequestHeader.RequestHeader4Test;
            instance.ESP_PackageIndex  = 0;
            instance.ESP_PackageLength = 0;
            instance.ESP_AppServerID   = 1;

            byte[] linkDat = EaseString.DefaultEncoding.GetBytes("http://118.123.205.218:888/images/testpic.gif");
            instance.ESP_AppRequestData   = linkDat;
            instance.ESP_AppRequestLength = linkDat.Length;


            byte[] testBytes = instance.GetNetworkBytes();

            Assert.That(ESPDataBase.IsValidNetworkBytes <ApplicationRequest>(testBytes, Console.Out));
        }
Exemple #4
0
        /// <summary>
        /// 修改节点绑定之后的更新
        /// </summary>
        public void RefreshSelectNode(TreeNode selectNode, LogWriter rptWriter)
        {
            TreeNodeInstanceBind bind = selectNode.Tag as TreeNodeInstanceBind;

            if (bind == null)
            {
                Log(rptWriter, "节点绑定Tag对象类型不为{0},操作不支持!", typeof(TreeNodeInstanceBind).FullName);
            }
            else
            {
                if (bind.NodeType.IsSubclassOf(typeof(ESPDataBase)))
                {
                    ESPDataBase instance = bind.NodeItem as ESPDataBase;
                    if (instance != null)
                    {
                        ReportToTreeView(instance, selectNode.Nodes, rptWriter, false);
                    }
                }
            }
        }
Exemple #5
0
        private void espMItemCreateNew_Click(object sender, EventArgs e)
        {
            TreeView             tv   = GetCurrentTreeView();
            TreeNode             node = tv.SelectedNode;
            TreeNodeInstanceBind bind = node.Tag as TreeNodeInstanceBind;

            if (bind == null)
            {
                ShowEror("节点绑定Tag对象类型不为{0},操作不支持!", typeof(TreeNodeInstanceBind).FullName);
            }
            else
            {
                TreeNodeInstanceBind newBind = new TreeNodeInstanceBind
                {
                    IsArrayItem = bind.IsArrayItem,
                    IsESPData   = bind.IsESPData,
                    IsFirstNode = bind.IsFirstNode,
                    StoreIndex  = bind.StoreIndex,
                    NodeType    = bind.NodeType,
                    SubType     = bind.SubType
                };

                if (bind.IsESPData)
                {
                    ESPDataBase instance = Activator.CreateInstance(bind.NodeType) as ESPDataBase;
                    newBind.NodeItem    = instance;
                    newBind.StoreLength = instance.GetContentLength();

                    node.Tag = newBind;

                    TesterPlugConfig.Instance.CurrentPlug.RefreshSelectNode(node, WriteLog);
                }
                else
                {
                    ShowEror("节点绑定Tag对象的值不为{0},操作不支持!", typeof(ESPDataBase).FullName);
                }
            }
        }
Exemple #6
0
        //HybridStream hs = null;

        private bool TryParseAsDefineType(byte[] espDataBin, Type typeTarget, TreeView tvDisplay, LogWriter writer)
        {
            bool result = true;

            //hs = new HybridStream(espDataBin.AsMemoryStream());

            //StringBuilder diffBuilder = new StringBuilder();
            //StringWriter sw = new StringWriter(diffBuilder);

            string      typeName = typeTarget.AssemblyQualifiedName;
            ESPDataBase instance = Activator.CreateInstance(typeTarget) as ESPDataBase;

            try
            {
                if (!ESPDataBase.IsValidInstance(espDataBin, typeTarget, null /*sw*/, out instance))
                {
                    result = false;
                    Log(writer, "解析为{0}无效!", typeName);
                    //Log(writer, "{0}", SpecUtil.ByteArrayToHexString(instance.GetNetworkBytes()));
                    //Log(writer, "{0}", diffBuilder.ToString());
                }
                else
                {
                    Log(writer, "解析为{0}成功!", typeName);
                }
            }
            catch (Exception exp)
            {
                result = false;
                Log(writer, "解析为{0}无效!", typeName);
                instance = Activator.CreateInstance(typeTarget) as ESPDataBase;
                Log(writer, "{0}\r\n{1}", exp.Message, exp.StackTrace);
            }

            //sw.Dispose();
            ReportToTreeView(instance, tvDisplay.Nodes, writer, true);
            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 获取返回包装对象子类(6种Response对象中的一种)
        /// </summary>
        /// <returns></returns>
        public ESPDataBase GetSubResponse(RequestBase request)
        {
            RequestType requestType = request.ESP_Header.ESP_Protocol;
            ESPDataBase resp        = null;

            System.IO.MemoryStream ms = ESP_TransferData.AsMemoryStream();
            switch (requestType)
            {
            case RequestType.PageV21:
                resp = new PageV21Response(Context);
                break;

            case RequestType.Mixed:
                resp = new MixedResponse(Context);
                break;

            case RequestType.Page:
                resp = new PageResponse(Context);
                break;

            case RequestType.Resource:
                ResourceRequest resReq = request as ResourceRequest;
                if (!resReq.IsPackageReqeust())
                {
                    resp = new ResourcePartialResponse(Context);
                }
                else
                {
                    resp = new ResourceResponse(Context);
                }
                break;

            case RequestType.Application:
                ApplicationRequest appReq = request as ApplicationRequest;
                if (!appReq.IsPackageReqeust())
                {
                    resp = new ApplicationResponse(Context);
                }
                else
                {
                    resp = new ApplicationPartialResponse(Context);
                }
                break;

            case RequestType.UpdateCenter:
                resp = new GatewayUpdateResponse(Context);
                break;

            case RequestType.SynServerAddress:
                resp = new SynServerAddressResponse(Context);
                break;

            default:
                break;
            }

            SpecUtil.BindFromNetworkStream(resp, ms, ms.Position, false, 0);
            resp.ContentRange[0] = 0;
            resp.ContentRange[1] = ESP_TransferData.LongLength - 1;
            ms.Close();
            ms.Dispose();

            return(resp);
        }
Exemple #8
0
        void ReportToTreeView(ESPDataBase instance, TreeNodeCollection targetNodes, LogWriter writer, bool appendRoot)
        {
            targetNodes.Clear();

            Type   instanceType     = instance.GetType();
            string targetObjectType = instanceType.FullName;

            TreeNode             rootNode = null;
            TreeNodeInstanceBind nodeBind = null;

            if (appendRoot)
            {
                rootNode            = new TreeNode(targetObjectType);
                rootNode.Name       = targetObjectType;
                rootNode.ImageIndex = rootNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Class;

                nodeBind = new TreeNodeInstanceBind
                {
                    IsFirstNode = true,
                    IsArrayItem = false,
                    IsESPData   = true,
                    NodeItem    = instance,
                    StoreIndex  = 0,
                    NodeType    = instanceType,
                    StoreLength = instance.GetContentLength()
                };
                rootNode.Tag = nodeBind;
                targetNodes.Add(rootNode);
            }

            ObjectTransferOrderAttribute[] configs = new ObjectTransferOrderAttribute[0];
            PropertyInfo[] transPropertys          = SpecUtil.GetTransferProperties(instance.GetType(), out configs);

            PropertyInfo lastProperty = null;

            for (int m = 0, n = transPropertys.Length; m < n; m++)
            {
                PropertyInfo pInfo = transPropertys[m];

                #region 依据属性依次绑定

                TreeNode propertyNode = new TreeNode(string.Format("{0} [{1}]", pInfo.Name, pInfo.PropertyType));
                propertyNode.Name       = pInfo.Name;
                propertyNode.ImageIndex = propertyNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Property;

                if (configs[m].Conditional)
                {
                    propertyNode.Text = propertyNode.Text + " *";
                }

                object propertyVal = pInfo.GetValue(instance, null);

                if (appendRoot && rootNode != null)
                {
                    rootNode.Nodes.Add(propertyNode);
                }
                else
                {
                    targetNodes.Add(propertyNode);
                }

                //if (propertyVal == null) continue;

                nodeBind = new TreeNodeInstanceBind
                {
                    IsFirstNode = lastProperty == null,
                    IsArrayItem = false,
                    IsESPData   = false,
                    NodeItem    = propertyVal,
                    NodeType    = pInfo.PropertyType,
                    StoreIndex  = GetTreeNodeStoreIndex(propertyNode),
                    StoreLength = 0  //TODO
                };

                if (pInfo.PropertyType.IsSubclassOf(typeof(ESPDataBase)))
                {
                    ESPDataBase subInstance = (ESPDataBase)propertyVal;
                    nodeBind.IsESPData      = true;
                    propertyNode.ImageIndex = propertyNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Class;
                    propertyNode.Tag        = nodeBind;
                    if (subInstance != null)
                    {
                        //递归子级属性
                        nodeBind.StoreLength = subInstance.GetContentLength();
                        ReportToTreeView(subInstance, propertyNode.Nodes, writer, false);
                    }
                }
                else
                {
                    if (pInfo.PropertyType.IsEnum)
                    {
                        nodeBind.StoreLength = SpecUtil.GetCLRTypeByteLength(pInfo.PropertyType);

                        propertyNode.ImageIndex = propertyNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Enum;
                        propertyNode.Text       = string.Format("{0} [{1}({2})]", pInfo.Name, pInfo.PropertyType, Enum.GetUnderlyingType(pInfo.PropertyType));
                        if (configs[m].Conditional)
                        {
                            propertyNode.Text = propertyNode.Text + " *";
                        }
                        propertyNode.Tag = nodeBind;
                    }
                    else if (pInfo.PropertyType.IsArray)
                    {
                        Type elementType = pInfo.PropertyType.GetElementType();
                        nodeBind.SubType = elementType;
                        propertyNode.Tag = nodeBind;

                        if (elementType.IsSubclassOf(typeof(ESPDataBase)))
                        {
                            #region 封装对象数组
                            ESPDataBase[] subItems = (ESPDataBase[])propertyVal;
                            if (subItems != null)
                            {
                                long totalLength = 0, currentLength = 0;
                                for (int p = 0, q = subItems.Length; p < q; p++)
                                {
                                    currentLength = subItems[p].GetContentLength();
                                    totalLength  += currentLength;

                                    TreeNode subPropertyNode = new TreeNode();
                                    subPropertyNode.Name = subItems[p].GetType().FullName + "[" + p + "]";
                                    subPropertyNode.Text = subItems[p].GetType().FullName + "[" + p + "]";

                                    propertyNode.Nodes.Add(subPropertyNode);

                                    subPropertyNode.ImageIndex = subPropertyNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Class;
                                    subPropertyNode.Tag        = new TreeNodeInstanceBind
                                    {
                                        IsFirstNode = p == 0,
                                        IsArrayItem = true,
                                        IsESPData   = true,
                                        NodeItem    = subItems[p],
                                        SubType     = null,
                                        NodeType    = elementType,
                                        StoreIndex  = GetTreeNodeStoreIndex(subPropertyNode),
                                        StoreLength = currentLength
                                    };



                                    ReportToTreeView(subItems[p], subPropertyNode.Nodes, writer, false);
                                }
                                nodeBind.StoreLength = totalLength;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 字节数组
                            if (propertyVal == null)
                            {
                                propertyVal = new byte[0];
                            }
                            if (elementType.Equals(typeof(byte)))
                            {
                                nodeBind.StoreLength = ((byte[])propertyVal).LongLength;

                                if (nodeBind.StoreLength > 0 && (instanceType.Equals(typeof(NetworkSwitchRequest)) ||
                                                                 instanceType.Equals(typeof(NetworkSwitchResponse)))
                                    )
                                {
                                    propertyNode.ImageIndex = propertyNode.SelectedImageIndex = (int)DataSpecTester.ImageListIcon.Class;

                                    if (instanceType.Equals(typeof(NetworkSwitchRequest)))
                                    {
                                        #region NetworkSwitchRequest
                                        RequestBase subRequest = ((NetworkSwitchRequest)instance).GetSubRequest();
                                        if (subRequest != null)
                                        {
                                            propertyNode.Text = string.Format("{0} [{1}({2})]", pInfo.Name, pInfo.PropertyType, subRequest.GetType());

                                            nodeBind.IsESPData = true;
                                            nodeBind.SubType   = subRequest.GetType();

                                            ReportToTreeView(subRequest, propertyNode.Nodes, writer, false);
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        //nodeBind.NodeItem
                                        #region  NetworkSwitchResponse
                                        object currentReqObj = ExchangeGet("Plug_Current_Request");
                                        if (currentReqObj != null)
                                        {
                                            //Trace.WriteLine("NetworkSwitchResponse of " + currentReqObj.GetType());
                                            RequestBase currentRequest = currentReqObj as RequestBase;
                                            if (currentReqObj.GetType().Equals(typeof(NetworkSwitchRequest)))
                                            {
                                                currentRequest = ((NetworkSwitchRequest)currentReqObj).GetSubRequest();
                                            }

                                            if (currentRequest != null)
                                            {
                                                ESPDataBase subResponse = ((NetworkSwitchResponse)instance).GetSubResponse(currentRequest);

                                                nodeBind.IsESPData = true;
                                                nodeBind.SubType   = subResponse.GetType();

                                                propertyNode.Text = string.Format("{0} [{1}({2})]", pInfo.Name, pInfo.PropertyType, nodeBind.SubType);

                                                ReportToTreeView(subResponse, propertyNode.Nodes, writer, false);
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        nodeBind.StoreLength = SpecUtil.GetCLRTypeByteLength(pInfo.PropertyType);
                        propertyNode.Tag     = nodeBind;
                    }
                }

                #endregion

                lastProperty = pInfo;
            }

            if (appendRoot && rootNode != null)
            {
                rootNode.Expand();
            }
        }
Exemple #9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (BindInstance == null)
            {
                BindInstance = new TreeNodeInstanceBind();
            }

            BindInstance.StoreIndex  = Convert.ToInt64(tbxStartIndex.Text.Trim());
            BindInstance.StoreLength = Convert.ToInt64(tbxStoreLength.Text.Trim());

            BindInstance.TagModified = true;

            if (BindInstance.IsESPData)
            {
                ESPDataBase instance = Activator.CreateInstance(BindInstance.NodeType) as ESPDataBase;
                if (instance != null)
                {
                    try
                    {
                        if (cbxReadFromRoot.Checked && RootStream != null)
                        {
                            RootStream.Result.Position = BindInstance.StoreIndex;
                            SpecUtil.BindFromNetworkStream(instance, RootStream.Result, BindInstance.StoreIndex, false);
                            BindInstance.StoreLength = instance.GetContentLength();
                        }
                        else
                        {
                            if (tbxNodeItem.Text.Trim() != string.Empty)
                            {
                                SpecUtil.BindFromNetworkStream(instance,
                                                               SpecUtil.HexPatternStringToByteArray(tbxNodeItem.Text.Trim()).AsMemoryStream(),
                                                               0, false);
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        Desktop.ShowEror(this, "Message:{0}\r\n{1}", exp.Message, exp.StackTrace);
                    }
                    BindInstance.NodeItem = instance;
                }
            }
            else
            {
                if (cbxReadFromRoot.Checked)
                {
                    RootStream.Result.Position = BindInstance.StoreIndex;
                    if (BindInstance.NodeType.Equals(typeof(byte[])))
                    {
                        BindInstance.NodeItem = RootStream.ReadSpecialLength((int)BindInstance.StoreLength);
                    }
                    else
                    {
                        BindInstance.NodeItem = RootStream.ReadAsValue(BindInstance.NodeType);
                    }
                }
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }