Ejemplo n.º 1
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(WatcherOutputPlugin plugin, String configOption, String defaultValue)
        {
            // The name of the check as it is stored in the application configuration
            String configurationName = plugin.GetName();

            if (configurationName.Length > 0)
            {
                // Prepend Plugin Class to KeyName
                String pluginOptionName = configurationName + '\\' + configOption;
                if (!String.IsNullOrEmpty(configurationName))
                {
                    String setting = String.Empty;

                    try
                    {
                        // Load the check configuration from the application configuration
                        setting = Get(pluginOptionName);// 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(plugin, configOption, defaultValue);
                        }

                        return(defaultValue);
                    }

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

            return(String.Empty);
        }
Ejemplo n.º 2
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(WatcherOutputPlugin plugin, String configOption, String value)
        {
            String configurationName = plugin.GetName();

            if (configurationName.Length > 0)
            {
                String pluginOptionName = configurationName + "\\" + configOption;
                if (!String.IsNullOrEmpty(configurationName))
                {
                    Remove(pluginOptionName);
                    Add(pluginOptionName, value);
                    if (_autosave)
                    {
                        Save();
                    }
                }
            }
            // TODO: return a bool for success
        }
Ejemplo n.º 3
0
        /// <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);
        }