public StartUp(DbContextOptions <MMdb> mmdb) { _mmdb = mmdb; _db = new MMdb(_mmdb); foreach (string cmdr in DSdata.s_races) { MMraces.TryAdd(cmdr, new MMplayerNG(cmdr)); } /** * using (var db = new MMdb(_mmdb)) * { * foreach (var ent in db.MMdbPlayers) * db.MMdbPlayers.Remove(ent); * foreach (var ent in db.MMdbRatings) * db.MMdbRatings.Remove(ent); * foreach (var ent in db.MMdbRaceRatings) * db.MMdbRaceRatings.Remove(ent); * * db.SaveChanges(); * } **/ // /** using (var db = new MMdb(_mmdb)) { foreach (var ent in db.MMdbPlayers) { MMplayers[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRaces) { MMraces[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRatings.OrderBy(o => o.Games)) { if (MMplayers.ContainsKey(ent.MMdbPlayer.Name)) { if (MMplayers[ent.MMdbPlayer.Name].AuthName == ent.MMdbPlayer.AuthName) { MMplayers[ent.MMdbPlayer.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } foreach (var ent in db.MMdbRaceRatings.OrderBy(o => o.Games)) { if (MMraces.ContainsKey(ent.MMdbRace.Name)) { MMraces[ent.MMdbRace.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } // **/ foreach (string name in MMplayers.Keys) { if (MMplayers[name].AuthName != null && MMplayers[name].AuthName != "") { Players.Add(MMplayers[name].Name); Auth.Add(MMplayers[name].AuthName, MMplayers[name].Name); } } if (!File.Exists(Program.myJson_file)) { File.Create(Program.myJson_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myJson_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { //rep.Init(); repHash.Add(rep.HASH); if (!replays.ContainsKey(rep.ID)) { replays[rep.ID] = new List <dsreplay>(); } replays[rep.ID].Add(rep); } } if (!File.Exists(Program.myReplays_file)) { File.Create(Program.myReplays_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myReplays_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { MyReplays.Add(rep); } } string exedir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Exedir = exedir; foreach (var file in Directory.EnumerateFiles(Program.replaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var file in Directory.EnumerateFiles(Program.myreplaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var dir in Directory.EnumerateDirectories(Program.workdir + "/tournaments")) { string tourny = Path.GetFileName(dir); if (File.Exists(dir + "/treplays.json")) { TournamentReplays.Add(tourny, new List <dsreplay>()); foreach (var line in File.ReadAllLines(dir + "/treplays.json")) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { TournamentReplays[tourny].Add(rep); } } if (!Directory.Exists(Exedir + "/treplays/" + tourny)) { Directory.CreateDirectory(Exedir + "/treplays/" + tourny); } foreach (var file in Directory.EnumerateFiles(dir + "/replays")) { string dest = Exedir + "/treplays/" + tourny + "/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } } if (File.Exists(dir + "/info.json")) { TournamentInfo t = JsonSerializer.Deserialize <TournamentInfo>(File.ReadAllText(dir + "/info.json")); TournamentInfo[tourny] = t; } } foreach (var file in Directory.EnumerateFiles(Program.commentdir)) { GameComment com = JsonSerializer.Deserialize <GameComment>(File.ReadAllText(file)); if (com != null) { GameComments[com.RepId] = com; } } // ladder init //LadderInit(); }
public async Task Reload() { replays.Clear(); await Task.Run(() => { foreach (var line in File.ReadAllLines(Program.myJson_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { //rep.Init(); repHash.Add(rep.HASH); if (!replays.ContainsKey(rep.ID)) { replays[rep.ID] = new List <dsreplay>(); } replays[rep.ID].Add(rep); } } }); MyReplays.Clear(); await Task.Run(() => { foreach (var line in File.ReadAllLines(Program.myReplays_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { MyReplays.Add(rep); } } }); TournamentReplays.Clear(); await Task.Run(() => { foreach (var dir in Directory.EnumerateDirectories(Program.workdir + "/tournaments")) { if (File.Exists(dir + "/treplays.json")) { string tourny = Path.GetFileName(dir); TournamentReplays.Add(tourny, new List <dsreplay>()); foreach (var line in File.ReadAllLines(dir + "/treplays.json")) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { TournamentReplays[tourny].Add(rep); } } if (!Directory.Exists(Exedir + "/treplays/" + tourny)) { Directory.CreateDirectory(Exedir + "/treplays/" + tourny); } foreach (var file in Directory.EnumerateFiles(dir + "/replays")) { string dest = Exedir + "/treplays/" + tourny + "/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } } } }); }