Ejemplo n.º 1
0
    public static int Main(string[] args)
    {
        if (Array.IndexOf(args, "--help") > -1)
        {
            VersionFu.PrintHeader();
            return(0);
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            return(0);
        }

        ShutdownRequest request = new ShutdownRequest();

        try {
            request.Send();
        } catch {
            Console.WriteLine("ERROR: The Beagle daemon does not appear to be running");
            return(1);
        }

        return(0);
    }
Ejemplo n.º 2
0
    static int Main(string[] args)
    {
        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            return(0);
        }

        if (Array.IndexOf(args, "--list-filters") > -1)
        {
            PrintFilterInformation();
        }
        else if (Array.IndexOf(args, "--list-backends") > -1)
        {
            PrintBackendInformation();
        }
        else if (Array.IndexOf(args, "--list-static-indexes") > -1)
        {
            PrintStaticIndexInformation();
        }
        else
        {
            return(PrintDaemonInformation(args));
        }

        return(0);
    }
Ejemplo n.º 3
0
        private static string ParseArgs(String[] args)
        {
            int    i     = 0;
            string query = String.Empty;

            while (i < args.Length)
            {
                switch (args [i])
                {
                case "--help":
                case "--usage":
                    PrintUsageAndExit();
                    return(null);

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                case "--icon":
                    icon_enabled = true;
                    break;

                case "--search-docs":
                    docs_enabled = true;
                    break;

                // Ignore session management
                case "--sm-config-prefix":
                case "--sm-client-id":
                case "--screen":
                    // These all take an argument, so
                    // increment i
                    i++;
                    break;

                default:
                    if (args [i].Length < 2 || args [i].Substring(0, 2) != "--")
                    {
                        if (query.Length != 0)
                        {
                            query += " ";
                        }
                        query += args [i];
                    }
                    break;
                }

                i++;
            }

            return(query);
        }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        if (Array.IndexOf(args, "--help") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            // Console.WriteLine (Qt.QT_VERSION_STR); // Uncomment when does not crash
            Environment.Exit(0);
        }

        // FIXME: Cant seem to pass the args to Qt!
        new QApplication(args);

        MainForm mf = new MainForm(args);

        mf.Show();

        QApplication.Exec();
    }
Ejemplo n.º 5
0
    static void Main(String[] args)
    {
        string uriStr           = null;
        string title            = null;
        string sourcefile       = null;
        bool   deletesourcefile = false;

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1)
        {
            PrintUsage();
            Environment.Exit(1);
        }

        for (int i = 0; i < args.Length; i++)
        {
            switch (args [i])
            {
            case "--url":
            case "--title":
            case "--sourcefile":
                if (i + 1 >= args.Length ||
                    args [i + 1].StartsWith("--"))
                {
                    PrintUsage();
                    Environment.Exit(1);
                }
                break;
            }

            switch (args [i])
            {
            case "--url":
                uriStr = args [++i];
                break;

            case "--title":
                title = args [++i];
                break;

            case "--sourcefile":
                sourcefile = args [++i];
                break;

            case "--deletesourcefile":
                deletesourcefile = true;
                break;

            case "--help":
                PrintUsage();
                return;

            case "--version":
                VersionFu.PrintVersion();
                return;
            }
        }

        if (uriStr == null)
        {
            Logger.Log.Error("URI not specified!\n");
            PrintUsage();
            Environment.Exit(1);
        }

        Uri uri = new Uri(uriStr, true);

        if (uri.Scheme == Uri.UriSchemeHttps)
        {
            // For security/privacy reasons, we don't index any
            // SSL-encrypted pages.
            Logger.Log.Error("Indexing secure https:// URIs is not secure!");
            Environment.Exit(1);
        }

        // We don't index file: Uris.  Silently exit.
        if (uri.IsFile)
        {
            return;
        }

        // We *definitely* don't index mailto: Uris.  Silently exit.
        if (uri.Scheme == Uri.UriSchemeMailto)
        {
            return;
        }

        Indexable indexable;

        indexable           = new Indexable(uri);
        indexable.HitType   = "WebHistory";
        indexable.MimeType  = "text/html";
        indexable.Timestamp = DateTime.Now;

        if (title != null)
        {
            indexable.AddProperty(Property.New("dc:title", title));
        }

        if (sourcefile != null)
        {
            if (!File.Exists(sourcefile))
            {
                Logger.Log.Error("sourcefile '{0}' does not exist!", sourcefile);
                Environment.Exit(1);
            }

            indexable.ContentUri    = UriFu.PathToFileUri(sourcefile);
            indexable.DeleteContent = deletesourcefile;
        }
        else
        {
            Stream stdin = Console.OpenStandardInput();
            if (stdin == null)
            {
                Logger.Log.Error("No sourcefile specified, and no standard input!\n");
                PrintUsage();
                Environment.Exit(1);
            }

            indexable.SetTextReader(new StreamReader(stdin));
        }

        IndexingServiceRequest req = new IndexingServiceRequest();

        req.Add(indexable);

        try {
            Logger.Log.Info("Indexing");
            Logger.Log.Debug("SendAsync");
            req.SendAsync();
            Logger.Log.Debug("Close");
            req.Close();
            Logger.Log.Debug("Done");
        } catch (Exception e) {
            Logger.Log.Error("Indexing failed: {0}", e);

            // Still clean up after ourselves, even if we couldn't
            // index the content.
            if (deletesourcefile)
            {
                File.Delete(sourcefile);
            }

            Environment.Exit(1);
        }
    }
