Пример #1
0
        private static int ProcessRecursively(string[] args)
        {
            var directories = new List <string>();

            var fileHandler = (IFileHandler)null;
            var log         = Console.Out;

            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                if (arg == "--text")
                {
                    // If "--text" is specified, write the discovered metadata into a sub-folder relative to the image
                    fileHandler = new TextFileOutputHandler();
                }
                else if (arg == "--markdown")
                {
                    // If "--markdown" is specified, write a summary table in markdown format
                    fileHandler = new MarkdownTableOutputHandler();
                }
//                else if (arg == "--unknown")
//                {
//                    // If "--unknown" is specified, write CSV tallying unknown tag counts
//                    fileHandler = new UnknownTagHandler();
//                }
                else if (arg == "--log-file")
                {
                    if (i == args.Length - 1)
                    {
                        PrintUsage();
                        if (Debugger.IsAttached)
                        {
                            Console.ReadLine();
                        }
                        return(1);
                    }
                    var fileStream = File.Open(args[++i], FileMode.Create);
                    log = new StreamWriter(fileStream, new UTF8Encoding(false));
                }
                else
                {
                    // Treat this argument as a directory
                    directories.Add(arg);
                }
            }

            if (directories.Count == 0)
            {
                Console.Error.WriteLine("Expects one or more directories as arguments.");
                PrintUsage();
                if (Debugger.IsAttached)
                {
                    Console.ReadLine();
                }
                return(1);
            }

            if (fileHandler == null)
            {
                fileHandler = new BasicFileHandler();
            }

            var stopwatch = Stopwatch.StartNew();

            foreach (var directory in directories)
            {
                ProcessDirectory(directory, fileHandler, "", log);
            }

            fileHandler.OnScanCompleted(log);

            Console.Out.WriteLine("Completed in {0:#,##0.##} ms", stopwatch.Elapsed.TotalMilliseconds);

            if (!ReferenceEquals(Console.Out, log))
            {
                log.Dispose();
            }

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }

            return(0);
        }
        private static int Main2(string[] args)
        {
            var directories = new List<string>();

            var fileHandler = (IFileHandler)null;
            var log = Console.Out;

            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                if (arg == "--text")
                {
                    // If "--text" is specified, write the discovered metadata into a sub-folder relative to the image
                    fileHandler = new TextFileOutputHandler();
                }
//                else if (arg == "--markdown")
//                {
//                    // If "--markdown" is specified, write a summary table in markdown format to standard out
//                    fileHandler = new MarkdownTableOutputHandler();
//                }
//                else if (arg == "--unknown")
//                {
//                    // If "--unknown" is specified, write CSV tallying unknown tag counts
//                    fileHandler = new UnknownTagHandler();
//                }
                else if (arg == "--log-file")
                {
                    if (i == args.Length - 1)
                    {
                        PrintUsage();
                        if (Debugger.IsAttached)
                            Console.ReadLine();
                        return 1;
                    }
                    log = new StreamWriter(args[++i], append: false);
                }
                else
                {
                    // Treat this argument as a directory
                    directories.Add(arg);
                }
            }

            if (directories.Count == 0)
            {
                Console.Error.WriteLine("Expects one or more directories as arguments.");
                PrintUsage();
                if (Debugger.IsAttached)
                    Console.ReadLine();
                return 1;
            }

            if (fileHandler == null)
                fileHandler = new BasicFileHandler();

            var stopwatch = Stopwatch.StartNew();

            foreach (var directory in directories)
                ProcessDirectory(directory, fileHandler, "", log);

            fileHandler.OnScanCompleted(log);

            Console.Out.WriteLine("Completed in {0:#,##0.##} ms", stopwatch.Elapsed.TotalMilliseconds);

            if (!ReferenceEquals(Console.Out, log))
                log.Dispose();

            if (Debugger.IsAttached)
                Console.ReadLine();

            return 0;
        }