示例#1
0
        /// <summary>
        /// Disable all checks
        /// </summary>
        private void labelDisableAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            for (int i = 0; i < enabledChecksListView.Items.Count; i++)
            {
                // Cast the List Box item to a Watcher Check
                WatcherCheck check = enabledChecksListView.Items[i].Tag as WatcherCheck;
                if (check == null)
                {
                    String errorMessage = "ListView item referenced is not a WatcherCheck.";
                    Trace.TraceError("Error: {0}", errorMessage);
                    Debug.Assert(false, errorMessage);
                    return;
                }

                // TODO: Have the configuration persist the check Enabled settings
                // Update the check configuration
                ((WatcherCheck)enabledChecksListView.Items[i].Tag).Enabled = false;
                enabledChecksListView.Items[i].Checked = false;
                WatcherEngine.Configuration.SetCheckEnabledConfig(check);

                int index = WatcherEngine.CheckManager.Checks.IndexOf(check);
                WatcherEngine.CheckManager.Checks[index]._enabled = false;
            }
            domainconfigButton_Click(sender, e);
        }
示例#2
0
        /// <summary>
        /// Scan through each check after a click and update the enabled/disabled state.
        /// </summary>
        private void checkenableListBox_ItemCheck(object sender, EventArgs e)
        {
            bool isCheckEnabled;

            for (int i = 0; i < enabledChecksListView.Items.Count; i++)
            {
                isCheckEnabled = enabledChecksListView.Items[i].Checked;

                // Cast the List Box item to a Watcher Check
                WatcherCheck check = enabledChecksListView.Items[i].Tag as WatcherCheck;
                if (check == null)
                {
                    String errorMessage = "ListView item referenced is not a WatcherCheck.";
                    Trace.TraceError("Error: {0}", errorMessage);
                    Debug.Assert(false, errorMessage);
                    return;
                }

                // TODO: Have the configuration persist the check Enabled settings
                // Update the check configuration
                ((WatcherCheck)enabledChecksListView.Items[i].Tag).Enabled = isCheckEnabled;
                WatcherEngine.Configuration.SetCheckEnabledConfig(check);

                int index = WatcherEngine.CheckManager.Checks.IndexOf(check);
                WatcherEngine.CheckManager.Checks[index]._enabled = isCheckEnabled;
            }
        }
示例#3
0
        /// <summary>
        /// This method returns an array of strings representing each level in the fully-qualified
        /// type-name heirarchy.
        /// </summary>
        /// <remarks>TODO: This should probably not return an array.</remarks>
        /// <param name="check">The Watcher check whose name is to be split.</param>
        /// <returns>An array of strings representing each level in the fully-qualified type-name heirarchy.</returns>
        private String[] GetCheckNameTokens(WatcherCheck check)
        {
            String[] tokens = check.GetType().ToString().Split('.');

            // Make sure the tokenization was sane
            if (tokens.Length < 1)
            {
                String errorMessage = String.Format("The name of the check could not be determined ({0}).", check.GetType());
                Trace.TraceError("Error: {0}", errorMessage);
                Debug.Assert(false, errorMessage);
                return(new String[] { String.Empty }); // Prevent null reference exceptions by callers doing indexing
            }

            return(tokens);
        }
示例#4
0
        /// <summary>
        /// Get a configuration item and return the specified default value if not already present.
        /// </summary>
        /// <param name="check">The Watcher check whose configuration option is to be retrieved.</param>
        /// <param name="configOption">The configuration option to retrieve.</param>
        /// <param name="defaultValue">The value to return if not already set in the configuration.</param>
        /// <returns>The value of the specified check's configuration option.</returns>
        public String GetConfigItem(WatcherCheck check, String configOption, String defaultValue)
        {
            // The name of the check as it is stored in the application configuration
            String[] configurationName = GetCheckNameTokens(check);
            if (configurationName.Length > 0)
            {
                // Prepend Check Class to KeyName
                String checkOptionName = configurationName[configurationName.Length - 1] + '\\' + configOption;
                if (!String.IsNullOrEmpty(configurationName[configurationName.Length - 1]))
                {
                    String setting = String.Empty;

                    try
                    {
                        // Load the check configuration from the application configuration
                        setting = Get(checkOptionName);// ConfigurationManager.AppSettings[checkOptionName];
                    }

                    catch (ConfigurationErrorsException e)
                    {
                        // Thrown if a failure occurs when reading the application configuration
                        String errorMessage = String.Format("Error: ConfigurationErrorsException: {0}", e.Message);
                        Trace.TraceError("Error: {0}", errorMessage);
                        Debug.Assert(false, errorMessage);
                    }

                    // If the configuration entry for the check does not exist, use the default value
                    if (String.IsNullOrEmpty(setting))
                    {
                        // Set the default value if it was specified
                        if (!String.IsNullOrEmpty(defaultValue))
                        {
                            SetConfigItem(check, configOption, defaultValue);
                        }

                        return(defaultValue);
                    }

                    // Note: checking a second time does not get an updated setting
                    return(setting);
                }
            }

            return(String.Empty);
        }
示例#5
0
 /// <summary>
 /// Set a configuration option for the specified check.  An entry will be created if it doesn't already exist.
 /// </summary>
 /// <param name="check">The Watcher check whose configuration option is to be set.</param>
 /// <param name="configOption">The configuration option to set.</param>
 /// <param name="value">The configuration value to set.</param>
 public void SetConfigItem(WatcherCheck check, String configOption, String value)
 {
     String[] configurationName = GetCheckNameTokens(check);
     if (configurationName.Length > 0)
     {
         String checkOptionName = configurationName[configurationName.Length - 1] + "\\" + configOption;
         if (!String.IsNullOrEmpty(configurationName[configurationName.Length - 1]))
         {
             Remove(checkOptionName);
             Add(checkOptionName, value);
             if (_autosave)
             {
                 Save();
             }
         }
     }
     // TODO: return a bool for success
 }
