public static async Task InitializeService(YuGiOhServices service) { await AltConsole.PrintAsync("Service", "Cache", "Initializing card cache..."); List <YuGiOhCard> cards; ConcurrentDictionary <string, EmbedBuilder> embeds; ConcurrentBag <string> cardNames; _service = service; var counter = 0; var DbPath = "Data Source = Databases/YgoSqliteDb/ygo.db"; using (var connection = new SqliteConnection(DbPath)) { await connection.OpenAsync(); await Print("Getting regular monsters..."); var regularMonsters = await connection.QueryAsync <RegularMonster>("select * from Card where level not like '' and pendulumScale like ''"); await Print("Getting xyz monsters..."); var xyzMonsters = await connection.QueryAsync <XyzMonster>("select * from Card where types like '%Xyz%'"); await Print("Getting pendulum monsters..."); var pendulumMonsters = await connection.QueryAsync <PendulumMonster>("select * from Card where types like '%Pendulum%'"); await Print("Getting link monsters..."); var linkMonsters = await connection.QueryAsync <LinkMonster>("select * from Card where types like '%Link%'"); await Print("Getting spell and traps..."); var spellTraps = await connection.QueryAsync <SpellTrapCard>("select * from Card where cardType like '%Spell%' or cardType like '%Trap%'"); connection.Close(); cards = regularMonsters.Concat <YuGiOhCard>(xyzMonsters).Concat(pendulumMonsters).Concat(linkMonsters).Concat(spellTraps).ToList(); } var totalAmount = cards.Count; embeds = new ConcurrentDictionary <string, EmbedBuilder>(); cardNames = new ConcurrentBag <string>(); Parallel.ForEach(cards, POptions, card => { var name = card.Name; var embed = GetEmbed(card); embeds[name.ToLower()] = embed; cardNames.Add(name); AltConsole.InLinePrint("Service", "Cache", $"Progress: {Interlocked.Increment(ref counter)}/{totalAmount}"); }); CardCache = new Dictionary <string, EmbedBuilder>(embeds); CardNames = new HashSet <string>(cardNames); await AltConsole.PrintAsync("Service", "Cache", "Card cache initialized."); }
public ChatService(YuGiOhServices yugiohServiceParams) { _yugiohService = yugiohServiceParams; }