|
@@ -8,7 +8,7 @@ namespace DataLayer;
|
|
|
|
|
|
|
|
public static class DbContextInitializer
|
|
public static class DbContextInitializer
|
|
|
{
|
|
{
|
|
|
- public static void Initialize(DeathwatchDbContext context)
|
|
|
|
|
|
|
+ public static void Initialize(DeathwatchDbContext context, string filepath = null)
|
|
|
{
|
|
{
|
|
|
context.Database.EnsureCreated();
|
|
context.Database.EnsureCreated();
|
|
|
|
|
|
|
@@ -43,36 +43,50 @@ public static class DbContextInitializer
|
|
|
foreach (var player in players) context.Players.Add(player);
|
|
foreach (var player in players) context.Players.Add(player);
|
|
|
context.SaveChanges();
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
- SeedDatabase(context);
|
|
|
|
|
|
|
+ SeedDatabase(context, filepath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void SeedDatabase(DeathwatchDbContext context)
|
|
|
|
|
|
|
+ public static void SeedDatabase(DeathwatchDbContext context, string filesPath = null)
|
|
|
{
|
|
{
|
|
|
// Define the paths to the XML files
|
|
// Define the paths to the XML files
|
|
|
- var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
|
|
|
|
|
- var folderPath = Path.Combine($"{parent}", "Dotnet", "DataLayer", "XML");
|
|
|
|
|
- var xmlFiles = Directory.GetFiles(folderPath, "*.xml");
|
|
|
|
|
|
|
|
|
|
//string accessoireFilePath = Path.Combine("XML", "Accessoires.xml");
|
|
//string accessoireFilePath = Path.Combine("XML", "Accessoires.xml");
|
|
|
//string ameliorationFilePath = Path.Combine("XML", "Ameliorations.xml");
|
|
//string ameliorationFilePath = Path.Combine("XML", "Ameliorations.xml");
|
|
|
//string extensionFilePath = Path.Combine("XML", "Extensions.xml");
|
|
//string extensionFilePath = Path.Combine("XML", "Extensions.xml");
|
|
|
- var roots = new List<Root>();
|
|
|
|
|
- try
|
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty(filesPath))
|
|
|
{
|
|
{
|
|
|
|
|
+ var roots = new List<Root>();
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ // Deserialize the XML files
|
|
|
|
|
+ GetRootsElements(roots, filesPath);
|
|
|
|
|
+ ExtractFromRoot(context, roots);
|
|
|
|
|
|
|
|
- foreach (var xmlFile in xmlFiles)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
{
|
|
|
- var root = XmlHelper.DeserializeXmlFile<Root>(xmlFile);
|
|
|
|
|
- roots.Add(root);
|
|
|
|
|
|
|
+ throw;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- catch (Exception e)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void GetRootsElements(List<Root> roots, string filesPath)
|
|
|
|
|
+ {
|
|
|
|
|
+ var fileExist = Directory.Exists(filesPath);
|
|
|
|
|
+ if (fileExist)
|
|
|
{
|
|
{
|
|
|
|
|
+ var xmlFiles = Directory.GetFiles(filesPath, "*.xml");
|
|
|
|
|
|
|
|
- throw;
|
|
|
|
|
|
|
+ foreach (var xmlFile in xmlFiles)
|
|
|
|
|
+ {
|
|
|
|
|
+ var root = XmlHelper.DeserializeXmlFile<Root>(xmlFile);
|
|
|
|
|
+ roots.Add(root);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Deserialize the XML files
|
|
|
|
|
|
|
+ private static void ExtractFromRoot(DeathwatchDbContext context, List<Root> roots)
|
|
|
|
|
+ {
|
|
|
foreach (var root in roots)
|
|
foreach (var root in roots)
|
|
|
{
|
|
{
|
|
|
if (root != null)
|
|
if (root != null)
|
|
@@ -104,144 +118,142 @@ public static class DbContextInitializer
|
|
|
if (root.Armes != null && root.Armes != null && !context.Armes.Any())
|
|
if (root.Armes != null && root.Armes != null && !context.Armes.Any())
|
|
|
{
|
|
{
|
|
|
context.Armes.AddRange(root.Armes);
|
|
context.Armes.AddRange(root.Armes);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Armures != null && root.Armures != null && !context.Armures.Any())
|
|
if (root.Armures != null && root.Armures != null && !context.Armures.Any())
|
|
|
{
|
|
{
|
|
|
context.Armures.AddRange(root.Armures);
|
|
context.Armures.AddRange(root.Armures);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Assermentations != null && root.Assermentations != null && !context.Assermentations.Any())
|
|
if (root.Assermentations != null && root.Assermentations != null && !context.Assermentations.Any())
|
|
|
{
|
|
{
|
|
|
context.Assermentations.AddRange(root.Assermentations);
|
|
context.Assermentations.AddRange(root.Assermentations);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.AttributsArmes != null && root.AttributsArmes != null && !context.Attributs.Any())
|
|
if (root.AttributsArmes != null && root.AttributsArmes != null && !context.Attributs.Any())
|
|
|
{
|
|
{
|
|
|
context.Attributs.AddRange(root.AttributsArmes);
|
|
context.Attributs.AddRange(root.AttributsArmes);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Carrières != null && root.Carrières != null && !context.Carrières.Any())
|
|
if (root.Carrières != null && root.Carrières != null && !context.Carrières.Any())
|
|
|
{
|
|
{
|
|
|
context.Carrières.AddRange(root.Carrières);
|
|
context.Carrières.AddRange(root.Carrières);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Competences != null && root.Competences != null && !context.Competences.Any())
|
|
if (root.Competences != null && root.Competences != null && !context.Competences.Any())
|
|
|
{
|
|
{
|
|
|
context.Competences.AddRange(root.Competences);
|
|
context.Competences.AddRange(root.Competences);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Coordonnées != null && root.Coordonnées != null && !context.Coordonnées.Any())
|
|
if (root.Coordonnées != null && root.Coordonnées != null && !context.Coordonnées.Any())
|
|
|
{
|
|
{
|
|
|
context.Coordonnées.AddRange(root.Coordonnées);
|
|
context.Coordonnées.AddRange(root.Coordonnées);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Cybernétiques != null && root.Cybernétiques != null && !context.Cybernétiques.Any())
|
|
if (root.Cybernétiques != null && root.Cybernétiques != null && !context.Cybernétiques.Any())
|
|
|
{
|
|
{
|
|
|
context.Cybernétiques.AddRange(root.Cybernétiques);
|
|
context.Cybernétiques.AddRange(root.Cybernétiques);
|
|
|
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Disciplines != null && root.Disciplines != null && !context.Disciplines.Any())
|
|
if (root.Disciplines != null && root.Disciplines != null && !context.Disciplines.Any())
|
|
|
{
|
|
{
|
|
|
context.Disciplines.AddRange(root.Disciplines);
|
|
context.Disciplines.AddRange(root.Disciplines);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Divinations != null && root.Divinations != null && !context.Divinations.Any())
|
|
if (root.Divinations != null && root.Divinations != null && !context.Divinations.Any())
|
|
|
{
|
|
{
|
|
|
context.Divinations.AddRange(root.Divinations);
|
|
context.Divinations.AddRange(root.Divinations);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Equipements != null && root.Equipements != null && !context.Equipements.Any())
|
|
if (root.Equipements != null && root.Equipements != null && !context.Equipements.Any())
|
|
|
{
|
|
{
|
|
|
context.Equipements.AddRange(root.Equipements);
|
|
context.Equipements.AddRange(root.Equipements);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Implants != null && root.Implants != null && !context.Implants.Any())
|
|
if (root.Implants != null && root.Implants != null && !context.Implants.Any())
|
|
|
{
|
|
{
|
|
|
context.Implants.AddRange(root.Implants);
|
|
context.Implants.AddRange(root.Implants);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Mondes != null && root.Mondes != null && !context.Mondes.Any())
|
|
if (root.Mondes != null && root.Mondes != null && !context.Mondes.Any())
|
|
|
{
|
|
{
|
|
|
context.Mondes.AddRange(root.Mondes);
|
|
context.Mondes.AddRange(root.Mondes);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Mutations != null && root.Mutations != null && !context.Mutations.Any())
|
|
if (root.Mutations != null && root.Mutations != null && !context.Mutations.Any())
|
|
|
{
|
|
{
|
|
|
context.Mutations.AddRange(root.Mutations);
|
|
context.Mutations.AddRange(root.Mutations);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Pouvoirs != null && root.Pouvoirs != null && !context.Pouvoirs.Any())
|
|
if (root.Pouvoirs != null && root.Pouvoirs != null && !context.Pouvoirs.Any())
|
|
|
{
|
|
{
|
|
|
context.Pouvoirs.AddRange(root.Pouvoirs);
|
|
context.Pouvoirs.AddRange(root.Pouvoirs);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Promotions != null && root.Promotions != null && !context.Promotions.Any())
|
|
if (root.Promotions != null && root.Promotions != null && !context.Promotions.Any())
|
|
|
{
|
|
{
|
|
|
context.Promotions.AddRange(root.Promotions);
|
|
context.Promotions.AddRange(root.Promotions);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.SeuilsXp != null && root.SeuilsXp != null && !context.Seuils.Any())
|
|
if (root.SeuilsXp != null && root.SeuilsXp != null && !context.Seuils.Any())
|
|
|
{
|
|
{
|
|
|
context.Seuils.AddRange(root.SeuilsXp);
|
|
context.Seuils.AddRange(root.SeuilsXp);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Sousmondes != null && root.Sousmondes != null && !context.Sousmondes.Any())
|
|
if (root.Sousmondes != null && root.Sousmondes != null && !context.Sousmondes.Any())
|
|
|
{
|
|
{
|
|
|
context.Sousmondes.AddRange(root.Sousmondes);
|
|
context.Sousmondes.AddRange(root.Sousmondes);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Talents != null && root.Talents != null && !context.Talents.Any())
|
|
if (root.Talents != null && root.Talents != null && !context.Talents.Any())
|
|
|
{
|
|
{
|
|
|
context.Talents.AddRange(root.Talents);
|
|
context.Talents.AddRange(root.Talents);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Traits != null && root.Traits != null && !context.Traits.Any())
|
|
if (root.Traits != null && root.Traits != null && !context.Traits.Any())
|
|
|
{
|
|
{
|
|
|
context.Traits.AddRange(root.Traits);
|
|
context.Traits.AddRange(root.Traits);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.Troubles != null && root.Troubles != null && !context.Troubles.Any())
|
|
if (root.Troubles != null && root.Troubles != null && !context.Troubles.Any())
|
|
|
{
|
|
{
|
|
|
context.Troubles.AddRange(root.Troubles);
|
|
context.Troubles.AddRange(root.Troubles);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.TypeMondes != null && root.TypeMondes != null && !context.TypeMondes.Any())
|
|
if (root.TypeMondes != null && root.TypeMondes != null && !context.TypeMondes.Any())
|
|
|
{
|
|
{
|
|
|
context.TypeMondes.AddRange(root.TypeMondes);
|
|
context.TypeMondes.AddRange(root.TypeMondes);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (root.TypesNom != null && root.TypesNom != null && !context.TypesNom.Any())
|
|
if (root.TypesNom != null && root.TypesNom != null && !context.TypesNom.Any())
|
|
|
{
|
|
{
|
|
|
context.TypesNom.AddRange(root.TypesNom);
|
|
context.TypesNom.AddRange(root.TypesNom);
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ context.SaveChanges();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|