コード例 #1
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);
            }
        }
コード例 #2
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;
        }
コード例 #3
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);
        }
コード例 #4
0
        static LoggingManager()
        {
            #region Microsoft Logging Test
            LoggerFactory = new MicrosoftMigrationLoggerFactory(
                new LoggerFactory()
                .AddConsole(Microsoft.Extensions.Logging.LogLevel.Trace, true)
                .AddDebug(Microsoft.Extensions.Logging.LogLevel.Trace));

            #endregion

            #region NLog Test
            DebuggerTarget debugTarget = new DebuggerTarget();
            debugTarget.Layout = "[${longdate}] [${uppercase:${level}}] [${logger}] [${gdc:item=assemblyVersion}] ${newline} [${ndlc}] ${newline} ${message} ${newline} ${exception:format=tostring}";

            var config = new NLog.Config.LoggingConfiguration();
            config.AddTarget("1", debugTarget);

            LoggingRule rule1 = new LoggingRule("*", NLog.LogLevel.Debug, debugTarget);
            LoggingRule rule2 = new LoggingRule("*", NLog.LogLevel.Info, debugTarget);
            LoggingRule rule3 = new LoggingRule("*", NLog.LogLevel.Error, debugTarget);
            LoggingRule rule4 = new LoggingRule("*", NLog.LogLevel.Fatal, debugTarget);
            LoggingRule rule5 = new LoggingRule("*", NLog.LogLevel.Trace, debugTarget);
            LoggingRule rule6 = new LoggingRule("*", NLog.LogLevel.Warn, debugTarget);
            LoggingRule rule7 = new LoggingRule("*", NLog.LogLevel.Off, debugTarget);
            config.LoggingRules.Add(rule1);
            config.LoggingRules.Add(rule2);
            config.LoggingRules.Add(rule3);
            config.LoggingRules.Add(rule4);
            config.LoggingRules.Add(rule5);
            config.LoggingRules.Add(rule6);
            config.LoggingRules.Add(rule7);

            LoggerFactory = new SimpleSoft.Database.Migrator.NLogMigrationLoggerFactory(
                new LogFactory(config)
                );

            #endregion
        }
コード例 #5
0
 /// <inheritdoc />
 public SqlServerMigrationContext(TOptions options, IMigrationLoggerFactory loggerFactory)
     : base(new SqlConnection(options.ConnectionString), loggerFactory)
 {
     Options = options ?? throw new ArgumentNullException(nameof(options));
 }
コード例 #6
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="context">The migration context</param>
 /// <param name="normalizer">The naming normalizer</param>
 /// <param name="loggerFactory">The logger factory</param>
 /// <param name="contextName">The context name</param>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public OracleMigrationManager(TContext context, INamingNormalizer <TContext> normalizer,
                               IMigrationLoggerFactory loggerFactory, string contextName)
     : base(context, normalizer, loggerFactory, contextName)
 {
 }
コード例 #7
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="context">The migration context</param>
 /// <param name="normalizer">The naming normalizer</param>
 /// <param name="loggerFactory">The logger factory</param>
 /// <param name="contextName">The context name</param>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 protected RelationalMigrationManager(TContext context, INamingNormalizer <TContext> normalizer, IMigrationLoggerFactory loggerFactory, string contextName)
     : base(context, normalizer, loggerFactory, contextName)
 {
 }
コード例 #8
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>
 public OracleMigrationManager(TContext context, IMigrationLoggerFactory loggerFactory = null)
     : base(context, loggerFactory)
 {
 }
コード例 #9
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 RelationalMigrationManager(TContext context, IMigrationLoggerFactory loggerFactory = null)
     : base(context, loggerFactory)
 {
 }
コード例 #10
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="context">The migration context</param>
 /// <param name="normalizer">The naming normalizer</param>
 /// <param name="loggerFactory">The logger factory</param>
 /// <exception cref="ArgumentNullException"></exception>
 public SqlServerMigrationManager(TContext context, INamingNormalizer <TContext> normalizer,
                                  IMigrationLoggerFactory loggerFactory)
     : base(context, normalizer, loggerFactory)
 {
 }
コード例 #11
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);
        }
コード例 #12
0
 /// <inheritdoc />
 public ApplyMigrationsContext(
     SqlServerMigrationOptions options, INamingNormalizer normalizer, IMigrationLoggerFactory loggerFactory)
     : base(options, normalizer, loggerFactory)
 {
 }
コード例 #13
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="options">The relational context options</param>
 /// <param name="normalizer">The naming normalizer</param>
 /// <param name="loggerFactory">The logger factory to use</param>
 /// <exception cref="ArgumentNullException"></exception>
 protected RelationalMigrationContext(
     IRelationalMigrationOptions options, INamingNormalizer normalizer, IMigrationLoggerFactory loggerFactory = null)
     : base(options, normalizer, loggerFactory)
 {
     Options = options;
 }
コード例 #14
0
 /// <inheritdoc />
 public ApplyMigrationsContext(
     SqlServerContextOptions <ApplyMigrationsContext> options, IMigrationLoggerFactory loggerFactory)
     : base(options, loggerFactory)
 {
 }
コード例 #15
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>
 public OracleMigrationContext(IOracleMigrationOptions options, INamingNormalizer normalizer, IMigrationLoggerFactory loggerFactory = null)
     : base(options, normalizer, loggerFactory)
 {
     Options = options;
 }
コード例 #16
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="context">The migration context</param>
 /// <param name="normalizer"></param>
 /// <param name="loggerFactory">The logger factory</param>
 /// <exception cref="ArgumentNullException"></exception>
 protected MigrationManager(TContext context, INamingNormalizer <TContext> normalizer, IMigrationLoggerFactory loggerFactory)
     : this(context, normalizer, loggerFactory, typeof(TContext).Name)
 {
 }
コード例 #17
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;
 }
コード例 #18
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>
 public SqlServerMigrationManager(TContext context, IMigrationLoggerFactory loggerFactory = null)
     : base(context, loggerFactory)
 {
 }