/// <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(); InitializeCustomAnalyzer( m_parent.Core, m_customCore, Constants.NamingRulesAnalyzerId, m_customNamingAnalyzer); InitializeCustomAnalyzer( m_parent.Core, m_customCore, Constants.LayoutRulesAnalyzerId, m_customLayoutAnalyzer); 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 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); } }
public void VsAnalysisHelperConstructorTest() { IServiceProvider serviceProvider = new MockServiceProvider(); StyleCopCore core = new StyleCopCore(); FileAnalysisHelper_Accessor specificTarget = new FileAnalysisHelper_Accessor(serviceProvider, core); AnalysisHelper_Accessor target = FileAnalysisHelper_Accessor.AttachShadow(specificTarget.Target); Assert.IsNotNull(target, "Unable to instantiate the AnalysisHelper class"); Assert.IsNotNull(target.Core, "AnalysisHelper.Core was null"); }
public void AnalysisHelperConstructorTest() { try { IServiceProvider serviceProvider = new MockServiceProvider(); StyleCopCore core = new StyleCopCore(); FileAnalysisHelper specificTarget = new FileAnalysisHelper(serviceProvider, core); Assert.IsNotNull(specificTarget, "Unable to instantiate the AnalysisHelper class"); Assert.IsNotNull(specificTarget.Core, "AnalysisHelper.Core was null"); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } }
/// <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 += this.OnSizeChanged; }
/// <summary> /// Disposes the contents of the class. /// </summary> /// <param name="disposing">Indicates whether to dispose managed resources.</param> protected override void Dispose(bool disposing) { Param.Ignore(disposing); base.Dispose(disposing); if (disposing) { if (this.helper != null) { this.helper.Dispose(); this.helper = null; } this.core = null; } }
private static AnalysisThread CreateAnalysisThread(bool isFull) { StyleCopCore core = new StyleCopCore(); List<CodeProject> projects = new List<CodeProject>(); Mock<CodeProject> mockCodeProject = new Mock<CodeProject>(); CodeProject codeProject = new CodeProject(0, "test", new Configuration(new string[0])); projects.Add(codeProject); AnalysisThread target = new AnalysisThread(isFull, projects, core); return target; }
/// <summary> /// Initializes a new instance of the Settings 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 Settings(StyleCopCore core, string path, string location, XmlDocument contents, DateTime writeTime) { Param.AssertNotNull(core, "core"); Param.Ignore(path); Param.Ignore(location); Param.Ignore(contents); Param.Ignore(writeTime); this.core = core; this.path = path; 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 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(); }
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); 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); } }
/// <summary> /// Initializes custom analyzer based on the standard one. /// </summary> public static void InitializeCustomAnalyzer( StyleCopCore originalCore, StyleCopCore customCore, string originalAnalyzerId, 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[originalAnalyzerId]; 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 }); }
/// <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="context">The run context.</param> /// <param name="autoSaveMode">Indicates whether to auto-save the document back to the source, if autoFixMode is true.</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, RunContext context, bool autoSaveMode, bool ignoreResultsCache, string settingsPath) { Param.AssertNotNull(core, "core"); Param.AssertNotNull(codeProjects, "codeProjects"); Param.Ignore(resultsCache); Param.Ignore(context); Param.Ignore(autoSaveMode); Param.Ignore(ignoreResultsCache); Param.Ignore(settingsPath); this.core = core; this.projects = codeProjects; this.cache = resultsCache; this.context = context; this.autoSaveMode = autoSaveMode; this.ignoreResultsCache = ignoreResultsCache; this.settingsPath = settingsPath; }
private static AnalysisThread CreateAnalysisThread(bool isFull) { AnalysisThread target = null; try { StyleCopCore core = new StyleCopCore(); List<CodeProject> projects = new List<CodeProject>(); Mock<CodeProject> mockCodeProject = new Mock<CodeProject>(); CodeProject codeProject = new CodeProject(0, "test", new Configuration(new string[0])); projects.Add(codeProject); target = new AnalysisThread(isFull, projects, core); } catch (Exception ex) { // Use try catch to test a workaround on CI build (AppVeyor) Console.WriteLine(ex.Message); } return target; }
private static AnalysisThread_Accessor CreateAnalysisThread(bool isFull) { var core = new StyleCopCore(); var projects = new List<CodeProject>(); var mockCodeProject = new Mock<CodeProject>(); var codeProject = new CodeProject(0, "test", new Configuration(new string[0])); projects.Add(codeProject); var target = new AnalysisThread_Accessor(isFull, projects, core); return target; }
/// <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); }
/// <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; }
/// <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 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); }
/// <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> /// 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 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> /// Initializes a new instance of the ResultsCache class. /// </summary> /// <param name="core"> /// The StyleCop core instance. /// </param> public ResultsCache(StyleCopCore core) { Param.AssertNotNull(core, "core"); this.core = core; }
/// <summary> /// Initializes a new instance of the Settings 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> internal Settings(StyleCopCore core, string path, string location) : this(core, path, location, null, new DateTime()) { Param.Ignore(core, path, location); }