Exemplo n.º 1
0
        private void HighlightSelectionClick(object sender, EventArgs e)
        {
            DialogResult dr = _colorDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                Dictionary <string, string> hDefs = _dataSource.Profile.GetHighlightingDefinitions();
                string selectedColor = TVColorConverter.GetARGBString(_colorDialog.Color);
                foreach (DataGridViewRow row in _dataGrid.SelectedRows)
                {
                    string id = (string)row.Cells["_id"].Value;
                    //save this to the current profile
                    if (!hDefs.ContainsKey(id))
                    {
                        hDefs.Add(id, selectedColor);
                    }
                    else
                    {
                        hDefs[id] = selectedColor;
                    }

                    //color the row
                    row.DefaultCellStyle.BackColor = _colorDialog.Color;
                    //deselect the row
                    row.Selected = false;
                }

                //apply new highlighting definitions
                _dataSource.Profile.SetHighlightingDefinitions(hDefs);
                //deselect all rows
            }
        }
Exemplo n.º 2
0
        private void HighlightDescriptionClick(object sender, EventArgs e)
        {
            DialogResult dr = _colorDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                //get current description
                string description = (string)_dataGrid.Rows[_currentRightClickedRow].Cells["_description"].Value;
                //save this to the current profile
                Dictionary <string, string> hDefs = _dataSource.Profile.GetHighlightingDefinitions();
                if (!hDefs.ContainsKey(description))
                {
                    hDefs.Add(description, TVColorConverter.GetARGBString(_colorDialog.Color));
                    _dataSource.Profile.SetHighlightingDefinitions(hDefs);
                }
                //color all the visible rows that have this description
                int    n = _dataGrid.Rows.Count;
                string c;
                for (int i = 0; i < n; i++)
                {
                    c = (string)_dataGrid.Rows[i].Cells["_description"].Value;
                    if (c == description)
                    {
                        _dataGrid.Rows[i].DefaultCellStyle.BackColor = _colorDialog.Color;
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the highlighting color based on request id
        /// </summary>
        /// <param name="profile">Profile options for this file</param>
        /// <param name="description">The request description</param>
        /// <returns>Color</returns>
        public static Color GetColorForRequestId(ParsingOptions profile, string requestId)
        {
            Dictionary <string, string> hDefs = profile.GetHighlightingDefinitions();

            //check first if there is an exact match
            if (hDefs.ContainsKey(requestId))
            {
                return(TVColorConverter.GetColorFromString(hDefs[requestId]));
            }
            else
            {
                return(Color.Black);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves the highlighting color based on request description
        /// </summary>
        /// <param name="profile">Profile options for this file</param>
        /// <param name="description">The request description</param>
        /// <returns>Color</returns>
        public static Color GetColorForRequestDescription(ParsingOptions profile, string description)
        {
            Dictionary <string, string> hDefs = profile.GetHighlightingDefinitions();

            //check first if there is an exact match
            if (hDefs.ContainsKey(description))
            {
                return(TVColorConverter.GetColorFromString(hDefs[description]));
            }
            else
            {
                //check for all definitions if there is a partial match
                foreach (KeyValuePair <string, string> hDef in hDefs)
                {
                    if (Utils.IsMatch(description, hDef.Key))
                    {
                        return(TVColorConverter.GetColorFromString(hDef.Value));
                    }
                }
            }
            return(Color.Black);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a header row to the request list
        /// </summary>
        /// <param name="header">the header id and the header</param>
        private void AddRow(KeyValuePair <int, RequestHeader> header)
        {
            if (header.Value == null)
            {
                //the request list was probably cleared in the meanwhile
                return;
            }

            //ADD
            //obtain custom values defined by the user
            string[] customFields = header.Value.GetCustomFieldsArray(MAX_CUSTOM_COLUMNS);
            decimal  respSize     = (decimal)header.Value.ResponseLength / 1024;
            //add the row
            string stringId = header.Key.ToString(NUMBER_FORMAT);

            _dataGrid.Rows.Add(stringId,
                               header.Value.RequestLine,
                               header.Value.ResponseStatus,
                               header.Value.ThreadId,
                               header.Value.Description,
                               header.Value.RequestTime.ToString(TIME_FORMAT),
                               header.Value.ResponseTime.ToString(TIME_FORMAT),
                               String.Format(SIZE_FORMAT, respSize),
                               customFields[0],
                               customFields[1],
                               customFields[2]);

            int currentId = _dataGrid.Rows.Count - 1;

            _addedRows.Add(stringId, _dataGrid.Rows[currentId]);

            //HIGHLIGHTING
            Color selectedColor, requestColor;

            selectedColor = TVColorConverter.GetColorForRequestDescription
                                (_dataSource.Profile, header.Value.Description);

            //check for specific request highlighting
            requestColor = TVColorConverter.GetColorForRequestId
                               (_dataSource.Profile, stringId);

            //if the user specified a highlight for this specific request this color takes precedence
            if (requestColor != Color.White)
            {
                selectedColor = requestColor;
            }

            //if there is a color defined for this description
            if (selectedColor != Color.White)
            {
                _dataGrid.Rows[currentId].DefaultCellStyle.BackColor = selectedColor;
            }

            //Filter
            _dataGrid.Rows[currentId].Visible = _filter.GetRowVisibility(_dataGrid.Rows[currentId]);

            //TAIL Select and Scroll
            //if auto scroll on add is enabled
            if (_tail && _dataGrid.SelectedRows.Count < 2)
            {
                bool tailNow = false;
                //check if the last row was selected previously
                if (_dataGrid.Rows.Count > 1)
                {
                    int selectedRow;
                    selectedRow = _dataGrid.Rows.GetLastRow(DataGridViewElementStates.Selected);
                    if (selectedRow == _dataGrid.Rows.Count - 2)
                    {
                        //deselect this row
                        _dataGrid.Rows[selectedRow].Selected = false;
                        tailNow = true;
                    }
                }

                //if the list was empty before automatically select
                if (_dataGrid.Rows.Count == 1)
                {
                    tailNow = true;
                }

                if (tailNow)
                {
                    //select the last visible element in the list
                    int l = _dataGrid.Rows.GetLastRow(DataGridViewElementStates.Visible);
                    _dataGrid.Rows[l].Selected = true;
                    //scroll to it
                    if (l > -1)
                    {
                        _dataGrid.FirstDisplayedScrollingRowIndex = l;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void OptionsEditorLoad(object sender, EventArgs e)
        {
            if (TrafficViewerOptions.Instance.MemoryBufferSize == 1 &&
                TrafficViewerOptions.Instance.EstimatedLineSize == 1024)
            {
                _checkOptMemory.Checked = true;
                _checkOptSpeed.Checked  = false;
            }
            else
            {
                _checkOptMemory.Checked = false;
                _checkOptSpeed.Checked  = true;
            }

            _boxIp.Text = TrafficViewerOptions.Instance.TrafficServerIp;

            _numProxyPort.Value        = (decimal)TrafficViewerOptions.Instance.TrafficServerPort;
            _numServerSecurePort.Value = (decimal)TrafficViewerOptions.Instance.TrafficServerPortSecure;


            _gridDynElems.SetValues(TrafficViewerOptions.Instance.GetDynamicElements());

            //initialize the variable definitions list (in case is not set)
            TrafficViewerOptions.Instance.VariableDefinitions = TrafficViewerOptions.Instance.VariableDefinitions;

            //set the definitions list in a option grid format
            _gridVarDefs.SetValues((List <string>)
                                   TrafficViewerOptions.Instance.GetOption("VariableDefinitions"));

            //startup info
            _fileAutoLoad.Text = TrafficViewerOptions.Instance.StartupImport;

            //load profiles
            List <string> profilePaths   = TrafficViewerOptions.Instance.GetProfilePaths();
            string        startupProfile = TrafficViewerOptions.Instance.StartupImportProfile;
            int           selectedIndex  = 0;

            _boxStartupProfile.Items.Clear();
            foreach (string path in profilePaths)
            {
                try
                {
                    string fName = Path.GetFileName(path);
                    _boxStartupProfile.Items.Add(fName);
                    if (fName == startupProfile)
                    {
                        selectedIndex = _boxStartupProfile.Items.Count - 1;
                    }
                }
                catch { }
            }
            _boxStartupProfile.SelectedIndex = selectedIndex;


            _boxStartupParser.Items.Clear();

            foreach (ITrafficParser parser in TrafficViewer.Instance.TrafficParsers)
            {
                _boxStartupParser.Items.Add(parser.Name);

                if (String.Compare(parser.Name, TrafficViewerOptions.Instance.StartupParser) == 0)
                {
                    _boxStartupParser.SelectedIndex = _boxStartupParser.Items.Count - 1;
                }
            }

            _swatchBackground.Color = TVColorConverter.GetColorFromString(
                TrafficViewerOptions.Instance.ColorTextboxBackground);
            _swatchTextColor.Color = TVColorConverter.GetColorFromString(
                TrafficViewerOptions.Instance.ColorTextboxText);
            _swatchDiffColor.Color = TVColorConverter.GetColorFromString(
                TrafficViewerOptions.Instance.ColorDiffText);
            _swatchHighlightColor.Color = TVColorConverter.GetColorFromString(
                TrafficViewerOptions.Instance.ColorHighlight);

            _extensionGrid.SetValues((IEnumerable <string>)TrafficViewerOptions.Instance.GetOption("Extensions"));

            _checkPrompt.Checked = TrafficViewerOptions.Instance.ActionOnClose == (int)ConfirmCloseResult.Unknown;


            _gridSessionIds.SetValues(TrafficViewerOptions.Instance.GetSessionIdRegexes());

            _gridResponsePatterns.SetValues(TrafficViewerOptions.Instance.GetResponsePatterns());

            _boxHttpClient.Items.Clear();

            foreach (IHttpClientFactory clientFactory in TrafficViewer.Instance.HttpClientFactoryList)
            {
                _boxHttpClient.Items.Add(clientFactory.ClientType);

                if (String.Compare(clientFactory.ClientType, TrafficViewerOptions.Instance.HttpClientName) == 0)
                {
                    _boxHttpClient.SelectedIndex = _boxHttpClient.Items.Count - 1;
                }
            }

            _checkIgnoreInvalidCert.Checked = TrafficViewerOptions.Instance.IgnoreInvalidSslCert;
            _checkUseProxy.Checked          = TrafficViewerOptions.Instance.UseProxy;


            _boxProxyHost.Text           = TrafficViewerOptions.Instance.HttpProxyServer;
            _proxyCertificate.Text       = TrafficViewerOptions.Instance.ProxyCert;
            _boxProxyCertPass.Text       = TrafficViewerOptions.Instance.ProxyCertPass;
            _boxProxyPort.Value          = (decimal)TrafficViewerOptions.Instance.HttpProxyPort;
            _boxTimeout.Value            = (decimal)TrafficViewerOptions.Instance.HttpRequestTimeout;
            _numericRequestDelay.Value   = (decimal)TrafficViewerOptions.Instance.RequestDelay;
            _textRequestDelayFilter.Text = TrafficViewerOptions.Instance.RequestDelayFilter;


            _textForwardingHost.Text = TrafficViewerOptions.Instance.ForwardingHost;
            _numForwardingPort.Value = TrafficViewerOptions.Instance.ForwardingPort;
        }
Exemplo n.º 7
0
        private void OkClick(object sender, EventArgs e)
        {
            if (_checkOptMemory.Checked)
            {
                TrafficViewerOptions.Instance.MemoryBufferSize  = 1;
                TrafficViewerOptions.Instance.EstimatedLineSize = 1024;
            }
            else
            {
                TrafficViewerOptions.Instance.EstimatedLineSize = 10240;
                TrafficViewerOptions.Instance.MemoryBufferSize  = 100;
            }

            TrafficViewerOptions.Instance.TrafficServerIp         = _boxIp.Text;
            TrafficViewerOptions.Instance.TrafficServerPort       = (int)_numProxyPort.Value;
            TrafficViewerOptions.Instance.TrafficServerPortSecure = (int)_numServerSecurePort.Value;

            //re-initialize the variable definitions so we can use the SetMultiValueOption method
            TrafficViewerOptions.Instance.VariableDefinitions = null;
            TrafficViewerOptions.Instance.SetMultiValueOption("VariableDefinitions", _gridVarDefs.GetValues());

            TrafficViewerOptions.Instance.SetDynamicElements(_gridDynElems.GetValues());
            //import at startup
            TrafficViewerOptions.Instance.StartupImport        = _fileAutoLoad.Text;
            TrafficViewerOptions.Instance.StartupImportProfile = _boxStartupProfile.Text;

            TrafficViewerOptions.Instance.ColorTextboxBackground = TVColorConverter.GetARGBString(
                _swatchBackground.Color);
            TrafficViewerOptions.Instance.ColorTextboxText = TVColorConverter.GetARGBString(
                _swatchTextColor.Color);
            TrafficViewerOptions.Instance.ColorDiffText = TVColorConverter.GetARGBString(
                _swatchDiffColor.Color);
            TrafficViewerOptions.Instance.ColorHighlight = TVColorConverter.GetARGBString(
                _swatchHighlightColor.Color);

            TrafficViewerOptions.Instance.SetExtensions(_extensionGrid.GetValues());

            TrafficViewerOptions.Instance.SetResponsePatterns(_gridResponsePatterns.GetValues());
            TrafficViewerOptions.Instance.SetSessionIdRegexes(_gridSessionIds.GetValues());


            if (_checkPrompt.Checked)
            {
                TrafficViewerOptions.Instance.ActionOnClose = (int)ConfirmCloseResult.Unknown;
            }


            TrafficViewerOptions.Instance.StartupParser = _boxStartupParser.SelectedItem as string;

            TrafficViewerOptions.Instance.HttpClientName = _boxHttpClient.SelectedItem as string;

            //http clients
            TrafficViewer.Instance.HttpClientFactory = TrafficViewer.Instance.HttpClientFactoryList[_boxHttpClient.SelectedIndex];


            TrafficViewerOptions.Instance.IgnoreInvalidSslCert = _checkIgnoreInvalidCert.Checked;

            TrafficViewerOptions.Instance.UseProxy = _checkUseProxy.Checked;


            TrafficViewerOptions.Instance.HttpProxyServer = _boxProxyHost.Text;
            TrafficViewerOptions.Instance.ProxyCert       = _proxyCertificate.Text;
            TrafficViewerOptions.Instance.ProxyCertPass   = _boxProxyCertPass.Text;

            TrafficViewerOptions.Instance.HttpProxyPort      = (int)_boxProxyPort.Value;
            TrafficViewerOptions.Instance.HttpRequestTimeout = (int)_boxTimeout.Value;
            TrafficViewerOptions.Instance.RequestDelay       = (int)_numericRequestDelay.Value;
            TrafficViewerOptions.Instance.RequestDelayFilter = _textRequestDelayFilter.Text;

            if (String.IsNullOrEmpty(TrafficViewerOptions.Instance.ForwardingHost) && !String.IsNullOrEmpty(_textForwardingHost.Text))
            {
                if (MessageBox.Show(Resources.WarnForwarding,
                                    Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No)
                {
                    _textForwardingHost.Text = String.Empty;
                }
            }

            TrafficViewerOptions.Instance.ForwardingHost = _textForwardingHost.Text;
            TrafficViewerOptions.Instance.ForwardingPort = (int)_numForwardingPort.Value;


            TrafficViewerOptions.Instance.Save();

            //TrafficViewer.Instance.LoadExtensions(); //this causes extensions added dynamically to be deleted

            //WarnRestartNeeded();
            TrafficViewer.InitSdkSettings();

            this.Hide();
        }