コード例 #1
0
 public static ShamanOptions WithLogger(this ShamanOptions options, IShamanLogger logger)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Logger = logger ?? EmptyShamanLogger.Instance;
     return(options);
 }
コード例 #2
0
 /// <summary>
 ///     Call this method at the end of <see cref="DbContext.OnModelCreating" />
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="modelBuilder"></param>
 /// <param name="shamanOptions"></param>
 public static void FixOnModelCreating <T>(this ModelBuilder modelBuilder, ShamanOptions shamanOptions = null)
     where T : DbContext
 {
     if (modelBuilder == null)
     {
         throw new ArgumentNullException(nameof(modelBuilder));
     }
     ModelCreatingFixer.FixOnModelCreating(modelBuilder, typeof(T), shamanOptions);
 }
コード例 #3
0
 public static ShamanOptions With <T>(this ShamanOptions options) where T : IShamanService, new()
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Services.Add(new T());
     return(options);
 }
コード例 #4
0
 /// <summary>
 ///     Call this method at the end of <see cref="DbContext.OnModelCreating" />
 /// </summary>
 /// <param name="context"></param>
 /// <param name="modelBuilder"></param>
 /// <param name="shamanOptions"></param>
 public static void FixOnModelCreating(this DbContext context, ModelBuilder modelBuilder,
                                       ShamanOptions shamanOptions = null)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     ModelCreatingFixer.FixOnModelCreating(modelBuilder, context.GetType(), shamanOptions);
 }
コード例 #5
0
 public static void FixOnModelCreating(ModelBuilder modelBuilder, Type contextType,
                                       ShamanOptions shamanOptions = null)
 {
     fixingHolder.TryFix(contextType, () =>
     {
         var modelFixer = new ModelFixer(contextType, shamanOptions);
         modelFixer.FixOnModelCreating(modelBuilder);
     });
 }
コード例 #6
0
 public static ShamanOptions With(this ShamanOptions options, IShamanService service)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     if (service == null)
     {
         throw new ArgumentNullException(nameof(service));
     }
     options.Services.Add(service);
     return(options);
 }
コード例 #7
0
        public static ShamanOptions ConfigureService <T>([NotNull] this ShamanOptions options, Action <T> configureAction)
            where T : IShamanService
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            foreach (var service in options.Services.OfType <T>())
            {
                configureAction(service);
            }

            return(options);
        }
コード例 #8
0
        public static ShamanOptions With(this ShamanOptions options, IShamanService service)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            options.Services.Add(service);
            var modificationService = service as IShamanOptionModificationService;

            modificationService?.ModifyShamanOptions(options);
            return(options);
        }
コード例 #9
0
 /// <summary>
 ///     Include support for TableAttribute, ColumnAttribute, NotMappedAttribute,
 ///     RequiredAttribute, MaxLengthAttribute, IndexAttribute, UniqueIndexAttribute
 ///     and other
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public static ShamanOptions WithDefaultServices(this ShamanOptions options)
 {
     return(options
            .With <ColumnAttributeUpdater>()
            .With <NotMappedAttributeUpdater>()
            .With <NavigationPropertyAttributeUpdater>()
            .With <TimestampAttributeUpdater>()
            .With <DatabaseGeneratedAttributeUpdater>()
            .With <KeyAttributeUpdater>()
            .With <IndexAttributeUpdater>()
            .With <RequiredAttributeUpdater>()
            .With <MaxLengthAttributeUpdater>()
            .With <DecimalTypeAttributeUpdater>()
            .With <TableAttributeUpdater>()
            .With <DefaultValueAttributeUpdater>()
            .With <DefaultValueSqlAttributeUpdater>());
 }
コード例 #10
0
        public static ShamanOptions Without <T>([NotNull] this ShamanOptions options)
            where T : IShamanService
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            var list = options.Services;

            for (var index = list.Count - 1; index >= 0; index--)
            {
                if (list[index].GetType() == typeof(T))
                {
                    list.RemoveAt(index);
                }
            }
            return(options);
        }
コード例 #11
0
        public static void DoInTransaction <T>(this T context, Action <ShamanTransactionInfo <T> > action) where T : DbContext
        {
            if (context.Database.CurrentTransaction != null)
            {
                var tmp = new ShamanTransactionInfo <T>(context, false);
                action(tmp);
                return;
            }
            using (var transaction = context.Database.BeginTransaction())
            {
                var transactionFinalize = TransactionAction.Commit;
                try
                {
                    var tmp = new ShamanTransactionInfo <T>(context, true);
                    action(tmp);
                    transactionFinalize = tmp.EndAction;
                }
                catch (Exception e)
                {
                    ShamanOptions.TryGetExceptionLogger(typeof(T))?
                    .LogException(Guid.Parse("{A84D312F-AD7D-4A80-B514-5E4714FD9A9E}"), e);
                    transaction.Rollback();
                    transactionFinalize = TransactionAction.None;
                    throw;
                }
                finally
                {
                    switch (transactionFinalize)
                    {
                    case TransactionAction.Commit:
                        transaction.Commit();
                        break;

                    case TransactionAction.Rollback:
                        transaction.Rollback();
                        break;
                    }
                }
            }
        }
コード例 #12
0
 /// <summary>
 ///     Include support for TableAttribute, ColumnAttribute, NotMappedAttribute,
 ///     RequiredAttribute, MaxLengthAttribute, IndexAttribute, UniqueIndexAttribute
 ///     and other
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public static ShamanOptions WithDefaultServices(this ShamanOptions options, Type dbContextType)
 {
     return(options
            .With <ColumnInfoColumnAttributeUpdater>()
            .With <NotMappedAttributeUpdater>()
            .With <NavigationPropertyAttributeUpdater>()
            .With(new NavigationPropertyByPropertyTypeUpdater(dbContextType))
            .With <TimestampAttributeUpdater>()
            .With <DatabaseGeneratedAttributeUpdater>()
            .With <KeyAttributeUpdater>()
            .With <IndexAttributeUpdater>()
            .With <RequiredAttributeUpdater>()
            .With <MaxLengthAttributeUpdater>()
            .With <DecimalTypeAttributeUpdater>()
            .With <UnicodeTextAttributeUpdater>()
            .With <TableAttributeUpdater>()
            .With <DefaultValueAttributeUpdater>()
            .With <DefaultValueSqlAttributeUpdater>()
            .With <DecimalPlacesColumnInfoUpdateService>()
            .With <DefaultValueColumnInfoUpdateService>()
            .With <UnicodeColumnInfoUpdateService>());
 }
コード例 #13
0
 public static void FixMigrationUp <T>(this MigrationBuilder migrationBuilder, ShamanOptions shamanOptions = null)
     where T : DbContext
 {
     if (migrationBuilder == null)
     {
         throw new ArgumentNullException(nameof(migrationBuilder));
     }
     MigrationFixer.FixMigrationUp <T>(migrationBuilder, shamanOptions);
 }
コード例 #14
0
 public ModelFixer(Type dbContextType, ShamanOptions shamanOptions, ModelInfo modelInfo = null)
 {
     _shamanOptions = shamanOptions ?? ShamanOptions.CreateShamanOptions(dbContextType);
     _info          = modelInfo ?? new ModelInfo(dbContextType, _shamanOptions.Services);
 }