private static DbContextAccessor CreateDbContextAccessor(Type type) { DbContextAccessor accessor = null; if (IsTypeOf(type, "System.Data.Entity.DbContext")) { Type type2 = type.GetInterface("System.Data.Entity.Infrastructure.IObjectContextAdapter", false); if (type2 != null) { PropertyInfo property = type2.GetProperty("ObjectContext", BindingFlags.Public | BindingFlags.Instance); if ((property != null) && (property.GetGetMethod() != null)) { MethodInfo method = type.GetMethod("SaveChanges", BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null); if (method != null) { accessor = new DbContextAccessor(); ParameterExpression expression = Expression.Parameter(typeof(object)); accessor.GetContext = Expression.Lambda <Func <object, ObjectContext> >(Expression.Property(Expression.Convert(expression, type2), property.GetGetMethod()), new ParameterExpression[] { expression }).Compile(); accessor.SaveChanges = Expression.Lambda <Func <object, int> >(Expression.Call(Expression.Convert(expression, type), method), new ParameterExpression[] { expression }).Compile(); } } } } return(accessor); }
public JudgingFinishedHandler( DbContextAccessor db, IContestStore contests, IProblemsetStore probs) { Context = db; Contests = contests; Problems = probs; }
/// <summary> /// 创建审计模型集合。 /// </summary> /// <param name="modelBuilder">给定的 <see cref="ModelBuilder"/>。</param> /// <param name="accessor">给定的 <see cref="DbContextAccessor"/>。</param> /// <returns>返回 <see cref="ModelBuilder"/>。</returns> public static ModelBuilder CreateAuditingModels(this ModelBuilder modelBuilder, DbContextAccessor accessor) { var limitableMaxLength = accessor.DataOptions.Store.LimitableMaxLengthOfProperty; var mapRelationship = accessor.DataOptions.Store.MapRelationship; modelBuilder.Entity <Audit>(b => { b.ToTableWithSharding(accessor.ShardingManager, accessor); b.HasIndex(i => new { i.TableName, i.EntityId }).HasDatabaseName(); b.HasKey(k => k.Id); b.Property(p => p.Id).ValueGeneratedNever() .Sharding <ModShardingStrategy>(accessor.ShardingManager); if (limitableMaxLength > 0) { b.Property(p => p.TableName).HasMaxLength(limitableMaxLength).IsRequired(); b.Property(p => p.EntityId).HasMaxLength(limitableMaxLength).IsRequired(); b.Property(p => p.StateName).HasMaxLength(limitableMaxLength); b.Property(p => p.EntityTypeName).HasMaxLength(limitableMaxLength); } }); modelBuilder.Entity <AuditProperty>(b => { b.ToTableWithSharding(accessor.ShardingManager, accessor); b.HasIndex(i => new { i.AuditId, i.PropertyName }).HasDatabaseName(); b.HasKey(k => k.Id); b.Property(x => x.Id).ValueGeneratedNever() .Sharding <ModShardingStrategy>(accessor.ShardingManager); if (limitableMaxLength > 0) { b.Property(p => p.AuditId).HasMaxLength(limitableMaxLength).IsRequired(); b.Property(p => p.PropertyName).HasMaxLength(limitableMaxLength); b.Property(p => p.PropertyTypeName).HasMaxLength(limitableMaxLength); } // MaxLength b.Property(p => p.OldValue); b.Property(p => p.NewValue); if (mapRelationship) { b.HasOne(f => f.Audit).WithMany(p => p.Properties).HasForeignKey(fk => fk.AuditId); } }); return(modelBuilder); }
public ContestFacade( DbContextAccessor context, IContestStore store1, IProblemsetStore store2, ITeamStore store3, ISubmissionStore store4) { Context = context; Contests = store1; Problemset = store2; Teams = store3; Submissions = store4; }
public static ObjectContext GetObjectContext(object o) { ObjectContext context = o as ObjectContext; if (context == null) { DbContextAccessor dbContextAccessor = GetDbContextAccessor(o.GetType()); if (dbContextAccessor != null) { context = dbContextAccessor.GetContext(o); } } return(context); }
/// <summary> /// Returns the ObjectContext for a particular instance. Either: /// 1. The object is an ObjectContext, or /// 2. The object is a DbContext and the ObjectContext can be retrieved /// </summary> /// <param name="o">The data source instance</param> /// <returns>The ObjectContext instance or null</returns> public static ObjectContext GetObjectContext(object o) { ObjectContext objectContext = o as ObjectContext; if (objectContext == null) { DbContextAccessor accessor = GetDbContextAccessor(o.GetType()); if (accessor != null) { objectContext = accessor.GetContext(o) as ObjectContext; } } return(objectContext); }
/// <summary> /// Returns the ObjectContext and SaveChanges method for a particular instance. Either: /// 1. The object is an ObjectContext, or /// 2. The object is a DbContext and the ObjectContext can be retrieved /// </summary> /// <param name="o">The data source instance</param> /// <param name="objectContext">The ObjectContext instance or null</param> /// <param name="saveChangesMethod">The SaveChanges method or null</param> public static void GetObjectContext(object o, out ObjectContext objectContext, out Func <int> saveChangesMethod) { objectContext = o as ObjectContext; saveChangesMethod = null; if (objectContext == null) { DbContextAccessor accessor = GetDbContextAccessor(o.GetType()); if (accessor != null) { objectContext = accessor.GetContext(o); saveChangesMethod = () => { return(accessor.SaveChanges(o)); }; } } else { saveChangesMethod = objectContext.SaveChanges; } }
/// <summary> /// Creates a DbContextAccessor for a given type if it exists /// </summary> /// <param name="type">The type to create the accessor for</param> /// <returns>A DbContextAccessor, or null if one cannot be created for the Type (i.e. it does not inherit from DbContext)</returns> private static DbContextAccessor CreateDbContextAccessor(Type type) { const BindingFlags DbContextBindingFlags = BindingFlags.Public | BindingFlags.Instance; const string DbContextTypeName = "System.Data.Entity.DbContext"; const string IObjectContextAdapterTypeName = "System.Data.Entity.Infrastructure.IObjectContextAdapter"; DbContextAccessor accessor = null; bool derivesFromDbContext = IsTypeOf(type, DbContextTypeName); if (derivesFromDbContext) { Type contextAdapterInterface = type.GetInterface(IObjectContextAdapterTypeName, false); if (contextAdapterInterface != null) { PropertyInfo contextProperty = contextAdapterInterface.GetProperty("ObjectContext", DbContextBindingFlags); if (contextProperty != null && contextProperty.GetGetMethod() != null) { MethodInfo saveChanges = type.GetMethod("SaveChanges", DbContextBindingFlags, null, Type.EmptyTypes, null); if (saveChanges != null) { accessor = new DbContextAccessor(); // Generate the ObjectContext getter ParameterExpression contextParameter = Expression.Parameter(typeof(object)); accessor.GetContext = Expression.Lambda <Func <object, ObjectContext> >( Expression.Property( Expression.Convert(contextParameter, contextAdapterInterface), contextProperty.GetGetMethod()), contextParameter).Compile(); // Generate the SaveChanges method accessor.SaveChanges = Expression.Lambda <Func <object, int> >( Expression.Call( Expression.Convert(contextParameter, type), saveChanges), contextParameter).Compile(); } } } } return(accessor); }
public static ModelBuilder CreateUserModel(this ModelBuilder modelBuilder, DbContextAccessor accessor) { modelBuilder.Entity <User>(b => { b.ToTableWithSharding(accessor.ShardingManager); b.HasKey(k => k.Id); b.HasIndex(i => i.Name); b.Property(p => p.Id).ValueGeneratedNever(); b.Property(p => p.Name).HasMaxLength(50); b.Property(p => p.Passwd).HasMaxLength(50); b.Property(p => p.CreatedTime).HasMaxLength(50) .Sharding <DateTimeOffsetShardingStrategy>(accessor.ShardingManager); }); return(modelBuilder); }
public static void GetObjectContext(object o, out ObjectContext objectContext, out Func <int> saveChangesMethod) { objectContext = o as ObjectContext; saveChangesMethod = null; if (objectContext == null) { Func <int> func = null; DbContextAccessor accessor = GetDbContextAccessor(o.GetType()); if (accessor != null) { objectContext = accessor.GetContext(o); if (func == null) { func = () => accessor.SaveChanges(o); } saveChangesMethod = func; } } else { saveChangesMethod = new Func <int>(objectContext.SaveChanges); } }
private static DbContextAccessor CreateDbContextAccessor(Type type) { DbContextAccessor accessor = null; if (IsTypeOf(type, "System.Data.Entity.DbContext")) { Type type2 = type.GetInterface("System.Data.Entity.Infrastructure.IObjectContextAdapter", false); if (type2 != null) { PropertyInfo property = type2.GetProperty("ObjectContext", BindingFlags.Public | BindingFlags.Instance); if ((property != null) && (property.GetGetMethod() != null)) { MethodInfo method = type.GetMethod("SaveChanges", BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null); if (method != null) { accessor = new DbContextAccessor(); ParameterExpression expression = Expression.Parameter(typeof(object)); accessor.GetContext = Expression.Lambda<Func<object, ObjectContext>>(Expression.Property(Expression.Convert(expression, type2), property.GetGetMethod()), new ParameterExpression[] { expression }).Compile(); accessor.SaveChanges = Expression.Lambda<Func<object, int>>(Expression.Call(Expression.Convert(expression, type), method), new ParameterExpression[] { expression }).Compile(); } } } } return accessor; }
public TeamStore(DbContextAccessor context) { Context = context; }
public RejudgingStore(DbContextAccessor context) { Context = context; }
public ContestStore(DbContextAccessor context) { Context = context; }
public StudentStore(DbContextAccessor context) => Context = context;
public PrintingStore(DbContextAccessor context) { Context = context; }
public BalloonStore(DbContextAccessor context) { Context = context; }
/// <summary> /// Creates a DbContextAccessor for a given type if it exists /// </summary> /// <param name="type">The type to create the accessor for</param> /// <returns>A DbContextAccessor, or null if one cannot be created for the Type (i.e. it does not inherit from DbContext)</returns> private static DbContextAccessor CreateDbContextAccessor(Type type) { const BindingFlags DbContextBindingFlags = BindingFlags.Public | BindingFlags.Instance; const string DbContextTypeName = "System.Data.Entity.DbContext"; const string IObjectContextAdapterTypeName = "System.Data.Entity.Infrastructure.IObjectContextAdapter"; DbContextAccessor accessor = null; bool derivesFromDbContext = IsTypeOf(type, DbContextTypeName); if (derivesFromDbContext) { Type contextAdapterInterface = type.GetInterface(IObjectContextAdapterTypeName, false); if (contextAdapterInterface != null) { PropertyInfo contextProperty = contextAdapterInterface.GetProperty("ObjectContext", DbContextBindingFlags); if (contextProperty != null && contextProperty.GetGetMethod() != null) { MethodInfo saveChanges = type.GetMethod("SaveChanges", DbContextBindingFlags, null, Type.EmptyTypes, null); if (saveChanges != null) { accessor = new DbContextAccessor(); // Generate the ObjectContext getter ParameterExpression contextParameter = Expression.Parameter(typeof(object)); accessor.GetContext = Expression.Lambda<Func<object, ObjectContext>>( Expression.Property( Expression.Convert(contextParameter, contextAdapterInterface), contextProperty.GetGetMethod()), contextParameter).Compile(); // Generate the SaveChanges method accessor.SaveChanges = Expression.Lambda<Func<object, int>>( Expression.Call( Expression.Convert(contextParameter, type), saveChanges), contextParameter).Compile(); } } } } return accessor; }
public ClarificationStore(DbContextAccessor context) { Context = context; }
public CategoryStore(DbContextAccessor context) { Context = context; }
public TestcaseStore(DbContextAccessor context, IProblemFileRepository fs) { Context = context; Files = fs; }
public RefreshScoreboardCacheHandler(DbContextAccessor db) { Context = db; }
public ContestEventNotifier(DbContextAccessor context) { Context = context; }
public ConfigurationRegistry(DbContextAccessor context) { Context = context; }
public JudgehostStore(DbContextAccessor context) { Context = context; }
public SubmissionStore(DbContextAccessor context) { Context = context; }
public AffiliationStore(DbContextAccessor context) { Context = context; }
public LanguageStore(DbContextAccessor context) { Context = context; }
public TrainingStore(DbContextAccessor context) => Context = context;
public JudgingStore(DbContextAccessor context, Features.Storage.IRunFileRepository runs) { Context = context; Files = runs; }
public ProblemsetStore(DbContextAccessor context, IProblemStore problem) { Context = context; Parent = problem; }
public ArchiveStore(DbContextAccessor context) { Context = context; }