Example #1
0
 /// <summary>
 /// Runs the <see cref="DatabaseExecutor"/> directly.
 /// </summary>
 /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
 /// <param name="connectionString">The database connection string.</param>
 /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
 /// <param name="codeGenArgs">The <see cref="DatabaseExecutorCommand.CodeGen"/> arguments.</param>
 /// <returns>The return code; zero equals success.</returns>
 public static int Run(DatabaseExecutorCommand command, string connectionString, Assembly[] assemblies, CodeGenExecutorArgs codeGenArgs = null)
 {
     using (var em = ExecutionManager.Create(() => new DatabaseExecutor(command, connectionString, assemblies, codeGenArgs)))
     {
         return(HandleRunResult(em.Run()));
     }
 }
Example #2
0
        /// <summary>
        /// Runs the <see cref="DatabaseExecutor"/> directly.
        /// </summary>
        /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
        /// <param name="connectionString">The database connection string.</param>
        /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
        /// <param name="codeGenArgs">The <see cref="DatabaseExecutorCommand.CodeGen"/> arguments.</param>
        /// <returns>The return code; zero equals success.</returns>
        public static async Task <int> RunAsync(DatabaseExecutorCommand command, string connectionString, Assembly[] assemblies, CodeGenExecutorArgs?codeGenArgs = null)
        {
            using var em = ExecutionManager.Create(() => new DatabaseExecutor(command, connectionString, assemblies, codeGenArgs));
            await em.RunAsync().ConfigureAwait(false);

            return(HandleRunResult(em));
        }
Example #3
0
 /// <summary>
 /// Runs the <see cref="DatabaseExecutor"/> directly.
 /// </summary>
 /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
 /// <param name="connectionString">The database connection string.</param>
 /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
 /// <returns>The return code; zero equals success.</returns>
 public static int Run(DatabaseExecutorCommand command, string connectionString, params Assembly[] assemblies)
 {
     using (var em = ExecutionManager.Create(() => new DatabaseExecutor(command, connectionString, assemblies, null)))
     {
         return(HandleRunResult(em.Run()));
     }
 }
Example #4
0
        /// <summary>
        /// Runs the <see cref="DatabaseExecutor"/> directly.
        /// </summary>
        /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
        /// <param name="connectionString">The database connection string.</param>
        /// <param name="useBeefDbo">Indicates whether to use the standard <i>Beef</i> <b>dbo</b> schema objects.</param>
        /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
        /// <param name="codeGenArgs">The <see cref="DatabaseExecutorCommand.CodeGen"/> arguments.</param>
        /// <returns>The return code; zero equals success.</returns>
        public static async Task <int> RunAsync(DatabaseExecutorCommand command, string connectionString, bool useBeefDbo, Assembly[] assemblies, CodeGenExecutorArgs?codeGenArgs = null)
        {
            using var em = ExecutionManager.Create(() => new DatabaseExecutor(command, connectionString, useBeefDbo ? assemblies.Prepend(typeof(DatabaseExecutor).Assembly).ToArray() : assemblies, codeGenArgs));
            await em.RunAsync().ConfigureAwait(false);

            return(HandleRunResult(em));
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseExecutor"/> class.
        /// </summary>
        /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
        /// <param name="connectionString">The database connection string.</param>
        /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
        /// <param name="codeGenArgs">The <see cref="DatabaseExecutorCommand.CodeGen"/> arguments.</param>
        public DatabaseExecutor(DatabaseExecutorCommand command, string connectionString, Assembly[] assemblies, CodeGenExecutorArgs?codeGenArgs = null)
        {
            _command          = command;
            _connectionString = Check.NotEmpty(connectionString, nameof(connectionString));
            _assemblies       = assemblies;

            Check.IsFalse(_command.HasFlag(DatabaseExecutorCommand.CodeGen) && codeGenArgs == null, nameof(codeGenArgs), "The code generation arguments must be provided when the 'command' includes 'CodeGen'.");
            _codeGenArgs = codeGenArgs ?? new CodeGenExecutorArgs();
            if (_codeGenArgs != null && !_codeGenArgs.Parameters.ContainsKey("ConnectionString"))
            {
                _codeGenArgs.Parameters.Add("ConnectionString", _connectionString);
            }

            _db = new Db(_connectionString);

            _assemblies.ForEach(ass => _namespaces.Add(ass.GetName().Name !));
            ReturnCode = -1;
        }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseExecutorArgs"/> class.
 /// </summary>
 /// <param name="command">The <see cref="DatabaseExecutorCommand"/>.</param>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="assemblies">The <see cref="Assembly"/> array whose embedded resources will be probed.</param>
 public DatabaseExecutorArgs(DatabaseExecutorCommand command, string connectionString, params Assembly[] assemblies) : base()
 {
     Command          = command;
     ConnectionString = Check.NotNull(connectionString, nameof(connectionString));
     AddAssembly(assemblies);
 }
Example #7
0
 /// <summary>
 /// Sets (overrides) the supported <see cref="DatabaseExecutorCommand"/> (defaults to <see cref="DatabaseExecutorCommand.All"/>.
 /// </summary>
 /// <param name="command">The supported <see cref="DatabaseExecutorCommand"/>.</param>
 /// <returns>The current instance to supported fluent-style method-chaining.</returns>
 public DatabaseConsoleWrapper Supports(DatabaseExecutorCommand command)
 {
     _supports = command;
     return(this);
 }