public async Task <WeissSchwarzDeck> Parse(string sourceUrlOrFile)
        {
            var        filePath = Path.Get(sourceUrlOrFile);
            SimpleDeck deckJSON = null;

            deckJSON = JsonSerializer.Deserialize <SimpleDeck>(filePath.ReadBytes());
            WeissSchwarzDeck deck = new WeissSchwarzDeck();

            deck.Name    = deckJSON.Name;
            deck.Remarks = deckJSON.Remarks;
            using (var db = _database())
            {
                await db.Database.MigrateAsync();

                foreach (var serial in deckJSON.Ratios.Keys)
                {
                    var card = await db.WeissSchwarzCards.FindAsync(serial);

                    if (card == null)
                    {
                        Log.Error("This card is missing in your local card db: {serial}", serial);
                        Log.Error("You must obtain information about this card first using the command {cmd}", "./wstools parse");
                        return(WeissSchwarzDeck.Empty);
                    }
                    else
                    {
                        deck.Ratios[card] = deckJSON.Ratios[serial];
                    }
                }
            }
            return(deck);
        }
Esempio n. 2
0
    public async Task <WeissSchwarzDeck> Parse(string sourceUrlOrFile, IProgress <DeckParserProgressReport> progress, CancellationToken cancellationToken = default)
    {
        // TODO: Add DeckLog code here for getting missing sets.
        DeckParserProgressReport report = DeckParserProgressReport.AsStarting("Local Deck File");

        progress.Report(report);

        var        filePath = Path.Get(sourceUrlOrFile);
        SimpleDeck deckJSON = null;

        deckJSON = JsonSerializer.Deserialize <SimpleDeck>(await filePath.ReadBytesAsync(cancellationToken));
        WeissSchwarzDeck deck = new WeissSchwarzDeck();

        deck.Name    = deckJSON.Name;
        deck.Remarks = deckJSON.Remarks;
        using (var db = _database())
        {
            await db.Database.MigrateAsync(cancellationToken);

            foreach (var serial in deckJSON.Ratios.Keys)
            {
                var card = await db.WeissSchwarzCards.FindAsync(new[] { serial }, cancellationToken);

                if (card == null)
                {
                    Log.Error("This card is missing in your local card db: {serial}", serial);
                    Log.Error("You must obtain information about this card first using the command {cmd}", "./wstools parse");
                    return(WeissSchwarzDeck.Empty);
                }
                else
                {
                    deck.Ratios[card] = deckJSON.Ratios[serial];
                }
            }
        }

        report = report.SuccessfullyParsedDeck(deck);
        progress.Report(report);

        return(deck);
    }