Ejemplo n.º 1
0
		public static int Main(string[] args)
		{ 
			int err = 0; 	
			
			try
			{
				GetOptions options = new GetOptions();
				DoParse(options, args);
				
				if (!DoProcessOptions(options))
				{
					if (DoValidate(options)) 
					{
						string[] assemblies = options.Value("-asm").Split(',');
						
						Analyze analyze = new Analyze();
						if (!analyze.Run(options.Value("-exe"), assemblies))
							err = 1;
					}
					else
					{
						err = -2;
					}
				}
			}
			catch (MalformedCommandLineException m)
			{
				Console.Error.WriteLine(m.Message);
				err = -2;
			}
			catch (Exception e)
			{
				Exception n = e;
				int indent = 0;
				while (n != null)
				{
					Console.Error.WriteLine("{0}{1}", new string(' ', 3*indent), n.Message);
					n = n.InnerException;
					++indent;
				}
				Console.Error.WriteLine("exception stack trace:");
				Console.Error.WriteLine(e.StackTrace);
				err = -1;
			}
			
			return err;
		}		
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
		}
Ejemplo n.º 4
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;
		}
Ejemplo n.º 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);
        }