|
|
@@ -11,18 +11,12 @@ public static class DbContextInitializer
|
|
|
public static void Initialize(DeathwatchDbContext context, string filepath = null)
|
|
|
{
|
|
|
context.Database.EnsureCreated();
|
|
|
+ SeedDatabase(context, filepath);
|
|
|
+ }
|
|
|
|
|
|
- // Look for any students.
|
|
|
- if (context.Players.Any()) return; // DB has been seeded
|
|
|
-
|
|
|
- var weapon = new Weapon
|
|
|
- {
|
|
|
- At = "test",
|
|
|
- Range = 30,
|
|
|
- Attribute = "CT",
|
|
|
- Type = "RANGE"
|
|
|
- };
|
|
|
-
|
|
|
+ private static bool SeedPlayers(DeathwatchDbContext context)
|
|
|
+ {
|
|
|
+ if (context.Players.Any()) return true;
|
|
|
var players = new[]
|
|
|
{
|
|
|
new Player
|
|
|
@@ -37,37 +31,28 @@ public static class DbContextInitializer
|
|
|
PER = 43,
|
|
|
FM = 43,
|
|
|
SOC = 40,
|
|
|
- Weapons = new List<Weapon> { weapon }
|
|
|
+ Weapons = new List<Weapon> { new()
|
|
|
+ {
|
|
|
+ At = "test",
|
|
|
+ Range = 30,
|
|
|
+ Attribute = "CT",
|
|
|
+ Type = "RANGE"
|
|
|
+ }}
|
|
|
}
|
|
|
};
|
|
|
foreach (var player in players) context.Players.Add(player);
|
|
|
context.SaveChanges();
|
|
|
-
|
|
|
- SeedDatabase(context, filepath);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
public static void SeedDatabase(DeathwatchDbContext context, string filesPath = null)
|
|
|
{
|
|
|
- // Define the paths to the XML files
|
|
|
-
|
|
|
- //string accessoireFilePath = Path.Combine("XML", "Accessoires.xml");
|
|
|
- //string ameliorationFilePath = Path.Combine("XML", "Ameliorations.xml");
|
|
|
- //string extensionFilePath = Path.Combine("XML", "Extensions.xml");
|
|
|
- if (!string.IsNullOrEmpty(filesPath))
|
|
|
- {
|
|
|
- var roots = new List<Root>();
|
|
|
- try
|
|
|
- {
|
|
|
- // Deserialize the XML files
|
|
|
- GetRootsElements(roots, filesPath);
|
|
|
- ExtractFromRoot(context, roots);
|
|
|
+ if (SeedPlayers(context)) return;
|
|
|
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- throw;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (string.IsNullOrEmpty(filesPath)) return;
|
|
|
+ var roots = new List<Root>();
|
|
|
+ GetRootsElements(roots, filesPath);
|
|
|
+ ExtractFromRoot(context, roots);
|
|
|
}
|
|
|
|
|
|
private static void GetRootsElements(List<Root> roots, string filesPath)
|