/// <summary>
        /// Gets the settings given the path to the local settings.
        /// </summary>
        /// <param name="settingsPath">The path to the settings to load.</param>
        /// <param name="merge">Indicates whether to merge the settings with parent settings before returning them.</param>
        /// <param name="exception">Returns an exception if one occured while loading the settings.</param>
        /// <returns>Returns the settings.</returns>
        public override Settings GetSettings(string settingsPath, bool merge, out Exception exception)
        {
            Param.RequireValidString(settingsPath, "settingsPath");
            Param.Ignore(merge);
            Param.Ignore(merge);

            // Load the settings file.
            Settings settings = this.LoadSettingsDocument(settingsPath, true, out exception);
            if (merge)
            {
                // If there are no local settings, create an empty settings file pointing
                // at the location where we expected the local settings to be. This
                // will allow us to do a parent merge from this location.
                if (settings == null)
                {
                    settings = new Settings(this.Core, settingsPath, Path.GetDirectoryName(settingsPath));
                }

                // Merge the file and return it.
                SettingsMerger merger = new SettingsMerger(settings, this);
                settings = merger.MergedSettings;
            }

            return settings;
        }
Пример #2
0
        public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment)
        {
            Param.RequireNotNull(environment, "environment");

            // Create a new document for the settings.
            XmlDocument document = WritableSettings.NewDocument();

            // Get the parent settings if there are any.
            SettingsMerger merger = new SettingsMerger(this, environment);
            Settings parentSettings = merger.ParentMergedSettings;

            // Add the global settings if there are any.
            if (this.GlobalSettings != null && this.GlobalSettings.Count > 0)
            {
                // Get the global settings from the parent.
                PropertyCollection parentGlobalSettings = null;
                if (parentSettings != null)
                {
                    parentGlobalSettings = parentSettings.GlobalSettings;
                }

                SavePropertyCollection(document.DocumentElement, "GlobalSettings", this.GlobalSettings, parentGlobalSettings, true, null);
            }

            // Add the parser settings if there are any.
            if (this.ParserSettings.Count > 0)
            {
                bool parserSettingsAdded = false;
                XmlElement parsersNode = document.CreateElement("Parsers");

                foreach (AddInPropertyCollection parserSettings in this.ParserSettings)
                {
                    // Add the settings for this parser if there are any.
                    if (parserSettings.Count > 0)
                    {
                        // Create a node for this parser.
                        XmlElement parserNode = document.CreateElement("Parser");
                        XmlAttribute parserIdAttribute = document.CreateAttribute("ParserId");
                        parserIdAttribute.Value = parserSettings.AddIn.Id;
                        parserNode.Attributes.Append(parserIdAttribute);

                        // Get the parser settings from the parent.
                        PropertyCollection parentParserSettings = null;
                        if (parentSettings != null)
                        {
                            parentParserSettings = parentSettings.GetAddInSettings(parserSettings.AddIn);
                        }

                        if (SavePropertyCollection(parserNode, "ParserSettings", parserSettings, parentParserSettings, true, null))
                        {
                            parsersNode.AppendChild(parserNode);
                            parserSettingsAdded = true;
                        }
                    }
                }

                if (parserSettingsAdded)
                {
                    document.DocumentElement.AppendChild(parsersNode);
                }
            }

            // Add the analyzer settings if there are any.
            if (this.AnalyzerSettings.Count > 0)
            {
                bool analyzerSettingsAdded = false;
                XmlElement analyzersNode = document.CreateElement("Analyzers");

                foreach (AddInPropertyCollection analyzerSettings in this.AnalyzerSettings)
                {
                    // Add the settings for this analyzer if there are any.
                    if (analyzerSettings.Count > 0)
                    {
                        // Create a node for this analzyer.
                        XmlElement analyzerNode = document.CreateElement("Analyzer");
                        XmlAttribute analyzerIdAttribute = document.CreateAttribute("AnalyzerId");
                        analyzerIdAttribute.Value = analyzerSettings.AddIn.Id;
                        analyzerNode.Attributes.Append(analyzerIdAttribute);

                        // Get the analyzer settings from the parent.
                        PropertyCollection parentAnalyzerSettings = null;
                        if (parentSettings != null)
                        {
                            parentAnalyzerSettings = parentSettings.GetAddInSettings(analyzerSettings.AddIn);
                        }

                        if (SavePropertyCollection(analyzerNode, "AnalyzerSettings", analyzerSettings, parentAnalyzerSettings, true, null))
                        {
                            analyzersNode.AppendChild(analyzerNode);
                            analyzerSettingsAdded = true;
                        }
                    }
                }

                if (analyzerSettingsAdded)
                {
                    document.DocumentElement.AppendChild(analyzersNode);
                }
            }

            return document;
        }
