Ejemplo n.º 1
0
 /// <summary>
 /// Instructs the provided <see cref="FxCopCommandAdapter"/> to ignore
 /// the rules which were specified in the settings dialog.
 /// </summary>
 private static void AddDisabledRules(FxCopCommandAdapter adapter)
 {
     if (Settings.Default.DisabledRules != null)
     {
         foreach (string disabledRule in Settings.Default.DisabledRules)
         {
             adapter.AddDisabledRule(disabledRule);
         }
     }
 }
Ejemplo n.º 2
0
        // [rgn] Private Methods (5)

        /// <summary>
        /// Instructs the provided <see cref="FxCopCommandAdapter"/> to use the
        /// custom rule assemblies which were specified in the settings dialog.
        /// </summary>
        /// <param name="adapter"></param>
        private static void AddCustomRuleAssemblies(FxCopCommandAdapter adapter)
        {
            if (Settings.Default.RuleAssemblies != null)
            {
                foreach (string ruleAssembly in Settings.Default.RuleAssemblies)
                {
                    adapter.AddRulesAssembly(ruleAssembly);
                }
            }
        }
Ejemplo n.º 3
0
        public override PolicyFailure[] Evaluate()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                CheckinAnalyzer     checkinAnalyzer = new CheckinAnalyzer(PendingCheckin);
                FxCopCommandAdapter adapter         = new FxCopCommandAdapter(Settings.Default.FxCopCommandPath);

                // Instruct the FxCopAdapter to analyze related assemblies.
                IList <string> relatedAssemblyPaths = checkinAnalyzer.GetRelatedAssemblyPaths();
                if (relatedAssemblyPaths.Count == 0)
                {
                    // No assemblies were modified, no need to evaluate.
                    return(new PolicyFailure[] { });
                }
                else
                {
                    DateTime latestChangeTime = GetLatestChangeTime();
                    foreach (string assemblyPath in relatedAssemblyPaths)
                    {
                        if (!AssemblyWasCompiled(assemblyPath, latestChangeTime))
                        {
                            // If any of the assemblies wasn't built since the change was made,
                            // the integrity of the analysis cannot be verified so a PolicyFailure is returned.
                            string fileName = Path.GetFileName(assemblyPath);
                            string message  = string.Format(AssemblyWatNotCompiledMessage, fileName);
                            return(new PolicyFailure[] { new PolicyFailure(message, this) });
                        }
                        else
                        {
                            adapter.AddTargetAssembly(assemblyPath);
                        }
                    }
                }

                // Instruct the FxCopAdapter to analyze the types which were modified during this checkin.
                IList <string> modifiedTypeNames = checkinAnalyzer.GetModifiedTypeNames();
                if (modifiedTypeNames.Count == 0)
                {
                    // No types were modified, no need to evaluate.
                    return(new PolicyFailure[] { });
                }
                else
                {
                    foreach (string modifiedType in modifiedTypeNames)
                    {
                        adapter.AddTargetType(modifiedType);
                    }
                }

                AddCustomRuleAssemblies(adapter);
                AddDisabledRules(adapter);

                // Start the FxCopAdapter and analyze the results.
                XmlDocument     results  = adapter.Analyze();
                PolicyFailure[] failures = GetPolicyFailures(results);

                return(failures);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }