/// <summary> /// Generate migrations before running this method, you can use these steps bellow: /// https://github.com/skoruba/IdentityServer4.Admin#ef-core--data-access /// </summary> /// <param name="host"></param> /// <param name="applyDbMigrationWithDataSeedFromProgramArguments"></param> /// <param name="seedConfiguration"></param> /// <param name="databaseMigrationsConfiguration"></param> public static async Task ApplyDbMigrationsWithDataSeedAsync <TIdentityServerDbContext, TIdentityDbContext, TPersistedGrantDbContext, TLogDbContext, TAuditLogDbContext, TDataProtectionDbContext, TUser, TRole>( IHost host, bool applyDbMigrationWithDataSeedFromProgramArguments, SeedConfiguration seedConfiguration, DatabaseMigrationsConfiguration databaseMigrationsConfiguration) where TIdentityServerDbContext : DbContext, IAdminConfigurationDbContext where TIdentityDbContext : DbContext where TPersistedGrantDbContext : DbContext, IAdminPersistedGrantDbContext where TLogDbContext : DbContext, IAdminLogDbContext where TAuditLogDbContext : DbContext, IAuditLoggingDbContext <AuditLog> where TDataProtectionDbContext : DbContext, IDataProtectionKeyContext where TUser : IdentityUser, new() where TRole : IdentityRole, new() { using (var serviceScope = host.Services.CreateScope()) { var services = serviceScope.ServiceProvider; if ((databaseMigrationsConfiguration != null && databaseMigrationsConfiguration.ApplyDatabaseMigrations) || (applyDbMigrationWithDataSeedFromProgramArguments)) { await EnsureDatabasesMigratedAsync <TIdentityDbContext, TIdentityServerDbContext, TPersistedGrantDbContext, TLogDbContext, TAuditLogDbContext, TDataProtectionDbContext>(services); } if ((seedConfiguration != null && seedConfiguration.ApplySeed) || (applyDbMigrationWithDataSeedFromProgramArguments)) { await EnsureSeedDataAsync <TIdentityServerDbContext, TUser, TRole>(services); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SeedConfiguration seed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); seed.Seed(); }
protected override void OnModelCreating(ModelBuilder builder) { builder .ApplyConfiguration(new GameConfiguration()); builder .ApplyConfiguration(new PublisherConfiguration()); builder .ApplyConfiguration(new GameGenreConfiguration()); builder .ApplyConfiguration(new GameGenrePivotConfiguration()); var seeder = new SeedConfiguration(); seeder.Seed(builder); }
public string GetPrefix(PrefabAI ai, bool isOneWay, bool isSymmetric, float width, byte lanes, Randomizer rand, ushort segmentId, ushort seedId) { Highway highway = Highway.ANY; RoadType type = RoadType.NONE; if (ai is RoadBaseAI baseAi) { if (baseAi is DamAI) { type = RoadType.DAM; } else if (baseAi is RoadBridgeAI) { type = RoadType.BRIDGE; } else if (baseAi.IsUnderground()) { type = RoadType.TUNNEL; } else { type = RoadType.GROUND; } highway = baseAi.m_highwayRules ? Highway.TRUE : Highway.FALSE; } if (type == RoadType.NONE) { LogUtils.DoLog($"AI NAO IDENTIFICADA: {ai}"); return(null); } OneWay wayVal = isOneWay ? OneWay.TRUE : OneWay.FALSE; Symmetry symVal = isSymmetric ? Symmetry.TRUE : Symmetry.FALSE; LinkingType linking = LinkingType.NO_LINKING; SeedConfiguration seedConfiguration = (AdrNameSeedDataXml.Instance.NameSeedConfigs.TryGetValue(seedId, out AdrNameSeedConfig seedConf) && !(seedConf.HighwayParent is null) ? SeedConfiguration.HAS_HIGHWAY_TYPE : SeedConfiguration.NO_HIGHWAY_TYPE) | ((seedConf?.ForcedName).IsNullOrWhiteSpace()? SeedConfiguration.NO_FORCED_NAME : SeedConfiguration.HAS_FORCED_NAME); bool hasStart = true; bool hasEnd = true; if (wayVal == OneWay.TRUE && lanes <= 2) { SegmentUtils.GetSegmentRoadEdges(segmentId, true, true, true, out ComparableRoad startRef, out ComparableRoad endRef, out _); LogUtils.DoLog($"OneWay s={startRef}; e= {endRef}"); if (startRef.segmentReference == 0 || endRef.segmentReference == 0) { hasStart = startRef.segmentReference != 0; hasEnd = endRef.segmentReference != 0; } else if ((NetManager.instance.m_segments.m_buffer[startRef.segmentReference].Info.GetAI() is RoadBaseAI baseAiSource && baseAiSource.m_highwayRules) || (NetManager.instance.m_segments.m_buffer[endRef.segmentReference].Info.GetAI() is RoadBaseAI baseAiTarget && baseAiTarget.m_highwayRules)) { switch (startRef.CompareTo(endRef)) { case 1: linking = LinkingType.FROM_BIG; break; case 0: linking = LinkingType.SAME_SIZE; break; case -1: linking = LinkingType.FROM_SMALL; break; } } } List <RoadPrefixFileItem> filterResult = m_prefixes.Where(x => (x.roadType & type) == type && (x.oneWay & wayVal) == wayVal && (x.symmetry & symVal) == symVal && (x.highway & highway) == highway && (wayVal == OneWay.FALSE || ((x.linking & linking) == linking)) && (hasStart || !x.requireSource) && (hasEnd || !x.requireTarget) && x.minWidth <= width + 0.99f && width + 0.99f < x.maxWidth && x.minLanes <= lanes && lanes < x.maxLanes && (x.seedConfig & seedConfiguration) == seedConfiguration ).ToList(); if (filterResult.Count == 0 && linking != LinkingType.NO_LINKING) { filterResult = m_prefixes.Where(x => (x.roadType & type) == type && (x.oneWay & wayVal) == wayVal && (x.symmetry & symVal) == symVal && (x.highway & highway) == highway && (wayVal == OneWay.FALSE || ((x.linking & LinkingType.NO_LINKING) == LinkingType.NO_LINKING)) && (hasStart || !x.requireSource) && (hasEnd || !x.requireTarget) && x.minWidth <= width + 0.99f && width + 0.99f < x.maxWidth && x.minLanes <= lanes && lanes < x.maxLanes && (x.seedConfig & seedConfiguration) == seedConfiguration ).ToList(); } LogUtils.DoLog($"Results for: {type} O:{wayVal} S:{symVal} H:{highway} W:{width} L:{lanes} Lk:{linking} Hs:{hasStart} He:{hasEnd} Sc:{seedConfiguration} = {filterResult?.Count}"); if (filterResult?.Count == 0) { return(null); } return(filterResult[rand.Int32((uint)(filterResult.Count))].name); }