Exemplo n.º 1
0
        /// <summary>
        ///     Creates an instance of the specified <see cref="DbContext"/> type using the standard design-time
        ///     mechanisms. When available, this will use any <see cref="IDesignTimeDbContextFactory{TContext}"/>
        ///     implementations or the application's service provider.
        /// </summary>
        /// <param name="contextType"> The <see cref="DbContext"/> type to instantiate. </param>
        /// <param name="startupAssembly"> The application's startup assembly. </param>
        /// <param name="reportHandler"> The design-time report handler. </param>
        /// <returns> The newly created object. </returns>
        public static DbContext CreateInstance(
            [NotNull] Type contextType,
            [CanBeNull] Assembly startupAssembly = null,
            [CanBeNull] IOperationReportHandler reportHandler = null)
        {
            Check.NotNull(contextType, nameof(contextType));

            return(new DbContextOperations(
                       new OperationReporter(reportHandler),
                       contextType.Assembly,
                       startupAssembly ?? contextType.Assembly)
                   .CreateContext(contextType.FullName));
        }
        /// <summary>
        ///     Creates an instance of the specified <see cref="DbContext" /> type using the standard design-time
        ///     mechanisms. When available, this will use any <see cref="IDesignTimeDbContextFactory{TContext}" />
        ///     implementations or the application's service provider.
        /// </summary>
        /// <param name="contextType"> The <see cref="DbContext" /> type to instantiate. </param>
        /// <param name="startupAssembly"> The application's startup assembly. </param>
        /// <param name="reportHandler"> The design-time report handler. </param>
        /// <returns> The newly created object. </returns>
        public static DbContext CreateInstance(
            [NotNull] Type contextType,
            [CanBeNull] Assembly startupAssembly = null,
            [CanBeNull] IOperationReportHandler reportHandler = null)
        {
            Check.NotNull(contextType, nameof(contextType));

            return(new DbContextOperations(
                       new OperationReporter(reportHandler),
                       contextType.Assembly,
                       startupAssembly ?? contextType.Assembly,
                       args: Array.Empty <string>()) // TODO: Issue #8332
                   .CreateContext(contextType.FullName));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Creates an instance of the specified <see cref="DbContext" /> type using the standard design-time
        ///     mechanisms. When available, this will use any <see cref="IDesignTimeDbContextFactory{TContext}" />
        ///     implementations or the application's service provider.
        /// </summary>
        /// <param name="contextType"> The <see cref="DbContext" /> type to instantiate. </param>
        /// <param name="startupAssembly"> The application's startup assembly. </param>
        /// <param name="reportHandler"> The design-time report handler. </param>
        /// <param name="args"> Arguments passed to the application. </param>
        /// <returns> The newly created object. </returns>
        public static DbContext CreateInstance(
            [NotNull] Type contextType,
            [CanBeNull] Assembly startupAssembly,
            [CanBeNull] IOperationReportHandler reportHandler,
            [CanBeNull] string[] args)
        {
            Check.NotNull(contextType, nameof(contextType));

            return(new DbContextOperations(
                       new OperationReporter(reportHandler),
                       contextType.Assembly,
                       startupAssembly ?? contextType.Assembly,
                       args: args ?? Array.Empty <string>())
                   .CreateContext(contextType.FullName));
        }
Exemplo n.º 4
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>
        ///     <para><c>language</c>--The programming language to be used to generate classes.</para>
        ///     <para><c>remainingArguments</c>--Extra arguments passed into the operation.</para>
        /// </summary>
        /// <param name="reportHandler"> The <see cref="IOperationReportHandler" />. </param>
        /// <param name="args"> The executor arguments. </param>
        public OperationExecutor(IOperationReportHandler reportHandler, IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            _reporter          = new OperationReporter(reportHandler);
            _targetName        = (string)args["targetName"] !;
            _startupTargetName = (string)args["startupTargetName"] !;
            _projectDir        = (string)args["projectDir"] !;
            _rootNamespace     = (string?)args["rootNamespace"];
            _language          = (string?)args["language"];
            _designArgs        = (string[]?)args["remainingArguments"];

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

            if (toolsVersion != null &&
                new SemanticVersionComparer().Compare(toolsVersion, runtimeVersion) < 0)
            {
                _reporter.WriteWarning(DesignStrings.VersionMismatch(toolsVersion, runtimeVersion));
            }
        }
Exemplo n.º 5
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] IOperationReportHandler reportHandler, [NotNull] IDictionary args)
        {
            Check.NotNull(reportHandler, nameof(reportHandler));
            Check.NotNull(args, nameof(args));

            _reporter          = new OperationReporter(reportHandler);
            _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));
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public OperationReporter([CanBeNull] IOperationReportHandler handler)
 {
     _handler = handler;
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Creates an instance of the specified <see cref="DbContext" /> type using the standard design-time
 ///     mechanisms. When available, this will use any <see cref="IDesignTimeDbContextFactory{TContext}" />
 ///     implementations or the application's service provider.
 /// </summary>
 /// <param name="contextType"> The <see cref="DbContext" /> type to instantiate. </param>
 /// <param name="startupAssembly"> The application's startup assembly. </param>
 /// <param name="reportHandler"> The design-time report handler. </param>
 /// <returns> The newly created object. </returns>
 public static DbContext CreateInstance(
     [NotNull] Type contextType,
     [CanBeNull] Assembly startupAssembly = null,
     [CanBeNull] IOperationReportHandler reportHandler = null)
 => CreateInstance(contextType, startupAssembly, reportHandler, null);