Beispiel #1
0
        private static int GenerateOnions(Settings settings)
        {
            OnionGenerator[] generators = null;
            try
            {
                IAppender appender = GetOnionLoggingAppender(settings);

                generators = PrepareGenerators(settings, appender);

                foreach (OnionGenerator g in generators)
                {
                    g.Start();
                }

                bool noPosix = false;
                try
                {
                    WaitForSignal(generators);
                }
                catch (FileNotFoundException ex)
                {
                    LogNoPosixMessage(ex);
                    noPosix = true;
                }
                catch (TypeLoadException ex)
                {
                    LogNoPosixMessage(ex);
                    noPosix = true;
                }

                if (noPosix)
                {
                    NonPosixWait(generators);
                }
            }
            finally
            {
                TerminateAllGenerators(generators);

                if (generators != null)
                {
                    for (int i = 0; i < generators.Length; ++i)
                    {
                        if (generators[i] != null)
                        {
                            generators[i].Dispose();
                            generators[i] = null;
                        }
                    }
                }
            }

            return 0;
        }
Beispiel #2
0
 private static int CheckOnionDirectory(Settings settings)
 {
     Log.DebugFormat("Checking onion directory: {0}", settings.CheckDir);
     try
     {
         OnionDirectory.Validate(settings.CheckDir);
     }
     catch (IOException ex)
     {
         Console.Error.WriteLine("Validation error (something missing): " + ex.Message);
         return 1;
     }
     catch (PorException ex)
     {
         Console.Error.WriteLine("Validation error: " + ex.Message);
         return 1;
     }
     return 0;
 }
Beispiel #3
0
 private static void ValidateBaseDirSetting(Settings settings)
 {
     if (string.IsNullOrEmpty(settings.BaseDir))
     {
         Log.Debug("Base directory set to invalid value, setting it to '.'");
         settings.BaseDir = ".";
     }
 }
Beispiel #4
0
 private static int RunMainProgram(Settings settings)
 {
     int retVal;
     if (!string.IsNullOrEmpty(settings.CheckDir))
     {
         retVal = CheckOnionDirectory(settings);
     }
     else if (!string.IsNullOrEmpty(settings.InFilename))
     {
         retVal = ProcessPriorLog(settings);
     }
     else
     {
         retVal = GenerateOnions(settings);
     }
     return retVal;
 }
Beispiel #5
0
        private static int ProcessPriorLog(Settings settings)
        {
            Log.DebugFormat("Processing prior run file: {0}", settings.InFilename);
            if (settings.ToMatch == null)
            {
                settings.ShowOptionsError("Reading in prior run (-i) requires a match to test (-m)");
                return 1;
            }
            Log.DebugFormat("Looking for matches to: {0}", settings.ToMatch.ToString());
            OnionLogProcessor processor
                = new OnionLogProcessor(Path.Combine(settings.BaseDir, settings.InFilename),
                                        settings.ToMatch) {
                PickDirectory = PickOutputDirectory,
                MatchMax = settings.MaxMatch,
            };
            processor.ProcessLog();

            return 0;
        }
Beispiel #6
0
 private static OnionGenerator[] PrepareGenerators(Settings settings, IAppender appender)
 {
     OnionGenerator[] generators = new OnionGenerator[settings.WorkerCount];
     for (int i = 0; i < generators.Length; ++i)
     {
         generators[i] = new OnionGenerator {
             OnionPattern = settings.ToMatch,
             PickDirectory = PickOutputDirectory,
             GenerateMax = settings.MaxGenerate,
             MatchMax = settings.MaxMatch,
         };
         generators[i].OnionAppender.AddAppender(appender);
     }
     return generators;
 }
Beispiel #7
0
        private static int Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            Settings settings = new Settings();

            if(!settings.TryParse(args))
            {
                return 1;
            }

            if (settings.ShouldShowHelp)
            {
                settings.ShowHelp(Console.Out);
                return 0;
            }

            ValidateBaseDirSetting(settings);

            Environment.CurrentDirectory = settings.BaseDir;

            return RunMainProgram(settings);
        }
Beispiel #8
0
        private static IAppender GetOnionLoggingAppender(Settings settings)
        {
            if(string.IsNullOrEmpty(settings.OutFilename))
            {
                return null;
            }

            FileAppender appender = new FileAppender {
                Layout = new PatternLayout("%m%n"),
                Encoding = System.Text.Encoding.ASCII,
                AppendToFile = true,
                File = settings.OutFilename,
                Name = "OnionLog",
            };
            appender.ActivateOptions();

            return appender;
        }