Esempio n. 1
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="ScaffoldContext" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>connectionString</c>--The connection string to the database.</para>
            ///     <para><c>provider</c>--The provider to use.</para>
            ///     <para><c>outputDir</c>--The directory to put files in. Paths are relative to the project directory.</para>
            ///     <para><c>outputDbContextDir</c>--The directory to put DbContext file in. Paths are relative to the project directory.</para>
            ///     <para><c>dbContextClassName</c>--The name of the DbContext to generate.</para>
            ///     <para><c>schemaFilters</c>--The schemas of tables to generate entity types for.</para>
            ///     <para><c>tableFilters</c>--The tables to generate entity types for.</para>
            ///     <para><c>useDataAnnotations</c>--Use attributes to configure the model (where possible). If false, only the fluent API is used.</para>
            ///     <para><c>overwriteFiles</c>--Overwrite existing files.</para>
            ///     <para><c>useDatabaseNames</c>--Use table and column names directly from the database.</para>
            ///     <para><c>modelNamespace</c>--Specify to override the namespace of the generated entity types.</para>
            ///     <para><c>contextNamespace</c>--Specify to override the namespace of the generated DbContext class.</para>
            ///     <para><c>noPluralize</c>--Don't use the pluralizer.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public ScaffoldContext(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var connectionString      = (string)args["connectionString"] !;
                var provider              = (string)args["provider"] !;
                var outputDir             = (string?)args["outputDir"];
                var outputDbContextDir    = (string?)args["outputDbContextDir"];
                var dbContextClassName    = (string?)args["dbContextClassName"];
                var schemaFilters         = (IEnumerable <string>)args["schemaFilters"] !;
                var tableFilters          = (IEnumerable <string>)args["tableFilters"] !;
                var modelNamespace        = (string?)args["modelNamespace"];
                var contextNamespace      = (string?)args["contextNamespace"];
                var useDataAnnotations    = (bool)args["useDataAnnotations"] !;
                var overwriteFiles        = (bool)args["overwriteFiles"] !;
                var useDatabaseNames      = (bool)args["useDatabaseNames"] !;
                var suppressOnConfiguring = (bool)(args["suppressOnConfiguring"] ?? false);
                var noPluralize           = (bool)(args["noPluralize"] ?? false);

                Execute(
                    () => executor.ScaffoldContextImpl(
                        provider, connectionString, outputDir, outputDbContextDir, dbContextClassName,
                        schemaFilters, tableFilters, modelNamespace, contextNamespace, useDataAnnotations,
                        overwriteFiles, useDatabaseNames, suppressOnConfiguring, noPluralize));
            }
            public ScaffoldRuntimeDirectives([NotNull] OperationExecutor executor, [NotNull] object resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                Execute(() => executor.ScaffoldRuntimeDirectivesImpl());
            }
Esempio n. 3
0
            public GetContextTypes([NotNull] OperationExecutor executor, [NotNull] object resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                Execute(executor.GetContextTypesImpl);
            }
Esempio n. 4
0
            public GetMigrations([NotNull] OperationExecutor executor, [NotNull] object resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType = (string)args["contextType"];

                Execute(() => executor.GetMigrationsImpl(contextType));
            }
Esempio n. 5
0
            public UpdateDatabase([NotNull] OperationExecutor executor, [NotNull] object resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var targetMigration = (string)args["targetMigration"];
                var contextType     = (string)args["contextType"];

                Execute(() => executor.UpdateDatabaseImpl(targetMigration, contextType));
            }
Esempio n. 6
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="ScriptDbContext" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public ScriptDbContext(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType = (string?)args["contextType"];

                Execute(() => executor.ScriptDbContextImpl(contextType));
            }
Esempio n. 7
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="GetMigrations" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            ///     <para><c>connectionString</c>--The connection string to the database. Defaults to the one specified in <see cref="O:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext"/> or <see cref="DbContext.OnConfiguring"/>.</para>
            ///     <para><c>noConnect</c>--Don't connect to the database.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public GetMigrations(
                [NotNull] OperationExecutor executor, [NotNull] IOperationResultHandler resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType      = (string)args["contextType"];
                var connectionString = (string)args["connectionString"];
                var noConnect        = (bool)(args["noConnect"] ?? true);

                Execute(() => executor.GetMigrationsImpl(contextType, connectionString, noConnect));
            }
Esempio n. 8
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="DropDatabase" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public DropDatabase(
                [NotNull] OperationExecutor executor,
                [NotNull] IOperationResultHandler resultHandler,
                [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType = (string)args["contextType"];

                Execute(() => executor.DropDatabaseImpl(contextType));
            }
            public DropDatabase(
                [NotNull] OperationExecutor executor,
                [NotNull] object resultHandler,
                [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType  = (string)args["contextType"];
                var confirmCheck = (Func <string, string, bool>)args["confirmCheck"];

                Execute(() => executor.DropDatabaseImpl(contextType, confirmCheck));
            }
Esempio n. 10
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="RemoveMigration" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            ///     <para><c>force</c>--Don't check to see if the migration has been applied to the database.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public RemoveMigration(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType = (string?)args["contextType"];
                var force       = (bool)args["force"] !;

                Execute(() => executor.RemoveMigrationImpl(contextType, force));
            }
Esempio n. 11
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="AddMigration" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>name</c>--The name of the migration.</para>
            ///     <para>
            ///         <c>outputDir</c>--The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to
            ///         "Migrations".
            ///     </para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> type to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public AddMigration(
                [NotNull] OperationExecutor executor,
                [NotNull] IOperationResultHandler resultHandler,
                [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var name        = (string)args["name"];
                var outputDir   = (string)args["outputDir"];
                var contextType = (string)args["contextType"];

                Execute(() => executor.AddMigrationImpl(name, outputDir, contextType));
            }
Esempio n. 12
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="Optimize" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>outputDir</c>--The directory to put files in. Paths are relative to the project directory.</para>
            ///     <para><c>modelNamespace</c>--Specify to override the namespace of the generated model.</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public Optimize(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var outputDir      = (string?)args["outputDir"];
                var modelNamespace = (string?)args["modelNamespace"];
                var contextType    = (string?)args["contextType"];

                Execute(() => executor.OptimizeImpl(outputDir, modelNamespace, contextType));
            }
