public void Report(SetParserProgressReport value) { _totalReport = _totalReport with { Percentage = 15 + (int)(value.Percentage * 0.80f), ReportMessage = value.ReportMessage }; _progress.Report(_totalReport); }
public void Report(DatabaseUpdateReport value) { _totalReport = _totalReport with { Percentage = 0 + (int)(value.Percentage * 0.15f), ReportMessage = value.ReportMessage }; _progress.Report(_totalReport); }
public async Task Run(IContainer ioc, IProgress <CommandProgressReport> progress, CancellationToken cancellationToken = default) { if (NoWarning) { NonInteractive = true; } Log.Information("Running..."); var report = CommandProgressReport.Starting(CommandProgressReportVerbType.DatabaseExport); var dbReportTranslator = progress.From().Translate <DatabaseUpdateReport>(TranslateDatabaseUpdate); // TODO: Add a translator for DB Exporter. progress.Report(report); await ioc.UpdateCardDatabase(dbReportTranslator, cancellationToken); using (var database = new CardDatabaseContext(new AppConfig() { DbName = Source })) { var exporter = ioc.GetAllInstances <IDatabaseExporter <CardDatabaseContext, WeissSchwarzCard> >() .Where(exporter => exporter.Alias.Contains(Exporter)) .First(); await exporter.Export(database, this); } report = report.AsDone(); progress.Report(report); /* * * var deck = await parser.Parse(Source); * var inspectionOptions = new InspectionOptions() * { * IsNonInteractive = this.NonInteractive, * NoWarning = this.NoWarning * }; * deck = await ioc.GetAllInstances<IExportedDeckInspector>() * .OrderByDescending(inspector => inspector.Priority) * .ToAsyncEnumerable() * .AggregateAwaitAsync(deck, async (d, inspector) => await inspector.Inspect(d, inspectionOptions)); * * if (deck != WeissSchwarzDeck.Empty) * { * var exporter = ioc.GetAllInstances<IDeckExporter>() * .Where(exporter => exporter.Alias.Contains(Exporter)) * .First(); * * await exporter.Export(deck, this); * } */ }
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); }
private DeckParserProgressReport TranslateProgress(CommandProgressReport arg) => arg.AsRatio <CommandProgressReport, DeckParserProgressReport>(10, 0.20f);
private static void ProgressReporter_ProgressChanged(object sender, CommandProgressReport e) { Console.Write($"{e.ReportMessage.EN} [{e.Percentage}%]\r"); }