Ejemplo n.º 6
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        string index_dir  = null;
        string target_dir = null;
        bool   mount      = false;

        int i = 0;

        while (i < args.Length)
        {
            string arg = args [i];
            ++i;
            string next_arg = i < args.Length ? args [i] : null;

            switch (arg)
            {
            case "-h":
            case "--help":
                PrintUsage();
                Environment.Exit(0);
                break;

            case "--indexdir":
                if (next_arg != null)
                {
                    index_dir = next_arg;
                }
                ++i;
                break;

            case "--mount":
                if (next_arg != null)
                {
                    target_dir = next_arg;
                    mount      = true;
                }
                ++i;
                break;

            case "--unmount":
                if (next_arg != null)
                {
                    target_dir = next_arg;
                    mount      = false;
                }
                ++i;
                break;

            case "--version":
                VersionFu.PrintVersion();
                Environment.Exit(0);
                break;

            default:
                PrintUsage();
                Environment.Exit(1);
                break;
            }
        }

        if (target_dir == null || index_dir == null)
        {
            PrintUsage();
            Environment.Exit(1);
        }

        if (mount)
        {
            MountRemovableIndex(index_dir, target_dir);
        }
        else
        {
            UnmountRemovableIndex(index_dir, target_dir);
        }
    }
Ejemplo n.º 7
0
        public static void DoMain(string[] args)
        {
            SystemInformation.InternalCallInitializer.Init();
            SystemInformation.SetProcessName("beagrepd");

            // Process the command-line arguments
            bool arg_debug        = false;
            bool arg_debug_memory = false;
            bool arg_fg           = false;

            int i = 0;

            while (i < args.Length)
            {
                string arg = args [i];
                ++i;
                string next_arg = i < args.Length ? args [i] : null;

                switch (arg)
                {
                case "-h":
                case "--help":
                    PrintUsage();
                    Environment.Exit(0);
                    break;

                case "--mdb":
                case "--mono-debug":
                    // Silently ignore these arguments: they get handled
                    // in the wrapper script.
                    break;

                case "--list-backends":
                    Console.WriteLine("Current available backends:");
                    Console.Write(QueryDriver.ListBackends());
                    Environment.Exit(0);
                    break;

                case "--fg":
                case "--foreground":
                    arg_fg = true;
                    break;

                case "--bg":
                case "--background":
                    arg_fg = false;
                    break;

                case "--replace":
                    arg_replace = true;
                    break;

                case "--debug":
                    arg_debug = true;
                    break;

                case "--heap-shot":
                    arg_heap_shot    = true;
                    arg_debug        = true;
                    arg_debug_memory = true;
                    break;

                case "--no-snapshots":
                case "--no-snapshot":
                    arg_heap_shot_snapshots = false;
                    break;

                case "--heap-buddy":
                case "--debug-memory":
                    arg_debug        = true;
                    arg_debug_memory = true;
                    break;

                case "--indexing-test-mode":
                    arg_indexing_test_mode = true;
                    arg_fg = true;
                    break;

                case "--backend":
                    if (next_arg == null)
                    {
                        Console.WriteLine("--backend requires a backend name");
                        Environment.Exit(1);
                        break;
                    }

                    if (next_arg.StartsWith("--"))
                    {
                        Console.WriteLine("--backend requires a backend name. Invalid name '{0}'", next_arg);
                        Environment.Exit(1);
                        break;
                    }

                    if (next_arg [0] != '+' && next_arg [0] != '-')
                    {
                        QueryDriver.OnlyAllow(next_arg);
                    }
                    else
                    {
                        if (next_arg [0] == '+')
                        {
                            QueryDriver.Allow(next_arg.Substring(1));
                        }
                        else
                        {
                            QueryDriver.Deny(next_arg.Substring(1));
                        }
                    }

                    ++i;                     // we used next_arg
                    break;

                case "--add-static-backend":
                    if (next_arg != null)
                    {
                        QueryDriver.AddStaticQueryable(next_arg);
                    }
                    ++i;
                    break;

                case "--disable-scheduler":
                    arg_disable_scheduler = true;
                    break;

                case "--indexing-delay":
                    if (next_arg != null)
                    {
                        try {
                            QueryDriver.IndexingDelay = Int32.Parse(next_arg);
                        } catch {
                            Console.WriteLine("'{0}' is not a valid number of seconds", next_arg);
                            Environment.Exit(1);
                        }
                    }

                    ++i;
                    break;

                case "--autostarted":
                    // FIXME: This option is deprecated and will be removed in a future release.
                    break;

                case "--disable-text-cache":
                    disable_textcache = true;
                    break;

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Unknown argument '{0}'", arg);
                    Environment.Exit(1);
                    break;
                }
            }

            if (Environment.GetEnvironmentVariable("SABAYON_SESSION_RUNNING") == "yes")
            {
                Console.WriteLine("Beagrep is running underneath Sabayon, exiting.");
                Environment.Exit(0);
            }

            if (arg_indexing_test_mode)
            {
                LuceneQueryable.OptimizeRightAway = true;
            }

            // Bail out if we are trying to run as root
            if (Environment.UserName == "root" && Environment.GetEnvironmentVariable("SUDO_USER") != null)
            {
                Console.WriteLine("You appear to be running beagrep using sudo.  This can cause problems with");
                Console.WriteLine("permissions in your .beagrep and .wapi directories if you later try to run");
                Console.WriteLine("as an unprivileged user.  If you need to run beagrep as root, please use");
                Console.WriteLine("'su -c' instead.");
                Environment.Exit(-1);
            }

            if (Environment.UserName == "root" && !Conf.Daemon.GetOption(Conf.Names.AllowRoot, false))
            {
                Console.WriteLine("You can not run beagrep as root.  Beagrep is designed to run from your own");
                Console.WriteLine("user account.  If you want to create multiuser or system-wide indexes, use");
                Console.WriteLine("the beagrep-build-index tool.");
                Console.WriteLine();
                Console.WriteLine("You can override this setting using the beagrep-config or beagrep-settings tools.");
                Environment.Exit(-1);
            }

            try {
                string tmp = PathFinder.HomeDir;
            } catch (Exception e) {
                Console.WriteLine("Unable to start the daemon: {0}", e.Message);
                Environment.Exit(-1);
            }

            MainLoopThread = Thread.CurrentThread;

            // FIXME: We always turn on full debugging output!  We are still
            // debugging this code, after all...
            // arg_debug ? LogLevel.Debug : LogLevel.Warn

            Log.Initialize(PathFinder.LogDir, "Beagrep", LogLevel.Debug, arg_fg);
            Log.Always("Starting Beagrep Daemon (version {0})", ExternalStringsHack.Version);
            Log.Always("Running on {0}", SystemInformation.MonoRuntimeVersion);
            Log.Always("Command Line: {0}",
                       Environment.CommandLine != null ? Environment.CommandLine : "(null)");

            if (!ExtendedAttribute.Supported)
            {
                Logger.Log.Warn("Extended attributes are not supported on this filesystem. " +
                                "Performance will suffer as a result.");
            }

            if (disable_textcache)
            {
                Log.Warn("Running with text-cache disabled!");
                Log.Warn("*** Snippets will not be returned for documents indexed in this session.");
            }

            // Check if global configuration files are installed
            if (!Conf.CheckGlobalConfig())
            {
                Console.WriteLine("Global configuration files not found in '{0}'", PathFinder.ConfigDataDir);
                Environment.Exit(-1);
            }

            // Start our memory-logging thread
            if (arg_debug_memory)
            {
                ExceptionHandlingThread.Start(new ThreadStart(LogMemoryUsage));
            }

            // Do BEAGREP_EXERCISE_THE_DOG_HARDER-related processing.
            ExerciseTheDogHarder();

            // Initialize GObject type system
            g_type_init();


            // Lower our CPU priority
            SystemPriorities.Renice(7);

            QueryDriver.Init();
            Server.Init();

#if MONO_1_9
            Shutdown.SetupSignalHandlers(new Shutdown.SignalHandler(HandleSignal));
#else
            SetupSignalHandlers();
#endif

            Shutdown.ShutdownEvent += OnShutdown;

            main_loop = new MainLoop();
            Shutdown.RegisterMainLoop(main_loop);

            // Defer all actual startup until the main loop is
            // running.  That way shutdowns during the startup
            // process work correctly.
            GLib.Idle.Add(new GLib.IdleHandler(StartupProcess));

            // Start our event loop.
            main_loop.Run();

            // We're out of the main loop now, join all the
            // running threads so we can exit cleanly.
            ExceptionHandlingThread.JoinAllThreads();

            // If we placed our sockets in a temp directory, try to clean it up
            // Note: this may fail because the helper is still running
            if (PathFinder.GetRemoteStorageDir(false) != PathFinder.StorageDir)
            {
                try {
                    Directory.Delete(PathFinder.GetRemoteStorageDir(false));
                } catch (IOException) { }
            }

            Log.Always("Beagrep daemon process shut down cleanly.");
        }
