Ejemplo n.º 1
0
        public static ScaffoldedModel ScaffoldContext(
            [NotNull] string provider,
            [NotNull] string connectionString,
            [CanBeNull] string outputDir,
            [CanBeNull] string outputContextDir,
            [CanBeNull] string dbContextClassName,
            [NotNull] IEnumerable <string> schemas,
            [NotNull] IEnumerable <string> tables,
            bool useDataAnnotations,
            bool overwriteFiles,
            bool useDatabaseNames)
        {
            var unwrappedReportHandler = ForwardingProxy.Unwrap <IOperationReportHandler>(new OperationReportHandler());
            var reporter         = new OperationReporter(unwrappedReportHandler);
            var _servicesBuilder = new DesignTimeServicesBuilder(Assembly.GetExecutingAssembly(), reporter, Array.Empty <string>());
            var services         = _servicesBuilder.Build(provider);
            var scaffolder       = services.GetRequiredService <IReverseEngineerScaffolder>();
            var @namespace       = "DiplomWork";
            var scaffoldedModel  = scaffolder.ScaffoldModel(
                connectionString,
                tables,
                schemas,
                @namespace,
                null,
                MakeDirRelative(outputDir, outputContextDir),
                dbContextClassName,
                new ModelReverseEngineerOptions {
                UseDatabaseNames = useDatabaseNames
            },
                new ModelCodeGenerationOptions {
                UseDataAnnotations = useDataAnnotations
            });

            return(scaffoldedModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     <para>Initializes a new instance of the <see cref="OperationExecutor" /> class.</para>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>targetName</c>--The assembly name of the target project.</para>
        ///     <para><c>startupTargetName</c>--The assembly name of the startup project.</para>
        ///     <para><c>projectDir</c>--The target project's root directory.</para>
        ///     <para><c>rootNamespace</c>--The target project's root namespace.</para>
        /// </summary>
        /// <param name="reportHandler"> The <see cref="IOperationReportHandler" />. </param>
        /// <param name="args"> The executor arguments. </param>
        public OperationExecutor([NotNull] object reportHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedReportHandler = ForwardingProxy.Unwrap <IOperationReportHandler>(reportHandler);

            _reporter          = new OperationReporter(unwrappedReportHandler);
            _targetName        = (string)args["targetName"];
            _startupTargetName = (string)args["startupTargetName"];
            _projectDir        = (string)args["projectDir"];
            _rootNamespace     = (string)args["rootNamespace"];
            _language          = (string)args["language"];

            // TODO: Flow in from tools (issue #8332)
            _designArgs = Array.Empty <string>();

            var toolsVersion   = (string)args["toolsVersion"];
            var runtimeVersion = ProductInfo.GetVersion();

            if (toolsVersion != null &&
                new SemanticVersionComparer().Compare(toolsVersion, runtimeVersion) < 0)
            {
                _reporter.WriteWarning(DesignStrings.VersionMismatch(toolsVersion, runtimeVersion));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     <para>Initializes a new instance of the <see cref="OperationExecutor" /> class.</para>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>targetName</c>--The assembly name of the target project.</para>
        ///     <para><c>startupTargetName</c>--The assembly name of the startup project.</para>
        ///     <para><c>projectDir</c>--The target project's root directory.</para>
        ///     <para><c>rootNamespace</c>--The target project's root namespace.</para>
        /// </summary>
        /// <param name="reportHandler"> The <see cref="IOperationReportHandler" />. </param>
        /// <param name="args"> The executor arguments. </param>
        public OperationExecutor([NotNull] object reportHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedReportHandler = ForwardingProxy.Unwrap <IOperationReportHandler>(reportHandler);
            var reporter = new OperationReporter(unwrappedReportHandler);

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];

            _projectDir = (string)args["projectDir"];
            var rootNamespace = (string)args["rootNamespace"];
            var language      = (string)args["language"];

            // TODO: Flow in from tools (issue #8332)
            var designArgs = Array.Empty <string>();

            // NOTE: LazyRef is used so any exceptions get passed to the resultHandler
            var startupAssembly = new LazyRef <Assembly>(
                () => Assembly.Load(new AssemblyName(startupTargetName)));
            var assembly = new LazyRef <Assembly>(
                () =>
            {
                try
                {
                    return(Assembly.Load(new AssemblyName(targetName)));
                }
                catch (Exception ex)
                {
                    throw new OperationException(
                        DesignStrings.UnreferencedAssembly(targetName, startupTargetName),
                        ex);
                }
            });

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    designArgs));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    reporter,
                    startupAssembly.Value,
                    _projectDir,
                    rootNamespace,
                    language,
                    designArgs));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    _projectDir,
                    rootNamespace,
                    language,
                    designArgs));
        }
