コード例 #1
0
        /// <summary>
        /// Occurs when the <see cref="LaunchStyleCopButton"/> is clicked.
        /// </summary>
        /// <param name="sender">The <see cref="System.Object"/> that raised the event.</param>
        /// <param name="e">An <see cref="System.EventArgs"/> containing event data.</param>
        private void LaunchStyleCopButton_Click(object sender, EventArgs e)
        {
            string tempFileName = Path.GetTempFileName();

            try
            {
                // Write the existing settings to the file before creating the UI.
                File.WriteAllText(tempFileName, this.Settings.StyleCopSettings);

                StyleCopCore core = new StyleCopCore(null, null);
                core.Initialize(null, true);
                core.DisplayUI         = true;
                core.WriteResultsCache = false;

                if (core.ShowSettings(tempFileName))
                {
                    // Read the new settings from the file.
                    this.Settings.StyleCopSettings = File.ReadAllText(tempFileName);
                }
            }
            finally
            {
                // Destroy the temp file so remnants aren't left lying around.
                File.Delete(tempFileName);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RalphJansen.StyleCopCheckInPolicy.Policy.StyleCopConsole"/> class.
        /// </summary>
        /// <param name="policySettingsPath">The path to the policy settings.</param>
        /// <param name="settings">The policy settings.</param>
        public StyleCopConsole(string policySettingsPath, PolicySettings settings)
        {
            this.PolicySettingsPath = policySettingsPath;
            this.Settings           = settings;

            StyleCopCore core = new StyleCopCore(new TfsCheckInPolicyEnvironment(), null);

            core.ViolationEncountered += new EventHandler <ViolationEventArgs>(this.VoilationEncounteredCallback);
            core.Initialize(null, true);
            core.WriteResultsCache = false;
            core.DisplayUI         = false;

            this.Core = core;
        }
コード例 #3
0
        /// <summary>
        /// Registers the rules. Do not put the contents of this method in the constructor.
        /// If you do *sometimes* the StyleCop object won't be loaded be the time you construct it.
        /// </summary>
        private void Init()
        {
            StyleCopCore core = new StyleCopCore();

            core.Initialize(new List <string>(), true);

            Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRulesDictionary = StyleCopRule.GetRules(core);

            HighlightingSettingsManager highlightManager = HighlightingSettingsManager.Instance;

            // TODO Not sure how to get a configurable severity id with the settings store so default to warning for now
            //// var defaultSeverity = highlightManager.GetConfigurableSeverity(DefaultSeverityId, null);
            this.RegisterRuleConfigurations(highlightManager, analyzerRulesDictionary, Severity.WARNING);
        }
コード例 #4
0
        /// <summary>
        /// Registers the rules. Do not put the contents of this method in the constructor.
        /// If you do *sometimes* the StyleCop object won't be loaded be the time you construct it.
        /// </summary>
        private void Init()
        {
            StyleCopCore core = new StyleCopCore();

            core.Initialize(new List <string>(), true);

            Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRulesDictionary = StyleCopRule.GetRules(core);

            HighlightingSettingsManager highlightManager = HighlightingSettingsManager.Instance;

            Severity defaultSeverity = highlightManager.GetConfigurableSeverity(DefaultSeverityId, null);

            this.RegisterRuleConfigurations(highlightManager, analyzerRulesDictionary, defaultSeverity);
        }
コード例 #5
0
        private static void Run(string code)
        {
            var filename = "1.cs";

            File.Delete(filename);
            File.WriteAllText(filename, code);
            var core = new StyleCopCore();

            core.Initialize(new[] { @"..\..\..\StyleCopAddOn\bin\debug\" }, true);
            var add = (dynamic)core.GetAnalyzer("StyleCopAddOn.StyleCopAddOn");

            core.ViolationEncountered += (sender, args) => { Console.WriteLine(args); };

            var parser = core.GetParser("StyleCop.CSharp.CsParser");

            CodeDocument doc = null;

            parser.ParseFile(new CodeFile(filename, new CodeProject(1, "", new Configuration(new string[0])), parser), 0, ref doc);
            add.AnalyzeDocument(doc);
        }
コード例 #6
0
        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);
            }
        }
        /// <summary>
        /// Adds the highlights.
        /// </summary>
        private void AddHighlights()
        {
            StyleCopCore core = new StyleCopCore();
            core.Initialize(new List<string>(), true);

            Dictionary<SourceAnalyzer, List<StyleCopRule>> analyzerRulesDictionary = StyleCopRule.GetRules(core);

            HighlightingSettingsManager highlightManager = HighlightingSettingsManager.Instance;

            AddDefaultOption();

            Severity defaultSeverity = highlightManager.GetConfigurableSeverity(DefaultSeverityId, null);

            this.RegisterRuleConfigurations(highlightManager, analyzerRulesDictionary, defaultSeverity);
        }
        /// <summary>
        /// Registers the rules. Do not put the contents of this method in the constructor.
        /// If you do *sometimes* the StyleCop object won't be loaded be the time you construct it.
        /// </summary>
        private void Init()
        {
            StyleCopCore core = new StyleCopCore();
            core.Initialize(new List<string>(), true);

            Dictionary<SourceAnalyzer, List<StyleCopRule>> analyzerRulesDictionary = StyleCopRule.GetRules(core);

            HighlightingSettingsManager highlightManager = HighlightingSettingsManager.Instance;

            // TODO Not sure how to get a configurable severity id with the settings store so default to warning for now
            //// var defaultSeverity = highlightManager.GetConfigurableSeverity(DefaultSeverityId, null);
            this.RegisterRuleConfigurations(highlightManager, analyzerRulesDictionary, Severity.WARNING);
        }