Пример #3
0
        /// <summary>
        /// Loads the settings files to use for the analysis.
        /// </summary>
        /// <param name="projects">The list of projects to use.</param>
        private void LoadSettingsFiles(IList<CodeProject> projects)
        {
            Param.AssertNotNull(projects, "projects");

            Settings mergedSettings = null;

            // Load the local settings without merging.
            Settings localSettings = null;
            if (this.settingsPath != null)
            {
                localSettings = this.core.Environment.GetSettings(this.settingsPath, false);
                if (localSettings != null)
                {
                    // Merge the local settings.
                    SettingsMerger merger = new SettingsMerger(localSettings, this.core.Environment);
                    mergedSettings = merger.MergedSettings;
                }
            }

            foreach (CodeProject project in projects)
            {
                Settings settingsToUse = mergedSettings;
                if (settingsToUse == null)
                {
                    settingsToUse = this.core.Environment.GetProjectSettings(project, true);
                }

                if (settingsToUse != null)
                {
                    project.Settings = settingsToUse;
                    project.SettingsLoaded = true;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// The control must be initialized by calling this method during the host's OnLoad event.
        /// </summary>
        /// <param name="hostInstance">Interface implemented by the host object.</param>
        /// <param name="propertyPages">The array of pages to display on the tab control.</param>
        /// <param name="settings">The settings to read from and write to.</param>
        /// <param name="coreInstance">The StyleCop core instance.</param>
        /// <param name="contextItem">The context for the property control.</param>
        internal void Initialize(
            IPropertyControlHost hostInstance, 
            IList<IPropertyControlPage> propertyPages,
            WritableSettings settings,
            StyleCopCore coreInstance, 
            params object[] contextItem)
        {
            Param.AssertNotNull(hostInstance, "hostInstance");
            Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty");
            Param.AssertNotNull(settings, "settings");
            Param.AssertNotNull(coreInstance, "coreInstance");
            Param.Ignore(contextItem);

            // Make sure we haven't already been intialized.
            if (this.host != null)
            {
                throw new StyleCopException(Strings.PropertyControlAlreadyInitialized);
            }

            this.host = hostInstance;
            this.pageInterfaces = propertyPages;
            this.localSettings = settings;
            this.core = coreInstance;
            this.context = contextItem;

            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);
            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            // Make sure the context is non-null.
            if (this.context == null)
            {
                this.context = new object[] { };
            }

            this.tabPages = new TabPage[propertyPages.Count];
            this.pages = new UserControl[propertyPages.Count];

            // Add each of the property pages.
            int pageCount = 0;

            // Initialize the settings pages.
            for (int i = 0; i < propertyPages.Count; ++i)
            {
                this.pages[pageCount] = (UserControl)this.pageInterfaces[i];
                TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName);

                this.tabPages[pageCount] = tabPage;
                tabPage.Controls.Add(this.pages[i]);
                this.Controls.Add(tabPage);

                this.pages[i].Dock = DockStyle.Fill;
                this.SizePage(i);

                // The first page has already been initialized.
                this.pageInterfaces[i].Initialize(this);

                ++pageCount;
            }

            // Activate the first page.
            if (this.TabPages[0] != null)
            {
                this.SelectedTab = this.tabPages[0];
                this.pageInterfaces[0].Activate(true);
            }

            this.SizeChanged += new System.EventHandler(this.OnSizeChanged);
        }
Пример #5
0
        /// <summary>
        /// Called when the parent settings have changed.
        /// </summary>
        public void RefreshMergedSettings()
        {
            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);
            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            for (int i = 0; i < this.pageInterfaces.Count; ++i)
            {
                if (this.pageInterfaces[i] != null)
                {
                    this.pageInterfaces[i].RefreshSettingsOverrideState();
                }
            }
        }
