internal Settings(StyleCopCore core) { this.globalSettings = new PropertyCollection(); this.parserSettings = new Dictionary<string, AddInPropertyCollection>(); this.analyzerSettings = new Dictionary<string, AddInPropertyCollection>(); this.core = core; }
/// <summary> /// Initializes a new instance of the Log class. /// </summary> /// <param name="core">The core instance.</param> public Log(StyleCopCore core) { Param.AssertNotNull(core, "core"); object data = core.Registry.CUGetValue("Logging"); if (data != null) { try { int level = (int)data; if (level > 0) { this.logLevel = StyleCopLogLevel.High; } } catch (FormatException) { // Do nothing here since data is registry is invalid. } } if (this.logLevel != StyleCopLogLevel.None) { this.listener = new Listener(); Trace.Listeners.Add(this.listener); } }
/// <summary> /// Initializes an add-in. /// </summary> public void InitializeAddIn() { m_customCore = new StyleCopCore(); m_customCore.ViolationEncountered += OnCustomViolationEncountered; m_customNamingAnalyzer = new CustomNamingRules(); m_customLayoutAnalyzer = new CustomLayoutRules(); m_customDocumentationAnalyzer = new CustomDocumentationRules(); StyleCop43Compatibility.InitializeCustomAnalyzer( m_parent.Core, m_customCore, Constants.NamingRulesAnalyzerId, m_customNamingAnalyzer); StyleCop43Compatibility.InitializeCustomAnalyzer( m_parent.Core, m_customCore, Constants.LayoutRulesAnalyzerId, m_customLayoutAnalyzer); StyleCop43Compatibility.InitializeCustomAnalyzer( m_parent.Core, m_customCore, Constants.DocumentationRulesAnalyzerId, m_customDocumentationAnalyzer); }
/// <summary> /// Shows the alert dialog. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="parent">The parent control.</param> /// <param name="message">The message to display on the dialog.</param> /// <param name="title">The title of the dialog.</param> /// <param name="buttons">The dialog buttons.</param> /// <param name="icon">The dialog icon.</param> /// <returns>Returns the dialog result.</returns> public static DialogResult Show( StyleCopCore core, Control parent, string message, string title, MessageBoxButtons buttons, MessageBoxIcon icon) { Param.RequireNotNull(core, "core"); Param.Ignore(parent); Param.RequireValidString(message, "message"); Param.RequireValidString(title, "title"); Param.Ignore(buttons); Param.Ignore(icon); if (core.DisplayUI) { return DisplayMessageBox(parent, message, title, buttons, icon); } else { // Alert Dialogs which provide options other than OK cannot be handled when the // program is running in a non-UI mode. if (buttons != MessageBoxButtons.OK) { throw new InvalidOperationException(Strings.AlertDialogWithOptionsInNonUIState); } SendToOutput(core, message, icon); return DialogResult.OK; } }
/// <summary> /// Initializes custom analyzer based on the standard one. /// </summary> public static void InitializeCustomAnalyzer( StyleCopCore originalCore, StyleCopCore customCore, string originalAnalyzerCode, SourceAnalyzer customAnalyzer) { Dictionary<string, SourceAnalyzer> originalAnalyzers = (Dictionary<string, SourceAnalyzer>)typeof(StyleCopCore).InvokeMember( "analyzers", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, originalCore, null); SourceAnalyzer originalAnalyzer = originalAnalyzers[originalAnalyzerCode]; Dictionary<string, Rule> originalRules = (Dictionary<string, Rule>)typeof(StyleCopAddIn).InvokeMember( "rules", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, originalAnalyzer, null); typeof(StyleCopAddIn).InvokeMember( "core", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, customAnalyzer, new object[] { customCore }); Dictionary<string, Rule> customRules = new Dictionary<string, Rule>(); foreach (KeyValuePair<string, Rule> pair in originalRules) { Rule originalRule = pair.Value; Rule customRule = (Rule)typeof(Rule).InvokeMember( "Rule", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, customCore, new object[] { originalRule.Name, originalRule.Namespace, originalRule.CheckId, originalRule.Context, originalRule.Warning, originalRule.Description, originalRule.RuleGroup, true, false }); customRules[pair.Key] = customRule; } typeof(StyleCopAddIn).InvokeMember( "rules", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, customAnalyzer, new object[] { customRules }); CustomCsParser customParser = new CustomCsParser(); typeof(SourceAnalyzer).InvokeMember( "parser", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField, null, customAnalyzer, new object[] { customParser }); }
public PropertyDialog(IList<IPropertyControlPage> pages, WritableSettings settingsFile, string id, StyleCopCore core, Help helpCallback, params object[] context) { this.pages = pages; this.settingsFile = settingsFile; this.id = id; this.core = core; this.helpCallback = helpCallback; this.context = context; this.InitializeComponent(); this.core.Registry.RestoreWindowPosition(this.id, this, base.Location, base.Size); }
internal Settings(StyleCopCore core, string path, string location, XmlDocument contents, DateTime writeTime) { this.globalSettings = new PropertyCollection(); this.parserSettings = new Dictionary<string, AddInPropertyCollection>(); this.analyzerSettings = new Dictionary<string, AddInPropertyCollection>(); this.core = core; this.path = path; this.location = location; this.contents = contents; this.writeTime = writeTime; this.LoadSettingsDocument(); }
private static void SendToOutput(StyleCopCore core, string message, MessageBoxIcon icon) { string format = "{0}"; if (((icon & MessageBoxIcon.Hand) != MessageBoxIcon.None) || ((icon & MessageBoxIcon.Hand) != MessageBoxIcon.None)) { format = Strings.ErrorTag; } else if ((icon & MessageBoxIcon.Exclamation) != MessageBoxIcon.None) { format = Strings.WarningTag; } core.SignalOutput(string.Format(CultureInfo.CurrentCulture, format, new object[] { message })); }
public static DialogResult Show(StyleCopCore core, Control parent, string message, string title, MessageBoxButtons buttons, MessageBoxIcon icon) { Param.RequireNotNull(core, "core"); Param.RequireValidString(message, "message"); Param.RequireValidString(title, "title"); if (core.DisplayUI) { return DisplayMessageBox(parent, message, title, buttons, icon); } if (buttons != MessageBoxButtons.OK) { throw new InvalidOperationException(Strings.AlertDialogWithOptionsInNonUIState); } SendToOutput(core, message, icon); return DialogResult.OK; }
public StyleCopConsole(string settings, bool writeResultsCache, string outputFile, ICollection<string> addInPaths, bool loadFromDefaultPath, object hostTag) { this.violations = new XmlDocument(); this.settingsPath = settings; if (outputFile == null) { this.outputFile = "StyleCopViolations.xml"; } else { this.outputFile = outputFile; } this.core = new StyleCopCore(null, hostTag); this.core.Initialize(addInPaths, loadFromDefaultPath); this.core.WriteResultsCache = writeResultsCache; this.core.DisplayUI = false; this.core.ViolationEncountered += new EventHandler<ViolationEventArgs>(this.CoreViolationEncountered); this.core.OutputGenerated += new EventHandler<OutputEventArgs>(this.CoreOutputGenerated); XmlElement newChild = this.violations.CreateElement("StyleCopViolations"); this.violations.AppendChild(newChild); }
public Log(StyleCopCore core) { object obj2 = core.Registry.CUGetValue("Logging"); if (obj2 != null) { try { int num = (int) obj2; if (num > 0) { this.logLevel = StyleCopLogLevel.High; } } catch (FormatException) { } } if (this.logLevel != StyleCopLogLevel.None) { this.listener = new Listener(); Trace.Listeners.Add(this.listener); } }
/// <summary> /// Initializes a new instance of the Settings class. /// </summary> /// <param name="core">The StyleCop core instance.</param> internal Settings(StyleCopCore core) { Param.AssertNotNull(core, "core"); this.core = core; }
internal Settings(StyleCopCore core, string path, string location) : this(core, path, location, null, new DateTime()) { }
/// <summary> /// Gets the pages to display on the settings dialog. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <returns>Returns the list of settings pages to display.</returns> internal static List<IPropertyControlPage> GetSettingsPages(StyleCopCore core) { Param.AssertNotNull(core, "core"); // Create an array of our property pages. List<IPropertyControlPage> pages = new List<IPropertyControlPage>(); try { // Get the list of options pages from the addins. foreach (SourceParser parser in core.Parsers) { // Load pages from this parser. ICollection<IPropertyControlPage> parserPages = parser.SettingsPages; if (parserPages != null && parserPages.Count > 0) { pages.AddRange(parserPages); } // Check each of the analyzers within this parser. foreach (SourceAnalyzer analyzer in parser.Analyzers) { // Load pages from this analyzer. ICollection<IPropertyControlPage> analyzerPages = analyzer.SettingsPages; if (analyzerPages != null && analyzerPages.Count > 0) { pages.AddRange(analyzerPages); } } } return pages; } catch (Exception) { foreach (IPropertyControlPage page in pages) { IDisposable disposable = page as IDisposable; if (disposable != null) { disposable.Dispose(); } } pages.Clear(); throw; } }
/// <summary> /// Initializes a new instance of the Data class. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="codeProjects">The list of code projects to analyze.</param> /// <param name="resultsCache">The results cache.</param> /// <param name="ignoreResultsCache">True to ignore the results cache.</param> /// <param name="settingsPath">The path to the settings to use during analysis.</param> public Data( StyleCopCore core, IList<CodeProject> codeProjects, ResultsCache resultsCache, bool ignoreResultsCache, string settingsPath) { Param.AssertNotNull(core, "core"); Param.AssertNotNull(codeProjects, "codeProjects"); Param.Ignore(resultsCache); Param.Ignore(ignoreResultsCache); Param.Ignore(settingsPath); this.core = core; this.projects = codeProjects; this.cache = resultsCache; this.ignoreResultsCache = ignoreResultsCache; this.settingsPath = settingsPath; }
/// <summary> /// Initializes a new instance of the WritableSettings class. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="path">The path to the settings document.</param> /// <param name="location">The location where the settings document is contained.</param> /// <param name="contents">The initial contents of the settings document.</param> /// <param name="writeTime">The time when the settings were last updated.</param> internal WritableSettings(StyleCopCore core, string path, string location, XmlDocument contents, DateTime writeTime) : base(core, path, location, contents, writeTime) { Param.Ignore(core, path, location, contents, writeTime); }
public ResultsCache(StyleCopCore core) { this.core = core; }
/// <summary> /// Initializes a new instance of the PropertyDialog class. /// </summary> /// <param name="pages">The array of pages to display on the property control.</param> /// <param name="settingsFile">The file that contains the settings being edited.</param> /// <param name="id">A unique ID that describes this set of property pages.</param> /// <param name="core">The StyleCop core instance.</param> /// <param name="helpCallback">Callback method for help, or null for no help.</param> /// <param name="context">The context to the send to the property page control.</param> public PropertyDialog( IList<IPropertyControlPage> pages, WritableSettings settingsFile, string id, StyleCopCore core, Help helpCallback, params object[] context) { Param.Assert(pages != null && pages.Count > 0, "pages", "Cannot be null or empty"); Param.Assert(settingsFile != null && settingsFile.Loaded, "settingsFile", "The settings file must be loaded."); Param.AssertValidString(id, "id"); Param.AssertNotNull(core, "core"); Param.Ignore(helpCallback); Param.Ignore(context); this.pages = pages; this.settingsFile = settingsFile; this.id = id; this.core = core; this.helpCallback = helpCallback; this.context = context; this.InitializeComponent(); this.core.Registry.RestoreWindowPosition(this.id, this, this.Location, this.Size); }
internal static List<IPropertyControlPage> GetSettingsPages(StyleCopCore core) { List<IPropertyControlPage> list = new List<IPropertyControlPage>(); foreach (SourceParser parser in core.Parsers) { ICollection<IPropertyControlPage> settingsPages = parser.SettingsPages; if ((settingsPages != null) && (settingsPages.Count > 0)) { list.AddRange(settingsPages); } foreach (SourceAnalyzer analyzer in parser.Analyzers) { ICollection<IPropertyControlPage> collection = analyzer.SettingsPages; if ((collection != null) && (collection.Count > 0)) { list.AddRange(collection); } } } return list; }
private static ICollection<SourceAnalyzer> DiscoverAnalyzerList(StyleCopCore core, CodeProject project, ICollection<SourceParser> parsers) { List<SourceAnalyzer> list = new List<SourceAnalyzer>(); foreach (SourceParser parser in parsers) { foreach (SourceAnalyzer analyzer in parser.Analyzers) { Dictionary<string, Rule> dictionary = new Dictionary<string, Rule>(); AddInPropertyCollection propertys = (project.Settings == null) ? null : project.Settings.GetAddInSettings(analyzer); foreach (Rule rule in analyzer.AddInRules) { bool flag = !core.AddinsDisabledByDefault && rule.EnabledByDefault; if ((propertys != null) && (!flag || rule.CanDisable)) { BooleanProperty property = propertys[rule.Name + "#Enabled"] as BooleanProperty; if (property != null) { flag = property.Value; } } if (flag) { dictionary.Add(rule.Name, rule); } } if (dictionary.Count > 0) { list.Add(analyzer); analyzer.EnabledRules.Add(project, dictionary); } } } return list; }
/// <summary> /// Initializes a new instance of the Settings class. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="location">The path to the settings document.</param> /// <param name="contents">The initial contents of the settings document.</param> /// <param name="writeTime">The time when the settings were last updated.</param> public Settings(StyleCopCore core, string location, XmlDocument contents, DateTime writeTime) { Param.RequireNotNull(core, "core"); Param.Ignore(location); Param.Ignore(contents); Param.Ignore(writeTime); this.core = core; this.location = location; this.contents = contents; this.writeTime = writeTime; this.LoadSettingsDocument(); }
/// <summary> /// Initializes a new instance of the Settings class. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="location">The location of the settings document.</param> public Settings(StyleCopCore core, string location) : this(core, location, null, new DateTime()) { Param.Ignore(core, location); }
/// <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); }
public static void Main(string[] args) { Param.Ignore(args); if (args != null && args.Length > 0 && !string.IsNullOrEmpty(args[0])) { try { string settingsFilePath = Path.GetFullPath(args[0]); settingsFilePath = Environment.ExpandEnvironmentVariables(settingsFilePath); if (File.Exists(settingsFilePath)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (StyleCopCore core = new StyleCopCore(null, null)) { core.Initialize(null, true); core.WriteResultsCache = false; core.DisplayUI = true; core.ShowSettings(settingsFilePath); } } else { MessageBox.Show( string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileDoesNotExist, settingsFilePath), null, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (IOException ex) { MessageBox.Show( string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message), null, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (UnauthorizedAccessException ex) { MessageBox.Show( string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message), null, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SecurityException ex) { MessageBox.Show( string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message), null, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentException ex) { MessageBox.Show( string.Format(CultureInfo.CurrentUICulture, Resources.SettingsFileCouldNotBeLoaded, ex.Message), null, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(Resources.InvalidArguments, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Data(StyleCopCore core, IList<CodeProject> codeProjects, Microsoft.StyleCop.ResultsCache resultsCache, bool ignoreResultsCache, string settingsPath) { this.core = core; this.projects = codeProjects; this.cache = resultsCache; this.ignoreResultsCache = ignoreResultsCache; this.settingsPath = settingsPath; }
/// <summary> /// Writes a message to do the output log. /// </summary> /// <param name="core">The StyleCop core instance.</param> /// <param name="message">The message to display on the dialog.</param> /// <param name="icon">The dialog icon.</param> private static void SendToOutput(StyleCopCore core, string message, MessageBoxIcon icon) { Param.Ignore(core); Param.AssertValidString(message, "message"); Param.Ignore(icon); // Set up the appropriate tag type based on the icon. string tag = "{0}"; if ((icon & MessageBoxIcon.Error) != 0 || (icon & MessageBoxIcon.Stop) != 0) { tag = Strings.ErrorTag; } else if ((icon & MessageBoxIcon.Exclamation) != 0) { tag = Strings.WarningTag; } // Send the output to the core module. core.SignalOutput(string.Format(CultureInfo.CurrentCulture, tag, message)); }
/// <summary> /// Initializes the add-in. /// </summary> /// <param name="styleCopCore">The StyleCop core instance.</param> /// <param name="initializationXml">The add-in's XML initialization document.</param> /// <param name="topMostType">Indicates whether the xml document comes from the top-most type in the /// add-in's type hierarchy.</param> /// <param name="isKnownAssembly">Indicates whether the add-in comes from a known assembly.</param> internal void Initialize( StyleCopCore styleCopCore, XmlDocument initializationXml, bool topMostType, bool isKnownAssembly) { Param.AssertNotNull(styleCopCore, "styleCopCore"); Param.AssertNotNull(initializationXml, "parserXml"); Param.Ignore(topMostType); Param.Ignore(isKnownAssembly); // Set the reference to the core instance. this.core = styleCopCore; // Parse the parser Xml. this.ImportInitializationXml(initializationXml, topMostType, isKnownAssembly); }
/// <summary> /// Loads the list of analyzers for the given project after looking at the project settings. /// </summary> /// <param name="core">The core instance.</param> /// <param name="project">The project to check.</param> /// <param name="parsers">The list of parsers current loaded.</param> /// <returns>Returns the list of analyzers discovered for this project.</returns> private static ICollection<SourceAnalyzer> DiscoverAnalyzerList( StyleCopCore core, CodeProject project, ICollection<SourceParser> parsers) { Param.AssertNotNull(core, "core"); Param.AssertNotNull(project, "project"); Param.AssertNotNull(parsers, "parsers"); // Create the list of enabled analyzers and rules which will be returned. List<SourceAnalyzer> list = new List<SourceAnalyzer>(); // Iterate through all loaded parsers. foreach (SourceParser parser in 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 = project.Settings == null ? null : project.Settings.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 = !core.AddinsDisabledByDefault && 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) { list.Add(analyzer); // The enables rules dictionary should have been created. Debug.Assert(analyzer.EnabledRules != null, "The enabled rules dictionary should not be null"); // The rules list should not already be set for this project on this analyzer. // If so, something is wrong. Debug.Assert( !analyzer.EnabledRules.ContainsKey(project), "The rule list for this analyzer on this code project should not be set yet."); // Store the list of enabled rules within the analyzer so it can be quickly // accessed at runtime. analyzer.EnabledRules.Add(project, enabledRulesForAnalyzer); } } } return list; }