Пример #1
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();
        }
Пример #2
0
		private static bool DoRun(GetOptions options)
		{ 
			Progress progress = null;
			if (!options.Has("-quiet"))
				progress = new Progress(options.Has("-verbose"));
				
			Watchdog watcher = new Watchdog(options.Has("-verbose"));
			
			Error[] errors = null;
			try
			{
				DateTime startTime = DateTime.Now;

				AnalyzeAssembly analyzer = new AnalyzeAssembly(delegate (string name)
				{
					progress.Add(name);
					watcher.Add(name);
				});
				
				List<string> excluded = new List<string>(options.Values("-exclude-check"));
				if (excluded.IndexOf("R1035") < 0)		// ValidateArgs2 is disabled by default
					excluded.Add("R1035");
				
				analyzer.ExcludedChecks = excluded.Except(options.Values("-include-check"));
				analyzer.ExcludeNames = options.Values("-exclude-name").Except(options.Values("-include-name"));
				
				string[] onlyType = options.Values("-only-type");
				
				string[] severities = options.Values("-severity");
				Severity severity = (Severity) Enum.Parse(typeof(Severity), severities[severities.Length - 1]);
				bool ignoreBreaks = options.Has("-ignore-breaking") && !options.Has("-include-breaking");
				errors = analyzer.Analyze(options.Operands[0], onlyType, severity, ignoreBreaks);
				TimeSpan elapsed = DateTime.Now - startTime;
				
				string assemblyPath = options.Operands[0];
				string outFile = options.Value("-out");
				
				if (options.Has("-xml"))
					XmlReport.Report(assemblyPath, outFile, errors);
				else if (options.Has("-html"))
					HtmlReport.Report(assemblyPath, outFile, errors, analyzer.NumRules, elapsed);
				else
					TextReport.Report(assemblyPath, outFile, errors, analyzer.NumRules, elapsed);
			}
			finally
			{
				if (progress != null)
					progress.Dispose();
				watcher.Dispose();
			}
			
			int count = errors.Count(x => x.Violation.Severity != Severity.Nitpick);
						
			return count == 0;
		}
Пример #3
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();
		}
Пример #4
0
		private static bool DoValidate(GetOptions options)
		{
			bool valid = true;
			
			// can't use both -verbose and -quiet
			if (options.Has("-verbose") && options.Has("-quiet"))
			{
				Console.Error.WriteLine("can't use both -verbose and -quiet");
				valid = false;
			}
			
			// -text, -html, and -xml are exclusive
			if (options.Has("-text") && (options.Has("-html") || options.Has("-xml")))
			{
				Console.Error.WriteLine("-text, -html, and -xml are exclusive options");
				valid = false;
			}
			if (options.Has("-html") && options.Has("-xml"))
			{
				Console.Error.WriteLine("-text, -html, and -xml are exclusive options");
				valid = false;
			}
			
			// -exclude-name values must be valid
			string[] names = options.Values("-exclude-name");
			if (!DoTypeMethodsValid(names, "-exclude-name"))
			{
				valid = false;
			}
						
			// -include-name values must be valid
			names = options.Values("-include-name");
			if (!DoTypeMethodsValid(names, "-include-name"))
			{
				valid = false;
			}
			
			// -severity must be legit
			foreach (string severity in options.Values("-severity"))
			{
				if (severity != "Error" && severity != "Warning" && severity != "Nitpick")
				{
					Console.Error.WriteLine("severity must be Error, Warning, or Nitpick");
					valid = false;
				}
			}
			
			// -set must be well formed
			string[] values = options.Values("-set");
			foreach (string value in values)
			{
				if (!value.Contains(":"))
				{
					Console.Error.WriteLine("-set:{0} is missing a colon", value);
					valid = false;
				}
			}
						
			// must have one assembly
			if (options.Operands.Length != 1)	
			{
				Console.Error.WriteLine("one assembly must be specified");
				valid = false;
			}
			
			return valid;
		}		
