Esempio n. 1
0
        /// <summary>
        /// 显示选择树中特定节点的详细信息并返回原始字节索引区间
        /// </summary>
        /// <remarks>[OK]</remarks>
        public long[] ReportNodeDetail(TreeView targetTree, TreeNode selectNode, LogWriter rptWriter)
        {
            long[] emptyResult = new long[] { 0, 0 };
            if (rptWriter == null)
            {
                return(emptyResult);
            }

            object nodeBindTag = selectNode.Tag;

            if (nodeBindTag == null || !nodeBindTag.GetType().Equals(typeof(TreeNodeInstanceBind)))
            {
                return(emptyResult);
            }
            else
            {
                TreeNodeInstanceBind nodeBind = (TreeNodeInstanceBind)nodeBindTag;

                StringBuilder sb = new StringBuilder();

                Type nodeBindType = nodeBind.NodeItem.GetType();
                if (nodeBindType.IsEnum)
                {
                    sb.AppendFormat("属性名称:{0}, 当前值: {1},实际值:{2}, 传输长度: {3}字节", selectNode.Name, nodeBind.NodeItem,
                                    Convert.ChangeType(nodeBind.NodeItem, Enum.GetUnderlyingType(nodeBindType)),
                                    nodeBind.StoreLength);
                }
                else if (nodeBindType.IsSubclassOf(typeof(ESPDataBase)))
                {
                    sb.AppendFormat("{0}", GetImpDescription(nodeBindType));
                    sb.AppendFormat("对象名称:{0}, 当前值: {1}, 传输长度: {2}字节", selectNode.Name, nodeBind.NodeItem, nodeBind.StoreLength);
                }
                else if (nodeBindType.IsArray)
                {
                    int subItemLength = (int)nodeBindType.GetProperty("Length").GetValue(nodeBind.NodeItem, null);
                    if (nodeBind.IsESPData && nodeBind.SubType != null)
                    {
                        sb.AppendFormat("{0}", GetImpDescription(nodeBind.SubType));
                    }
                    sb.AppendFormat("属性名称:{0}, 当前值:{1}, 元素项:{2}, 传输长度: {3}字节", selectNode.Name, nodeBind.NodeItem, subItemLength, nodeBind.StoreLength);
                }
                else
                {
                    if (nodeBind.IsArrayItem && nodeBind.SubType != null)
                    {
                        sb.AppendFormat("{0}", GetImpDescription(nodeBind.SubType));
                    }
                    sb.AppendFormat("属性名称:{0}, 当前值: {1}, 传输长度: {2}字节", selectNode.Name, nodeBind.NodeItem, nodeBind.StoreLength);
                }
                rptWriter(sb.ToString());

                return(new long[] { nodeBind.StoreIndex, nodeBind.StoreIndex + nodeBind.StoreLength - 1 });
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }
Esempio n. 3
0
 long GetTreeNodeStoreIndex(TreeNode currentNode)
 {
     if (currentNode.PrevNode == null)
     {
         if (currentNode.Parent != null)
         {
             TreeNodeInstanceBind parentNodeBind = (TreeNodeInstanceBind)currentNode.Parent.Tag;
             if (parentNodeBind != null)
             {
                 return(parentNodeBind.StoreIndex);
             }
         }
         return(0);
     }
     else
     {
         TreeNodeInstanceBind nodeBind = (TreeNodeInstanceBind)currentNode.PrevNode.Tag;
         return(nodeBind.StoreIndex + nodeBind.StoreLength);
     }
 }
Esempio n. 4
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();
            }
        }