2018-04-08 02:44:42 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-11-27 22:52:52 -05:00
|
|
|
|
using System.Threading;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2020-11-27 22:52:52 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using static SharedLibraryCore.Database.Models.EFClient;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
|
|
|
|
namespace SharedLibraryCore.Database
|
|
|
|
|
{
|
2020-11-27 22:52:52 -05:00
|
|
|
|
public static class ContextSeed
|
2018-04-08 02:44:42 -04:00
|
|
|
|
{
|
2020-11-27 22:52:52 -05:00
|
|
|
|
public static async Task Seed(IDatabaseContextFactory contextFactory, CancellationToken token)
|
2018-04-08 02:44:42 -04:00
|
|
|
|
{
|
2020-11-29 17:01:52 -05:00
|
|
|
|
await using var context = contextFactory.CreateContext();
|
2020-11-27 22:52:52 -05:00
|
|
|
|
var strategy = context.Database.CreateExecutionStrategy();
|
|
|
|
|
await strategy.ExecuteAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
await context.Database.MigrateAsync(token);
|
|
|
|
|
});
|
2018-04-09 15:17:10 -04:00
|
|
|
|
|
2020-11-27 22:52:52 -05:00
|
|
|
|
if (!await context.AliasLinks.AnyAsync(token))
|
2018-04-08 02:44:42 -04:00
|
|
|
|
{
|
2019-04-28 21:54:11 -04:00
|
|
|
|
var link = new EFAliasLink();
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
|
|
|
|
context.Clients.Add(new EFClient()
|
|
|
|
|
{
|
|
|
|
|
Active = false,
|
|
|
|
|
Connections = 0,
|
|
|
|
|
FirstConnection = DateTime.UtcNow,
|
|
|
|
|
LastConnection = DateTime.UtcNow,
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Level = Permission.Console,
|
2018-04-08 02:44:42 -04:00
|
|
|
|
Masked = true,
|
|
|
|
|
NetworkId = 0,
|
2019-04-28 21:54:11 -04:00
|
|
|
|
AliasLink = link,
|
|
|
|
|
CurrentAlias = new EFAlias()
|
|
|
|
|
{
|
|
|
|
|
Link = link,
|
|
|
|
|
Active = true,
|
|
|
|
|
DateAdded = DateTime.UtcNow,
|
|
|
|
|
Name = "IW4MAdmin",
|
|
|
|
|
},
|
2018-04-08 02:44:42 -04:00
|
|
|
|
});
|
|
|
|
|
|
2020-11-27 22:52:52 -05:00
|
|
|
|
await context.SaveChangesAsync(token);
|
2018-04-08 02:44:42 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-27 22:52:52 -05:00
|
|
|
|
}
|