Ejemplo n.º 4
0
        public OperationExecutor([NotNull] object logHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(logHandler, nameof(logHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedLogHandler = ForwardingProxy.Unwrap <IOperationLogHandler>(logHandler);
            var loggerProvider      = new LoggerProvider(name => new CommandLoggerAdapter(name, unwrappedLogHandler));

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];
            var projectDir        = (string)args["projectDir"];
            var rootNamespace     = (string)args["rootNamespace"];

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    loggerProvider,
                    targetName,
                    startupTargetName));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    loggerProvider,
                    targetName,
                    startupTargetName,
                    projectDir,
                    rootNamespace));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    loggerProvider,
                    targetName,
                    startupTargetName,
                    projectDir,
                    rootNamespace));
        }
Ejemplo n.º 5
0
        public OperationExecutor([NotNull] object reportHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedReportHandler = ForwardingProxy.Unwrap <IOperationReportHandler>(reportHandler);
            var reporter = new OperationReporter(unwrappedReportHandler);

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];
            var environment       = (string)args["environment"];

            _projectDir = (string)args["projectDir"];
            var contentRootPath = (string)args["contentRootPath"];
            var rootNamespace   = (string)args["rootNamespace"];

            // NOTE: LazyRef is used so any exceptions get passed to the resultHandler
            var startupAssembly = new LazyRef <Assembly>(
                () => Assembly.Load(new AssemblyName(startupTargetName)));
            var assembly = new LazyRef <Assembly>(
                () =>
            {
                try
                {
                    return(Assembly.Load(new AssemblyName(targetName)));
                }
                catch (Exception ex)
                {
                    throw new OperationException(
                        DesignStrings.UnreferencedAssembly(targetName, startupTargetName),
                        ex);
                }
            });

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    environment,
                    contentRootPath));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    reporter,
                    startupAssembly.Value,
                    environment,
                    _projectDir,
                    contentRootPath,
                    rootNamespace));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    environment,
                    _projectDir,
                    contentRootPath,
                    rootNamespace));
        }
        public OperationExecutor([NotNull] object logHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(logHandler, nameof(logHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedLogHandler = ForwardingProxy.Unwrap <IOperationLogHandler>(logHandler);
            var loggerProvider      = new LoggerProvider(name => new CommandLoggerAdapter(name, unwrappedLogHandler));

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];
            var environment       = (string)args["environment"];
            var projectDir        = (string)args["projectDir"];
            var rootNamespace     = (string)args["rootNamespace"];

            var startupAssembly = Assembly.Load(new AssemblyName(startupTargetName));

            Assembly assembly;

            try
            {
                assembly = Assembly.Load(new AssemblyName(targetName));
            }
            catch (Exception ex)
            {
                throw new OperationException(CommandsStrings.UnreferencedAssembly(targetName, startupTargetName), ex);
            }

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    loggerProvider,
                    assembly,
                    startupAssembly,
                    projectDir, environment));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    loggerProvider,
                    assembly,
                    startupAssembly,
                    environment,
                    projectDir,
                    rootNamespace));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    loggerProvider,
                    assembly,
                    startupAssembly,
                    environment,
                    projectDir,
                    rootNamespace));
        }
