예제 #1
0
        static void Main(string[] args)
        {
            IDictionary <string, string> argsDic = CmdArgsParser.Parse(args);

            IOUtils.SetExtValues(argsDic);

            Menu.ClearItems();
            Menu.AddItem(new MenuItemExit());
            Menu.AddItem("Hello world!", PrintHelloWorld);
            Menu.AddItem(new MenuItemCalc());
            Menu.AddItem(new MenuItemDate());
            Menu.AddItem(new MenuItemSafeIntReading());

            if (argsDic != null)
            {
                try
                {
                    Menu.Execute();
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("ERROR: " + ex.Message);
                }
            }
            else
            {
                while (true)
                {
                    Menu.ShowMenu();
                    Menu.Execute();
                }
            }
        }
예제 #2
0
        public void TestEnum()
        {
            Res <Conf> res = CmdArgsParser <Conf> .Parse(new[] { "-a", "2", "-b", "two", "-c" });

            Assert.AreEqual(Constraint.Two, res.Args.A);
            Assert.AreEqual(Constraint.Two, res.Args.B);
            Assert.AreEqual(Constraint.Three, res.Args.C);
            Assert.AreEqual(null, res.Args.D);
        }
예제 #3
0
        public void TestPredicateBad()
        {
            var             testi = 20;
            Predicate <int> pred  = i => i <= testi;  // using closure

            ConfPredicate.B_Predicate_closure = pred; // using delegate variable
            ConfPredicate.B_Predicate_set     = i => i % 3 == 0;

            Assert.Throws <CmdException>(() =>
                                         CmdArgsParser <ConfPredicate> .Parse(new[] { "--IntPredicate", "25" }));
        }
예제 #4
0
        public void TestPredicateOk()
        {
            var             testi = 20;
            Predicate <int> pred  = i => i <= testi;  // using closure

            ConfPredicate.B_Predicate_closure = pred; // using delegate variable
            ConfPredicate.B_Predicate_set     = i => i % 3 == 0;

            // must be 1..20 and divides by 3
            Res <ConfPredicate> res = CmdArgsParser <ConfPredicate> .Parse(new[] { "-b", "9" });

            Assert.AreEqual(9, res.Args.B);
        }
예제 #5
0
        static void Main(string[] args)
        {
            _args = new Args();

            if (!CmdArgsParser.Parse(_args, args))
            {
                return;
            }

            if (!ConsoleArgsParser.Fill(_args))
            {
                return;
            }

            if (!Connect())
            {
                Output("Can't connect. Maybe your password is wrong", OutputType.Error);
                return;
            }
            Output("Connected", OutputType.Verbose);

            if (!ExecCommand())
            {
                Output("Executed with errors.", OutputType.Error);
                return;
            }
            _connetions.WriteAll();
            Output("Success!", OutputType.Verbose);
            //debug
            var v = _connetions?.PhoneBase?.Base?.HBTKey;

            if (v != null)
            {
                Console.WriteLine("Phone base's BtKey first byte: {0}", _connetions.PhoneBase?.Base?.HBTKey[0].ToString());
            }
            if (_connetions?.PsdBase?.Base?.HBTKey != null)
            {
                Console.WriteLine("PSD base's BtKey first byte: {0}", _connetions?.PsdBase?.Base?.HBTKey[0].ToString());
            }
        }
예제 #6
0
 public void TestDefErrorMandatory()
 {
     Assert.Throws <ConfException>(() =>
                                   CmdArgsParser <ConfDefErrorMandatory> .Parse(new[] { "--deftrue" }));
 }