public static ShamanOptions WithLogger(this ShamanOptions options, IShamanLogger logger)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     options.Logger = logger ?? EmptyShamanLogger.Instance;
     return(options);
 }
 /// <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);
 }
 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);
 }
 /// <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);
 }
Exemplo n.º 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);
     });
 }
 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);
 }
Exemplo n.º 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);
        }
        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);
        }
 /// <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>());
 }
Exemplo n.º 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);
        }
        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;
                    }
                }
            }
        }
Exemplo n.º 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>());
 }
Exemplo n.º 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);
 }
Exemplo n.º 14
0
 public ModelFixer(Type dbContextType, ShamanOptions shamanOptions, ModelInfo modelInfo = null)
 {
     _shamanOptions = shamanOptions ?? ShamanOptions.CreateShamanOptions(dbContextType);
     _info          = modelInfo ?? new ModelInfo(dbContextType, _shamanOptions.Services);
 }