Esempio n. 1
0
        private Dictionary <String, String> verifyParseDictionary(String[] input, String[] expected)
        {
            Dictionary <String, String> switches = ArgsUtil.parseDictionary(ref input);

            Assert.Equal(expected, input);
            return(switches);
        }
Esempio n. 2
0
        public void parseArgs(String[] argArray)
        {
            argArray = argArray.ToArray();        // Copies so that caller is unchanged
            Dictionary <String, String> switches = ArgsUtil.parseDictionary(ref argArray);

            Params = argArray;
            if (argArray.Length == 3)
            {
                ServerName   = argArray[0];
                DatabaseName = argArray[1];
                Path         = argArray[2];
            }
            else if (argArray.Length == 5)
            {
                ServerName   = argArray[0];
                DatabaseName = argArray[1];
                UserName     = argArray[2];
                Password     = argArray[3];
                Path         = argArray[4];
            }

            RequireRollback = switches.hasAny("-requirerollback", "--requirerollback", "-rr");
            UseTransactions = switches.hasAny("-usetransactions", "--usetransactions", "-ut");
            MaxPatch        = switches.valueLong("-maxpatch", "--maxpatch", "-mp");
            SqlFile         = switches.hasAny("-sqlfile", "--sqlfile", "-sf");
            SslMode         = switches.value("--sslmode", "-sm");

            double?timeoutValue = switches.valueDouble("-trantimeout", "--trantimeout", "-to");             // specified in minutes, fractional is fine

            if (timeoutValue.HasValue)
            {
                // Validates that timeout against maximum value
                TimeSpan timeout = TimeSpan.FromMinutes(timeoutValue.Value);
                if (timeout > TransactionManager.MaximumTimeout)
                {
                    throw new ArgumentException(String.Format("TransactionManager restricts timeouts to a maximum of {0}.\n" +
                                                              "Specified timeout value of {1} is too large.\n" +
                                                              "Issue can be resolved by changing `maching.config` value for <system.transactions><machineSettings maxTimeout=\"\"/></system.transactions>",
                                                              TransactionManager.MaximumTimeout,
                                                              timeout
                                                              ));
                }

                if (timeout < TimeSpan.Zero)
                {
                    throw new ArgumentException(String.Format("Invalid timeout ", timeout));
                }

                TransactionTimeout = timeout;
            }
        }
Esempio n. 3
0
        public void ArgsManagerTestSimplePasses()
        {
            string sArg = "--name = Eriri --full-name = \"Sawamura Spencer Eriri\" --enable --CV= \"Oonishi Saori\"";

            string[] args = ArgsUtil.ParseArgsText(sArg).ToArray();
            var      mgr  = new ArgsManager();

            mgr.AddArgs(args);

            Assert.AreEqual(mgr.GetValue("name"), "Eriri");
            Assert.AreEqual(mgr.GetValue("full-name"), "Sawamura Spencer Eriri");
            Assert.IsTrue(mgr.GetBool("enable"));
            Assert.AreEqual(mgr.GetValue("CV"), "Oonishi Saori");
        }
Esempio n. 4
0
        public static int Main(String[] args)
        {
            Dictionary <String, String> switches = ArgsUtil.parseDictionary(ref args);

            try
            {
                if (switches.hasAny("-h", "--help"))
                {
                    return(printUsage());
                }
                if (switches.hasAny("-v", "--version"))
                {
                    return(runVersion());
                }
                if (switches.hasAny("-vs", "--verboseSettings"))
                {
                    return(runVerboseSettings(switches, args));
                }

                // Reads settings file
                SettingsYaml.parseSetting();

                // Undocumented flag / used for testing
                String example = switches.value("-e", "--example");
                if (example != null)
                {
                    return(runExample(example, switches, args));
                }

                return(runCSharp(switches, args));
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                Console.WriteLine(e.Message);
                if (switches.hasAny("-d", "--debug"))
                {
                    Console.WriteLine(e.StackTrace);
                }
                return(1);
            }
        }
Esempio n. 5
0
        public static int sqlFileMain(NameValueCollection appSettings, string[] argArray)
        {
            Dictionary <String, String> switches = ArgsUtil.parseDictionary(ref argArray);

            if (argArray.Length == 0)
            {
                Console.WriteLine("Please enter sqlFile to execute: ");
                String userPath = Console.ReadLine();

                Console.WriteLine("Please enter database to update [{0}]:", String.Join(", ", appSettings.AllKeys));
                String userTarget = Console.ReadLine();
                if (!appSettings.AllKeys.Contains(userTarget.ToLower()))
                {
                    Console.WriteLine("Invalidate selection: {0}", userTarget);
                    return(519);
                }

                MapHelper.setValue(switches, "-sqlFile", userPath);
                argArray = new[] { userTarget };
            }

            if (argArray.Length != 1 || switches.value("-sqlFile") == null)
            {
                Console.WriteLine("Missing required field.");
                Console.WriteLine("Usage: -sqlFile=<path> <db_target>");
                return(402);
            }

            Console.WriteLine("Current directory: " + Directory.GetCurrentDirectory());

            String path   = switches.value("-sqlFile");
            String target = argArray[0];

            String targetValue = appSettings[target.ToLower()];

            Console.WriteLine("Target {0} with value: {1}", target, targetValue);
            Options options = Options.build(targetValue.Split(' '));

            options.Path = path;

            int result = Program.executeSqlFile(options);

            Console.WriteLine(result == 0 ? "COMPLETE" : "FAIL");
            return(result);
        }
Esempio n. 6
0
        public static int Main(String[] args)
        {
            Dictionary <String, String> switches = ArgsUtil.parseDictionary(ref args);

            try
            {
                if (switches.hasAny("-h", "--help"))
                {
                    return(printUsage());
                }
                if (switches.hasAny("-v", "--version"))
                {
                    return(runVersion());
                }
                if (switches.hasAny("-vs", "--verboseSettings"))
                {
                    return(runVerboseSettings(switches, args));
                }

                // Reads settings file
                SettingsYaml.parseSetting();

                return(runYaml(switches, args));
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                Console.WriteLine(e.Message);
                if (switches.hasAny("-d", "--debug"))
                {
                    Console.WriteLine(e.StackTrace);
                }
                return(1);
            }
        }
        public void ReturnsIndexValue_WhenFound()
        {
            var arg = ArgsUtil.GetArgument(new[] { "first", "second" }, 1, "default");

            Assert.That(arg, Is.EqualTo("second"));
        }
        public void ReturnsDefaultValue_WhenRequiredIndexMissing()
        {
            var arg = ArgsUtil.GetArgument(new [] { "first" }, 1, "default");

            Assert.That(arg, Is.EqualTo("default"));
        }
        public void ReturnsDefaultValue_WithEmptyArgs()
        {
            var arg = ArgsUtil.GetArgument(new string[0], 0, "default");

            Assert.That(arg, Is.EqualTo("default"));
        }