Наследование: CmdLineObject
Пример #1
0
        public static int ProcessMerge(CommandLineArgs args)
        {
            try
            {
                IEnumerable<string> inputPaths = GetInputFiles(args);
                string outputPath = "CustomInstrumentation.xml";

                if (!string.IsNullOrWhiteSpace(args.OutputFile))
                {
                    outputPath = args.OutputFile;
                }

                var merger = new CustomInstrumentationMerger(inputPaths, outputPath);
                merger.ContinueOnFailure = args.ContinueOnFailure;

                bool result = merger.Execute();

                return result ? 0 : -1;
            }
            catch (Exception ex)
            {
                ErrorOut("Failed to process instrumentation: {0}", ex, args.Verbose || args.VeryVerbose);
                return -1;
            }
        }
Пример #2
0
        public static int ProcessCreate(CommandLineArgs args)
        {
            try
            {
                IEnumerable<string> inputPaths = GetInputFiles(args);
                string outputPath = "CustomInstrumentation.xml";

                if (!string.IsNullOrWhiteSpace(args.OutputFile))
                {
                    outputPath = args.OutputFile;
                }

                var generator = new CustomInstrumentationGenerator(inputPaths, outputPath);
                if (args.ForceIfNotMarkedUpValid)
                {
                    generator.AutomaticInstrumentationScopes = args.ForceIfNotMarkedUpValidScopes;
                }

                generator.UseReflectionBasedDiscovery = args.LegacyMode;
                generator.ContinueOnFailure = args.ContinueOnFailure;
                generator.IncludeCompilerGeneratedCode = args.IncludeCompilerGeneratedCode ?? false;

                bool result = generator.Execute();

                return result ? RETURN_SUCCESS : RETURN_FAILURE;
            }
            catch (Exception ex)
            {
                ErrorOut("Failed to process instrumentation: {0}", ex, args.Verbose || args.VeryVerbose);
                return RETURN_FAILURE;
            }
        }
Пример #3
0
 private static IEnumerable <string> GetInputFiles(CommandLineArgs args)
 {
     return(PathHelper.GetMatchingPaths(args.InputFiles, !args.ContinueOnFailure));
 }
Пример #4
0
        static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var parsedArgs = new CommandLineArgs();

            parsedArgs.Initialize();
            if (parsedArgs.Help || !parsedArgs.IsValid())
            {
                try
                {
                    _windowWidth = Console.WindowWidth;
                }
                catch (IOException)
                {
                    // Running in powershell?
                }

                Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));
                return(Environment.ExitCode = RETURN_FAILURE);
            }

            LogConfigurator.Configure(parsedArgs.Verbose || parsedArgs.VeryVerbose, parsedArgs.VeryVerbose);

            var mode = OperationMode.Create;

            if (parsedArgs.MergeInputs)
            {
                mode = OperationMode.Merge;
            }

            // Validate the output filename
            try
            {
                var pathPart = Path.GetDirectoryName(parsedArgs.OutputFile);
                var filePart = Path.GetFileName(parsedArgs.OutputFile);

                var invalidFilenameCharacters = Path.GetInvalidFileNameChars();
                var invalidPathCharacters     = Path.GetInvalidPathChars().Concat(new[] { '*', '?' }); // Because invalid path characters doesn't include *...

                if (pathPart.Any(x => invalidPathCharacters.Any(y => y == x)) || filePart.Any(x => invalidFilenameCharacters.Any(y => y == x)))
                {
                    Console.WriteLine("The specified output filename is invalid : " + parsedArgs.OutputFile + " " + pathPart + " " + filePart);
                    Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));

                    return(Environment.ExitCode = RETURN_FAILURE);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The specified output filename is invalid ({0})", ex.Message);
                Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));

                return(Environment.ExitCode = RETURN_FAILURE);
            }

            DateTime start = DateTime.Now;

            switch (mode)
            {
            case OperationMode.Create:
                Environment.ExitCode = ProcessCreate(parsedArgs);
                break;

            case OperationMode.Merge:
                Environment.ExitCode = ProcessMerge(parsedArgs);
                break;
            }

            return(Environment.ExitCode);
        }
Пример #5
0
 private static IEnumerable<string> GetInputFiles(CommandLineArgs args)
 {
     return PathHelper.GetMatchingPaths(args.InputFiles, !args.ContinueOnFailure);
 }
Пример #6
0
        static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var parsedArgs = new CommandLineArgs();
            parsedArgs.Initialize();
            if (parsedArgs.Help || !parsedArgs.IsValid())
            {
                try
                {
                    _windowWidth = Console.WindowWidth;
                }
                catch (IOException)
                {
                    // Running in powershell?
                }

                Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));
                return Environment.ExitCode = RETURN_FAILURE;
            }

            LogConfigurator.Configure(parsedArgs.Verbose || parsedArgs.VeryVerbose, parsedArgs.VeryVerbose);

            var mode = OperationMode.Create;
            if (parsedArgs.MergeInputs)
            {
                mode = OperationMode.Merge;
            }

            // Validate the output filename
            try
            {
                var pathPart = Path.GetDirectoryName(parsedArgs.OutputFile);
                var filePart = Path.GetFileName(parsedArgs.OutputFile);

                var invalidFilenameCharacters = Path.GetInvalidFileNameChars();
                var invalidPathCharacters = Path.GetInvalidPathChars().Concat(new[] { '*', '?' }); // Because invalid path characters doesn't include *...

                if (pathPart.Any(x => invalidPathCharacters.Any(y => y == x)) || filePart.Any(x => invalidFilenameCharacters.Any(y => y == x)))
                {
                    Console.WriteLine("The specified output filename is invalid : " + parsedArgs.OutputFile + " " + pathPart + " " + filePart);
                    Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));

                    return Environment.ExitCode = RETURN_FAILURE;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("The specified output filename is invalid ({0})", ex.Message);
                Console.WriteLine(parsedArgs.GetHelpText(_windowWidth));

                return Environment.ExitCode = RETURN_FAILURE;
            }

            DateTime start = DateTime.Now;

            switch (mode)
            {
                case OperationMode.Create:
                    Environment.ExitCode = ProcessCreate(parsedArgs);
                    break;
                case OperationMode.Merge:
                    Environment.ExitCode = ProcessMerge(parsedArgs);
                    break;
            }

            return Environment.ExitCode;
        }