Esempio n. 13
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="UpdateDatabase" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para>
            ///         <c>targetMigration</c>--The target <see cref="Migration" />. If <see cref="Migration.InitialDatabase" />, all migrations will be
            ///         reverted. Defaults to the last migration.
            ///     </para>
            ///     <para>
            ///         <c>connectionString</c>--The connection string to the database. Defaults to the one specified in
            ///         <see cref="O:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext" /> or
            ///         <see cref="DbContext.OnConfiguring" />.
            ///     </para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public UpdateDatabase(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var targetMigration  = (string?)args["targetMigration"];
                var connectionString = (string?)args["connectionString"];
                var contextType      = (string?)args["contextType"];

                Execute(() => executor.UpdateDatabaseImpl(targetMigration, connectionString, contextType));
            }
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="RemoveMigration" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            ///     <para><c>force</c>--Don't check to see if the migration has been applied to the database.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public RemoveMigration(
                [NotNull] OperationExecutor executor,
                [NotNull] object resultHandler,
                [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var contextType = (string)args["contextType"];
                var force       = (bool)args["force"];
                var revert      = (bool)args["revert"];

                Execute(() => executor.RemoveMigrationImpl(contextType, force, revert));
            }
Esempio n. 15
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="ScriptMigration" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>fromMigration</c>--The starting migration. Defaults to <see cref="Migration.InitialDatabase" />.</para>
            ///     <para><c>toMigration</c>--The ending migration. Defaults to the last migration.</para>
            ///     <para><c>idempotent</c>--Generate a script that can be used on a database at any migration.</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public ScriptMigration(
                [NotNull] OperationExecutor executor,
                [NotNull] IOperationResultHandler resultHandler,
                [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var fromMigration = (string)args["fromMigration"];
                var toMigration   = (string)args["toMigration"];
                var idempotent    = (bool)args["idempotent"];
                var contextType   = (string)args["contextType"];

                Execute(() => executor.ScriptMigrationImpl(fromMigration, toMigration, idempotent, contextType));
            }
Esempio n. 16
0
            /// <summary>
            ///     <para>Initializes a new instance of the <see cref="ScriptMigration" /> class.</para>
            ///     <para>The arguments supported by <paramref name="args" /> are:</para>
            ///     <para><c>fromMigration</c>--The starting migration. Defaults to <see cref="Migration.InitialDatabase" />.</para>
            ///     <para><c>toMigration</c>--The ending migration. Defaults to the last migration.</para>
            ///     <para><c>idempotent</c>--Generate a script that can be used on a database at any migration.</para>
            ///     <para><c>noTransactions</c>--Don't generate SQL transaction statements.</para>
            ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
            /// </summary>
            /// <param name="executor"> The operation executor. </param>
            /// <param name="resultHandler"> The <see cref="IOperationResultHandler" />. </param>
            /// <param name="args"> The operation arguments. </param>
            public ScriptMigration(
                OperationExecutor executor,
                IOperationResultHandler resultHandler,
                IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var fromMigration  = (string?)args["fromMigration"];
                var toMigration    = (string?)args["toMigration"];
                var idempotent     = (bool)args["idempotent"] !;
                var noTransactions = (bool)(args["noTransactions"] ?? false);
                var contextType    = (string?)args["contextType"];

                Execute(() => executor.ScriptMigrationImpl(fromMigration, toMigration, idempotent, noTransactions, contextType));
            }
Esempio n. 17
0
            public ScaffoldContext([NotNull] OperationExecutor executor, [NotNull] object resultHandler, [NotNull] IDictionary args)
                : base(resultHandler)
            {
                Check.NotNull(executor, nameof(executor));
                Check.NotNull(args, nameof(args));

                var connectionString   = (string)args["connectionString"];
                var provider           = (string)args["provider"];
                var outputDir          = (string)args["outputDir"];
                var dbContextClassName = (string)args["dbContextClassName"];
                var schemaFilters      = (IEnumerable <string>)args["schemaFilters"];
                var tableFilters       = (IEnumerable <string>)args["tableFilters"];
                var useDataAnnotations = (bool)args["useDataAnnotations"];
                var overwriteFiles     = (bool)args["overwriteFiles"];

                Execute(() => executor.ScaffoldContextImpl(provider,
                                                           connectionString, outputDir, dbContextClassName,
                                                           schemaFilters, tableFilters, useDataAnnotations, overwriteFiles));
            }