Ejemplo n.º 8
0
    static int Main(string[] args)
    {
        SystemInformation.SetProcessName ("beagle-extract-content");

        if (args.Length < 1 || Array.IndexOf (args, "--help") != -1) {
            PrintUsage ();
            return 0;
        }

        if (Array.IndexOf (args, "--debug") == -1)
            Log.Disable ();

        if (Array.IndexOf (args, "--version") != -1) {
            VersionFu.PrintVersion ();
            return 0;
        }

        if (Array.IndexOf (args, "--tokenize") != -1)
            tokenize = true;

        if (Array.IndexOf (args, "--analyze") != -1)
            analyze = true;

        if (Array.IndexOf (args, "--show-generated") != -1 || Array.IndexOf (args, "--show-children") != -1)
            show_generated = true;

        StreamWriter writer = null;
        string outfile = null;
        foreach (string arg in args) {

            // mime-type option
            if (arg.StartsWith ("--mimetype=")) {
                mime_type = arg.Substring (11);
                continue;
            // output file option
            // we need this in case the output contains different encoding
            // printing to Console might not always display properly
            } else if (arg.StartsWith ("--outfile=")) {
                outfile = arg.Substring (10);
                Console.WriteLine ("Redirecting output to " + outfile);
                FileStream f = new FileStream (outfile, FileMode.Create);
                writer = new StreamWriter (f, System.Text.Encoding.UTF8);
                continue;
            } else if (arg.StartsWith ("--")) // option, skip it
                continue;

            Uri uri = UriFu.PathToFileUri (arg);
            Indexable indexable = new Indexable (uri);
            if (mime_type != null)
                indexable.MimeType = mime_type;

            try {
                if (writer != null) {
                    Console.SetOut (writer);
                }

                Display (indexable);
                if (writer != null) {
                    writer.Flush ();
                }

                if (outfile != null) {
                    StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                    standardOutput.AutoFlush = true;
                    Console.SetOut(standardOutput);
                }

            } catch (Exception e) {
                Console.WriteLine ("Unable to filter {0}: {1}", uri, e.Message);
                return -1;
            }

            // Super Lame Hack: gtk-sharp up to 2.10 requires a main loop
            // to dispose of any managed wrappers around GObjects.  Since
            // we don't have one, we'll process all the pending items in
            // a loop here.  This is particularly an issue with maildirs,
            // because we need the loop to clean up after GMime.  Without
            // it, GMime's streams are never completely unref'd, the
            // file descriptors aren't closed, and we run out and crash.
            while (GLib.MainContext.Pending ())
                GLib.MainContext.Iteration ();
        }
        if (writer != null)
            writer.Close ();

        return 0;
    }