Пример #5
0
        private static bool DoRun(GetOptions options)
        {
            Progress progress = null;

            if (!options.Has("-quiet"))
            {
                progress = new Progress(options.Has("-verbose"));
            }

            Watchdog watcher = new Watchdog(options.Has("-verbose"));

            Error[] errors = null;
            try
            {
                DateTime startTime = DateTime.Now;

                AnalyzeAssembly analyzer = new AnalyzeAssembly(delegate(string name)
                {
                    progress.Add(name);
                    watcher.Add(name);
                });

                List <string> excluded = new List <string>(options.Values("-exclude-check"));
                if (excluded.IndexOf("R1035") < 0)                              // ValidateArgs2 is disabled by default
                {
                    excluded.Add("R1035");
                }

                analyzer.ExcludedChecks = excluded.Except(options.Values("-include-check"));
                analyzer.ExcludeNames   = options.Values("-exclude-name").Except(options.Values("-include-name"));

                string[] onlyType = options.Values("-only-type");

                string[] severities   = options.Values("-severity");
                Severity severity     = (Severity)Enum.Parse(typeof(Severity), severities[severities.Length - 1]);
                bool     ignoreBreaks = options.Has("-ignore-breaking") && !options.Has("-include-breaking");
                errors = analyzer.Analyze(options.Operands[0], onlyType, severity, ignoreBreaks);
                TimeSpan elapsed = DateTime.Now - startTime;

                string assemblyPath = options.Operands[0];
                string outFile      = options.Value("-out");

                if (options.Has("-xml"))
                {
                    XmlReport.Report(assemblyPath, outFile, errors);
                }
                else if (options.Has("-html"))
                {
                    HtmlReport.Report(assemblyPath, outFile, errors, analyzer.NumRules, elapsed);
                }
                else
                {
                    TextReport.Report(assemblyPath, outFile, errors, analyzer.NumRules, elapsed);
                }
            }
            finally
            {
                if (progress != null)
                {
                    progress.Dispose();
                }
                watcher.Dispose();
            }

            int count = errors.Count(x => x.Violation.Severity != Severity.Nitpick);

            return(count == 0);
        }
Пример #6
0
        private static bool DoValidate(GetOptions options)
        {
            bool valid = true;

            // can't use both -verbose and -quiet
            if (options.Has("-verbose") && options.Has("-quiet"))
            {
                Console.Error.WriteLine("can't use both -verbose and -quiet");
                valid = false;
            }

            // -text, -html, and -xml are exclusive
            if (options.Has("-text") && (options.Has("-html") || options.Has("-xml")))
            {
                Console.Error.WriteLine("-text, -html, and -xml are exclusive options");
                valid = false;
            }
            if (options.Has("-html") && options.Has("-xml"))
            {
                Console.Error.WriteLine("-text, -html, and -xml are exclusive options");
                valid = false;
            }

            // -exclude-name values must be valid
            string[] names = options.Values("-exclude-name");
            if (!DoTypeMethodsValid(names, "-exclude-name"))
            {
                valid = false;
            }

            // -include-name values must be valid
            names = options.Values("-include-name");
            if (!DoTypeMethodsValid(names, "-include-name"))
            {
                valid = false;
            }

            // -severity must be legit
            foreach (string severity in options.Values("-severity"))
            {
                if (severity != "Error" && severity != "Warning" && severity != "Nitpick")
                {
                    Console.Error.WriteLine("severity must be Error, Warning, or Nitpick");
                    valid = false;
                }
            }

            // -set must be well formed
            string[] values = options.Values("-set");
            foreach (string value in values)
            {
                if (!value.Contains(":"))
                {
                    Console.Error.WriteLine("-set:{0} is missing a colon", value);
                    valid = false;
                }
            }

            // must have one assembly
            if (options.Operands.Length != 1)
            {
                Console.Error.WriteLine("one assembly must be specified");
                valid = false;
            }

            return(valid);
        }