public AppDomainOperationExecutor(
            string assembly,
            string startupAssembly,
            string projectDir,
            string dataDirectory,
            string rootNamespace,
            string language,
            string[] remainingArguments)
            : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments)
        {
            var info = new AppDomainSetup {
                ApplicationBase = AppBasePath
            };

            var configurationFile = (startupAssembly ?? assembly) + ".config";

            if (File.Exists(configurationFile))
            {
                Reporter.WriteVerbose(Resources.UsingConfigurationFile(configurationFile));
                info.ConfigurationFile = configurationFile;
            }

            _domain = AppDomain.CreateDomain("EntityFrameworkCore.DesignDomain", null, info);

            if (dataDirectory != null)
            {
                Reporter.WriteVerbose(Resources.UsingDataDir(dataDirectory));
                _domain.SetData("DataDirectory", dataDirectory);
            }

            var reportHandler = new OperationReportHandler(
                Reporter.WriteError,
                Reporter.WriteWarning,
                Reporter.WriteInformation,
                Reporter.WriteVerbose);

            _executor = _domain.CreateInstanceAndUnwrap(
                DesignAssemblyName,
                ExecutorTypeName,
                false,
                BindingFlags.Default,
                null,
                new object[]
            {
                reportHandler,
                new Hashtable
                {
                    { "targetName", AssemblyFileName },
                    { "startupTargetName", StartupAssemblyFileName },
                    { "projectDir", ProjectDirectory },
                    { "rootNamespace", RootNamespace },
                    { "language", Language },
                    { "toolsVersion", ProductInfo.GetVersion() },
                    { "remainingArguments", RemainingArguments }
                }
            },
                null,
                null);
        }
        public void On_methods_are_noops_when_null()
        {
            var handler = new OperationReportHandler();

            handler.OnWarning("Princess Celestia is in danger.");
            handler.OnInformation("Princess Celestia is on her way.");
            handler.OnVerbose("Princess Celestia is an alicorn.");
        }
        public void OnVerbose_works()
        {
            string result  = null;
            var    handler = new OperationReportHandler(verboseHandler: m => result = m);
            var    message = "Princess Celestia is an alicorn.";

            handler.OnVerbose(message);

            Assert.Equal(message, result);
        }
        public void OnInformation_works()
        {
            string result  = null;
            var    handler = new OperationReportHandler(informationHandler: m => result = m);
            var    message = "Princess Celestia is on her way.";

            handler.OnInformation(message);

            Assert.Equal(message, result);
        }
        public void OnWarning_works()
        {
            string result  = null;
            var    handler = new OperationReportHandler(warningHandler: m => result = m);
            var    message = "Princess Celestia is in danger.";

            handler.OnWarning(message);

            Assert.Equal(message, result);
        }
        public AppDomainOperationExecutor(
            string assembly,
            string startupAssembly,
            string projectDir,
            string contentRootPath,
            string dataDirectory,
            string rootNamespace,
            string environment)
            : base(assembly, startupAssembly, projectDir, contentRootPath, dataDirectory, rootNamespace, environment)
        {
            var info = new AppDomainSetup {
                ApplicationBase = AppBasePath
            };

            var configurationFile = (startupAssembly ?? assembly) + ".config";

            if (File.Exists(configurationFile))
            {
                Reporter.WriteVerbose(string.Format(Resources.UsingConfigurationFile, configurationFile));
                info.ConfigurationFile = configurationFile;
            }

            _domain = AppDomain.CreateDomain("EntityFrameworkCore.DesignDomain", null, info);

            if (dataDirectory != null)
            {
                _domain.SetData("DataDirectory", dataDirectory);
            }

            var reportHandler = new OperationReportHandler();

            _executor = _domain.CreateInstanceAndUnwrap(
                DesignAssemblyName,
                ExecutorTypeName,
                false,
                BindingFlags.Default,
                null,
                new object[]
            {
                reportHandler,
                new Hashtable
                {
                    { "targetName", AssemblyFileName },
                    { "startupTargetName", StartupAssemblyFileName },
                    { "projectDir", ProjectDirectory },
                    { "contentRootPath", ContentRootPath },
                    { "rootNamespace", RootNamespace },
                    { "environment", EnvironmentName }
                }
            },
                null,
                null);
        }
        private DbContext TryCreateContextUsingAppCode(Type dbContextType, Type startupType)
        {
            try
            {
                // Use EF design APIs to get the DBContext instance.
                // EF infers the environment (Development/ Production) based on the environment variable
                // ASPNETCORE_ENVIRONMENT. This should already be set up by the CodeGeneration.Design process.
                OperationReportHandler operationHandler = new OperationReportHandler();

                return(DbContextActivator.CreateInstance(dbContextType, startupType.GetTypeInfo().Assembly, operationHandler));
            }
            catch (Exception ex)
            {
                throw ex.Unwrap(_logger);
            }
        }
        private DbContext TryCreateContextUsingAppCode(Type dbContextType, Type startupType)
        {
            try
            {
                // Use EF design APIs to get the DBContext instance.
                var operationHandler  = new OperationReportHandler();
                var operationReporter = new OperationReporter(operationHandler);
                // EF infers the environment (Development/ Production) based on the environment variable
                // ASPNETCORE_ENVIRONMENT. This should already be set up by the CodeGeneration.Design process.
                var dbContextOperations = new DbContextOperations(
                    operationReporter,
                    dbContextType.GetTypeInfo().Assembly,
                    startupType.GetTypeInfo().Assembly,
                    Array.Empty <string>());

                var dbContextService = dbContextOperations.CreateContext(dbContextType.FullName);

                return(dbContextService);
            }
            catch (Exception ex)
            {
                throw ex.Unwrap(_logger);
            }
        }