private void btnDoCopy_Click(object sender, EventArgs e) { if (srcTreeview == null) { return; } string strStart = tbxNumBegin.Text.Trim(); string strEnd = tbxNumEnd.Text.Trim(); string strProtocol = tbxProtocol.Text; string strHost = tbxSrcHost.Text.Trim(); string strDest = tbxDestHost.Text.Trim(); MemoryStream ms = new MemoryStream(); TreeNodeCollection itemCol = srcTreeview.Nodes; bool blnFindBeginNode = false; for (int i = 0, j = itemCol.Count; i < j; i++) { TreeNode itemNode = itemCol[i]; TreeNode targetNode = null; string strNodeNum = itemNode.Text.Substring(1, itemNode.Text.IndexOf(' ') - 1).TrimStart('0'); if (!blnFindBeginNode && strNodeNum.Equals(strStart)) { blnFindBeginNode = true; } if (!blnFindBeginNode) { continue; } //#017 => TCP of 192.168.8.119:1035 -> 118.123.205.211:8000 //-------Found MATCH---Length:5---- //(#017 => TCP of 192.168.8.119:1035 -> 118.123.205.211:8000)(017)(TCP)(192.168.8.119:1035)(118.123.205.211:8000) Match m = Regex.Match(itemNode.Text, Desktop.ITEM_NODE_PATTERN); #region 自动交换客户端与服务器端 if (m.Success && itemNode.ForeColor.Equals(Desktop.NODE_NOT_EMPTY_COLOR)) { if (strProtocol.Equals(m.Groups[2].Value + "/IP") && strHost.Equals(m.Groups[4].Value) && strDest.Equals(m.Groups[3].Value) ) { if (cbxAutoSwap.Checked) { AutoSwap <string>(ref strHost, ref strDest); } else { //智能终止(请求或返回数据结束) if (strEnd.Equals("$")) { break; } } } } #endregion #region 结束点为数字时中断 if (strEnd != "*" && strEnd != "$" && Convert.ToInt64(strNodeNum) > Convert.ToInt64(strEnd)) { break; } #endregion #region 符合主客户端参数跳过分析节点 if (m.Success) { if (!strProtocol.Equals(m.Groups[2].Value + "/IP") || !strHost.Equals(m.Groups[3].Value) || !strDest.Equals(m.Groups[4].Value)) { continue; } } else { continue; } #endregion #region 设置目标节点targetNode targetNode = FindTargetNodeAt(itemNode, TargetLevel, tbxNodeName.Text.Trim()); #endregion if (targetNode != null) { System.Diagnostics.Trace.TraceInformation("*找到匹配节点:{0}, Level:{1}, 数据项:#{2}", targetNode.Text, targetNode.Level, strNodeNum); Desktop.AppendTreeNodeBinData(targetNode, ms); } } if (ms.Length > 0) { Desktop.SaveBinDataToFileDialog(this, ms.ToArray()); } ms.Dispose(); }
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(); }