示例#6
0
        /// <summary>
        /// This method sets the enabled/disabled state of the check in the application configuration.
        /// </summary>
        /// <remarks>TODO: Names can collide</remarks>
        /// <param name="check">The check whose status is to be stored.</param>
        public void SetCheckEnabledConfig(WatcherCheck check)
        {
            // Determine the name of the check entry from its type
            String[] configurationName = GetCheckNameTokens(check);

            String checkstate = check.Enabled ? "True" : "False";

            // Store the check enabled/disabled state
            if (Get(configurationName[configurationName.Length - 1]) != checkstate)
            {
                Remove(configurationName[configurationName.Length - 1]);
                Add(configurationName[configurationName.Length - 1], check.Enabled ? "True" : "False");
                if (_autosave)
                {
                    Save();
                }
            }
        }
示例#7
0
        /// <summary>
        /// This method determines if the specified check is enabled in the configuration.  If it is
        /// not, it creates an entry for the check in the application configuration using the default
        /// setting retrieved from the check's Enabled property.
        /// </summary>
        /// <remarks>TODO: Check names can collide</remarks>
        /// <param name="check">The check whose status is to be retrieved.</param>
        /// <returns>True if the check is enabled; False if it is not.  The check's default (Check.Enabled) is returned if the check did not exist in the configuration.</returns>
        public Boolean GetCheckEnabledConfig(WatcherCheck check)
        {
            // Determine the name of the check configuration entry from its type
            String[] configurationName = GetCheckNameTokens(check);

            // Default: the check's enabled/disabled value
            Boolean enabled = check.Enabled;

            // Determine the check's value from the configuration, if it has been set
            String configurationValue = Get(configurationName[configurationName.Length - 1]);//ConfigurationManager.AppSettings[configurationName[configurationName.Length - 1]];

            if (String.IsNullOrEmpty(configurationValue))
            {
                // TODO: Trace addition of configuration option
                // The item doesn't exist in the configuration, use the check's default enabled/disabled value
                Add(configurationName[configurationName.Length - 1], enabled ? "True" : "False");
            }
            else
            {
                enabled = (configurationValue == "True");
            }

            return(enabled);
        }
示例#8
0
 /// <summary>
 /// Get a configuration item with no default value set.
 /// </summary>
 /// <param name="check">The Watcher check whose configuration option is to be retrieved.</param>
 /// <param name="configOption">The configuration option to retrieve.</param>
 /// <returns>The value of the specified option.</returns>
 public String GetConfigItem(WatcherCheck check, String configOption)
 {
     return(GetConfigItem(check, configOption, String.Empty));
 }
示例#9
0
        /// <summary>
        /// Updates UI when a check is clicked on.
        /// </summary>
        private void enabledChecksListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // No need to continue processing this event if there are no items selected
            if (enabledChecksListView.SelectedItems.Count < 1)
            {
                Debug.Print("EnabledChecksListView_SelectedIndexChanged event fired, but no items were selected.");
                return;
            }

            domainconfigButton.Visible = true;
            checklistsplitContainer.Panel2.SuspendLayout();
            checklistsplitContainer.Panel2.Controls.Clear();

            // Retrieve the check object from the user-data associated with the item
            WatcherCheck check = (WatcherCheck)enabledChecksListView.SelectedItems[0].Tag;

            RichTextBox description = new RichTextBox();

            description.SuspendLayout();
            //description.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
            //description.BackColor = System.Drawing.SystemColors.Control;
            description.BackColor   = WatcherEngine.UI.watcherResultsTab.BackColor;
            description.BorderStyle = BorderStyle.None;
            description.Multiline   = true;
            description.Margin      = new System.Windows.Forms.Padding(3, 10, 3, 10);
            description.Dock        = DockStyle.Fill; // Default to filling the entire panel (in the event that there is no configuration)
            description.DetectUrls  = true;
            description.ScrollBars  = RichTextBoxScrollBars.Vertical;
            description.Text        = check.GetDescription();
            description.WordWrap    = true;
            description.Font        = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            //description.Height = description.GetLineFromCharIndex(description.Text.Length) + 1 * description.Font.Height + 1 + description.Margin.Vertical;
            description.Height = 130;
            // Display the configuration options for this check if they exist
            Panel panelCheckConfiguration = check.GetConfigPanel();

            if (panelCheckConfiguration != null)
            {
                // Prepare to display the check configuration
                panelCheckConfiguration.SuspendLayout();
                panelCheckConfiguration.Dock       = DockStyle.Fill;
                panelCheckConfiguration.AutoScroll = true;
                // Setup scroll bars for when the display is too small
                panelCheckConfiguration.AutoScrollMinSize = new System.Drawing.Size(500, 250);
                panelCheckConfiguration.Padding           = new System.Windows.Forms.Padding(0, 10, 0, 0);

                // Add the configuration options to the bottom panel of the check list tab
                checklistsplitContainer.Panel2.Controls.Add(panelCheckConfiguration);
                panelCheckConfiguration.ResumeLayout();

                // Since a configuration panel exists, we'll need to adjust the location of the description
                description.Dock = DockStyle.Top;
            }

            reflinkLabel.Text = check.GetRefLink();
            // Add the check description to the bottom panel of the check list tab
            checklistsplitContainer.Panel2.Controls.Add(description);
            checklistsplitContainer.Panel2.Controls.Add(referencepanel);

            description.ResumeLayout();

            // Display the check's description/configuration panel
            checklistsplitContainer.Panel2.ResumeLayout();
            checklistsplitContainer.Panel2.Show();
        }