private void AddAlert(Session session, WatcherResultSeverity severity, String context) { String name = ShortName; String text = ShortDescription + session.fullUrl + "\r\n\r\n" + context; WatcherEngine.Results.Add(severity, session.id, session.fullUrl, name, text, StandardsCompliance, findingnum, Reference); }
/// <summary> /// This method adds a result from a check to the UI result control. /// </summary> /// <param name="resultSeverity">The severity of the finding.</param> /// <param name="sessionId">The ID of the Fiddler Session where the finding was discovered.</param> /// <param name="sessionUrl">The URL where the finding was discovered.</param> /// <param name="checkName">The name of the check that performed the analysis.</param> /// <param name="resultDescription">The description of the finding.</param> /// <param name="compliesWith">Standards implemented by Watcher that this check conforms to.</param> /// <param name="count">The number of times the finding was discovered.</param> public void Add(WatcherResultSeverity resultSeverity, Int32 sessionId, String sessionUrl, String checkName, String resultDescription, WatcherCheckStandardsCompliance compliesWith, Int32 count, String refLink) { WatcherResultsControl control = WatcherEngine.UI.WatcherResultsControl; // A control cannot be updated from a non-UI thread. If the InvokeRequired property is set, // we are on a non-UI thread and must post a message to the UI thread to handle the update on // our behalf. According to Richter, this is one of the few instances where BeginInvoke can // be called without a corresponding EndInvoke(). if (control.InvokeRequired) { // We're not the UI thread: marshall an update to the control asynchronously control.BeginInvoke(new AddAlertCallback(control.AddAlert), new Object[] { resultSeverity, sessionId, sessionUrl, checkName, resultDescription, compliesWith, count, refLink }); } else { // We're the UI thread, update the control directly control.AddAlert(resultSeverity, sessionId, sessionUrl, checkName, resultDescription, compliesWith, count, refLink); } }
/// <summary> /// This event handler method is called when the Alert Filter combobox is changed. /// </summary> private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string selection = this.noisereductioncomboBox.SelectedItem.ToString(); if (selection == WatcherResultSeverity.Informational.ToString()) { this.noisereduction = WatcherResultSeverity.Informational; } else if (selection == WatcherResultSeverity.Low.ToString()) { this.noisereduction = WatcherResultSeverity.Low; } else if (selection == WatcherResultSeverity.Medium.ToString()) { this.noisereduction = WatcherResultSeverity.Medium; } else if (selection == WatcherResultSeverity.High.ToString()) { this.noisereduction = WatcherResultSeverity.High; } this.alertListView.BeginUpdate(); foreach (ListViewItem item in this.alertListView.Items) { this.alertListView.Items.Remove(item); this.alertTextBox.Clear(); } foreach (AlertListViewItem item in alerts) { if (item.Severity >= this.noisereduction) { this.alertListView.Items.Add(item); } } this.alertListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.alertListView.EndUpdate(); WatcherEngine.Configuration.Remove("DefaultFilter"); WatcherEngine.Configuration.Add("DefaultFilter", this.noisereductioncomboBox.SelectedItem.ToString()); }
/// <summary> /// This method initializes the control values prior to displaying the control. /// </summary> /// <remarks> /// This event occurs before the control becomes visible for the first time (ref: MSDN). /// </remarks> protected override void OnLoad(EventArgs e) { // Don't load the configuration in design mode if (this.Site == null || this.Site.DesignMode == false) { //Initialize Save Method //String savetoXML = "XML File"; //this.cbExportMethod.Items.Add(savetoXML); foreach (WatcherOutputPlugin plugin in WatcherEngine.OutputPluginManager.OutputPlugins) { this.cbExportMethod.Items.Add(plugin); } String SaveMethod = WatcherEngine.Configuration.Get("DefaultSaveMethod"); if (!String.IsNullOrEmpty(SaveMethod)) { SaveMethod = Utility.Base64Decode(SaveMethod); //Store with Base64 since plugins may use dangerous characters for (int i = 0; i < cbExportMethod.Items.Count; i++) { WatcherOutputPlugin OutPlugin = (WatcherOutputPlugin)this.cbExportMethod.Items[i]; if (SaveMethod == OutPlugin.GetName()) { this.cbExportMethod.SelectedItem = this.cbExportMethod.Items[i]; break; } } } // Reduce flicker ListViewHelper.EnableDoubleBuffer(this.alertListView); // Instantiate the list view comparison class alvwColumnSorter = new AlertListViewColumnSorter(); this.alertListView.ListViewItemSorter = alvwColumnSorter; // Set the default filter level for check alerts this.noisereduction = WatcherResultSeverity.Informational; // TODO: Use custom Watcher configuration section // Use the filter level from the configuration, if it exists if (!String.IsNullOrEmpty(WatcherEngine.Configuration.Get("DefaultFilter"))) { this.noisereductioncomboBox.SelectedItem = WatcherEngine.Configuration.Get("DefaultFilter"); } else { //Update the Selected Item since the configuration item did not exist. this.noisereductioncomboBox.SelectedItem = "Informational"; } // Determine whether to auto-scroll alerts if (!String.IsNullOrEmpty(WatcherEngine.Configuration.Get("AutoScroll"))) { string temp = WatcherEngine.Configuration.Get("AutoScroll"); this.autoscrollcheckBox.Checked = Boolean.Parse(temp); } int index = this.label3.Text.IndexOf(","); Version currentver = new UpdateManager().CurrentVersionEngine; this.label3.Text = this.label3.Text.Insert(index, " v" + currentver.ToString()); } textBoxSearchResults.TextChanged += new EventHandler(textBoxSearchResults_TextChanged); base.OnLoad(e); }
/// <summary> /// This method adds a check result to the list view. /// </summary> /// <param name="resultSeverity">The severity of the finding.</param> /// <param name="sessionId">The ID of the Fiddler Session where the finding was discovered.</param> /// <param name="sessionUrl">The URL where the finding was discovered.</param> /// <param name="checkName">The name of the check that performed the analysis.</param> /// <param name="resultDescription">The description of the finding.</param> /// <param name="compliesWith">Standards implemented by Watcher that this check conforms to.</param> /// <param name="count">The number of times the finding was discovered.</param> public void AddAlert(WatcherResultSeverity resultSeverity, int sessionId, String sessionUrl, String checkName, String resultDescription, WatcherCheckStandardsCompliance compliesWith, int count, String reflink) { AlertListViewItem alvi = null; int highincrement = 0; int mediumincrement = 0; int lowincrement = 0; int informationalincrement = 0; int highissueincrement = 0; int mediumissueincrement = 0; int lowissueincrement = 0; int informationalissueincrement = 0; switch (resultSeverity) { case WatcherResultSeverity.High: alvi = new AlertListViewItem(resultSeverity, sessionId, checkName, sessionUrl, resultDescription, count, reflink); alvi.ForeColor = Color.Red; highissueincrement = count; highincrement++; break; case WatcherResultSeverity.Medium: alvi = new AlertListViewItem(resultSeverity, sessionId, checkName, sessionUrl, resultDescription, count, reflink); alvi.ForeColor = Color.Orange; mediumissueincrement = count; mediumincrement++; break; case WatcherResultSeverity.Low: alvi = new AlertListViewItem(resultSeverity, sessionId, checkName, sessionUrl, resultDescription, count, reflink); alvi.ForeColor = Color.Blue; lowissueincrement = count; lowincrement++; break; case WatcherResultSeverity.Informational: alvi = new AlertListViewItem(resultSeverity, sessionId, checkName, sessionUrl, resultDescription, count, reflink); alvi.ForeColor = Color.Green; informationalissueincrement = count; informationalincrement++; break; default: Debug.Assert(false, "Alert severity not specified."); break; } // Remove dupes // Testing if this is necessary for (int x = 0; x < this.alertListView.Items.Count; ++x) { AlertListViewItem tlvi = (AlertListViewItem)this.alertListView.Items[x]; if (tlvi != null) { if (tlvi.Equals(alvi)) { return; } } } // Update count after dealing with duplicates highcount = highcount + highincrement; mediumcount = mediumcount + mediumincrement; lowcount = lowcount + lowincrement; informationalcount = informationalcount + informationalincrement; highissues = highissues + highissueincrement; mediumissues = mediumissues + mediumissueincrement; lowissues = lowissues + lowissueincrement; informationalissues = informationalissues + informationalissueincrement; total = total + informationalincrement + lowincrement + mediumincrement + highincrement; RenderCount(); alvi.SubItems.Add(sessionId.ToString()); alvi.SubItems.Add(checkName); alvi.SubItems.Add(sessionUrl); alerts.Add(alvi); if (this.noisereduction <= resultSeverity) { this.alertListView.BeginUpdate(); this.alertListView.Items.Add(alvi); if (autoscroll) { this.alertListView.EnsureVisible(alertListView.Items.Count - 1); } this.alertListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.alertListView.EndUpdate(); } }
/// <summary> /// TODO: fixup documentation for this function. /// </summary> /// <param name="resultSeverity"></param> /// <param name="sessionId"></param> /// <param name="sessionUrl"></param> /// <param name="checkName"></param> /// <param name="resultDescription"></param> /// <param name="compliesWith"></param> /// <param name="num"></param> public void Add(WatcherResultSeverity resultSeverity, Int32 sessionId, String sessionUrl, String checkName, String resultDescription, WatcherCheckStandardsCompliance compliesWith, Int32 num) { Add(resultSeverity, sessionId, sessionUrl, checkName, resultDescription, compliesWith, num, String.Empty); }