Пример #1
0
        /// <summary>
        /// Saves the given boolean property into the given node.
        /// </summary>
        /// <param name="rootNode">
        /// The node under which to store the new property node.
        /// </param>
        /// <param name="property">
        /// The property to save.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property.
        /// </param>
        /// <returns>
        /// Returns true if the property was written.
        /// </returns>
        private static bool SaveBooleanProperty(XmlNode rootNode, BooleanProperty property, string propertyName)
        {
            Param.AssertNotNull(rootNode, "rootNode");
            Param.AssertNotNull(property, "property");
            Param.AssertValidString(propertyName, "propertyName");

            // Create and append the root node for this property.
            XmlNode propertyNode = rootNode.OwnerDocument.CreateElement("BooleanProperty");

            rootNode.AppendChild(propertyNode);

            XmlAttribute propertyNameAttribute = rootNode.OwnerDocument.CreateAttribute("Name");

            propertyNameAttribute.Value = propertyName;
            propertyNode.Attributes.Append(propertyNameAttribute);

            // Add the value.
            propertyNode.InnerText = property.Value.ToString();

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Adds or updates a property to enable or disable a rule depending on the value of a
        /// legacy property.
        /// </summary>
        /// <param name="ruleName">
        /// The name of the rule to enable or disable.
        /// </param>
        /// <param name="value">
        /// The value of the legacy property.
        /// </param>
        /// <param name="properties">
        /// The collection of properties.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void AddOrUpdateLegacyBooleanProperty(string ruleName, bool value, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(ruleName, "ruleName");
            Param.Ignore(value);
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Determine whethere is already an Enabled property for this rule.
            string          propertyName = ruleName + "#Enabled";
            BooleanProperty property     = properties[propertyName] as BooleanProperty;

            if (property == null)
            {
                // Add a new property which enables or disables this rule depending on the
                // value of the legacy property.
                AddBooleanProperty(propertyName, value, properties, propertyDescriptors);
            }
            else if (!value)
            {
                // The rule has already been explictely enabled or disabled. In this case we
                // never enable the rule, but we may disable it if the legacy property is set to false.
                property.Value = false;
            }
        }
Пример #3
0
        /// <summary>
        /// Refreshes the merged override state of properties on the page.
        /// </summary>
        public void RefreshSettingsOverrideState()
        {
            this.writeCacheParentProperty = this.tabControl.ParentSettings == null
                                                ? null
                                                : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.writeCachePropertyDescriptor.PropertyName) as
                                            BooleanProperty;

            this.maxViolationCountParentProperty = this.tabControl.ParentSettings == null
                                                       ? null
                                                       : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.maxViolationCountPropertyDescriptor.PropertyName)
                                                   as IntProperty;

            this.cultureParentProperty = this.tabControl.ParentSettings == null
                                             ? null
                                             : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.culturePropertyDescriptor.PropertyName) as StringProperty;

            this.violationsAsErrorsParentProperty = this.tabControl.ParentSettings == null
                                                        ? null
                                                        : this.tabControl.ParentSettings.GlobalSettings.GetProperty(
                this.violationsAsErrorsPropertyDescriptor.PropertyName) as
                                                    BooleanProperty;

            this.SetBoldState();
        }
