Ejemplo n.º 1
0
 public BufferedUdpNetConn(NetConn conn)
     : base(conn.OutputFilepath, conn.AppendOutputFile)
 {
     m_conn          = conn;
     m_buf           = new byte[BufBlockSize];
     m_udp           = new UdpClient(m_conn.Port);
     m_specific_host = !string.IsNullOrEmpty(m_conn.Hostname);
 }
Ejemplo n.º 2
0
        /// <summary>Open a TCP network connection and log anything read</summary>
        private void LogTcpNetConnection(NetConn conn)
        {
            BufferedTcpNetConn buffered_tcp_netconn = null;

            try
            {
                // Close any currently open file
                // Strictly, we don't have to close because OpenLogFile closes before opening
                // however if the user reopens the same connection the existing connection will
                // hold a lock on the capture file preventing the new connection being created.
                Src = null;

                // Set options so that data always shows
                PrepareForStreamedData(conn.OutputFilepath);

                // Launch the process with standard output/error redirected to the temporary file
                buffered_tcp_netconn = new BufferedTcpNetConn(conn);

                // Give some UI feedback if the connection drops
                buffered_tcp_netconn.ConnectionDropped += (s, a) =>
                {
                    this.BeginInvoke(() => SetStaticStatusMessage("Connection dropped", Color.Black, Color.LightSalmon));
                };

                // Open the capture file created by buffered_process
                OpenSingleLogFile(buffered_tcp_netconn.Filepath, !buffered_tcp_netconn.TmpFile);
                buffered_tcp_netconn.Start(this);
                SetStaticStatusMessage("Connected", Color.Black, Color.LightGreen);

                // Pass over the ref
                if (m_buffered_tcp_netconn != null)
                {
                    m_buffered_tcp_netconn.Dispose();
                }
                m_buffered_tcp_netconn = buffered_tcp_netconn;
                buffered_tcp_netconn   = null;
            }
            catch (OperationCanceledException) {}
            catch (Exception ex)
            {
                Log.Write(ELogLevel.Error, ex, $"Failed to connect {conn.Hostname}:{conn.Port} -> {conn.OutputFilepath}");
                Misc.ShowMessage(this, $"Failed to connect to {conn.Hostname}:{conn.Port}.", Application.ProductName, MessageBoxIcon.Error, ex);
            }
            finally
            {
                if (buffered_tcp_netconn != null)
                {
                    buffered_tcp_netconn.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
 public NetConn(NetConn rhs)
 {
     ProtocolType     = rhs.ProtocolType;
     Listener         = rhs.Listener;
     Hostname         = rhs.Hostname;
     Port             = rhs.Port;
     ProxyType        = rhs.ProxyType;
     ProxyHostname    = rhs.ProxyHostname;
     ProxyPort        = rhs.ProxyPort;
     ProxyUserName    = rhs.ProxyUserName;
     ProxyPassword    = rhs.ProxyPassword;
     OutputFilepath   = rhs.OutputFilepath;
     AppendOutputFile = rhs.AppendOutputFile;
 }
Ejemplo n.º 4
0
 public BufferedTcpNetConn(NetConn conn)
     : base(conn.OutputFilepath, conn.AppendOutputFile)
 {
     m_conn = conn;
     m_buf  = new byte[BufBlockSize];
 }
Ejemplo n.º 5
0
        public NetworkConnectionUI(Settings settings)
        {
            InitializeComponent();
            m_settings     = settings;
            m_outp_history = new List <string>(m_settings.OutputFilepathHistory);
            Conn           = m_settings.NetworkConnectionHistory.Length != 0 ? new NetConn(m_settings.NetworkConnectionHistory[0]) : new NetConn();
            m_tt           = new ToolTip();
            string tt;

            // Protocol type
            m_combo_protocol_type.ToolTip(m_tt, "The connection type");
            var allowed = new[] { ProtocolType.Tcp, ProtocolType.Udp };

            foreach (var i in allowed)
            {
                m_combo_protocol_type.Items.Add(i);
            }
            m_combo_protocol_type.SelectedIndex         = 0;
            m_combo_protocol_type.SelectedIndexChanged += (s, a) =>
            {
                Conn.ProtocolType = (ProtocolType)m_combo_protocol_type.SelectedItem;
                UpdateUI();
            };

            // Listen
            tt = "When checked will act as a server listening for incoming connections.\r\nWhen not checked, will act as a client and attempt to connect to the remote system";
            m_check_listener.ToolTip(m_tt, tt);
            m_check_listener.Checked = Conn.Listener;
            m_check_listener.Click  += (s, a) =>
            {
                Conn.Listener = m_check_listener.Checked;
                UpdateUI();
            };

            // Hostname
            tt = "The remote host to connect to and receive data from";
            m_lbl_hostname.ToolTip(m_tt, tt);
            m_combo_hostname.ToolTip(m_tt, tt);
            foreach (var i in m_settings.NetworkConnectionHistory)
            {
                m_combo_hostname.Items.Add(i);
            }
            if (m_settings.NetworkConnectionHistory.Length != 0)
            {
                m_combo_hostname.SelectedIndex = 0;
            }
            m_combo_hostname.TextChanged += (s, a) =>
            {
                Conn.Hostname = m_combo_hostname.Text;
                UpdateUI();
            };
            m_combo_hostname.SelectedIndexChanged += (s, a) =>
            {
                Conn = new NetConn((NetConn)m_combo_hostname.SelectedItem);
                UpdateUI();
            };

            // Port
            tt = "The remote port to connect to and receive data from";
            m_lbl_port.ToolTip(m_tt, tt);
            m_spinner_port.ToolTip(m_tt, tt);
            m_spinner_port.Value         = Conn.Port;
            m_spinner_port.ValueChanged += (s, a) =>
            {
                Conn.Port = (ushort)m_spinner_port.Value;
                UpdateUI();
            };

            // Use proxy
            m_combo_proxy_type.ToolTip(m_tt, "Select if using a proxy server");
            m_combo_proxy_type.DataSource            = Enum.GetValues(typeof(Proxy.EType));
            m_combo_proxy_type.SelectedIndex         = (int)Conn.ProxyType;
            m_combo_proxy_type.SelectedIndexChanged += (s, a) =>
            {
                Conn.ProxyType = (Proxy.EType)m_combo_proxy_type.SelectedItem;
                Conn.ProxyPort = Proxy.PortDefault(Conn.ProxyType);
                UpdateUI();
            };

            // Proxy host
            tt = "The host name of the proxy server";
            m_lbl_proxy_hostname.ToolTip(m_tt, tt);
            m_edit_proxy_hostname.ToolTip(m_tt, tt);
            m_edit_proxy_hostname.Text         = Conn.ProxyHostname;
            m_edit_proxy_hostname.TextChanged += (s, a) =>
            {
                if (!((TextBox)s).Modified)
                {
                    return;
                }
                Conn.ProxyHostname = m_edit_proxy_hostname.Text;
                UpdateUI();
            };

            // Proxy port
            tt = "The remote port of the proxy server";
            m_lbl_proxy_port.ToolTip(m_tt, tt);
            m_spinner_proxy_port.ToolTip(m_tt, tt);
            m_spinner_proxy_port.Value         = Conn.ProxyPort;
            m_spinner_proxy_port.ValueChanged += (s, a) =>
            {
                Conn.ProxyPort = (ushort)m_spinner_proxy_port.Value;
                UpdateUI();
            };

            // Proxy user name
            tt = "The username used to connect to the proxy server.\r\nLeave blank if no username is required";
            m_lbl_proxy_username.ToolTip(m_tt, tt);
            m_edit_proxy_username.ToolTip(m_tt, tt);
            m_edit_proxy_username.Text         = Conn.ProxyUserName;
            m_edit_proxy_username.TextChanged += (s, a) =>
            {
                if (!((TextBox)s).Modified)
                {
                    return;
                }
                Conn.ProxyUserName = m_edit_proxy_username.Text;
                UpdateUI();
            };

            // Proxy password
            tt = "The password used to connect to the proxy server.\r\nLeave blank if no password is required";
            m_lbl_proxy_password.ToolTip(m_tt, tt);
            m_edit_proxy_password.ToolTip(m_tt, tt);
            m_edit_proxy_password.Text         = Conn.ProxyPassword;
            m_edit_proxy_password.TextChanged += (s, a) =>
            {
                if (!((TextBox)s).Modified)
                {
                    return;
                }
                Conn.ProxyPassword = m_edit_proxy_password.Text;
                UpdateUI();
            };

            // Output file
            m_combo_output_filepath.ToolTip(m_tt, "The file to capture network data in.\r\nLeave blank to not save captured data");
            foreach (var i in m_outp_history)
            {
                m_combo_output_filepath.Items.Add(i);
            }
            m_combo_output_filepath.Text         = Conn.OutputFilepath;
            m_combo_output_filepath.TextChanged += (s, a) =>
            {
                Conn.OutputFilepath = m_combo_output_filepath.Text;
                UpdateUI();
            };

            // Browse output file
            m_btn_browse_output.Click += (s, a) =>
            {
                var dg = new SaveFileDialog {
                    Filter = Constants.LogFileFilter, CheckPathExists = true, OverwritePrompt = false
                };
                if (dg.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                Conn.OutputFilepath = dg.FileName;
                UpdateUI();
            };

            // Append to existing
            m_check_append.ToolTip(m_tt, "If checked, captured data is appended to the capture file.\r\nIf not, then the capture file is overwritten");
            m_check_append.Checked = Conn.AppendOutputFile;
            m_check_append.Click  += (s, a) =>
            {
                Conn.AppendOutputFile = m_check_append.Checked;
                UpdateUI();
            };

            Shown += (s, a) =>
            {
                UpdateUI();
            };

            // Save settings on close
            FormClosing += (s, a) =>
            {
                // If launch is selected, add the launch command line to the history
                if (DialogResult == DialogResult.OK && Conn.Hostname.Length != 0)
                {
                    m_settings.NetworkConnectionHistory = Util.AddToHistoryList(m_settings.NetworkConnectionHistory, Conn, true, Constants.MaxNetConnHistoryLength);
                }
            };

            Disposed += (s, a) =>
            {
                m_tt.Dispose();
            };
        }
Ejemplo n.º 6
0
        public Settings()
        {
            RecentFiles       = string.Empty;
            RecentPatternSets = string.Empty;
            Font                        = new Font("Consolas", 8.25f, GraphicsUnit.Point);
            RestoreScreenLoc            = false;             // False so that first runs start in the default window position
            ScreenPosition              = new Point(100, 100);
            WindowSize                  = new Size(640, 480);
            PatternSetDirectory         = Util.ResolveUserDocumentsPath(Application.CompanyName, Application.ProductName);
            ExportFilepath              = null;
            AlternateLineColours        = true;
            LineSelectBackColour        = Color.DarkGreen;
            LineSelectForeColour        = Color.White;
            LineBackColour1             = Color.WhiteSmoke;
            LineBackColour2             = Color.White;
            LineForeColour1             = Color.Black;
            LineForeColour2             = Color.Black;
            FileScrollWidth             = Constants.FileScrollWidthDefault;
            ScrollBarFileRangeColour    = Color.FromArgb(0x80, Color.White);
            ScrollBarCachedRangeColour  = Color.FromArgb(0x40, Color.LightBlue);
            ScrollBarDisplayRangeColour = Color.FromArgb(0x80, Color.SteelBlue);
            BookmarkColour              = Color.Violet;
            RowHeight                   = Constants.RowHeightDefault;
            LoadLastFile                = false;
            LastLoadedFile              = string.Empty;
            OpenAtEnd                   = true;
            FullPathInTitle             = true;
            TabSizeInSpaces             = 4;
            FileChangesAdditive         = true;
            IgnoreBlankLines            = false;
            AlwaysOnTop                 = false;
            FirstRun                    = true;
            ShowTOTD                    = true;
            CheckForUpdates             = false;
            CheckForUpdatesServer       = "http://www.rylogic.co.nz/";
            UseWebProxy                 = false;
            WebProxyHost                = string.Empty;
            WebProxyPort                = Constants.PortNumberWebProxyDefault;
            QuickFilterEnabled          = false;
            HighlightsEnabled           = true;
            FiltersEnabled              = false;
            TransformsEnabled           = false;
            ActionsEnabled              = false;
            TailEnabled                 = true;
            WatchEnabled                = true;
            FileBufSize                 = Constants.FileBufSizeDefault;
            MaxLineLength               = Constants.MaxLineLengthDefault;
            LineCacheCount              = Constants.LineCacheCountDefault;
            Patterns                    = PatternSet.Default();
            RowDelimiter                = string.Empty;             // stored in humanised form, empty means auto detect
            ColDelimiter                = string.Empty;             // stored in humanised form, empty means auto detect
            ColumnCount                 = 2;
            Encoding                    = string.Empty;             // empty means auto detect
            OutputFilepathHistory       = new string[0];
            LogProgramOutputHistory     = new LaunchApp[0];
            NetworkConnectionHistory    = new NetConn[0];
            SerialConnectionHistory     = new SerialConn[0];
            PipeConnectionHistory       = new PipeConn[0];
            AndroidLogcat               = new AndroidLogcat();

            AutoSaveOnChanges = true;
        }