Ejemplo n.º 1
0
        public void TestZZMissingArgument()
        {
            GetOpt getopt = new GetOpt(new[] { "-abcc-arg", "-c" }, "abc:");
            Option opt;

            opt = getopt.NextOption();
            Assert.IsNotNull(opt, "should have had a valid option");
            Assert.AreEqual('a', opt.Character);
            Assert.IsNull(opt.Argument, "doesn't have an argument");

            opt = getopt.NextOption();
            Assert.IsNotNull(opt, "should have had a valid option");
            Assert.AreEqual('b', opt.Character);
            Assert.IsNull(opt.Argument, "doesn't have an argument");

            opt = getopt.NextOption();
            Assert.IsNotNull(opt, "should have had a valid option");
            Assert.AreEqual('c', opt.Character);
            Assert.IsNotNull(opt.Argument, "should have an argument");
            Assert.AreEqual("c-arg", opt.Argument, "argument isn't quite right!");

            try
            {
                opt = getopt.NextOption();
                Assert.Fail("Should have thrown " + typeof(MissingOptionException));
            }
            catch (MissingOptionException)
            {
                /* ignore */
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int port = (int)DefaultPort;
            uint verbose = DefaultVerbosity;
            uint maxPacketSize = 0;
            int sessionChannelId = DefaultSessionChannelId;
            TimeSpan timeout = DefaultInactiveTimeout;

            GetOpt options = new GetOpt(args, "ql:vm:s:M:T:");
            try
            {
                Option opt;
                while ((opt = options.NextOption()) != null)
                {
                    switch (opt.Character)
                    {
                        case 'q':
                            LogManager.Adapter = new NoOpLoggerFactoryAdapter();
                            break;
                        case 'v':
                            verbose++;
                            break;
                        case 'l':
                            NameValueCollection prop = new NameValueCollection();
                            prop["level"] = opt.Argument;
                            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(prop);
                            break;
                        case 'm':
                            maxPacketSize = uint.Parse(opt.Argument);
                            break;
                        case 'b':
                            sessionChannelId = int.Parse(opt.Argument);
                            break;

                        case 'M':
                            Environment.SetEnvironmentVariable(MillipedeRecorder.ConfigurationEnvironmentVariableName, opt.Argument);
                            break;

                        case 'T':
                            int t = int.Parse(opt.Argument);
                            timeout = t <= 0 ? TimeSpan.Zero : TimeSpan.FromSeconds(t);
                            break;
                    }
                }
            }
            catch (GetOptException e)
            {
                Console.WriteLine(e.Message);
                Usage();
                return;
            }
            args = options.RemainingArguments();
            if (args.Length > 1)
            {
                Usage();
                return;
            }
            if (args.Length == 1)
            {
                port = Int32.Parse(args[0]);
                if (port <= 0)
                {
                    Console.WriteLine("error: port must be greater than 0");
                    return;
                }
            }

            if (verbose > 0)
            {
                LogManager.GetLogger(typeof (ClientRepeater)).Info(String.Format("Starting server on port {0}", port));
            }
            RepeaterConfiguration config = new RepeaterConfiguration(port);
            config.MaximumPacketSize = maxPacketSize;
            ClientRepeater cr = new ClientRepeater(config);
            cr.SessionChangesChannelId = sessionChannelId;
            cr.Verbose = verbose;
            cr.InactiveTransportTimeout = timeout;
            cr.StartListening();
            if (verbose > 0)
            {
                LogManager.GetLogger(typeof (ClientRepeater)).Info("Server stopped");
            }
        }
Ejemplo n.º 3
0
        public void TestStackedOptionsWithArgs()
        {
            GetOpt getopt = new GetOpt(new[] { "-abcc-arg", "-c", "c-arg", "-cc-arg", "rest" }, "abc:");
            Option opt;

            opt = getopt.NextOption();
            Assert.IsNotNull(opt, "should have had a valid option");
            Assert.AreEqual('a', opt.Character);
            Assert.IsNull(opt.Argument, "doesn't have an argument");

            opt = getopt.NextOption();
            Assert.IsNotNull(opt, "should have had a valid option");
            Assert.AreEqual('b', opt.Character);
            Assert.IsNull(opt.Argument, "doesn't have an argument");

            for (int i = 0; i < 3; i++)
            {
                opt = getopt.NextOption();
                Assert.IsNotNull(opt, "should have had a valid option");
                Assert.AreEqual('c', opt.Character);
                Assert.IsNotNull(opt.Argument, "should have an argument");
                Assert.AreEqual("c-arg", opt.Argument, "argument isn't quite right!");
            }

            opt = getopt.NextOption();
            Assert.IsNull(opt, "should have no more options");

            string[] remainder = getopt.RemainingArguments();
            Assert.IsNotNull(remainder);
            Assert.AreEqual(1, remainder.Length);
            Assert.AreEqual("rest", remainder[0]);
        }