Пример #4
0
        /// <summary>
        /// Initializes the page.
        /// </summary>
        /// <param name="propertyControl">
        /// The tab control object.
        /// </param>
        public void Initialize(PropertyControl propertyControl)
        {
            Param.AssertNotNull(propertyControl, "propertyControl");

            this.tabControl = propertyControl;

            // Get the cache setting.
            this.writeCachePropertyDescriptor = this.tabControl.Core.PropertyDescriptors["WriteCache"] as PropertyDescriptor <bool>;

            this.writeCacheParentProperty = this.tabControl.ParentSettings == null
                                                ? null
                                                : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.writeCachePropertyDescriptor.PropertyName) as
                                            BooleanProperty;

            BooleanProperty mergedWriteCacheProperty = this.tabControl.MergedSettings == null
                                                           ? null
                                                           : this.tabControl.MergedSettings.GlobalSettings.GetProperty(this.writeCachePropertyDescriptor.PropertyName) as
                                                       BooleanProperty;

            this.enableCache.Checked = mergedWriteCacheProperty == null ? this.writeCachePropertyDescriptor.DefaultValue : mergedWriteCacheProperty.Value;

            // Max Violation Count
            this.maxViolationCountPropertyDescriptor = this.tabControl.Core.PropertyDescriptors["MaxViolationCount"] as PropertyDescriptor <int>;

            this.maxViolationCountParentProperty = this.tabControl.ParentSettings == null
                                                       ? null
                                                       : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.maxViolationCountPropertyDescriptor.PropertyName)
                                                   as IntProperty;

            IntProperty mergedMaxViolationCountProperty = this.tabControl.MergedSettings == null
                                                              ? null
                                                              : this.tabControl.MergedSettings.GlobalSettings.GetProperty(
                this.maxViolationCountPropertyDescriptor.PropertyName) as IntProperty;

            this.maxViolationCountMaskedTextBox.Text = mergedMaxViolationCountProperty == null
                                                           ? this.maxViolationCountPropertyDescriptor.DefaultValue.ToString(CultureInfo.InvariantCulture)
                                                           : mergedMaxViolationCountProperty.Value.ToString(CultureInfo.InvariantCulture);

            // Culture
            this.culturePropertyDescriptor = this.tabControl.Core.PropertyDescriptors["Culture"] as PropertyDescriptor <string>;

            this.cultureParentProperty = this.tabControl.ParentSettings == null
                                             ? null
                                             : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.culturePropertyDescriptor.PropertyName) as StringProperty;

            StringProperty mergedCultureProperty = this.tabControl.MergedSettings == null
                                                       ? null
                                                       : this.tabControl.MergedSettings.GlobalSettings.GetProperty(this.culturePropertyDescriptor.PropertyName) as
                                                   StringProperty;

            this.cultureComboBox.SelectedIndex =
                this.cultureComboBox.FindStringExact(
                    mergedCultureProperty == null
                        ? this.culturePropertyDescriptor.DefaultValue.ToString(CultureInfo.InvariantCulture)
                        : mergedCultureProperty.Value.ToString(CultureInfo.InvariantCulture));

            // Errors As Warnings
            this.violationsAsErrorsPropertyDescriptor = this.tabControl.Core.PropertyDescriptors["ViolationsAsErrors"] as PropertyDescriptor <bool>;

            this.violationsAsErrorsParentProperty = this.tabControl.ParentSettings == null
                                                ? null
                                                : this.tabControl.ParentSettings.GlobalSettings.GetProperty(this.violationsAsErrorsPropertyDescriptor.PropertyName) as
                                                    BooleanProperty;

            BooleanProperty mergedViolationsAsErrorsProperty = this.tabControl.MergedSettings == null
                                                           ? null
                                                           : this.tabControl.MergedSettings.GlobalSettings.GetProperty(
                this.violationsAsErrorsPropertyDescriptor.PropertyName) as BooleanProperty;

            this.violationsAsErrorsCheckBox.Checked = mergedViolationsAsErrorsProperty == null
                                                          ? this.violationsAsErrorsPropertyDescriptor.DefaultValue
                                                          : mergedViolationsAsErrorsProperty.Value;

            this.SetBoldState();

            // Reset the dirty flag to false now.
            this.dirty = false;
            this.tabControl.DirtyChanged();
        }
Пример #5
0
        /// <summary>
        /// Initializes the collection of enabled analyzers and rules based on these settings.
        /// </summary>
        private void InitializeEnabledRules()
        {
            if (this.enabledRules == null)
            {
                LockCookie cookie = this.enabledRulesLock.UpgradeToWriterLock(Timeout.Infinite);

                try
                {
                    if (this.enabledRules == null)
                    {
                        this.enabledRules = new Dictionary <StyleCopAddIn, Dictionary <string, Rule> >();

                        // Determine whether addins are enabled or disabled by default.
                        bool enabledByDefault = this.RulesEnabledByDefault;

                        // Iterate through all loaded parsers.
                        foreach (SourceParser parser in this.core.Parsers)
                        {
                            // Iterate through each analyzer attached to this parser.
                            foreach (SourceAnalyzer analyzer in parser.Analyzers)
                            {
                                // Create a dictionary to hold each enabled rule for the analyzer.
                                Dictionary <string, Rule> enabledRulesForAnalyzer = new Dictionary <string, Rule>();

                                // Get the settings for this analyzer, if there are any.
                                AddInPropertyCollection analyzerSettings = this.GetAddInSettings(analyzer);

                                // Iterate through each of the analyzer's rules.
                                foreach (Rule rule in analyzer.AddInRules)
                                {
                                    // Determine whether the rule is currently enabled.
                                    bool ruleEnabled = enabledByDefault && rule.EnabledByDefault;

                                    // Determine whether there is a setting which enables or disables the rules.
                                    // If the rule is set to CanDisable = false, then ignore the setting unless
                                    // we are in disabled by default mode.
                                    if (analyzerSettings != null && (!ruleEnabled || rule.CanDisable))
                                    {
                                        BooleanProperty property = analyzerSettings[rule.Name + "#Enabled"] as BooleanProperty;
                                        if (property != null)
                                        {
                                            ruleEnabled = property.Value;
                                        }
                                    }

                                    // If the rule is enabled, add it to the enabled rules dictionary.
                                    if (ruleEnabled)
                                    {
                                        enabledRulesForAnalyzer.Add(rule.Name, rule);
                                    }
                                }

                                // If the analyzer has at least one enabled rule, add the analyzer to the list
                                // of enabled analyzers.
                                if (enabledRulesForAnalyzer.Count > 0)
                                {
                                    // The rules list should not already be set for this project on this analyzer.
                                    // If so, something is wrong.
                                    Debug.Assert(!this.enabledRules.ContainsKey(analyzer), "The rule list for this analyzer should not be set yet.");

                                    this.enabledRules.Add(analyzer, enabledRulesForAnalyzer);
                                }
                            }
                        }
                    }
                }
                finally
                {
                    this.enabledRulesLock.DowngradeFromWriterLock(ref cookie);
                }
            }
        }