public async Task Run(IContainer ioc) { Log.Information("Starting."); var language = InterpretLanguage(Language); IAsyncEnumerable <WeissSchwarzCard> list = null; using (var db = ioc.GetInstance <CardDatabaseContext>()) { await db.Database.MigrateAsync(); if (language == null) { try { var tuple = WeissSchwarzCard.ParseSerial(ReleaseIDorFullSerialID); } catch (Exception) { Log.Error("Serial cannot be parsed properly. Did you mean to cache a release set? If so, please indicate the language (EN/JP) as well."); return; } var query = from card in db.WeissSchwarzCards.AsQueryable() where card.Serial.ToLower() == ReleaseIDorFullSerialID.ToLower() select card; list = query.ToAsyncEnumerable().Take(1); } else { var releaseID = ReleaseIDorFullSerialID.ToLower().Replace("%", ""); var query = from card in db.WeissSchwarzCards.AsQueryable() where EF.Functions.Like(card.Serial.ToLower(), $"%/{releaseID}%") select card; list = query.ToAsyncEnumerable().Where(c => c.Language == language.Value); } await foreach (var card in list) { await AddCachedImageAsync(card); } Log.Information("Done."); Log.Information("PS: Please refrain from executing this command continuously as this may cause your IP address to get tagged as a DDoS bot."); Log.Information(" Only cache the images you may need."); Log.Information(" -ronelm2000"); } }
public async Task Run(IContainer ioc, IProgress <CommandProgressReport> progress, CancellationToken cancellationToken = default) { Log.Information("Starting."); var report = CommandProgressReport.Starting(CommandProgressReportVerbType.Caching); progress.Report(report); var language = InterpretLanguage(Language); IAsyncEnumerable <WeissSchwarzCard> list = null; Func <Flurl.Url, CookieSession> _cookieSession = (url) => ioc.GetInstance <GlobalCookieJar>()[url.Root]; using (var db = ioc.GetInstance <CardDatabaseContext>()) { await db.Database.MigrateAsync(cancellationToken); if (language == null) { try { var tuple = WeissSchwarzCard.ParseSerial(ReleaseIDorFullSerialID); } catch (Exception) { Log.Error("Serial cannot be parsed properly. Did you mean to cache a release set? If so, please indicate the language (EN/JP) as well."); return; } var query = from card in db.WeissSchwarzCards.AsQueryable() where card.Serial.ToLower() == ReleaseIDorFullSerialID.ToLower() select card; list = query.ToAsyncEnumerable().Take(1); } else { var releaseID = ReleaseIDorFullSerialID.ToLower().Replace("%", ""); var query = from card in db.WeissSchwarzCards.AsQueryable() where EF.Functions.Like(card.Serial.ToLower(), $"%/{releaseID}%") select card; list = query.ToAsyncEnumerable().Where(c => c.Language == language.Value); } await foreach (var card in list.WithCancellation(cancellationToken)) { report = report with { MessageType = MessageType.InProgress, ReportMessage = new Card.API.Entities.Impls.MultiLanguageString { EN = $"Caching [${card.Serial}]..." }, Percentage = 50 }; progress.Report(report); await AddCachedImageAsync(card, _cookieSession, cancellationToken); } Log.Information("Done."); Log.Information("PS: Please refrain from executing this command continuously as this may cause your IP address to get tagged as a DDoS bot."); Log.Information(" Only cache the images you may need."); Log.Information(" -ronelm2000"); } report = report.AsDone(); progress.Report(report); }