Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BinaryMessageFiddlerExtension/BinaryRequestInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public override int GetOrder()
return 1;
}

public override void AssignSession(Session oS)
{
if (viewControl != null && oS != null)
viewControl.DefaultSaveFileName = String.Format("request{0}.xml", oS.id);

base.AssignSession(oS);
}

public bool bDirty { get; set; }

public bool bReadOnly
Expand Down Expand Up @@ -130,6 +138,9 @@ public byte[] body
{
// when fiddler updates this inspector's content, our controls' content
binaryContent = value;
if (viewControl != null && String.IsNullOrEmpty(viewControl.DefaultSaveFileName))
viewControl.DefaultSaveFileName = "request.xml";

UpdateControlContent();
}
}
Expand Down
11 changes: 11 additions & 0 deletions BinaryMessageFiddlerExtension/BinaryResponseInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public override int GetOrder()
return 1;
}

public override void AssignSession(Session oS)
{
if (viewControl != null && oS != null)
viewControl.DefaultSaveFileName = String.Format("response{0}.xml", oS.id);

base.AssignSession(oS);
}

public bool bDirty
{
get { return false; }
Expand All @@ -80,6 +88,9 @@ public byte[] body
{
// when fiddler updates this inspector's content, our control's content
binaryContent = value;
if (viewControl != null && String.IsNullOrEmpty(viewControl.DefaultSaveFileName))
viewControl.DefaultSaveFileName = "response.xml";

UpdateControlContent();
}
}
Expand Down
56 changes: 56 additions & 0 deletions BinaryMessageFiddlerExtension/XmlTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace BinaryMessageFiddlerExtension
{
Expand All @@ -17,6 +18,8 @@ public partial class XmlTreeView : UserControl
// if the message body has fewer than this number of nodes, expand the entire body subtree.
private const int AutoExpandAllThreshold = 50; //entirely arbitrary.

public string DefaultSaveFileName { get; set; }

public TreeView TreeView
{
get
Expand All @@ -38,10 +41,12 @@ private void BuildContextMenu()
// NodeMouseClick doesn't fire for middle click, so emulate that using mouseup/mousedown
TreeView.MouseUp += new MouseEventHandler(TreeView_MouseUp);
TreeView.MouseDown += new MouseEventHandler(TreeView_MouseDown);
TreeView.KeyDown += new KeyEventHandler(TreeView_KeyDown);
TreeView.ContextMenu.MenuItems.Add(new MenuItem("Expand All", ExpandAll_Click, Shortcut.AltRightArrow));
TreeView.ContextMenu.MenuItems.Add(new MenuItem("Collapse All", CollapseAll_Click, Shortcut.AltLeftArrow));
TreeView.ContextMenu.MenuItems.Add(new MenuItem("Copy", CopyMenuItem_Click, Shortcut.CtrlC));
TreeView.ContextMenu.MenuItems.Add(new MenuItem("Copy Tree", CopyTreeMenuItem_Click, Shortcut.CtrlShiftC));
TreeView.ContextMenu.MenuItems.Add(new MenuItem("Save Tree...", SaveTreeMenuItem_Click, Shortcut.CtrlS));
}

public void LoadXml(XmlDocument doc)
Expand Down Expand Up @@ -207,6 +212,42 @@ private void CopySubtreeContentToClipboard()
System.Windows.Forms.Clipboard.SetText(subtreeContent);
}

private void SaveSubtreeContentToFile()
{
if (TreeView.SelectedNode == null)
return;

String subtreeContent = GenerateSubtreeString(TreeView.SelectedNode);
if (subtreeContent == null)
return;

using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "xml";
saveFileDialog.FileName = String.IsNullOrEmpty(DefaultSaveFileName) ? "decoded-wcf.xml" : DefaultSaveFileName;
saveFileDialog.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.Title = "Save decoded WCF XML";

if (saveFileDialog.ShowDialog(this) != DialogResult.OK)
return;

try
{
File.WriteAllText(saveFileDialog.FileName, subtreeContent, Encoding.UTF8);
}
catch (Exception ex)
{
MessageBox.Show(this,
"Unable to save decoded XML: " + ex.Message,
"Save decoded WCF XML",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}

private string GenerateSubtreeString(TreeNode treeNode)
{
XmlNode xml = treeNode.Tag as XmlNode;
Expand Down Expand Up @@ -264,6 +305,16 @@ private void TreeView_MouseUp(object sender, MouseEventArgs e)
}
}

private void TreeView_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && !e.Shift && e.KeyCode == Keys.S)
{
SaveSubtreeContentToFile();
e.SuppressKeyPress = true;
e.Handled = true;
}
}

private void CopyMenuItem_Click(Object sender, System.EventArgs e)
{
CopySelectedNodeContentToClipboard();
Expand All @@ -274,6 +325,11 @@ private void CopyTreeMenuItem_Click(Object sender, System.EventArgs e)
CopySubtreeContentToClipboard();
}

private void SaveTreeMenuItem_Click(Object sender, System.EventArgs e)
{
SaveSubtreeContentToFile();
}

private void ExpandAll_Click(Object sender, System.EventArgs e)
{
ExpandAllSelectedNode();
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The tree view provides the following shortcuts:

* Ctrl+c — Copy current node XML
* Ctrl+Shift+c — Copy tree XML
* Ctrl+s — Save tree XML to a file
* Alt+→ — Expand node and all child nodes
* Alt+← — Collapse node and all child nodes
* Middle-click — Toggle expand/collapse of node and all child nodes
Expand Down