Ejemplo n.º 9
0
        private static void ParseArgs(string [] args)
        {
            if (args.Length < 1)
            {
                PrintUsageAndExit();
            }

            for (int i = 0; i < args.Length; i++)
            {
                switch (args [i])
                {
                case "-h":
                case "--help":
                    PrintUsageAndExit();
                    break;

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                case "--highlight-search":
                    highlight = args [i + 1];
                    i++;
                    break;

                case "--search":
                    search = args [i + 1];
                    i++;
                    break;

                case "--client":
                    client = args [i + 1];
                    i++;
                    break;

                default:
                    if (args [i].StartsWith("--"))
                    {
                        Console.WriteLine("WARN: Invalid option {0}", args [i]);
                    }
                    else
                    {
                        path = args [i];
                    }
                    break;
                }
            }

            if (path == null)
            {
                Console.WriteLine("ERROR: Please specify a valid log path or log directory.");
                Environment.Exit(1);
            }

            if (client == null)
            {
                Console.WriteLine("ERROR: Please specify a valid client name.");
                Environment.Exit(2);
            }
        }
Ejemplo n.º 10
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        main_loop = new MainLoop();

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1 || Array.IndexOf(args, "--usage") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            Environment.Exit(0);
        }

        StringBuilder query_str = new StringBuilder();

        query = new Query();

        QueryDomain domain = 0;

        // Parse args
        int i = 0;

        while (i < args.Length)
        {
            switch (args [i])
            {
            case "--live-query":
                keep_running = true;
                break;

            case "--verbose":
                verbose = true;
                break;

            case "--cache":
                display_cached_text = true;
                break;

            case "--stats-only":
                verbose      = true;
                display_hits = false;
                break;

            case "--max-hits":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                query.MaxHits = Int32.Parse(args[i]);
                break;

            case "--flood":
                flood = true;
                break;

            case "--listener":
                listener     = true;
                keep_running = true;
                break;

            case "--raw-uri":
                raw_uri = true;
                break;

            case "--keywords":
                PropertyKeywordFu.ReadKeywordMappings();

                Console.WriteLine("Supported query keywords are:");

                foreach (string key in PropertyKeywordFu.Keys)
                {
                    foreach (QueryKeywordMapping mapping in PropertyKeywordFu.Properties(key))
                    {
                        // Dont print properties without description; they confuse people
                        if (string.IsNullOrEmpty(mapping.Description))
                        {
                            continue;
                        }
                        Console.WriteLine("  {0,-20} for {1}", key, mapping.Description);
                    }
                }

                System.Environment.Exit(0);
                break;

            case "--domain":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                switch (args [i].ToLower())
                {
                case "local":
                    domain |= QueryDomain.Local;
                    break;

                case "system":
                    domain |= QueryDomain.System;
                    break;

                case "network":
                    domain |= QueryDomain.Neighborhood;
                    break;

                case "global":
                    domain |= QueryDomain.Global;
                    break;

                case "all":
                    domain |= QueryDomain.All;
                    break;

                default:
                    PrintUsageAndExit();
                    break;
                }
                break;

            default:
                if (args [i].StartsWith("--"))
                {
                    PrintUsageAndExit();
                }
                if (query_str.Length > 0)
                {
                    query_str.Append(' ');
                }
                query_str.Append(args [i]);

                break;
            }

            ++i;
        }

        if (domain != 0)
        {
            query.QueryDomain = domain;
        }

        if (listener)
        {
            query.IsIndexListener = true;
        }
        else
        {
            if (query_str.Length > 0)
            {
                query.AddText(query_str.ToString());
            }
        }

        query.HitsAddedEvent      += OnHitsAdded;
        query.HitsSubtractedEvent += OnHitsSubtracted;

        if (!keep_running)
        {
            query.FinishedEvent += OnFinished;
        }
        else
        {
            query.ClosedEvent += OnClosed;
        }

        SendQuery();

        main_loop.Run();
    }
