/// <summary> /// Initializes the <see cref="Alliances"/> class. /// </summary> internal static void Init() { if (Alliances.Initialized) { return; } Alliances.Pool = new ConcurrentDictionary <long, Alliance>(); switch (Settings.Database) { case DBMS.Mongo: { foreach (AllianceDb dbEntry in Mongo.Alliances.Find(db => true).ToList()) { if (dbEntry != null) { Alliance alliance = new Alliance(dbEntry.HighID, dbEntry.LowID); JsonConvert.PopulateObject(dbEntry.Profile.ToJson(), alliance, AllianceDb.JsonSettings); Alliances.Add(alliance); } } Alliances.Seed = Mongo.AllianceSeed; break; } case DBMS.File: { DirectoryInfo directory = new DirectoryInfo($"{System.IO.Directory.GetCurrentDirectory()}/Saves/Alliances/"); directory.CreateIfNotExists(); directory.DeleteIfExists(".json"); Parallel.ForEach(directory.GetFiles("*.json"), file => { string[] id = Path.GetFileNameWithoutExtension(file.Name).Split('-'); Alliances.Add(Alliances.Get(LogicStringUtil.ConvertToInt(id[0]), LogicStringUtil.ConvertToInt(id[1]))); }); Alliances.Seed = directory.GetFiles("*.json").Length; break; } } Console.WriteLine($"Loaded {Avatars.Count} {((Avatars.Count != 1) ? "avatars" : "avatar")} and {Alliances.Count} {((Alliances.Count != 1) ? "alliances" : "alliance")} into memory." + Environment.NewLine); Alliances.Initialized = true; }
/// <summary> /// Gets the alliance using the specified identifier in the specified database. /// </summary> internal static Alliance Get(LogicLong identifier, DBMS database = Settings.Database, bool store = true) { return(Alliances.Get(identifier.High, identifier.Low, database)); }