Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1193 → Rev 1194

/TCPproxy/trunk/MainForm.cs
19,59 → 19,81
{
public class MainForm : System.Windows.Forms.Form
{
#region constants and settings
private const int RECENT_LENGTH = 5;
 
#endregion constants and settings
 
#region private fields
 
private ListenForm listenForm = new ListenForm();
private TcpListener tcpListener = null;
private LogMessages logMessages = null;
private Hashtable treeNodes = new Hashtable();
private ArrayList recentItems = new ArrayList();
 
private int listenPort;
private string resendHost;
private int resendPort;
private TcpShowMode tcpShowMode = TcpShowMode.ByDirection;
private bool autoExpand = true;
 
private string defaultCaption;
 
#endregion private fields
 
#region web forms fields
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button startButton;
private System.Windows.Forms.MenuItem saveXmlMenuItem;
private System.Windows.Forms.ListBox logBox;
private System.Windows.Forms.MenuItem tcpShowByTimeMenuItem;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.SaveFileDialog saveLogDialog;
private System.Windows.Forms.MenuItem clearMenuItem;
private System.Windows.Forms.StatusBarPanel connectionStatusBar;
private System.Windows.Forms.Label levelLabel;
private TCPproxy.ViewControl messagesBox;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Button saveButton;
private System.Windows.Forms.MenuItem saveHttpMenuItem;
private System.Windows.Forms.TextBox resendPortBox;
private System.Windows.Forms.MenuItem selectAllmenuItem;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MenuItem autoExpandMenuItem;
private System.Windows.Forms.MenuItem copyMenuItem;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.ContextMenu viewContextMenu;
private System.Windows.Forms.TreeView messageView;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.MenuItem saveTcpMenuItem;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.MenuItem closeConnectionMenuItem;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.StatusBarPanel connectionStatusBar;
private System.Windows.Forms.MenuItem selectAllmenuItem;
private System.Windows.Forms.MenuItem copyMenuItem;
private System.Windows.Forms.ContextMenu viewContextMenu;
private System.Windows.Forms.MenuItem closeConnectionMenuItem;
private System.Windows.Forms.ImageList saveButtonImageList;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.MenuItem saveLogMenuItem;
private System.Windows.Forms.ContextMenu saveLogMenu;
private System.Windows.Forms.Button stopButton;
private System.Windows.Forms.ContextMenu messagesContextMenu;
private System.Windows.Forms.MenuItem tcpShowByDirectionMenuItem;
private System.Windows.Forms.TextBox listenPortBox;
private System.Windows.Forms.ComboBox levelBox;
private System.Windows.Forms.Button clearButton;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.ContextMenu messagesContextMenu;
private System.Windows.Forms.ImageList treeImageList;
private System.Windows.Forms.MenuItem wordWrapMenuItem;
private System.Windows.Forms.TextBox resendHostBox;
private MenuStrip mainMenu;
private ToolStripMenuItem fileMenu;
private ToolStripMenuItem loadBinLogMenuItem;
private ToolStripMenuItem saveBinLogMenuItem;
private ToolStripSeparator menuSeparator1;
private ToolStripMenuItem exitMenuItem;
private ToolStripMenuItem viewMenu;
private ToolStripMenuItem clearMainMenuItem;
private ToolStripMenuItem messagesMenu;
private ToolStripMenuItem saveFullLogMenuItem;
private ToolStripMenuItem saveTcoLogMenuItem;
private ToolStripMenuItem saveHttpLogMenuItem;
private ToolStripMenuItem saveXmlLogMenuItem;
private ToolStripSeparator menuSeparator2;
private ToolStripMenuItem allMessagesMenuItem;
private ToolStripMenuItem importantMessagesMenuItem;
private ToolStripMenuItem infoMessagesMenuItem;
private ToolStripSeparator menuSeparator3;
private ToolStripMenuItem tcpShowByDirectionMenuItem;
private ToolStripMenuItem tcpShowByTimeMenuItem;
private ToolStripSeparator menuSeparator4;
private ToolStripMenuItem autoExpandMenuItem;
private ToolStripMenuItem wordWrapMainMenuItem;
private ToolStripMenuItem helpMenu;
private Panel panel1;
private Panel panel3;
private Panel panel4;
private ViewControl messagesBox;
private Splitter splitter2;
private ListBox logBox;
private Splitter splitter1;
private TreeView messageView;
private ToolStripMenuItem startMenuItem;
private ToolStripMenuItem stopMenuItem;
private ToolStripSeparator menuSeparator5;
private ToolStripMenuItem recentListeningMenu;
private ToolStripMenuItem recentListeningNoItem;
private ToolStripMenuItem aboutMenuItem;
#endregion web forms fields
 
#region Windows Form Designer generated code
81,300 → 103,367
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.resendHostBox = new System.Windows.Forms.TextBox();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.wordWrapMenuItem = new System.Windows.Forms.MenuItem();
this.treeImageList = new System.Windows.Forms.ImageList(this.components);
this.clearButton = new System.Windows.Forms.Button();
this.levelBox = new System.Windows.Forms.ComboBox();
this.listenPortBox = new System.Windows.Forms.TextBox();
this.tcpShowByDirectionMenuItem = new System.Windows.Forms.MenuItem();
this.messagesContextMenu = new System.Windows.Forms.ContextMenu();
this.stopButton = new System.Windows.Forms.Button();
this.saveLogMenu = new System.Windows.Forms.ContextMenu();
this.saveLogMenuItem = new System.Windows.Forms.MenuItem();
this.selectAllmenuItem = new System.Windows.Forms.MenuItem();
this.copyMenuItem = new System.Windows.Forms.MenuItem();
this.statusBar = new System.Windows.Forms.StatusBar();
this.connectionStatusBar = new System.Windows.Forms.StatusBarPanel();
this.saveButtonImageList = new System.Windows.Forms.ImageList(this.components);
this.panel4 = new System.Windows.Forms.Panel();
this.closeConnectionMenuItem = new System.Windows.Forms.MenuItem();
this.viewContextMenu = new System.Windows.Forms.ContextMenu();
this.saveLogDialog = new System.Windows.Forms.SaveFileDialog();
this.mainMenu = new System.Windows.Forms.MenuStrip();
this.fileMenu = new System.Windows.Forms.ToolStripMenuItem();
this.startMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.loadBinLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveBinLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.saveFullLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveTcoLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveHttpLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveXmlLogMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.exitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewMenu = new System.Windows.Forms.ToolStripMenuItem();
this.clearMainMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.messagesMenu = new System.Windows.Forms.ToolStripMenuItem();
this.allMessagesMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.infoMessagesMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importantMessagesMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.tcpShowByDirectionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tcpShowByTimeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.autoExpandMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.wordWrapMainMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpMenu = new System.Windows.Forms.ToolStripMenuItem();
this.aboutMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.saveTcpMenuItem = new System.Windows.Forms.MenuItem();
this.splitter1 = new System.Windows.Forms.Splitter();
this.messageView = new System.Windows.Forms.TreeView();
this.viewContextMenu = new System.Windows.Forms.ContextMenu();
this.splitter2 = new System.Windows.Forms.Splitter();
this.copyMenuItem = new System.Windows.Forms.MenuItem();
this.autoExpandMenuItem = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.selectAllmenuItem = new System.Windows.Forms.MenuItem();
this.resendPortBox = new System.Windows.Forms.TextBox();
this.saveHttpMenuItem = new System.Windows.Forms.MenuItem();
this.saveButton = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.messagesBox = new TCPproxy.ViewControl();
this.levelLabel = new System.Windows.Forms.Label();
this.connectionStatusBar = new System.Windows.Forms.StatusBarPanel();
this.clearMenuItem = new System.Windows.Forms.MenuItem();
this.saveLogDialog = new System.Windows.Forms.SaveFileDialog();
this.tcpShowByTimeMenuItem = new System.Windows.Forms.MenuItem();
this.splitter2 = new System.Windows.Forms.Splitter();
this.logBox = new System.Windows.Forms.ListBox();
this.saveXmlMenuItem = new System.Windows.Forms.MenuItem();
this.startButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.panel4.SuspendLayout();
this.splitter1 = new System.Windows.Forms.Splitter();
this.messageView = new System.Windows.Forms.TreeView();
this.recentListeningMenu = new System.Windows.Forms.ToolStripMenuItem();
this.recentListeningNoItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.connectionStatusBar)).BeginInit();
this.mainMenu.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.connectionStatusBar)).BeginInit();
this.panel4.SuspendLayout();
this.SuspendLayout();
//
// resendHostBox
//
this.resendHostBox.Location = new System.Drawing.Point(88, 48);
this.resendHostBox.Name = "resendHostBox";
this.resendHostBox.TabIndex = 3;
this.resendHostBox.Text = "";
//
//
// wordWrapMenuItem
//
this.wordWrapMenuItem.Index = 3;
//
this.wordWrapMenuItem.Index = 2;
this.wordWrapMenuItem.Text = "Word &Wrap";
this.wordWrapMenuItem.Click += new System.EventHandler(this.wordWrapMenuItem_Click);
//
//
// treeImageList
//
this.treeImageList.ImageSize = new System.Drawing.Size(16, 16);
this.treeImageList.TransparentColor = System.Drawing.Color.Transparent;
//
// clearButton
//
this.clearButton.Location = new System.Drawing.Point(288, 16);
this.clearButton.Name = "clearButton";
this.clearButton.TabIndex = 6;
this.clearButton.Text = "Clear";
this.clearButton.Click += new System.EventHandler(this.clearButton_Click);
//
// levelBox
//
this.levelBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.levelBox.Items.AddRange(new object[] {
"All",
"Info",
"Important"});
this.levelBox.Location = new System.Drawing.Point(472, 16);
this.levelBox.Name = "levelBox";
this.levelBox.Size = new System.Drawing.Size(121, 21);
this.levelBox.TabIndex = 8;
this.levelBox.SelectedIndexChanged += new System.EventHandler(this.levelBox_SelectedIndexChanged);
//
// listenPortBox
//
this.listenPortBox.Location = new System.Drawing.Point(88, 16);
this.listenPortBox.Name = "listenPortBox";
this.listenPortBox.TabIndex = 2;
this.listenPortBox.Text = "";
//
// tcpShowByDirectionMenuItem
//
this.tcpShowByDirectionMenuItem.Checked = true;
this.tcpShowByDirectionMenuItem.Index = 1;
this.tcpShowByDirectionMenuItem.Text = "TCP Show by &Direction";
this.tcpShowByDirectionMenuItem.Click += new System.EventHandler(this.tcpShowByDirectionMenuItem_Click);
//
//
this.treeImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("treeImageList.ImageStream")));
this.treeImageList.TransparentColor = System.Drawing.Color.Magenta;
this.treeImageList.Images.SetKeyName(0, "clear.bmp");
this.treeImageList.Images.SetKeyName(1, "connected.bmp");
this.treeImageList.Images.SetKeyName(2, "disconnected.bmp");
//
// messagesContextMenu
//
//
this.messagesContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.selectAllmenuItem,
this.copyMenuItem,
this.clearMenuItem,
this.wordWrapMenuItem});
this.messagesContextMenu.Popup += new System.EventHandler(this.messagesContextMenu_Popup);
//
// stopButton
//
this.stopButton.Location = new System.Drawing.Point(192, 16);
this.stopButton.Name = "stopButton";
this.stopButton.TabIndex = 5;
this.stopButton.Text = "Stop";
this.stopButton.Visible = false;
this.stopButton.Click += new System.EventHandler(this.stopButton_Click);
//
// saveLogMenu
//
this.saveLogMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.saveLogMenuItem,
this.saveTcpMenuItem,
this.saveHttpMenuItem,
this.saveXmlMenuItem});
//
// saveLogMenuItem
//
this.saveLogMenuItem.Index = 0;
this.saveLogMenuItem.Text = "Save Log";
this.saveLogMenuItem.Click += new System.EventHandler(this.saveLogMenuItem_Click);
//
this.selectAllmenuItem,
this.copyMenuItem,
this.wordWrapMenuItem});
//
// selectAllmenuItem
//
this.selectAllmenuItem.Index = 0;
this.selectAllmenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.selectAllmenuItem.Text = "Select &All";
this.selectAllmenuItem.Click += new System.EventHandler(this.selectAllMenuItem_Click);
//
// copyMenuItem
//
this.copyMenuItem.Index = 1;
this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.copyMenuItem.Text = "&Copy";
this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click);
//
// statusBar
//
//
this.statusBar.Location = new System.Drawing.Point(0, 619);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.connectionStatusBar});
this.connectionStatusBar});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(780, 22);
this.statusBar.TabIndex = 0;
//
//
// connectionStatusBar
//
this.connectionStatusBar.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.connectionStatusBar.Name = "connectionStatusBar";
this.connectionStatusBar.Width = 764;
//
// saveButtonImageList
//
this.saveButtonImageList.ImageSize = new System.Drawing.Size(16, 16);
this.saveButtonImageList.TransparentColor = System.Drawing.Color.Transparent;
//
// panel4
//
this.panel4.Controls.Add(this.messagesBox);
this.panel4.Controls.Add(this.splitter2);
this.panel4.Controls.Add(this.logBox);
this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel4.Location = new System.Drawing.Point(163, 0);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(617, 539);
this.panel4.TabIndex = 13;
//
//
this.saveButtonImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("saveButtonImageList.ImageStream")));
this.saveButtonImageList.TransparentColor = System.Drawing.Color.Magenta;
this.saveButtonImageList.Images.SetKeyName(0, "arrow.bmp");
//
// closeConnectionMenuItem
//
//
this.closeConnectionMenuItem.Index = 0;
this.closeConnectionMenuItem.Text = "&Close connection";
this.closeConnectionMenuItem.Click += new System.EventHandler(this.closeConnectionMenuItem_Click);
//
//
// viewContextMenu
//
this.viewContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.closeConnectionMenuItem});
//
// saveLogDialog
//
this.saveLogDialog.DefaultExt = "txt";
this.saveLogDialog.Filter = "Text Files|*.txt|All Files|*.*";
this.saveLogDialog.Title = "Save Log";
//
// mainMenu
//
this.mainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileMenu,
this.viewMenu,
this.helpMenu});
this.mainMenu.Location = new System.Drawing.Point(0, 0);
this.mainMenu.Name = "mainMenu";
this.mainMenu.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;
this.mainMenu.Size = new System.Drawing.Size(780, 24);
this.mainMenu.TabIndex = 10;
//
// fileMenu
//
this.fileMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.startMenuItem,
this.stopMenuItem,
this.recentListeningMenu,
this.menuSeparator5,
this.loadBinLogMenuItem,
this.saveBinLogMenuItem,
this.menuSeparator1,
this.saveFullLogMenuItem,
this.saveTcoLogMenuItem,
this.saveHttpLogMenuItem,
this.saveXmlLogMenuItem,
this.menuSeparator2,
this.exitMenuItem});
this.fileMenu.Name = "fileMenu";
this.fileMenu.Size = new System.Drawing.Size(35, 20);
this.fileMenu.Text = "File";
//
// startMenuItem
//
this.startMenuItem.Name = "startMenuItem";
this.startMenuItem.Size = new System.Drawing.Size(174, 22);
this.startMenuItem.Text = "Start...";
this.startMenuItem.Click += new System.EventHandler(this.startMenuItem_Click);
//
// stopMenuItem
//
this.stopMenuItem.Enabled = false;
this.stopMenuItem.Name = "stopMenuItem";
this.stopMenuItem.Size = new System.Drawing.Size(174, 22);
this.stopMenuItem.Text = "Stop";
this.stopMenuItem.Click += new System.EventHandler(this.stopMenuItem_Click);
//
// menuSeparator5
//
this.menuSeparator5.Name = "menuSeparator5";
this.menuSeparator5.Size = new System.Drawing.Size(171, 6);
//
// loadBinLogMenuItem
//
this.loadBinLogMenuItem.Name = "loadBinLogMenuItem";
this.loadBinLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.loadBinLogMenuItem.Text = "Load Bin Log...";
//
// saveBinLogMenuItem
//
this.saveBinLogMenuItem.Name = "saveBinLogMenuItem";
this.saveBinLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.saveBinLogMenuItem.Text = "Save Bin Log...";
this.saveBinLogMenuItem.Click += new System.EventHandler(this.saveBinLogMenuItem_Click);
//
// menuSeparator1
//
this.menuSeparator1.Name = "menuSeparator1";
this.menuSeparator1.Size = new System.Drawing.Size(171, 6);
//
// saveFullLogMenuItem
//
this.saveFullLogMenuItem.Name = "saveFullLogMenuItem";
this.saveFullLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.saveFullLogMenuItem.Text = "Save Full Text Log...";
this.saveFullLogMenuItem.Click += new System.EventHandler(this.saveLogMenuItem_Click);
//
// saveTcoLogMenuItem
//
this.saveTcoLogMenuItem.Name = "saveTcoLogMenuItem";
this.saveTcoLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.saveTcoLogMenuItem.Text = "Save TCP Log...";
this.saveTcoLogMenuItem.Click += new System.EventHandler(this.saveTcpMenuItem_Click);
//
// saveHttpLogMenuItem
//
this.saveHttpLogMenuItem.Name = "saveHttpLogMenuItem";
this.saveHttpLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.saveHttpLogMenuItem.Text = "Save Http Log...";
this.saveHttpLogMenuItem.Click += new System.EventHandler(this.saveHttpMenuItem_Click);
//
// saveXmlLogMenuItem
//
this.saveXmlLogMenuItem.Name = "saveXmlLogMenuItem";
this.saveXmlLogMenuItem.Size = new System.Drawing.Size(174, 22);
this.saveXmlLogMenuItem.Text = "Save XML Log...";
this.saveXmlLogMenuItem.Click += new System.EventHandler(this.saveXmlMenuItem_Click);
//
// menuSeparator2
//
this.menuSeparator2.Name = "menuSeparator2";
this.menuSeparator2.Size = new System.Drawing.Size(171, 6);
//
// exitMenuItem
//
this.exitMenuItem.Name = "exitMenuItem";
this.exitMenuItem.Size = new System.Drawing.Size(174, 22);
this.exitMenuItem.Text = "Exit";
//
// viewMenu
//
this.viewMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.clearMainMenuItem,
this.messagesMenu,
this.menuSeparator3,
this.tcpShowByDirectionMenuItem,
this.tcpShowByTimeMenuItem,
this.menuSeparator4,
this.autoExpandMenuItem,
this.wordWrapMainMenuItem});
this.viewMenu.Name = "viewMenu";
this.viewMenu.Size = new System.Drawing.Size(41, 20);
this.viewMenu.Text = "View";
//
// clearMainMenuItem
//
this.clearMainMenuItem.Name = "clearMainMenuItem";
this.clearMainMenuItem.Size = new System.Drawing.Size(182, 22);
this.clearMainMenuItem.Text = "Clear";
this.clearMainMenuItem.Click += new System.EventHandler(this.clearMenuItem_Click);
//
// messagesMenu
//
this.messagesMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.allMessagesMenuItem,
this.infoMessagesMenuItem,
this.importantMessagesMenuItem});
this.messagesMenu.Name = "messagesMenu";
this.messagesMenu.Size = new System.Drawing.Size(182, 22);
this.messagesMenu.Text = "Messages";
//
// allMessagesMenuItem
//
this.allMessagesMenuItem.Checked = true;
this.allMessagesMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.allMessagesMenuItem.Name = "allMessagesMenuItem";
this.allMessagesMenuItem.Size = new System.Drawing.Size(122, 22);
this.allMessagesMenuItem.Text = "All";
this.allMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
// infoMessagesMenuItem
//
this.infoMessagesMenuItem.Name = "infoMessagesMenuItem";
this.infoMessagesMenuItem.Size = new System.Drawing.Size(122, 22);
this.infoMessagesMenuItem.Text = "Info";
this.infoMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
// importantMessagesMenuItem
//
this.importantMessagesMenuItem.Name = "importantMessagesMenuItem";
this.importantMessagesMenuItem.Size = new System.Drawing.Size(122, 22);
this.importantMessagesMenuItem.Text = "Important";
this.importantMessagesMenuItem.Click += new System.EventHandler(this.messagesMenuItem_Click);
//
// menuSeparator3
//
this.menuSeparator3.Name = "menuSeparator3";
this.menuSeparator3.Size = new System.Drawing.Size(179, 6);
//
// tcpShowByDirectionMenuItem
//
this.tcpShowByDirectionMenuItem.Checked = true;
this.tcpShowByDirectionMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.tcpShowByDirectionMenuItem.Name = "tcpShowByDirectionMenuItem";
this.tcpShowByDirectionMenuItem.Size = new System.Drawing.Size(182, 22);
this.tcpShowByDirectionMenuItem.Text = "TCP Show by Direction";
this.tcpShowByDirectionMenuItem.Click += new System.EventHandler(this.tcpShowByDirectionMenuItem_Click);
//
// tcpShowByTimeMenuItem
//
this.tcpShowByTimeMenuItem.Name = "tcpShowByTimeMenuItem";
this.tcpShowByTimeMenuItem.Size = new System.Drawing.Size(182, 22);
this.tcpShowByTimeMenuItem.Text = "TCP Show by Time";
this.tcpShowByTimeMenuItem.Click += new System.EventHandler(this.tcpShowByTimeMenuItem_Click);
//
// menuSeparator4
//
this.menuSeparator4.Name = "menuSeparator4";
this.menuSeparator4.Size = new System.Drawing.Size(179, 6);
//
// autoExpandMenuItem
//
this.autoExpandMenuItem.Name = "autoExpandMenuItem";
this.autoExpandMenuItem.Size = new System.Drawing.Size(182, 22);
this.autoExpandMenuItem.Text = "Auto Expand";
this.autoExpandMenuItem.Click += new System.EventHandler(this.autoExpandMenuItem_Click);
//
// wordWrapMainMenuItem
//
this.wordWrapMainMenuItem.Name = "wordWrapMainMenuItem";
this.wordWrapMainMenuItem.Size = new System.Drawing.Size(182, 22);
this.wordWrapMainMenuItem.Text = "Word Wrap";
this.wordWrapMainMenuItem.Click += new System.EventHandler(this.wordWrapMenuItem_Click);
//
// helpMenu
//
this.helpMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aboutMenuItem});
this.helpMenu.Name = "helpMenu";
this.helpMenu.Size = new System.Drawing.Size(40, 20);
this.helpMenu.Text = "Help";
//
// aboutMenuItem
//
this.aboutMenuItem.Name = "aboutMenuItem";
this.aboutMenuItem.Size = new System.Drawing.Size(152, 22);
this.aboutMenuItem.Text = "About...";
this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
//
// panel1
//
//
this.panel1.Controls.Add(this.panel3);
this.panel1.Controls.Add(this.panel2);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Location = new System.Drawing.Point(0, 24);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(780, 619);
this.panel1.TabIndex = 1;
//
// panel2
//
this.panel2.Controls.Add(this.levelLabel);
this.panel2.Controls.Add(this.levelBox);
this.panel2.Controls.Add(this.saveButton);
this.panel2.Controls.Add(this.clearButton);
this.panel2.Controls.Add(this.stopButton);
this.panel2.Controls.Add(this.startButton);
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.label1);
this.panel2.Controls.Add(this.resendPortBox);
this.panel2.Controls.Add(this.resendHostBox);
this.panel2.Controls.Add(this.listenPortBox);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 539);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(780, 80);
this.panel2.TabIndex = 3;
//
// saveTcpMenuItem
//
this.saveTcpMenuItem.Index = 1;
this.saveTcpMenuItem.Text = "Save TCP";
this.saveTcpMenuItem.Click += new System.EventHandler(this.saveTcpMenuItem_Click);
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(160, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 539);
this.splitter1.TabIndex = 12;
this.splitter1.TabStop = false;
//
// messageView
//
this.messageView.ContextMenu = this.viewContextMenu;
this.messageView.Dock = System.Windows.Forms.DockStyle.Left;
this.messageView.HideSelection = false;
this.messageView.ImageList = this.treeImageList;
this.messageView.Location = new System.Drawing.Point(0, 0);
this.messageView.Name = "messageView";
this.messageView.Size = new System.Drawing.Size(160, 539);
this.messageView.TabIndex = 11;
this.messageView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.messageView_AfterSelect);
this.messageView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.messageView_BeforeSelect);
//
// viewContextMenu
//
this.viewContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.closeConnectionMenuItem,
this.tcpShowByDirectionMenuItem,
this.tcpShowByTimeMenuItem,
this.autoExpandMenuItem});
this.viewContextMenu.Popup += new System.EventHandler(this.listContextMenu_Popup);
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(0, 468);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(617, 3);
this.splitter2.TabIndex = 9;
this.splitter2.TabStop = false;
//
// copyMenuItem
//
this.copyMenuItem.Index = 1;
this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.copyMenuItem.Text = "&Copy";
this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click);
//
// autoExpandMenuItem
//
this.autoExpandMenuItem.Index = 3;
this.autoExpandMenuItem.Text = "Auto &Expand";
this.autoExpandMenuItem.Click += new System.EventHandler(this.autoExpandMenuItem_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(73, 16);
this.label1.TabIndex = 3;
this.label1.Text = "Listen on port";
//
// selectAllmenuItem
//
this.selectAllmenuItem.Index = 0;
this.selectAllmenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.selectAllmenuItem.Text = "Select &All";
this.selectAllmenuItem.Click += new System.EventHandler(this.selectAllMenuItem_Click);
//
// resendPortBox
//
this.resendPortBox.Location = new System.Drawing.Point(192, 48);
this.resendPortBox.Name = "resendPortBox";
this.resendPortBox.Size = new System.Drawing.Size(72, 20);
this.resendPortBox.TabIndex = 4;
this.resendPortBox.Text = "";
//
// saveHttpMenuItem
//
this.saveHttpMenuItem.Index = 2;
this.saveHttpMenuItem.Text = "Save HTTP";
this.saveHttpMenuItem.Click += new System.EventHandler(this.saveHttpMenuItem_Click);
//
// saveButton
//
this.saveButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.saveButton.ImageList = this.saveButtonImageList;
this.saveButton.Location = new System.Drawing.Point(288, 48);
this.saveButton.Name = "saveButton";
this.saveButton.TabIndex = 7;
this.saveButton.Text = "Save Log";
this.saveButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
//
this.panel1.Size = new System.Drawing.Size(780, 595);
this.panel1.TabIndex = 11;
//
// panel3
//
//
this.panel3.Controls.Add(this.panel4);
this.panel3.Controls.Add(this.splitter1);
this.panel3.Controls.Add(this.messageView);
381,103 → 470,108
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(0, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(780, 539);
this.panel3.Size = new System.Drawing.Size(780, 595);
this.panel3.TabIndex = 5;
//
//
// panel4
//
this.panel4.Controls.Add(this.messagesBox);
this.panel4.Controls.Add(this.splitter2);
this.panel4.Controls.Add(this.logBox);
this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel4.Location = new System.Drawing.Point(163, 0);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(617, 595);
this.panel4.TabIndex = 13;
//
// messagesBox
//
//
this.messagesBox.ContextMenu = this.messagesContextMenu;
this.messagesBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.messagesBox.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.messagesBox.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.messagesBox.Location = new System.Drawing.Point(0, 0);
this.messagesBox.Name = "messagesBox";
this.messagesBox.Size = new System.Drawing.Size(617, 468);
this.messagesBox.Size = new System.Drawing.Size(617, 524);
this.messagesBox.TabIndex = 7;
this.messagesBox.WordWrap = true;
//
// levelLabel
//
this.levelLabel.AutoSize = true;
this.levelLabel.Location = new System.Drawing.Point(384, 20);
this.levelLabel.Name = "levelLabel";
this.levelLabel.Size = new System.Drawing.Size(86, 16);
this.levelLabel.TabIndex = 9;
this.levelLabel.Text = "Messages Level";
//
// connectionStatusBar
//
this.connectionStatusBar.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.connectionStatusBar.Width = 764;
//
// clearMenuItem
//
this.clearMenuItem.Index = 2;
this.clearMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlL;
this.clearMenuItem.Text = "C&lear";
this.clearMenuItem.Click += new System.EventHandler(this.clearButton_Click);
//
// saveLogDialog
//
this.saveLogDialog.DefaultExt = "txt";
this.saveLogDialog.Filter = "Text Files|*.txt|All Files|*.*";
this.saveLogDialog.Title = "Save Log";
//
// tcpShowByTimeMenuItem
//
this.tcpShowByTimeMenuItem.Index = 2;
this.tcpShowByTimeMenuItem.Text = "TCP Show by &Time";
this.tcpShowByTimeMenuItem.Click += new System.EventHandler(this.tcpShowByTimeMenuItem_Click);
//
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(0, 524);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(617, 3);
this.splitter2.TabIndex = 9;
this.splitter2.TabStop = false;
//
// logBox
//
//
this.logBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.logBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.logBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.logBox.HorizontalScrollbar = true;
this.logBox.ItemHeight = 16;
this.logBox.Location = new System.Drawing.Point(0, 471);
this.logBox.Location = new System.Drawing.Point(0, 527);
this.logBox.Name = "logBox";
this.logBox.ScrollAlwaysVisible = true;
this.logBox.Size = new System.Drawing.Size(617, 68);
this.logBox.TabIndex = 8;
//
// saveXmlMenuItem
//
this.saveXmlMenuItem.Index = 3;
this.saveXmlMenuItem.Text = "Save XML";
this.saveXmlMenuItem.Click += new System.EventHandler(this.saveXmlMenuItem_Click);
//
// startButton
//
this.startButton.Location = new System.Drawing.Point(192, 16);
this.startButton.Name = "startButton";
this.startButton.TabIndex = 5;
this.startButton.Text = "Start";
this.startButton.Click += new System.EventHandler(this.startButton_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 52);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 4;
this.label2.Text = "Resend to";
//
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(160, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 595);
this.splitter1.TabIndex = 12;
this.splitter1.TabStop = false;
//
// messageView
//
this.messageView.ContextMenu = this.viewContextMenu;
this.messageView.Dock = System.Windows.Forms.DockStyle.Left;
this.messageView.HideSelection = false;
this.messageView.ImageIndex = 0;
this.messageView.ImageList = this.treeImageList;
this.messageView.Location = new System.Drawing.Point(0, 0);
this.messageView.Name = "messageView";
this.messageView.SelectedImageIndex = 0;
this.messageView.Size = new System.Drawing.Size(160, 595);
this.messageView.TabIndex = 11;
//
// recentListeningMenu
//
this.recentListeningMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.recentListeningNoItem});
this.recentListeningMenu.Name = "recentListeningMenu";
this.recentListeningMenu.Size = new System.Drawing.Size(174, 22);
this.recentListeningMenu.Text = "Recent Listenings";
//
// recentListeningNoItem
//
this.recentListeningNoItem.Enabled = false;
this.recentListeningNoItem.Name = "recentListeningNoItem";
this.recentListeningNoItem.Size = new System.Drawing.Size(152, 22);
this.recentListeningNoItem.Text = "(no items)";
//
// MainForm
//
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(780, 641);
this.Controls.Add(this.panel1);
this.Controls.Add(this.mainMenu);
this.Controls.Add(this.statusBar);
this.MainMenuStrip = this.mainMenu;
this.MinimumSize = new System.Drawing.Size(400, 200);
this.Name = "MainForm";
this.Text = "TCPproxy";
this.panel4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.connectionStatusBar)).EndInit();
this.mainMenu.ResumeLayout(false);
this.mainMenu.PerformLayout();
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.connectionStatusBar)).EndInit();
this.panel4.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
 
}
#endregion
 
