Galen.Ci.EntityFramework.DbDeploymentManager.LazyLoadDeployedAssembly C# (CSharp) Method

LazyLoadDeployedAssembly() private method

private LazyLoadDeployedAssembly ( ) : Assembly
return System.Reflection.Assembly
        private Assembly LazyLoadDeployedAssembly()
        {
            var isOverrideDeploymentHistory = !string.IsNullOrEmpty(m_Config.DeployedAssemblyOverridePath);
            if (isOverrideDeploymentHistory)
            {
                Log.Information(
                    "Override deployed assembly path {overridePath} specified.  Deployment History will not be used!", 
                    m_Config.DeployedAssemblyOverridePath);
                return m_AssemblyLoader.Load(MigrationsSource.Deployed, m_Config.DeployedAssemblyOverridePath);
            }

            if (m_Config.Mode == DeploymentMode.InitializeOnly || m_Config.Mode == DeploymentMode.SeedOnly)
            {
                return null;
            }

            string deploymentHistoryAssemblyPath = null;
            var targetContextKeySchema = GetContextKeySchema(TargetAssembly, m_Config.MigrationConfig.Type);
            if (targetContextKeySchema == null)
            {
                Log.Warning(
                    "Failed to determine context key and schema name for config type {configType} in target assembly {assemblyPath}.  " +
                    "The cause is most likely an attempt to migrate downward to a version in which {configType} does not exist.  " +
                    "A deployed assembly override must be specified in these cases.  Downward migrations will either not occur or will fail.",
                    m_Config.MigrationConfig.Type,
                    TargetAssembly.CodeBase);
                return null;
            }

            if (!GetIsTargetDatabaseExists())
            {
                Log.Debug(
                    "Database {endpointDatabase} does not exist on {endPointServer}.  Deployment History will not be used.",
                    m_Config.Database.DatabaseName, 
                    m_Config.Database.ServerName);
                return null;
            }

            var factory = DbProviderFactories.GetFactory(m_ConnectionInfoBuilder.ProviderName);
            using (var connection = factory.CreateConnection())
            {
                connection.ConnectionString = m_ConnectionInfoBuilder.BuildConnectionString(
                    m_Config.Database,
                    m_Config.AuthMode,
                    m_Config.SqlLogin,
                    m_Config.SqlPassword);

                connection.Open();

                Log.Debug(
                    "Extracting current deployment history assemblies " +
                    "for {contextKey} in {schemaName} schema on {endPointServer}\\{endpointDatabase} to {extractPath}.",
                    targetContextKeySchema.ContextKey,
                    targetContextKeySchema.SchemaName,
                    m_Config.Database.ServerName,
                    m_Config.Database.DatabaseName,
                    m_Config.DeploymentHistoryExtractPath);

                deploymentHistoryAssemblyPath = DeploymentHistory.ExtractCurrent(
                    targetContextKeySchema.ContextKey, 
                    connection, 
                    targetContextKeySchema.SchemaName,
                    m_Config.DeploymentHistoryExtractPath);
                connection.Close();
            }

            if (string.IsNullOrEmpty(deploymentHistoryAssemblyPath))
            {
                Log.Warning("No {targetSchemaName} Deployment History available for {targetContextKey} on {endPointServer}\\{endpointDatabase}.",
                    targetContextKeySchema.SchemaName,
                    targetContextKeySchema.ContextKey,
                    m_Config.Database.ServerName,
                    m_Config.Database.DatabaseName);
                return null;
            }

            return m_AssemblyLoader.Load(MigrationsSource.Deployed, deploymentHistoryAssemblyPath);
        }