示例#1
0
        private int DoLoadCustomRules(AssemblyCache cache, Severity severity, bool ignoreBreaks)
        {
            int count = 0;

            string paths = Settings.Get("custom", string.Empty);

            foreach (string path in paths.Split(':'))
            {
                try
                {
                    if (path.Length > 0)
                    {
                        System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(path);
                        ViolationDatabase.LoadCustom(assembly);
                        count += DoLoadRules(assembly, cache, severity, ignoreBreaks);
                    }
                }
                catch (Exception)
                {
                    // DoPostOptionsInit will handle alerting the user
                }
            }

            return(count);
        }
示例#2
0
        public void Check()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (string file in ViolationDatabase.XmlFiles())
            {
                Stream stream = assembly.GetManifestResourceStream(file);
                LoadXML(stream);
            }
        }
示例#3
0
        public void MethodFailed(MethodDefinition method, string checkID, int offset, string details)
        {
            if (!method.CustomAttributes.HasDisableRule(checkID))
            {
                Location  location  = m_cache.Symbols.Location(method, offset, details);
                Violation violation = ViolationDatabase.Get(checkID);

                m_errors.Add(new Error(location, violation));
            }
        }
示例#4
0
        public void AssemblyFailed(AssemblyDefinition assembly, string checkID, string details)
        {
            if (assembly == null || !assembly.CustomAttributes.HasDisableRule(checkID))
            {
                Location loc = new Location();
                loc.Name = assembly != null?string.Format("Assembly: {0}", assembly.Name.Name) : string.Empty;

                loc.Line    = -1;
                loc.Offset  = -1;
                loc.Details = details;

                Violation violation = ViolationDatabase.Get(checkID);
                m_errors.Add(new Error(loc, violation));
            }
        }
示例#5
0
        public void TypeFailed(TypeDefinition type, string checkID, string details)
        {
            if (!type.CustomAttributes.HasDisableRule(checkID))
            {
                DBC.Assert(m_cache != null, "m_cache is null");
                DBC.Assert(m_cache.Symbols != null, "m_cache.Symbols is null");
                DBC.Assert(type != null, "type is null");
                DBC.Assert(details != null, "details is null");

                Location  location  = m_cache.Symbols.Location(type, details);
                Violation violation = ViolationDatabase.Get(checkID);
                DBC.Assert(violation != null, "violation is null");
                DBC.Assert(m_errors != null, "m_errors is null");

                m_errors.Add(new Error(location, violation));
            }
        }
示例#6
0
        private static bool DoProcessOptions(GetOptions options)
        {
            bool processed = true;

            if (options.Has("-help"))
            {
                DoShowHelp(options);
            }

            else if (options.Has("-version"))
            {
                DoShowVersion();
            }

            else if (options.Has("-usage"))
            {
                DoShowUsage();
            }

#if DEBUG
            else if (options.Has("-check-xml"))
            {
                CheckXml checker = new CheckXml();
                checker.Check();
            }
            else if (options.Has("-generate-html-violations"))
            {
                ViolationDatabase.Init();

                HtmlViolations html = new HtmlViolations();
                html.Write(options.Value("-generate-html-violations"));
            }
            else if (options.Has("-dump-strings"))
            {
                string assemblyPath = options.Operands[0];
                DumpStrings.Dump(assemblyPath);
            }
#endif
            else
            {
                processed = false;
            }

            return(processed);
        }
示例#7
0
        private static void DoPostOptionsInit(GetOptions options, string[] args)
        {
            if (options.Has("-not-localized"))
            {
                Settings.Add("*localized*", "false");
            }

            Log.Init(options.Has("-append"));
            Log.InfoLine(true, "started up on {0}, version {1}", DateTime.Now, Assembly.GetExecutingAssembly().GetName().Version);
            Log.InfoLine(true, "arguments are '{0}'", string.Join(", ", args));

            string paths = Settings.Get("custom", string.Empty);

            foreach (string path in paths.Split(':'))
            {
                if (path.Length > 0)
                {
                    try
                    {
                        Unused.Value = System.Reflection.Assembly.LoadFrom(path);                               // need to load these before we init the logger
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Couldn't load the '{0}' custom assembly. See the log for details.", path);
                        Log.ErrorLine(true, e.Message);
                        Log.ErrorLine(true, e.StackTrace);
                    }
                }
            }

#if DEBUG
            AssertTraceListener.Install();
#endif

            foreach (string entry in options.Values("-set"))
            {
                string key   = entry.Split(':')[0];
                string value = entry.Split(':')[1];
                Settings.Add(key, value);
            }

            ViolationDatabase.Init();
        }
示例#8
0
        // Don't bother with a rule if the user doesn't care about rules of that
        // severity or he's excluded the rule.
        private bool DoRuleRequiresCheck(string checkID, Severity severity, bool ignoreBreaks)
        {
            Violation violation = ViolationDatabase.Get(checkID);

            if (violation.Severity > severity)
            {
                return(false);
            }

            if (ignoreBreaks && violation.Breaking)
            {
                return(false);
            }

            if (m_excludedChecks.Contains(checkID))
            {
                return(false);
            }

            return(true);
        }