コード例 #1
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="context">The migration context</param>
        /// <param name="normalizer"></param>
        /// <param name="loggerFactory">The class logger factory</param>
        /// <param name="contextName">The context name</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        protected MigrationManager(
            TContext context, INamingNormalizer <TContext> normalizer, IMigrationLoggerFactory loggerFactory, string contextName)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (normalizer == null)
            {
                throw new ArgumentNullException(nameof(normalizer));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            if (contextName == null)
            {
                throw new ArgumentNullException(nameof(contextName));
            }
            if (string.IsNullOrWhiteSpace(contextName))
            {
                throw new ArgumentException("Value cannot be whitespace.", nameof(contextName));
            }

            ContextName = normalizer.Normalize(contextName);
            Normalizer  = normalizer;
            Context     = context;
            Logger      = loggerFactory.Get(GetType().FullName) ?? NullMigrationLogger.Default;
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="instanceScopeFactory">The instance scope factory</param>
        /// <param name="namingNormalizer">The naming normalizer</param>
        /// <param name="migrations">The migrations found</param>
        /// <param name="loggerFactory">The logger factory</param>
        /// <exception cref="ArgumentNullException"></exception>
        public MigrationRunner(
            IMigrationInstanceScopeFactory instanceScopeFactory, INamingNormalizer <TContext> namingNormalizer,
            IEnumerable <MigrationNormalizedMeta> migrations, IMigrationLoggerFactory loggerFactory = null)
        {
            if (namingNormalizer == null)
            {
                throw new ArgumentNullException(nameof(namingNormalizer));
            }
            if (migrations == null)
            {
                throw new ArgumentNullException(nameof(migrations));
            }

            Logger               = loggerFactory?.Get(GetType().FullName) ?? NullMigrationLogger.Default;
            ContextName          = namingNormalizer.Normalize(typeof(TContext).Name);
            NamingNormalizer     = namingNormalizer;
            InstanceScopeFactory = instanceScopeFactory ?? throw new ArgumentNullException(nameof(instanceScopeFactory));

            _migrations = new SortedList <string, MigrationNormalizedMeta>();
            foreach (var migration in migrations)
            {
                var meta = MigrationNormalizedMeta.Build(namingNormalizer, migration.Type);
                if (_migrations.ContainsKey(meta.Id))
                {
                    throw new ArgumentException(
                              $"Collection contains duplicated migrations with name '{meta.Id}' for context '{ContextName}'",
                              nameof(migrations));
                }

                _migrations.Add(migration.Id, meta);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="options">The context options</param>
        /// <param name="normalizer">The naming normalizer</param>
        /// <param name="loggerFactory">An optional class logger factory</param>
        /// <exception cref="ArgumentNullException"></exception>
        protected MigrationContext(IMigrationOptions options, INamingNormalizer normalizer, IMigrationLoggerFactory loggerFactory = null)
        {
            Options    = options ?? throw new ArgumentNullException(nameof(options));
            Normalizer = normalizer ?? throw new ArgumentNullException(nameof(normalizer));
            Logger     = loggerFactory?.Get(GetType().FullName) ?? NullMigrationLogger.Default;

            NormalizedName = normalizer.Normalize(options.ContextName);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="connection">The connection to use</param>
        /// <param name="loggerFactory">The logger factory to use</param>
        /// <exception cref="ArgumentNullException"></exception>
        protected RelationalMigrationContext(IDbConnection connection, IMigrationLoggerFactory loggerFactory)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            Connection = connection ?? throw new ArgumentNullException(nameof(connection));
            Logger     = loggerFactory.Get(GetType().FullName);
        }
コード例 #5
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="context">The migration context</param>
 /// <param name="loggerFactory">An optional class logger factory</param>
 /// <exception cref="ArgumentNullException"></exception>
 protected MigrationManager(TContext context, IMigrationLoggerFactory loggerFactory = null)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
     Logger  = loggerFactory?.Get(GetType().FullName) ?? NullMigrationLogger.Default;
 }