486,19 → 580,41
{
InitializeComponent();
logMessages = new LogMessages(logBox);
LoadFromRegistry();
if(levelBox.SelectedIndex < 0) levelBox.SelectedIndex = 0;
try {
LoadFromRegistry();
LoadRecentItemsFromRegistry();
}
catch(Exception) {}
 
// update visual elements
UpdateMessagesMenuItems();
 
if(tcpShowMode == TcpShowMode.ByDirection) {
tcpShowByDirectionMenuItem.Checked = true;
tcpShowByTimeMenuItem.Checked = false;
}
else {
tcpShowByDirectionMenuItem.Checked = false;
tcpShowByTimeMenuItem.Checked = true;
}
 
autoExpandMenuItem.Checked = autoExpand;
wordWrapMainMenuItem.Checked = messagesBox.WordWrap;
 
// save default values
defaultCaption = this.Text;
}
 
protected override void Dispose( bool disposing )
protected override void Dispose(bool disposing)
{
if(tcpListener != null)
{
if(tcpListener != null) {
tcpListener.StopListening(); // stop listening
tcpListener.CancelAll(); // cancel all open connections
}
 
SaveToRegistry(); // save settings
// save settings
SaveToRegistry();
SaveRecentItemsToRegistry();
 
if( disposing )
{
516,28 → 632,50
Application.Run(new MainForm());
}
 
private LogLevel ParseLogLevel(string str)
{
if(str == "Important")
return LogLevel.Important;
else if(str == "Info")
return LogLevel.Info;
else
return LogLevel.Debug;
}
 
private void LoadFromRegistry()
{
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"Software\Anatoli Klassen\TCPproxy");
 
if(subkey != null)
{
listenPortBox.Text = (string)subkey.GetValue("Listen Port", "");
resendHostBox.Text = (string)subkey.GetValue("Resend Host", "");
resendPortBox.Text = (string)subkey.GetValue("Resend Port", "");
levelBox.SelectedIndex = (int)subkey.GetValue("Message Level", 0);
autoExpand = (int)subkey.GetValue("Auto Expand", 1) == 1;
messagesBox.WordWrap = (int)subkey.GetValue("Word Wrap", 1) == 1;
if(subkey == null) return;
 
object tcpShowModeStr = (object)subkey.GetValue("Tcp Show Mode", TcpShowMode.ByDirection);
tcpShowMode = (tcpShowModeStr as string) == "ByDirection"
? TcpShowMode.ByDirection : TcpShowMode.ByTime;
listenPort = (int)subkey.GetValue("Listen Port", 0);
resendHost = (string)subkey.GetValue("Resend Host", "");
resendPort = (int)subkey.GetValue("Resend Port", 0);
logMessages.Level = ParseLogLevel((string)subkey.GetValue("Messages Level", ""));
autoExpand = (int)subkey.GetValue("Auto Expand", 1) == 1;
messagesBox.WordWrap = (int)subkey.GetValue("Word Wrap", 1) == 1;
 
// this.Top = (int)subkey.GetValue("Window.Top", this.Top);
// this.Left = (int)subkey.GetValue("Window.Left", this.Left);
// this.Hight = (int)subkey.GetValue("Window.Hight", this.Hight);
// this.Width = (int)subkey.GetValue("Window.Width", this.Width);
object tcpShowModeStr = (object)subkey.GetValue("Tcp Show Mode", TcpShowMode.ByDirection);
tcpShowMode = (tcpShowModeStr as string) == "ByDirection"
? TcpShowMode.ByDirection : TcpShowMode.ByTime;
 
// this.Top = (int)subkey.GetValue("Window.Top", this.Top);
// this.Left = (int)subkey.GetValue("Window.Left", this.Left);
// this.Hight = (int)subkey.GetValue("Window.Hight", this.Hight);
// this.Width = (int)subkey.GetValue("Window.Width", this.Width);
}
 
private void LoadRecentItemsFromRegistry()
{
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"Software\Anatoli Klassen\TCPproxy\Recent Listenings");
 
if(subkey == null) return;
 
foreach(string name in subkey.GetValueNames()) {
if(name == "") continue;
AddRecentItem(RecentItem.LoadFromRegistry((string)subkey.GetValue(name, "")));
}
}
 
546,13 → 684,13
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(
@"Software\Anatoli Klassen\TCPproxy");
 
subkey.SetValue("Listen Port", listenPortBox.Text);
subkey.SetValue("Resend Host", resendHostBox.Text);
subkey.SetValue("Resend Port", resendPortBox.Text);
subkey.SetValue("Message Level", levelBox.SelectedIndex);
subkey.SetValue("Tcp Show Mode", tcpShowMode);
subkey.SetValue("Auto Expand", autoExpand ? 1 : 0);
subkey.SetValue("Word Wrap", messagesBox.WordWrap ? 1 : 0);
subkey.SetValue("Listen Port", listenPort);
subkey.SetValue("Resend Host", resendHost == null ? "" : resendHost);
subkey.SetValue("Resend Port", resendPort);
subkey.SetValue("Messages Level", logMessages.Level);
subkey.SetValue("Tcp Show Mode", tcpShowMode);
subkey.SetValue("Auto Expand", autoExpand ? 1 : 0);
subkey.SetValue("Word Wrap", messagesBox.WordWrap ? 1 : 0);
 
subkey.SetValue("Window.Top", this.Top);
subkey.SetValue("Window.Left", this.Left);
560,75 → 698,54
subkey.SetValue("Window.Width", this.Width);
}
 