Ejemplo n.º 11
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        Beagrep.Util.Log.Level = LogLevel.Always;         // shhhh... silence

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1 || Array.IndexOf(args, "--usage") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            Environment.Exit(0);
        }

        StringBuilder query_str = new StringBuilder();

        query = new Query();

        // Parse args
        int    i = 0;
        string next_arg;

        while (i < args.Length)
        {
            switch (args [i])
            {
            case "--verbose":
                verbose = true;
                break;

            case "--cache":
                display_cached_text = true;
                break;

            case "--stats-only":
                verbose      = true;
                display_hits = false;
                break;

            case "--max-hits":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                query.MaxHits = Int32.Parse(args[i]);
                break;

            case "--list-backends":
                Console.WriteLine("Current available backends:");
                Console.Write(QueryDriver.ListBackends());
                Environment.Exit(0);
                break;

            case "--backend":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }

                next_arg = args [i];
                if (next_arg.StartsWith("--"))
                {
                    Console.WriteLine("--backend requires a backend name. Invalid name '{0}'", next_arg);
                    Environment.Exit(1);
                    break;
                }

                if (next_arg [0] != '+' && next_arg [0] != '-')
                {
                    QueryDriver.OnlyAllow(next_arg);
                }
                else
                {
                    if (next_arg [0] == '+')
                    {
                        QueryDriver.Allow(next_arg.Substring(1));
                    }
                    else
                    {
                        QueryDriver.Deny(next_arg.Substring(1));
                    }
                }

                break;

            case "--add-static-backend":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }

                next_arg = args [i];
                if (!next_arg.StartsWith("--"))
                {
                    QueryDriver.AddStaticQueryable(next_arg);
                }
                break;

            case "--keywords":
                PropertyKeywordFu.ReadKeywordMappings();

                Console.WriteLine("Supported query keywords are:");

                foreach (string key in PropertyKeywordFu.Keys)
                {
                    foreach (QueryKeywordMapping mapping in PropertyKeywordFu.Properties(key))
                    {
                        // Dont print properties without description; they confuse people
                        if (string.IsNullOrEmpty(mapping.Description))
                        {
                            continue;
                        }
                        Console.WriteLine("  {0,-20} for {1}", key, mapping.Description);
                    }
                }

                System.Environment.Exit(0);
                break;

            default:
                if (args [i].StartsWith("--"))
                {
                    PrintUsageAndExit();
                }
                if (query_str.Length > 0)
                {
                    query_str.Append(' ');
                }
                query_str.Append(args [i]);

                break;
            }

            ++i;
        }

        if (verbose)
        {
            Beagrep.Util.Log.Level = LogLevel.Debug;
        }

        if (query_str.Length > 0)
        {
            query.AddText(query_str.ToString());
        }

        Stopwatch watch = new Stopwatch();

        watch.Start();
        StartQueryDriver();
        watch.Stop();
        if (verbose)
        {
            Console.WriteLine("QueryDriver started in {0}", watch);
        }

        QueryResult result = new QueryResult();

        result.HitsAddedEvent += OnHitsAdded;
        result.FinishedEvent  += OnFinished;

        queryStartTime = DateTime.Now;
        QueryDriver.DoQueryLocal(query, result);
    }
