Example #1
0
 private static string GetUsageMessage(CommandLineParser parser)
 {
     string usage = "Migrate.exe <target> [<Arguments>]" + Environment.NewLine + Environment.NewLine +
                    "target:     name of the connectionString as specified in Generate.exe.config" + Environment.NewLine +
                    Environment.NewLine + parser.GetUsage();
     return string.Format(CultureInfo.CurrentCulture, "Usage:{0}{1}", Environment.NewLine, usage);
 }
Example #2
0
        internal static void ParseCommandLineArguments(CommandLineOptions options, CommandLineParser parser, ConnectionStringSettingsCollection connectionStrings, out string connectionString, out string[] excludedTables)
        {
            if (parser.Parameters.Length < 1 || // expect at least the target
                parser.UnhandledSwitches.Length > 0)
            {
                throw new InvalidCommandLineArgumentException("Invalid command line arguments. Specify the target." + Environment.NewLine + Environment.NewLine + GetUsageMessage(parser),
                    InvalidArgumentsExitCode);
            }

            // connection string
            string target = parser.Parameters[0];
            ConnectionStringSettings settings = connectionStrings[target];
            if (settings == null)
            {
                throw new InvalidCommandLineArgumentException(string.Format(CultureInfo.CurrentCulture,
                    "Missing target: '{0}'. Could not find entry in the configuration file.", target),
                    InvalidTargetExitCode);
            }
            connectionString = settings.ConnectionString;
            if (connectionString == null)
            {
                throw new InvalidCommandLineArgumentException(string.Format(CultureInfo.CurrentCulture,
                    "Empty target: '{0}'. The entry in the configuration file is empty.", target),
                    InvalidTargetExitCode);
            }

            // additional parameters
            excludedTables = (options.Exclude ?? string.Empty).Split(',');
        }
Example #3
0
        private static bool DisplayHelp(string commandLine, out CommandLineOptions options, out CommandLineParser parser)
        {
            options = new CommandLineOptions();
            parser = new CommandLineParser(commandLine, options);
            parser.Parse();

            return options.Help;
        }
Example #4
0
        internal static void ParseCommandLineArguments(CommandLineOptions options, CommandLineParser parser, ConnectionStringSettingsCollection connectionStrings,
            out string connectionString,
            out string migrationNamespace,
            out string moduleName,
            out string versioningTableName,
            out string versioningTableSchema,
            out string[] includedSchemas,
            out string[] excludedTables,
            out bool includeData)
        {
            if (parser.Parameters.Length < 1 || // expect at least the target
                parser.UnhandledSwitches.Length > 0)
            {
                throw new InvalidCommandLineArgumentException("Invalid command line arguments. Specify the target." + Environment.NewLine + Environment.NewLine + GetUsageMessage(parser),
                    InvalidArgumentsExitCode);
            }

            // connection string
            string target = parser.Parameters[0];
            ConnectionStringSettings settings = connectionStrings[target];
            if (settings == null)
            {
                throw new InvalidCommandLineArgumentException(string.Format(CultureInfo.CurrentCulture,
                        "Missing target: '{0}'. Could not find entry in the configuration file.", target),
                    InvalidTargetExitCode);
            }
            connectionString = settings.ConnectionString;
            if (connectionString == null)
            {
                throw new InvalidCommandLineArgumentException(string.Format(CultureInfo.CurrentCulture,
                        "Empty target: '{0}'. The entry in the configuration file is empty.", target),
                    InvalidTargetExitCode);
            }

            // additional parameters
            migrationNamespace = options.Namespace;
            moduleName = options.ModuleName;
            versioningTableName = options.VersioningTableName;
            versioningTableSchema = options.VersioningTableSchema;
            includedSchemas = (options.Schemas ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            excludedTables = (options.Exclude ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            includeData = options.IncludeData;
        }