2021-03-22 12:09:25 -04:00
|
|
|
|
using System;
|
2020-11-27 22:52:52 -05:00
|
|
|
|
using System.Threading;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Abstractions;
|
|
|
|
|
using Data.Models;
|
|
|
|
|
using Data.Models.Client;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
namespace Data.Context
|
2018-04-08 02:44:42 -04:00
|
|
|
|
{
|
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
|
|
|
|
|
2022-01-28 10:35:01 -05:00
|
|
|
|
context.Clients.Add(new EFClient
|
2018-04-08 02:44:42 -04:00
|
|
|
|
{
|
|
|
|
|
Active = false,
|
|
|
|
|
Connections = 0,
|
|
|
|
|
FirstConnection = DateTime.UtcNow,
|
|
|
|
|
LastConnection = DateTime.UtcNow,
|
2021-03-22 12:09:25 -04:00
|
|
|
|
Level = EFClient.Permission.Console,
|
2018-04-08 02:44:42 -04:00
|
|
|
|
Masked = true,
|
|
|
|
|
NetworkId = 0,
|
2019-04-28 21:54:11 -04:00
|
|
|
|
AliasLink = link,
|
2022-01-28 10:35:01 -05:00
|
|
|
|
CurrentAlias = new EFAlias
|
2019-04-28 21:54:11 -04:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 10:35:01 -05:00
|
|
|
|
}
|