private void startButton_Click(object sender, System.EventArgs e)
private void SaveRecentItemsToRegistry()
{
int listenPort = -1;
IPAddress resendHost;
int resendPort = -1;
ArrayList tcpConnections = new ArrayList();
Microsoft.Win32.RegistryKey subkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(
@"Software\Anatoli Klassen\TCPproxy\Recent Listenings");
 
// parse listen port
try
{
listenPort = int.Parse(listenPortBox.Text);
// load existing from registry
ArrayList old = new ArrayList();
foreach(string name in subkey.GetValueNames()) {
if(name == "") continue;
old.Add(RecentItem.LoadFromRegistry((string)subkey.GetValue(name, "")));
}
catch(FormatException)
{
MessageBox.Show("Listen port must be an integer number");
return;
}
 
// get resend host
if(resendHostBox.Text == "")
{
resendHost = null;
// merge - for the case another program instance has changed the list
foreach(RecentItem item in old) {
int existingIdx = recentItems.IndexOf(item);
if(existingIdx >= 0)
((RecentItem)recentItems[existingIdx]).UpdateTimestamp(item);
else
recentItems.Add(item);
}
else
{
Regex ipRegex = new Regex(@"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$");
if(ipRegex.Match(resendHostBox.Text).Success)
{
try
{
resendHost = IPAddress.Parse(resendHostBox.Text);
}
catch(FormatException)
{
MessageBox.Show("Wrong IP address of the resend host");
return;
}
}
else
{
IPHostEntry hostInfo = Dns.GetHostByName(resendHostBox.Text);
 
if(hostInfo.AddressList.Length > 0)
{
resendHost = hostInfo.AddressList[0];
}
else
{
MessageBox.Show("Cannot find IP address of the resend host");
return;
}
}
recentItems.Sort();
if(recentItems.Count > 0) // take tail
recentItems = recentItems.GetRange(Math.Max(0, recentItems.Count - RECENT_LENGTH),
Math.Min(recentItems.Count, RECENT_LENGTH));
 
// parse resend port
try
{
resendPort = int.Parse(resendPortBox.Text);
}
catch(FormatException)
{
MessageBox.Show("Resend port must be an integer number");
return;
}
int count = 0;
foreach(RecentItem item in recentItems) {
subkey.SetValue(string.Format("{0:0000}", count++), item.SaveToRegistry());
}
}
 
private void startMenuItem_Click(object sender, System.EventArgs e)
{
IPAddress resendIp;
 
if(!listenForm.Execute(this,
ref listenPort, ref resendHost, out resendIp, ref resendPort)) return;
 
StartListening(listenPort, resendIp, resendPort);
}
 
private void StartListening(int listenPort, IPAddress resendIp, int resendPort)
{
// listen to the port
try
{
Start(listenPort, resendHost, resendPort);
Start(listenPort, resendIp, resendPort);
}
catch(Exception ex)
{
638,25 → 755,34
return;
}
 
startButton.Visible = false;
stopButton.Visible = true;
listenPortBox.Enabled = false;
resendHostBox.Enabled = false;
resendPortBox.Enabled = false;
AddRecentItem(listenPort, resendHost, resendPort);
 
startMenuItem.Enabled = false;
stopMenuItem.Enabled = true;
 
foreach(ToolStripItem subitem in recentListeningMenu.DropDownItems) {
subitem.Enabled = false;
}
 
this.Text = string.Format("{0}: {1} to {2}:{3}",
defaultCaption, listenPort, resendHost, resendPort);
}
 
private void stopButton_Click(object sender, System.EventArgs e)
private void stopMenuItem_Click(object sender, System.EventArgs e)
{
if(tcpListener != null) tcpListener.StopListening();
 
startButton.Visible = true;
stopButton.Visible = false;
listenPortBox.Enabled = true;
resendHostBox.Enabled = true;
resendPortBox.Enabled = true;
startMenuItem.Enabled = true;
stopMenuItem.Enabled = false;
 
foreach(ToolStripItem subitem in recentListeningMenu.DropDownItems) {
if(subitem.Tag != null) subitem.Enabled = true;
}
 
this.Text = defaultCaption;
}
 
private void clearButton_Click(object sender, System.EventArgs e)
private void clearMenuItem_Click(object sender, System.EventArgs e)
{
// close all connetions
foreach(object tcp in treeNodes.Keys)
669,16 → 795,6
logMessages.Clear();
}
 
private void saveButton_Click(object sender, System.EventArgs e)
{
saveLogMenu.Show(saveButton, new Point(saveButton.Width, 0));
}
 
private void messagesContextMenu_Popup(object sender, System.EventArgs e)
{
wordWrapMenuItem.Checked = messagesBox.WordWrap;
}
 
private void selectAllMenuItem_Click(object sender, System.EventArgs e)
{
messagesBox.SelectAll();
692,14 → 808,22
 
private void wordWrapMenuItem_Click(object sender, System.EventArgs e)
{
messagesBox.WordWrap = !messagesBox.WordWrap;
messagesBox.WordWrap = !messagesBox.WordWrap;
wordWrapMenuItem.Checked = messagesBox.WordWrap;
wordWrapMainMenuItem.Checked = messagesBox.WordWrap;
}
 
private void autoExpandMenuItem_Click(object sender, System.EventArgs e)
{
autoExpand = !autoExpand;
autoExpand = !autoExpand;
autoExpandMenuItem.Checked = autoExpand;
}
 
private void aboutMenuItem_Click(object sender, EventArgs e)
{
(new AboutForm()).ShowDialog(this);
}
 
private void messageView_BeforeSelect(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
{
if(messageView.SelectedNode == null) return;
740,6 → 864,8
private void tcpShowByDirectionMenuItem_Click(object sender, System.EventArgs e)
{
tcpShowMode = TcpShowMode.ByDirection;
tcpShowByDirectionMenuItem.Checked = true;
tcpShowByTimeMenuItem.Checked = false;
 
if(messageView.SelectedNode == null) return;
 
751,6 → 877,8
private void tcpShowByTimeMenuItem_Click(object sender, System.EventArgs e)
{
tcpShowMode = TcpShowMode.ByTime;
tcpShowByDirectionMenuItem.Checked = false;
tcpShowByTimeMenuItem.Checked = true;
 
if(messageView.SelectedNode == null) return;
 
759,22 → 887,6
UpdateTcpNodeInternal(((TcpNodeData)tag).Tcp);
}
 
private void listContextMenu_Popup(object sender, System.EventArgs e)
{
if(tcpShowMode == TcpShowMode.ByDirection)
{
tcpShowByDirectionMenuItem.Checked = true;
tcpShowByTimeMenuItem.Checked = false;
}
else
{
tcpShowByDirectionMenuItem.Checked = false;
tcpShowByTimeMenuItem.Checked = true;
}
 
autoExpandMenuItem.Checked = autoExpand;
}
 
private void saveLogMenuItem_Click(object sender, System.EventArgs e)
{
if(saveLogDialog.ShowDialog() == DialogResult.OK)
807,18 → 919,100
}
}
 
private void levelBox_SelectedIndexChanged(object sender, System.EventArgs e)
private void messagesMenuItem_Click(object sender, EventArgs e)
{
LogLevel level = LogLevel.Debug;
if(sender == importantMessagesMenuItem)
logMessages.Level = LogLevel.Important;
else if(sender == infoMessagesMenuItem)
logMessages.Level = LogLevel.Info;
else
logMessages.Level = LogLevel.Debug;
 
if(levelBox.SelectedIndex == 1)
level = LogLevel.Info;
else if(levelBox.SelectedIndex == 2)
level = LogLevel.Important;
UpdateMessagesMenuItems();
}
 
logMessages.Level = level;
private void saveBinLogMenuItem_Click(object sender, EventArgs e)
{
 
}
 
private void recentMenuItem_Click(object sender, EventArgs e)
{
RecentItem recentItem = (RecentItem)((ToolStripMenuItem)sender).Tag;
IPAddress resendIp;
 
this.listenPort = recentItem.ListenPort;
this.resendHost = recentItem.ResendHost;
this.resendPort = recentItem.ResendPort;
try
{
resendIp = HostUtils.ResendHostToIp(resendHost);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
 
StartListening(listenPort, resendIp, resendPort);
}
 
private void UpdateMessagesMenuItems()
{
switch(logMessages.Level) {
case LogLevel.Critical:
case LogLevel.Error:
case LogLevel.Warning:
case LogLevel.Important:
importantMessagesMenuItem.Checked = true;
infoMessagesMenuItem.Checked = false;
allMessagesMenuItem.Checked = false;
break;
 
case LogLevel.Info:
importantMessagesMenuItem.Checked = false;
infoMessagesMenuItem.Checked = true;
allMessagesMenuItem.Checked = false;
break;
 
case LogLevel.Debug:
importantMessagesMenuItem.Checked = false;
infoMessagesMenuItem.Checked = false;
allMessagesMenuItem.Checked = true;
break;
}
}
 
private void AddRecentItem(int listenPort, string resendHost, int resendPort)
{
RecentItem recentItem = new RecentItem(listenPort, resendHost, resendPort);
recentItem.UpdateTimestamp();
AddRecentItem(recentItem);
}
 
private void AddRecentItem(RecentItem recentItem)
{
int existingIdx = recentItems.IndexOf(recentItem);
if(existingIdx >= 0) {
((RecentItem)recentItems[existingIdx]).UpdateTimestamp(recentItem);
return;
}
 
recentItems.Add(recentItem);
 
if(this.recentListeningMenu.DropDownItems[0].Tag == null)
this.recentListeningMenu.DropDownItems.RemoveAt(0);
 
ToolStripMenuItem menuItem = new ToolStripMenuItem();
this.recentListeningMenu.DropDownItems.Insert(0, menuItem);
menuItem.Size = recentListeningNoItem.Size;
menuItem.Text = string.Format("{0} to {1}:{2}",
recentItem.ListenPort, recentItem.ResendHost, recentItem.ResendPort);
menuItem.Click += new System.EventHandler(recentMenuItem_Click);
menuItem.Tag = recentItem;
}
 
#endregion windows forms methods
 
#region core methods
2387,4 → 2581,109
ByDirection,
ByTime
}
 
public class RecentItem : IComparable
{
private int listenPort;
 
public int ListenPort
{
get { return listenPort; }
set { listenPort = value; }
}
 
private string resendHost;
 
public string ResendHost
{
get { return resendHost; }
set { resendHost = value; }
}
 
private int resendPort;
 
public int ResendPort
{
get { return resendPort; }
set { resendPort = value; }
}
 
private DateTime timestamp;
 
public DateTime Timestamp
{
get { return timestamp; }
}
 
public RecentItem(int listenPort, string resendHost, int resendPort)
{
this.listenPort = listenPort;
this.resendHost = resendHost;
this.resendPort = resendPort;
}
 
public override string ToString()
{
return string.Format("{0} to {1}:{2} at {3:HH:mm:ss.ff}",
listenPort, resendHost, resendPort, timestamp);
}
 
public override bool Equals(object obj)
{
if(!(obj is RecentItem)) return false;
 
RecentItem i2 = (RecentItem)obj;
 
return (i2.listenPort == this.listenPort) && (i2.resendHost == this.resendHost)
&& (i2.resendPort == this.resendPort);
}
 
public override int GetHashCode()
{
return this.resendHost.GetHashCode();
}
 
public string SaveToRegistry()
{
return string.Format("{0}:{1}:{2}:{3}",
listenPort, resendPort, timestamp.Ticks, resendHost);
}
 
public static RecentItem LoadFromRegistry(string str)
{
Regex re = new Regex(@"^(\d+):(\d+):(\d+):(.+)$");
Match m = re.Match(str);
if(!m.Success) throw new Exception("Cannot parse recent item");
 
RecentItem item = new RecentItem(int.Parse(m.Groups[1].Value),
m.Groups[4].Value, int.Parse(m.Groups[2].Value));
 
item.timestamp = new DateTime(long.Parse(m.Groups[3].Value));
 
return item;
}
 
public void UpdateTimestamp()
{
timestamp = DateTime.Now;
}
 
public void UpdateTimestamp(RecentItem second)
{
if(second.timestamp > timestamp)
timestamp = second.timestamp;
}
 
#region IComparable Members
 
int IComparable.CompareTo(object obj)
{
if(!(obj is RecentItem))
throw new Exception("Cannot compare");
 
return this.timestamp.CompareTo(((RecentItem)obj).timestamp);
}
 
#endregion
}
}