Ejemplo n.º 12
0
    public static void Main(string [] args)
    {
        if (args.Length == 0)
        {
            PrintUsageAndExit();
        }

        for (int i = 0; i < args.Length; i++)
        {
            switch (args [i])
            {
            case "--list-sections":
                ListSections();
                return;

            case "--list-backends":
                ListBackends();
                return;

            case "--reload":
            case "--beagled-reload-config":
                ReloadConfig();
                return;

            case "--write-xml":
                if (args.Length == i + 1)
                {
                    PrintUsageAndExit();
                }
                PrintSectionXml(args [i + 1]);
                return;

            case "--read-xml":
                if (args.Length == i + 1)
                {
                    PrintUsageAndExit();
                }
                ReadSectionXml(args [i + 1]);
                return;

            case "--help":
            case "--usage":
                PrintUsageAndExit();
                return;

            case "--version":
                VersionFu.PrintVersion();
                Environment.Exit(0);
                break;

            default:
                break;
            }
        }

        if (args [0].StartsWith("--"))
        {
            PrintUsageAndExit();
        }

        Config config = Conf.Load(args [0]);

        if (config == null)
        {
            Console.WriteLine("No section found: " + args [0]);
            return;
        }

        if (args.Length >= 2)
        {
            try {
                if (HandleArgs(config, args))
                {
                    Conf.Save(config);
                }
            } catch (ArgumentException e) {
                Console.WriteLine("** Error: " + e.Message);
            }

            return;
        }

        foreach (Option option in config.Options.Values)
        {
            ShowOption(config, option);
        }
    }