示例#1
0
        public virtual void CommitConfiguration([NotNull] IConfigurationSourceContainer configuration)
        {
            Check.NotNull(configuration, "configuration");

            var configFile = configuration.Get(Constants.ConfigFileOption);

            if (string.IsNullOrEmpty(configFile))
            {
                configFile = Constants.DefaultConfigFile;
            }

            configFile = ResolvePath(configFile);

            var iniFileConfigurationSource = CreateIniFileConfigurationSource(configFile);

            if (!File.Exists(configFile))
            {
                WriteFile(configFile, CreateEmptyConfiguration(), true);
            }

            iniFileConfigurationSource.Load();

            foreach (var key in GetCommitableSettings())
            {
                var value = configuration.Get(key);
                if (!string.IsNullOrEmpty(value))
                {
                    iniFileConfigurationSource.Set(key, value);
                }
            }

            iniFileConfigurationSource.Commit();
        }
示例#2
0
        // Internal for testing.
        protected internal virtual DbContext LoadContext(IConfigurationSourceContainer configuration)
        {
            var contextAssemblyRef = configuration.Get(Constants.ContextAssemblyOption);

            if (string.IsNullOrEmpty(contextAssemblyRef))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var contextTypeName = configuration.Get(Constants.ContextTypeOption);

            return(LoadContext(contextAssemblyRef, contextTypeName));
        }
示例#3
0
        public virtual ScaffoldedMigration CreateMigration([NotNull] IConfigurationSourceContainer configuration)
        {
            Check.NotNull(configuration, "configuration");

            var migrationName = configuration.Get(Constants.MigrationNameOption);

            if (string.IsNullOrEmpty(migrationName))
            {
                throw new InvalidOperationException(Strings.MigrationNameNotSpecified);
            }

            var migrationDirectory = configuration.Get(Constants.MigrationDirectoryOption);

            var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption);

            if (string.IsNullOrEmpty(contextAssemblyFile))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var references            = configuration.Get(Constants.ReferencesOption);
            var contextTypeName       = configuration.Get(Constants.ContextTypeOption);
            var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption);
            var migrationNamespace    = configuration.Get(Constants.MigrationNamespaceOption);

            return(CreateMigration(
                       migrationName,
                       contextAssemblyFile,
                       migrationDirectory,
                       references,
                       contextTypeName,
                       migrationAssemblyFile,
                       migrationNamespace));
        }
示例#4
0
        // TODO: Add support for --SourceMigration
        // TODO: Add support for --Verbose
        public virtual void UpdateDatabase([NotNull] IConfigurationSourceContainer configuration)
        {
            Check.NotNull(configuration, "configuration");

            var targetMigrationName = configuration.Get(Constants.TargetMigrationOption);
            var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption);

            if (string.IsNullOrEmpty(contextAssemblyFile))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var references            = configuration.Get(Constants.ReferencesOption);
            var contextTypeName       = configuration.Get(Constants.ContextTypeOption);
            var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption);
            var migrationNamespace    = configuration.Get(Constants.MigrationNamespaceOption);

            UpdateDatabase(
                contextAssemblyFile,
                targetMigrationName,
                references,
                contextTypeName,
                migrationAssemblyFile,
                migrationNamespace);
        }
示例#5
0
        // TODO: Add support for --SourceMigration
        public virtual IReadOnlyList <SqlStatement> GenerateScript([NotNull] IConfigurationSourceContainer configuration)
        {
            Check.NotNull(configuration, "configuration");

            var targetMigrationName = configuration.Get(Constants.TargetMigrationOption);

            var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption);

            if (string.IsNullOrEmpty(contextAssemblyFile))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var references            = configuration.Get(Constants.ReferencesOption);
            var contextTypeName       = configuration.Get(Constants.ContextTypeOption);
            var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption);
            var migrationNamespace    = configuration.Get(Constants.MigrationNamespaceOption);

            return(GenerateScript(
                       contextAssemblyFile,
                       targetMigrationName,
                       references,
                       contextTypeName,
                       migrationAssemblyFile,
                       migrationNamespace));
        }
示例#6
0
        public virtual IReadOnlyList <IMigrationMetadata> GetMigrations([NotNull] IConfigurationSourceContainer configuration)
        {
            Check.NotNull(configuration, "configuration");

            var source = configuration.Get(Constants.MigrationSourceOption);

            var contextAssemblyRef = configuration.Get(Constants.ContextAssemblyOption);

            if (string.IsNullOrEmpty(contextAssemblyRef))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var contextTypeName      = configuration.Get(Constants.ContextTypeOption);
            var migrationAssemblyRef = configuration.Get(Constants.MigrationAssemblyOption);
            var migrationNamespace   = configuration.Get(Constants.MigrationNamespaceOption);

            return(GetMigrations(
                       contextAssemblyRef,
                       source,
                       contextTypeName,
                       migrationAssemblyRef,
                       migrationNamespace));
        }
示例#7
0
        // Internal for testing.
        protected internal virtual DbContext LoadContext(IConfigurationSourceContainer configuration)
        {
            var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption);
            if (string.IsNullOrEmpty(contextAssemblyFile))
            {
                throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified);
            }

            var references = configuration.Get(Constants.ReferencesOption);
            var contextTypeName = configuration.Get(Constants.ContextTypeOption);

            return LoadContext(contextAssemblyFile, references, contextTypeName);
        }