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); } } }
//查看图片数据 private void espMItemViewPic_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 { if (bind.NodeType.Equals(typeof(Byte[]))) { if (viewForm == null) { //WriteLog("viewForm == null : {0}", viewForm == null); viewForm = new PicViewForm(); viewForm.Owner = this; viewForm.Show(this); } viewForm.PicBytes = bind.NodeItem as byte[]; viewForm.RefreshPic(); viewForm.Visible = true; } } }
private void espMItemSet_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 { NodeTagSet setForm = new NodeTagSet(); TextBox targetTextBox = null; MemoryStream ms = GetCurrentViewBytes(out targetTextBox).AsMemoryStream(); setForm.RootStream = new HybridStream(ms); TreeNode preNode = node.PrevNode; if (preNode != null && preNode.Tag is TreeNodeInstanceBind) { TreeNodeInstanceBind preBind = preNode.Tag as TreeNodeInstanceBind; if (preBind.TagModified) { bind.StoreIndex = preBind.StoreIndex + preBind.StoreLength; } } setForm.BindInstance = bind; DialogResult dr = setForm.ShowDialog(this); if (dr == DialogResult.OK) { if (setForm.BindInstance != null) { node.Tag = setForm.BindInstance; TesterPlugConfig.Instance.CurrentPlug.RefreshSelectNode(node, WriteLog); WriteLog("刷新节点绑定:{0}", node.Text); } } setForm.Dispose(); ms.Dispose(); } }
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); } } }
void HandlerReFactoryText(object sender, KeyEventArgs e) { //重排 if (e.Control && e.KeyCode == Keys.F2) { TextBox tbxSender = (TextBox)sender; tbxSender.Text = RefactoryHexString(tbxSender.Text); WriteOutput("执行文本重排完毕!"); } //还原 if (e.Control && e.KeyCode == Keys.F8) { TextBox tbxRawTarget = (VieMode == InterfaceViewMode.RequestView) ? tbxRequestBin : tbxRespBin; TreeView tvTarget = (VieMode == InterfaceViewMode.RequestView) ? tvRequestView : tvRespView; TreeNodeInstanceBind nodeBind = tvTarget.Nodes[0].Tag as TreeNodeInstanceBind; if (nodeBind != null) { tbxRawTarget.Text = SpecUtil.ByteArrayToHexString(((ESPDataBase)nodeBind.NodeItem).GetNetworkBytes()); WriteOutput("执行文本还原完毕!"); } } }
private void btnParse_Click(object sender, EventArgs e) { if (VieMode != InterfaceViewMode.RequestView && VieMode != InterfaceViewMode.ResponseView) { ShowEror("当前Tab视图既不是请求(Request)视图,也不是响应(Response)视图,无须解析!", ""); return; } if (TesterPlugConfig.Instance.CurrentPlug == null) { ShowEror("没有加载任何解析插件在目录{0}中!", TesterPlugConfig.Instance.PlugInDirectory); } else { try { TextBox targetTextBox = null; bool blnSucess = false; if (string.IsNullOrEmpty(cbxParseType.Text)) { //new System.Threading.Thread(() => // { string resultType = string.Empty; blnSucess = TesterPlugConfig.Instance.CurrentPlug.Parse(GetCurrentViewBytes(out targetTextBox) , (VieMode == InterfaceViewMode.RequestView) ? tvRequestView : tvRespView, WriteOutput, out resultType); //if (InvokeRequired) //{ cbxParseType.Text = ""; cbxParseType.SelectedText = resultType; //} //}).Start(); } else { blnSucess = TesterPlugConfig.Instance.CurrentPlug.TryParseAsType(GetCurrentViewBytes(out targetTextBox), cbxParseType.Text, (VieMode == InterfaceViewMode.RequestView) ? tvRequestView : tvRespView, WriteOutput); } if (targetTextBox != null) { targetTextBox.BackColor = (blnSucess) ? System.Drawing.ColorTranslator.FromHtml("#D6F7D6") : System.Drawing.ColorTranslator.FromHtml("#FCCBCB"); if (blnSucess && VieMode == InterfaceViewMode.RequestView) { TreeNodeInstanceBind nodeBind = tvRequestView.Nodes[0].Tag as TreeNodeInstanceBind; //保存请求对象引用 TesterPlugConfig.Instance.CurrentPlug.ExchangeStore("Plug_Current_Request", nodeBind.NodeItem); } } } catch (Exception plugExp) { plugExp = SpecUtil.GetTriggerException(plugExp); ShowEror("插件解析失败,错误消息及跟踪:\r\nMessage:{0} \r\nStackTrace:{1}", plugExp.Message, plugExp.StackTrace); } } }
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(); }