예제 #1
0
        /// <summary>
        /// Searches and redacts text from all PDF-files found in input directory. Writes result to output directory.
        /// </summary>
        /// <param name="inDir">Directory to read PDFs from</param>
        /// <param name="outDir">Directory to write redacted PDFs to</param>
        /// <param name="textToSearchAfter">Text to be redacted</param>
        /// <param name="regexStr">Regular expression for searching specific filenames</param>
        public void SearchAndRedact(string inDir, string outDir, string textToSearchAfter, string regexStr)
        {
            List <RectAndText> RATs        = null;
            string             newFilePath = "";

            System.IO.DirectoryInfo directoryInfo = null;
            int counterSearchedFiles = 0;
            int counterRedactedFiles = 0;

            Regex regex = new Regex(regexStr);

            // Turns off AGPL licence note when looping many times (thousands).
            CounterFactory.getInstance().SetCounter(new NoOpCounter());

            List <string> files = Directory.GetFiles(inDir, "*.pdf", System.IO.SearchOption.AllDirectories)
                                  .Where(path => regex.IsMatch(System.IO.Path.GetFileName(path)))
                                  .ToList();


            foreach (string filePath in files)
            {
                logger.Debug("Checking if following file needs redact: " + filePath);
                counterSearchedFiles++;

                if (counterSearchedFiles % 100 == 0)
                {
                    logger.Info("Number of searched files: " + counterSearchedFiles);
                    Console.WriteLine("Number of searched files: " + counterSearchedFiles);
                }

                RATs = GetTextAndCoords(filePath, textToSearchAfter);

                if (RATs.Count != 0)
                {
                    logger.Info("Executing redact on: " + filePath);

                    directoryInfo = System.IO.Directory.GetParent(filePath);

                    newFilePath = outDir + directoryInfo.Name + @"\" + System.IO.Path.GetFileName(filePath);

                    new FileInfo(newFilePath).Directory.Create();

                    Redact(filePath, newFilePath, RATs);

                    logger.Info("Done... saved to: " + newFilePath);

                    counterRedactedFiles++;
                    if (counterRedactedFiles % 100 == 0)
                    {
                        logger.Info("Number of redacted files: " + counterRedactedFiles);
                        Console.WriteLine("Number of redacted files: " + counterRedactedFiles);
                    }
                }
            }

            logger.Info("Total number of searched files: " + counterSearchedFiles);
            Console.WriteLine("Total number of searched files: " + counterSearchedFiles);
            logger.Info("Total number of redacted files: " + counterRedactedFiles);
            Console.WriteLine("Total number of redacted files: " + counterRedactedFiles);
        }
예제 #2
0
        static void Main(string[] args)
        {
            CounterFactory.getInstance().SetCounter(new AGPLWarningRemoverCounter());

            var uri = "http://localhost:8888";

            Console.WriteLine("Starting Nancy on " + uri);

            // initialize an instance of NancyHost
            var host = new NancyHost(new HostConfiguration()
            {
                UrlReservations = new UrlReservations()
                {
                    CreateAutomatically = true
                },
                RewriteLocalhost = true
            }, new Uri(uri));


            host.Start();  // start hosting

            Console.ReadLine();

            Console.WriteLine("Stopping Nancy");
            host.Stop();  // stop hosting
        }