private string[] GetRuleAssemblyList(bool replacePath)
        {
            List <string> list      = new List <string>();
            string        fxCopPath = FxCopWrapper.FindFxCopPath();

            foreach (string dir in ruleAssemblies.Split(';'))
            {
                if (string.Equals(dir, "$(FxCopDir)\\rules", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (string.Equals(dir, "$(FxCopDir)/rules", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (replacePath && !string.IsNullOrEmpty(fxCopPath))
                {
                    list.Add(Regex.Replace(dir, @"\$\(FxCopDir\)", fxCopPath, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase));
                }
                else
                {
                    list.Add(dir);
                }
            }
            return(list.ToArray());
        }
        static List <FxCopCategory> GetRuleListAndSort(string fxCopPath, string[] ruleAssemblies)
        {
            AppDomainSetup setup = new AppDomainSetup();

            setup.DisallowCodeDownload = true;
            setup.ApplicationBase      = fxCopPath;
            AppDomain domain = AppDomain.CreateDomain("FxCop Rule Loading Domain", AppDomain.CurrentDomain.Evidence, setup);

            FxCopRule[] ruleList;
            try {
                FxCopWrapper wrapper = (FxCopWrapper)domain.CreateInstanceFromAndUnwrap(typeof(FxCopWrapper).Assembly.Location, typeof(FxCopWrapper).FullName);

                ruleList = wrapper.GetRuleListInstanceMethod(fxCopPath, ruleAssemblies);
            } finally {
                AppDomain.Unload(domain);
            }

            Array.Sort(ruleList);
            List <FxCopCategory> rules = new List <FxCopCategory>();

            lock (ruleDict) {
                FxCopCategory cat = null;
                foreach (FxCopRule rule in ruleList)
                {
                    if (cat == null || cat.Name != rule.CategoryName)
                    {
                        cat = new FxCopCategory(rule.CategoryName);
                        rules.Add(cat);
                    }
                    cat.Rules.Add(rule);
                }
                ruleDict[ruleAssemblies] = rules;
            }
            return(rules);
        }
 void ReloadRuleList()
 {
     ruleTreeView.Root = new SharpTreeNode();
     FxCopWrapper.GetRuleList(GetRuleAssemblyList(true), Callback);
     if (ruleTreeView.Root.Children.Count == 0)
     {
         ruleTreeView.Root.Children.Add(new MessageNode(StringParser.Parse("${res:ICSharpCode.CodeAnalysis.ProjectOptions.LoadingRules}")));
     }
 }
 void ReloadRuleList()
 {
     ruleTreeView.Nodes.Clear();
     FxCopWrapper.GetRuleList(GetRuleAssemblyList(true), Callback);
     if (ruleTreeView.Nodes.Count == 0)
     {
         ruleTreeView.Nodes.Add(StringParser.Parse("${res:ICSharpCode.CodeAnalysis.ProjectOptions.LoadingRules}"));
     }
 }
Esempio n. 5
0
        void ShowStatus()
        {
            string path = FxCopWrapper.FindFxCopPath();

            if (path == null)
            {
                Get <Label>("status").Text = StringParser.Parse("${res:ICSharpCode.CodeAnalysis.IdeOptions.FxCopNotFound}");
            }
            else
            {
                Get <Label>("status").Text = StringParser.Parse("${res:ICSharpCode.CodeAnalysis.IdeOptions.FxCopFoundInPath}")
                                             + Environment.NewLine + path;
            }
        }
Esempio n. 6
0
 void FindFxCopPathClick(object sender, EventArgs e)
 {
     using (OpenFileDialog dlg = new OpenFileDialog()) {
         dlg.DefaultExt = "exe";
         dlg.Filter     = StringParser.Parse("FxCop|fxcop.exe|${res:SharpDevelop.FileFilter.AllFiles}|*.*");
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             string path = Path.GetDirectoryName(dlg.FileName);
             if (FxCopWrapper.IsFxCopPath(path))
             {
                 FxCopPath = path;
             }
             else
             {
                 MessageService.ShowError("${res:ICSharpCode.CodeAnalysis.IdeOptions.DirectoryDoesNotContainFxCop}");
             }
         }
     }
     ShowStatus();
 }