Ejemplo n.º 7
0
            protected OperationBase([NotNull] object resultHandler)
            {
                Check.NotNull(resultHandler, nameof(resultHandler));

                _resultHandler = ForwardingProxy.Unwrap <IOperationResultHandler>(resultHandler);
            }
        /// <summary>
        ///     <para>Initializes a new instance of the <see cref="OperationExecutor" /> class.</para>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>targetName</c>--The assembly name of the target project.</para>
        ///     <para><c>startupTargetName</c>--The assembly name of the startup project.</para>
        ///     <para><c>projectDir</c>--The target project's root directory.</para>
        ///     <para><c>rootNamespace</c>--The target project's root namespace.</para>
        /// </summary>
        /// <param name="reportHandler"> The <see cref="IOperationReportHandler" />. </param>
        /// <param name="args"> The executor arguments. </param>
        public OperationExecutor([NotNull] object reportHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            var unwrappedReportHandler = ForwardingProxy.Unwrap <IOperationReportHandler>(reportHandler);
            var reporter = new OperationReporter(unwrappedReportHandler);

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];

            _projectDir = (string)args["projectDir"];
            var rootNamespace = (string)args["rootNamespace"];
            var language      = (string)args["language"];
            var toolsVersion  = (string)args["toolsVersion"];

            // TODO: Flow in from tools (issue #8332)
            var designArgs = Array.Empty <string>();

            var runtimeVersion = ProductInfo.GetVersion();

            if (toolsVersion != null &&
                new SemanticVersionComparer().Compare(RemovePatch(toolsVersion), RemovePatch(runtimeVersion)) < 0)
            {
                reporter.WriteWarning(DesignStrings.VersionMismatch(toolsVersion, runtimeVersion));
            }

            // NOTE: LazyRef is used so any exceptions get passed to the resultHandler
            var startupAssembly = new LazyRef <Assembly>(
                () => Assembly.Load(new AssemblyName(startupTargetName)));
            var assembly = new LazyRef <Assembly>(
                () =>
            {
                try
                {
                    return(Assembly.Load(new AssemblyName(targetName)));
                }
                catch (Exception ex)
                {
                    throw new OperationException(
                        DesignStrings.UnreferencedAssembly(targetName, startupTargetName),
                        ex);
                }
            });

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    designArgs));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    _projectDir,
                    rootNamespace,
                    language,
                    designArgs));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    reporter,
                    assembly.Value,
                    startupAssembly.Value,
                    _projectDir,
                    rootNamespace,
                    language,
                    designArgs));

            string RemovePatch(string versionString)
            {
                var prereleaseIndex = versionString.IndexOf("-", StringComparison.Ordinal);

                if (prereleaseIndex != -1)
                {
                    versionString = versionString.Substring(0, prereleaseIndex);
                }

                var version = new Version(versionString);

                return(new Version(version.Major, version.Minor).ToString());
            }
        }
Ejemplo n.º 9
0
        public OperationExecutor([NotNull] object logHandler, [NotNull] IDictionary args, [NotNull] AssemblyLoader assemblyLoader)
        {
            Check.NotNull(logHandler, nameof(logHandler));
            Check.NotNull(args, nameof(args));
            Check.NotNull(assemblyLoader, nameof(assemblyLoader));

            var unwrappedLogHandler = ForwardingProxy.Unwrap <IOperationLogHandler>(logHandler);
            var loggerProvider      = new LoggerProvider(name => new CommandLoggerAdapter(name, unwrappedLogHandler));

            var targetName        = (string)args["targetName"];
            var startupTargetName = (string)args["startupTargetName"];
            var environment       = (string)args["environment"];

            _projectDir = (string)args["projectDir"];
            var startupProjectDir = (string)args["startupProjectDir"];
            var rootNamespace     = (string)args["rootNamespace"];

            // NOTE: LazyRef is used so any exceptions get passed to the resultHandler
            var startupAssembly = new LazyRef <Assembly>(
                () => assemblyLoader.Load(startupTargetName));
            var assembly = new LazyRef <Assembly>(
                () =>
            {
                try
                {
                    return(assemblyLoader.Load(targetName));
                }
                catch (Exception ex)
                {
                    throw new OperationException(
                        ToolsCoreStrings.UnreferencedAssembly(targetName, startupTargetName),
                        ex);
                }
            });

            _contextOperations = new LazyRef <DbContextOperations>(
                () => new DbContextOperations(
                    loggerProvider,
                    assembly.Value,
                    startupAssembly.Value,
                    environment,
                    startupProjectDir));
            _databaseOperations = new LazyRef <DatabaseOperations>(
                () => new DatabaseOperations(
                    loggerProvider,
                    assemblyLoader,
                    startupAssembly.Value,
                    environment,
                    _projectDir,
                    startupProjectDir,
                    rootNamespace));
            _migrationsOperations = new LazyRef <MigrationsOperations>(
                () => new MigrationsOperations(
                    loggerProvider,
                    assembly.Value,
                    assemblyLoader,
                    startupAssembly.Value,
                    environment,
                    _projectDir,
                    startupProjectDir,
                    rootNamespace));
        }