1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| public void CsvLoad(string Path)
{
List<Importcsv> importedList = ReadFile<Importcsv>(Path);
for (int i = 0; i < importedList.Count; i++)
{
if (importedList[i].itemtype != "expansion")
{
BoardGame newBg = new BoardGame(importedList[i].objectname);
newBg.SetMinPlayerFromCsv(importedList[i].minplayers);
newBg.SetMaxPlayerFromCsv(importedList[i].maxplayers);
newBg.SetDurationFromCsv(importedList[i].minplaytime, importedList[i].maxplaytime);
BoardGamesList.Add(newBg);
}
}
for (int i = 0; i < importedList.Count; i++)
{
if (importedList[i].itemtype == "expansion")
{
ShowThirdScreen();
Indications.Text = " Vous allez rentrer une extension dont le titre est : \n " + importedList[i].objectname;
newExpansion();
}
}
}
List<T> ReadFile<T>(string path) where T : class
{
List<T> result = new List<T>();
using (TextReader tr = new StreamReader(path, Encoding.GetEncoding(1252)))
{
var csv = new CsvReader(tr);
try
{
result = csv.GetRecords<T>().ToList();
}
catch (Exception ex)
{
Console.Write("!Attention! il est impératif de nettoyer le fichier csv au préalable en ne gardant que les colonnes \"objectname\", \"minplayers\", \"maxplayers\", \"maxplaytime\",\"minplaytime\" et \"itemtype\"");
Console.WriteLine(ex.ToString());
}
}
return result;
} |
Partager