/// <summary> /// Initializes a new instance of the <see cref="GenericRepository{T}"/> class. /// </summary> /// <param name="contextProvider">The repository manager.</param> public GenericRepository(PersistenceContextProvider contextProvider) { this.contextProvider = contextProvider; using (var completeContext = new EntityDataContext()) { this.fullEntityType = completeContext.Model.FindEntityType(typeof(T)); } }
/// <summary> /// Registers the repositories. /// </summary> /// <param name="contextProvider">The context provider which is required in most of the repositories.</param> public void RegisterRepositories(PersistenceContextProvider contextProvider) { this.RegisterRepository(new AccountRepository(contextProvider)); this.RegisterRepository(new LetterBodyRepository(contextProvider)); this.RegisterRepository(new CachedRepository <GameConfiguration>(new GameConfigurationRepository(contextProvider))); this.RegisterRepository(new GenericRepository <GameServerConfiguration>(contextProvider)); this.RegisterRepository(new GenericRepository <GameClientDefinition>(contextProvider)); this.RegisterRepository(new GenericRepository <ConnectServerDefinition>(contextProvider)); this.RegisterRepository(new GenericRepository <ChatServerDefinition>(contextProvider)); this.RegisterRepository(new GenericRepository <ChatServerEndpoint>(contextProvider)); this.RegisterRepository(new GenericRepository <GameServerEndpoint>(contextProvider)); this.RegisterRepository(new GameServerDefinitionRepository(contextProvider)); this.RegisterRepository(new ConfigurationTypeRepository <ItemOptionDefinition>(contextProvider, config => config.RawItemOptions)); this.RegisterRepository(new ConfigurationTypeRepository <IncreasableItemOption>( contextProvider, config => config.RawItemOptions.SelectMany(o => o.RawPossibleOptions).Concat(config.RawItemSetGroups.SelectMany(g => g.RawOptions)).Distinct().ToList())); this.RegisterRepository(new ConfigurationTypeRepository <AttributeDefinition>(contextProvider, config => config.RawAttributes)); this.RegisterRepository(new ConfigurationTypeRepository <DropItemGroup>(contextProvider, config => config.RawBaseDropItemGroups)); this.RegisterRepository(new ConfigurationTypeRepository <CharacterClass>(contextProvider, config => config.RawCharacterClasses)); this.RegisterRepository(new ConfigurationTypeRepository <ItemOptionType>(contextProvider, config => config.RawItemOptionTypes)); this.RegisterRepository(new ConfigurationTypeRepository <ItemSetGroup>(contextProvider, config => config.RawItemSetGroups)); this.RegisterRepository(new ConfigurationTypeRepository <ItemSlotType>(contextProvider, config => config.RawItemSlotTypes)); this.RegisterRepository(new ConfigurationTypeRepository <ItemDefinition>(contextProvider, config => config.RawItems)); this.RegisterRepository(new ConfigurationTypeRepository <JewelMix>(contextProvider, config => config.RawJewelMixes)); this.RegisterRepository(new ConfigurationTypeRepository <MagicEffectDefinition>(contextProvider, config => config.RawMagicEffects)); this.RegisterRepository(new ConfigurationTypeRepository <GameMapDefinition>(contextProvider, config => config.RawMaps)); this.RegisterRepository(new ConfigurationTypeRepository <MasterSkillRoot>(contextProvider, config => config.RawMasterSkillRoots)); this.RegisterRepository(new ConfigurationTypeRepository <MonsterDefinition>(contextProvider, config => config.RawMonsters)); this.RegisterRepository(new ConfigurationTypeRepository <Skill>(contextProvider, config => config.RawSkills)); this.RegisterRepository(new ConfigurationTypeRepository <PlugInConfiguration>(contextProvider, config => config.RawPlugInConfigurations)); var registeredTypes = this.Repositories.Keys.ToList(); using (var entityContext = new EntityDataContext()) { var modelTypes = entityContext.Model.GetEntityTypes().Select(e => e.ClrType); var missingTypes = modelTypes.Where(t => !registeredTypes.Contains(t.BaseType) && !(t.BaseType?.Namespace?.Contains("Configuration") ?? false)).ToList(); foreach (var type in missingTypes) { Log.Debug($"No repository registered for type {type}, creating a generic one."); var repositoryType = typeof(GenericRepository <>).MakeGenericType(type); var repository = Activator.CreateInstance(repositoryType, contextProvider) as IRepository; this.RegisterRepository(type, repository); } } }
/// <summary> /// Initializes a new instance of the <see cref="GuildServerContext"/> class. /// </summary> /// <param name="guildContext">The guild context.</param> /// <param name="persistenceContextProvider">The persistence context provider.</param> public GuildServerContext(GuildContext guildContext, PersistenceContextProvider persistenceContextProvider) : base(guildContext, persistenceContextProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="LetterBodyRepository"/> class. /// </summary> /// <param name="contextProvider">The context provider.</param> public LetterBodyRepository(PersistenceContextProvider contextProvider) : base(contextProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="EntityFrameworkContext" /> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> /// <param name="isOwner">if set to <c>true</c> this instance owns the <paramref name="context" />.</param> public EntityFrameworkContext(DbContext context, PersistenceContextProvider contextProvider, bool isOwner) { this.Context = context; this.contextProvider = contextProvider; this.isOwner = isOwner; }
/// <summary> /// Initializes a new instance of the <see cref="EntityFrameworkContext" /> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> public EntityFrameworkContext(DbContext context, PersistenceContextProvider contextProvider) : this(context, contextProvider, true) { }
/// <summary> /// Initializes a new instance of the <see cref="PlayerContext"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> public PlayerContext(DbContext context, PersistenceContextProvider contextProvider) : base(context, contextProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="PlayerContext"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> /// <param name="isOwner">if set to <c>true</c> this instance owns the <paramref name="context" />.</param> public PlayerContext(DbContext context, PersistenceContextProvider contextProvider, bool isOwner = true) : base(context, contextProvider, isOwner) { }
/// <summary> /// Initializes a new instance of the <see cref="GameServerDefinitionRepository"/> class. /// </summary> /// <param name="contextProvider">The repository manager.</param> public GameServerDefinitionRepository(PersistenceContextProvider contextProvider) : base(contextProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationTypeRepository{T}"/> class. /// </summary> /// <param name="persistenceContextProvider">The persistence context provider.</param> /// <param name="collectionSelector">The collection selector which returns the collection of <typeparamref name="T"/> of a <see cref="GameConfiguration"/>.</param> public ConfigurationTypeRepository(PersistenceContextProvider persistenceContextProvider, Func <GameConfiguration, ICollection <T> > collectionSelector) { this.persistenceContextProvider = persistenceContextProvider; this.collectionSelector = collectionSelector; }
/// <summary> /// Initializes a new instance of the <see cref="GameConfigurationRepository"/> class. /// </summary> /// <param name="contextProvider">The context provider.</param> public GameConfigurationRepository(PersistenceContextProvider contextProvider) : base(contextProvider) { this.objectLoader = new GameConfigurationJsonObjectLoader(); }
/// <summary> /// Initializes a new instance of the <see cref="AccountRepository"/> class. /// </summary> /// <param name="contextProvider">The context provider.</param> public AccountRepository(PersistenceContextProvider contextProvider) : base(contextProvider) { }
/// <summary> /// Initializes a new instance of the <see cref="FriendServerContext"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> /// <param name="isOwner">if set to <c>true</c> this instance owns the <paramref name="context" />.</param> public FriendServerContext(FriendContext context, PersistenceContextProvider contextProvider, bool isOwner = true) : base(context, contextProvider, isOwner) { }
/// <summary> /// Initializes a new instance of the <see cref="FriendServerContext"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="contextProvider">The contextProvider.</param> public FriendServerContext(FriendContext context, PersistenceContextProvider contextProvider) : base(context, contextProvider) { }