Beispiel #1
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();
    }
Beispiel #2
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);
    }