protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new[] { new Tenant { Id = Constants.Demo.Tenancies.A.Id, IsDefault = null, Enabled = true , Key = Constants.Demo.Tenancies.A.Key, DisplayName = Constants.Demo.Tenancies.A.Name, HostName = Constants.Demo.Tenancies.A.HostName }, new Tenant { Id = Constants.Demo.Tenancies.B.Id, IsDefault = null, Enabled = true, Key = Constants.Demo.Tenancies.B.Key, DisplayName = Constants.Demo.Tenancies.B.Name, HostName = Constants.Demo.Tenancies.B.HostName }, //new Tenant {Id=3.ToGuid(),IsDefault = null, Enabled=true, Key="OrgC", HostName =".C.",DisplayName="Org C, Inc."}, }; context.Set<Tenant>().AddOrUpdate(p => p.Id, records); }
// This method will be called after migrating to the latest version. public void Initialize(AppCoreDbContext context) { using (ElapsedTime elapsedTime = new ElapsedTime()) { //if (!PowershellServiceLocatorConfig.Activated) //{ // //Actually, Seeding needs to be done in a specific order // //so for now ByHand is preferable // SeedByReflection(context); //} //else //{ // //Reflection does not work under Powershell, so: SeedByHand(context); //} var color = ConfigurationStepStatus.White; if (elapsedTime.Elapsed.TotalMilliseconds >= 5000) { color = ConfigurationStepStatus.Orange; } if (elapsedTime.Elapsed.TotalMilliseconds >= 1000) { color = ConfigurationStepStatus.Red; } this._configurationStepService.Register(ConfigurationStepType.General, color, "Seeding", $"Core seeding completed. Took {elapsedTime.ElapsedText}."); } }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { // var records = new[] //{ // new Session // { // Id = 0.ToGuid(), // Enabled = false, // CreatedOnUtc = DateTime.UtcNow, // PrincipalFK = 0.ToGuid() // }, // new Session // { // Id = 1.ToGuid(), // Enabled = false, // CreatedOnUtc = DateTime.UtcNow.AddDays(-3), // PrincipalFK = 1.ToGuid() // }, // new Session // { // Id = 2.ToGuid(), // Enabled = false, // CreatedOnUtc = DateTime.UtcNow.AddDays(-6), // PrincipalFK = 1.ToGuid() // } //}; //context.Set<Session>().AddOrUpdate(p => p.Id, records); //context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var g = context.Set <TenancySecurityProfileRoleGroup>().Where(x => x.TenantFK == App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id).ToArray(); var r = context.Set <TenancySecurityProfileAccountRole>().Where(x => x.TenantFK == App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id).ToArray(); var records = new TenancySecurityProfile[] { new TenancySecurityProfile { Id = 1.ToGuid(), Key = "*****@*****.**", }, new TenancySecurityProfile { Id = 2.ToGuid(), Key = "*****@*****.**", Roles = new Collection <TenancySecurityProfileAccountRole>() { r.Where(x => x.Id == 3.ToGuid()).SingleOrDefault() } } }; var dbSet = context.Set <TenancySecurityProfile>(); dbSet.AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
/// <summary> /// Seed records that are part of this Module, no matter what (Immutable). /// <para> /// NOT the right place for demo entries, or data that will be updated /// by end users. /// </para> /// </summary> /// <param name="context"></param> protected void SeedImmutableEntries(AppCoreDbContext context) { { var records = new[] { //Policy and Privacy: new DataClassification { Id = NZDataClassification.Unspecified, Title = "Unspecified", DisplayOrderHint = 1 }, new DataClassification { Id = NZDataClassification.Unclassified, Title = "Unclassified", DisplayOrderHint = 2 }, new DataClassification { Id = NZDataClassification.InConfidence, Title = "In Confidence", DisplayOrderHint = 3 }, new DataClassification { Id = NZDataClassification.Sensitive, Title = "Sensitive", DisplayOrderHint = 4 }, //National Security: new DataClassification { Id = NZDataClassification.Restricted, Title = "Restricted", DisplayOrderHint = 5 }, new DataClassification { Id = NZDataClassification.Confidential, Title = "Confidential", DisplayOrderHint = 6 }, new DataClassification { Id = NZDataClassification.Secret, Title = "Secret", DisplayOrderHint = 7 }, new DataClassification { Id = NZDataClassification.TopSecret, Title = "TopSecret", DisplayOrderHint = 8 } }; context.Set <DataClassification>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); } }
// I spend ages on this...but it won't work. // Even though Db Modeling can work via reflection // even when invoked from powershell (add-migration) // This approach will work from code, but not powershell (update-database) // You *have* to define Seed elements by hand. // In one way it's better. There's an order which must be followed // when seeding, that can be done via Attributes ([After/Before]) // but for now this is ok. private void SeedByReflection(AppCoreDbContext context) { AppDependencyLocator.Current.GetAllInstances <IHasAppModuleDbContextSeedInitializer>() .ForEach(x => { if (!(typeof(IHasIgnoreThis).IsAssignableFrom(x.GetType()))) { x.Seed(context); } }); }
private static void SeedPrincipals(AppCoreDbContext dbContext) { AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipalTag>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipalCategory>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipal>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipalLogin>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipalProperty>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederPrincipalClaim>().Seed(dbContext); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new TenancySecurityProfilePermission[] { // for Role 1: new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 1.ToGuid(), Title = "Permission 1" }, new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 2.ToGuid(), Title = "Permission 2" }, // for Role 2: new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 3.ToGuid(), Title = "Permission 3" }, new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 4.ToGuid(), Title = "Permission 4" }, // for Role 3: new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 5.ToGuid(), Title = "Permission 5" }, new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 6.ToGuid(), Title = "Permission 6" }, new TenancySecurityProfilePermission { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 7.ToGuid(), Title = "Permission 7" } }; var dbSet = context.Set <TenancySecurityProfilePermission>(); dbSet.AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
/// <summary> /// Seed records that are part of this Module, no matter what (Immutable). /// <para> /// NOT the right place for demo entries, or data that will be updated /// by end users. /// </para> /// </summary> /// <param name="context"></param> protected void SeedImmutableEntries(AppCoreDbContext context) { //TODO : Select to see if there is one with default first var records = new[] { App.Core.Infrastructure.Constants.Tenancy.Default.DefaultTenant }; context.Set<Tenant>().AddOrUpdate(p => p.Id, records); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var r = context.Set <TenancySecurityProfileAccountRole>().Where(x => x.TenantFK == App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id).ToArray(); var records = new TenancySecurityProfileRoleGroup[] { new TenancySecurityProfileRoleGroup { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 1.ToGuid(), Title = "GroupA", Description = "...." }, new TenancySecurityProfileRoleGroup { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 2.ToGuid(), Title = "GroupB" }, new TenancySecurityProfileRoleGroup { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 3.ToGuid(), ParentFK = 2.ToGuid(), Title = "GroupB.1", Description = "A Group nested under GroupB" }, new TenancySecurityProfileRoleGroup { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 4.ToGuid(), ParentFK = 2.ToGuid(), Title = "GroupB.2", Description = "A Group nested under GroupB" }, new TenancySecurityProfileRoleGroup { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 5.ToGuid(), ParentFK = 4.ToGuid(), Title = "GroupB.2.1", Description = "A Group nested under GroupB.2", } }; var dbSet = context.Set <TenancySecurityProfileRoleGroup>(); dbSet.AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { // var records = new[] //{ // //People: // new Principal {Id = Constants.Demo.Users.U1.Id, Enabled = true, CategoryFK = 1.ToGuid(), DisplayName = Constants.Demo.Users.U1.Name}, // new Principal {Id = Constants.Demo.Users.U2.Id, Enabled = true, CategoryFK = 1.ToGuid(), DisplayName = Constants.Demo.Users.U2.Name} //}; //context.Set<Principal>().AddOrUpdate(p => p.Id, records); //context.SaveChanges(); }
/// <summary> /// Seed records that are part of this Module, no matter what (Immutable). /// <para> /// NOT the right place for demo entries, or data that will be updated /// by end users. /// </para> /// </summary> /// <param name="context"></param> protected void SeedImmutableEntries(AppCoreDbContext context) { var records = new[] { //People: GetDefaultPrincipalCategory(), GetSystemPrincipalCategory(), }; context.Set <PrincipalCategory>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
public void Seed(AppCoreDbContext context) { CodeFirstMigrationConfigurationSettings debuggerConfiguration = this._hostSettingsService.GetObject <CodeFirstMigrationConfigurationSettings>(); SeedImmutableEntries(context); if (debuggerConfiguration.CodeFirstSeedDemoStuff) { SeedDevOnlyEntries(context); } }
/// <summary> /// Seed records that are part of this Module, no matter what (Immutable). /// <para> /// NOT the right place for demo entries, or data that will be updated /// by end users. /// </para> /// </summary> /// <param name="context"></param> protected void SeedImmutableEntries(AppCoreDbContext context) { var records = new[] { new Principal { Id = Constants.Users.Anon.Id, Enabled = true, CategoryFK = 1.ToGuid(), DisplayName = Constants.Users.Anon.Name }, //new Principal {Id = Constants.Users.SysDaemon.Id, Enabled = true, CategoryFK = 2.ToGuid(), DisplayName = Constants.Users.SysDaemon.Name}, }; context.Set <Principal>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var p = context.Set <TenancySecurityProfilePermission>().Where(x => x.TenantFK == App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id).ToArray(); var records = new TenancySecurityProfileAccountRole[] { new TenancySecurityProfileAccountRole { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 1.ToGuid(), Title = "Role 1", Permissions = new Collection <TenancySecurityProfilePermission>() { p.Single(x => x.Id == 1.ToGuid()), p.Single(x => x.Id == 2.ToGuid()) } }, new TenancySecurityProfileAccountRole { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 2.ToGuid(), Title = "Role 2", Permissions = new Collection <TenancySecurityProfilePermission>() { p.Single(x => x.Id == 3.ToGuid()), p.Single(x => x.Id == 4.ToGuid()) } }, new TenancySecurityProfileAccountRole { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, Id = 3.ToGuid(), Title = "Role 3", Permissions = new Collection <TenancySecurityProfilePermission>() { p.Single(x => x.Id == 5.ToGuid()), p.Single(x => x.Id == 6.ToGuid()), p.Single(x => x.Id == 7.ToGuid()) } } }; var dbSet = context.Set <TenancySecurityProfileAccountRole>(); dbSet.AddOrUpdate(x => x.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new [] { new Notification { Id = 1.ToGuid(), TenantFK = 1.ToGuid(), Type = NotificationType.Notification, Level = TraceLevel.Info, From = "System", Class = "xyz", ImageUrl = "...", Text = "Some Message about Foo.", DateTimeCreatedUtc = DateTime.UtcNow }, new Notification { Id = 2.ToGuid(), TenantFK = 1.ToGuid(), Type = NotificationType.Message, Level = TraceLevel.Warn, From = "System", Class = "xyz", ImageUrl = "...", Text = "Another Message for you.", DateTimeCreatedUtc = DateTime.UtcNow }, new Notification { Id = 3.ToGuid(), TenantFK = 1.ToGuid(), Type = NotificationType.Task, Level = TraceLevel.Info, From = "System", Class = "xyz", ImageUrl = "...", Text = "A Message you've read.", DateTimeCreatedUtc = DateTime.UtcNow, DateTimeReadUtc = DateTime.UtcNow } }; context.Set <Notification>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new[] { new TenantClaim { Id = 1.ToGuid(), TenantFK = Constants.Demo.Tenancies.A.Id, Authority = "N/A", AuthoritySignature = "A", Key = "SomePropA", Value = "SomeValueA1" }, new TenantClaim { Id = 2.ToGuid(), TenantFK = Constants.Demo.Tenancies.A.Id, Authority = "N/A", AuthoritySignature = "A", Key = "SomePropB", Value = "SomeValueB1" }, new TenantClaim { Id = 3.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Authority = "N/A", AuthoritySignature = "A", Key = "SomePropA", Value = "SomeValueA1" }, new TenantClaim { Id = 4.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Authority = "N/A", AuthoritySignature = "A", Key = "SomePropB", Value = "SomeValueB1" } }; context.Set <TenantClaim>().AddOrUpdate(p => p.Id, records); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new[] { //People: new SystemRole { Id = 1.ToGuid(), Enabled = false, ModuleKey = Constants.Module.Names.ModuleKey, Key = Constants.Roles.RoleKeys.SystemUser, DataClassificationFK = NZDataClassification.InConfidence, }, new SystemRole { Id = 2.ToGuid(), Enabled = false, ModuleKey = Constants.Module.Names.ModuleKey, Key = Constants.Roles.RoleKeys.SystemAdmin, DataClassificationFK = NZDataClassification.InConfidence, }, //People: new SystemRole { Id = 3.ToGuid(), Enabled = false, ModuleKey = Constants.Module.Names.ModuleKey, Key = Constants.Roles.RoleKeys.TenantMember, DataClassificationFK = NZDataClassification.InConfidence }, new SystemRole { Id = 4.ToGuid(), Enabled = false, ModuleKey = Constants.Module.Names.ModuleKey, Key = Constants.Roles.RoleKeys.TenantAdmin, DataClassificationFK = NZDataClassification.InConfidence, } }; context.Set <SystemRole>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new[] { new TenantProperty { Id = 1.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Key = "SomePropA", Value = "SomeValueA1" }, new TenantProperty { Id = 2.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Key = "SomePropB", Value = "SomeValueB1" }, new TenantProperty { Id = 3.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Key = "SomePropC", Value = "SomeValueC1" }, new TenantProperty { Id = 4.ToGuid(), TenantFK = Constants.Demo.Tenancies.B.Id, Key = "SomePropD", Value = "SomeValueD1" } }; context.Set <TenantProperty>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { // var records = new[] // { // //People: // new SessionOperation // { // Id = 1.ToGuid(), // SessionFK = 1.ToGuid(), // ClientIp = "12.34.56.78", // Url = "https://localhost:123/TenantA/Foo/Bar/12", // ResourceTenantKey="TenantA", // ControllerName = "FooController", // ActionName = "BarAction", // ActionArguments = "12", // Duration = TimeSpan.FromMilliseconds(112), // ResponseCode = "200" //}, // }; // context.Set<SessionOperation>().AddOrUpdate(p => p.Id, records); // context.SaveChanges(); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new [] { new ExceptionRecord() { Id = 1.ToGuid(), Level = TraceLevel.Warn, Title = "Demo Warning", Stack = "blah...." }, new ExceptionRecord() { Id = 2.ToGuid(), Level = TraceLevel.Error, Title = "Demo Error", Stack = "blah again...." }, }; context.Set <ExceptionRecord>().AddOrUpdate(p => p.Id, records); context.SaveChanges(); }
private void SeedByHand(AppCoreDbContext dbContext) { AttachDebuggerWhenRunningUnderPowershell(); // Ensure sequence is DataClassification, Tenant, Principal, Role, Session, then Etc. _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Exception Records. Start..."); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederExceptionRecord>().Seed(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding End. Start..."); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Data Classifications. Start..."); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederDataClassification>().Seed(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Data Classifications. End."); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding System Roles. Start..."); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederSystemRole>().Seed(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding System Roles. End."); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Tenants. Start..."); SeedTenants(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Tenants. End."); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Pricipals. Start..."); SeedPrincipals(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Principals. End."); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Sessions. Start..."); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederSession>().Seed(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Sessions. End."); //After Tenant _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Notifications. Start..."); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederNotification>().Seed(dbContext); _diagnosticsTracingService.Trace(TraceLevel.Verbose, $"Seeding Notifications. End."); }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { }
private static void SeedDevOnlyEntries(AppCoreDbContext context) { }
protected void SeedDevOnlyEntries(AppCoreDbContext context) { var records = new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment[] { // for Role 1: new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 1.ToGuid(), PermissionFK = 1.ToGuid(), AssignmentType = AssignmentType.Add }, new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 1.ToGuid(), PermissionFK = 2.ToGuid(), AssignmentType = AssignmentType.Add }, // for Role 2: new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 2.ToGuid(), PermissionFK = 3.ToGuid(), AssignmentType = AssignmentType.Add }, new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 2.ToGuid(), PermissionFK = 4.ToGuid(), AssignmentType = AssignmentType.Add }, // for Role 3: new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 3.ToGuid(), PermissionFK = 5.ToGuid(), AssignmentType = AssignmentType.Add }, new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 3.ToGuid(), PermissionFK = 6.ToGuid(), AssignmentType = AssignmentType.Add }, new TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment { TenantFK = App.Core.Infrastructure.Constants.Demo.Tenancies.A.Id, RoleFK = 3.ToGuid(), PermissionFK = 7.ToGuid(), AssignmentType = AssignmentType.Add }, }; var dbSet = context.Set <TenancySecurityProfileRoleTenancySecurityProfilePermissionAssignment>(); dbSet.AddOrUpdate(x => new { x.RoleFK, x.PermissionFK }, records); context.SaveChanges(); }
protected void SeedImmutableEntries(AppCoreDbContext context) { }
private static void SeedTenants(AppCoreDbContext dbContext) { AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederTenant>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederTenantProperty>().Seed(dbContext); AppDependencyLocator.Current.GetInstance <AppCoreDbContextSeederTenantClaim>().Seed(dbContext); }
public void Seed(AppCoreDbContext context) { }