예제 #1
0
    public static int Main(string[] args)
    {
        bus = null;
        bool          readIn  = false;
        bool          readOut = false;
        List <string> rules   = new List <string> ();

        for (int i = 0; i != args.Length; i++)
        {
            string arg = args[i];

            if (!arg.StartsWith("--"))
            {
                rules.Add(arg);
                continue;
            }

            switch (arg)
            {
            case "--stdin":
                readIn = true;
                break;

            case "--stdout":
                readOut = true;
                break;

            case "--system":
                bus = Bus.System;
                break;

            case "--session":
                bus = Bus.Session;
                break;

            default:
                Console.Error.WriteLine("Usage: monitor.exe [--stdin|--stdout|--system|--session] [watch expressions]");
                Console.Error.WriteLine("       If no watch expressions are provided, defaults will be used.");
                return(1);
            }
        }

        if (bus == null)
        {
            bus = Bus.Session;
        }

        if (rules.Count != 0)
        {
            //install custom match rules only
            foreach (string rule in rules)
            {
                bus.AddMatch(rule);
            }
        }
        else
        {
            //no custom match rules, install the defaults
            bus.AddMatch(MessageFilter.CreateMatchRule(MessageType.Signal));
            bus.AddMatch(MessageFilter.CreateMatchRule(MessageType.MethodReturn));
            bus.AddMatch(MessageFilter.CreateMatchRule(MessageType.Error));
            bus.AddMatch(MessageFilter.CreateMatchRule(MessageType.MethodCall));
        }

        if (readIn)
        {
            ReadIn();
            return(0);
        }

        if (readOut)
        {
            ReadOut();
            return(0);
        }

        PrettyPrintOut();
        return(0);
    }