Пример #6
0
 private void LoadSettingsFiles(IList<CodeProject> projects)
 {
     Settings mergedSettings = null;
     Settings localSettings = null;
     if (this.settingsPath != null)
     {
         localSettings = this.core.Environment.GetSettings(this.settingsPath, false);
         if (localSettings != null)
         {
             SettingsMerger merger = new SettingsMerger(localSettings, this.core.Environment);
             mergedSettings = merger.MergedSettings;
         }
     }
     foreach (CodeProject project in projects)
     {
         Settings projectSettings = mergedSettings;
         if (projectSettings == null)
         {
             projectSettings = this.core.Environment.GetProjectSettings(project, true);
         }
         if (projectSettings != null)
         {
             project.Settings = projectSettings;
             project.SettingsLoaded = true;
         }
     }
 }
 public override Settings GetSettings(string settingsPath, bool merge, out Exception exception)
 {
     Param.RequireValidString(settingsPath, "settingsPath");
     Settings localSettings = this.LoadSettingsDocument(settingsPath, true, out exception);
     if (!merge)
     {
         return localSettings;
     }
     if (localSettings == null)
     {
         localSettings = new Settings(base.Core, settingsPath, Path.GetDirectoryName(settingsPath));
     }
     SettingsMerger merger = new SettingsMerger(localSettings, this);
     return merger.MergedSettings;
 }
Пример #8
0
 public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment)
 {
     Param.RequireNotNull(environment, "environment");
     XmlDocument document = NewDocument();
     SettingsMerger merger = new SettingsMerger(this, environment);
     Settings parentMergedSettings = merger.ParentMergedSettings;
     if ((base.GlobalSettings != null) && (base.GlobalSettings.Count > 0))
     {
         PropertyCollection parentProperties = null;
         if (parentMergedSettings != null)
         {
             parentProperties = parentMergedSettings.GlobalSettings;
         }
         SavePropertyCollection(document.DocumentElement, "GlobalSettings", base.GlobalSettings, parentProperties, true, null);
     }
     if (base.ParserSettings.Count > 0)
     {
         bool flag = false;
         XmlElement newChild = document.CreateElement("Parsers");
         foreach (AddInPropertyCollection propertys2 in base.ParserSettings)
         {
             if (propertys2.Count > 0)
             {
                 XmlElement rootNode = document.CreateElement("Parser");
                 XmlAttribute node = document.CreateAttribute("ParserId");
                 node.Value = propertys2.AddIn.Id;
                 rootNode.Attributes.Append(node);
                 PropertyCollection addInSettings = null;
                 if (parentMergedSettings != null)
                 {
                     addInSettings = parentMergedSettings.GetAddInSettings(propertys2.AddIn);
                 }
                 if (SavePropertyCollection(rootNode, "ParserSettings", propertys2, addInSettings, true, null))
                 {
                     newChild.AppendChild(rootNode);
                     flag = true;
                 }
             }
         }
         if (flag)
         {
             document.DocumentElement.AppendChild(newChild);
         }
     }
     if (base.AnalyzerSettings.Count > 0)
     {
         bool flag2 = false;
         XmlElement element3 = document.CreateElement("Analyzers");
         foreach (AddInPropertyCollection propertys4 in base.AnalyzerSettings)
         {
             if (propertys4.Count > 0)
             {
                 XmlElement element4 = document.CreateElement("Analyzer");
                 XmlAttribute attribute2 = document.CreateAttribute("AnalyzerId");
                 attribute2.Value = propertys4.AddIn.Id;
                 element4.Attributes.Append(attribute2);
                 PropertyCollection propertys5 = null;
                 if (parentMergedSettings != null)
                 {
                     propertys5 = parentMergedSettings.GetAddInSettings(propertys4.AddIn);
                 }
                 if (SavePropertyCollection(element4, "AnalyzerSettings", propertys4, propertys5, true, null))
                 {
                     element3.AppendChild(element4);
                     flag2 = true;
                 }
             }
         }
         if (flag2)
         {
             document.DocumentElement.AppendChild(element3);
         }
     }
     return document;
 }