コード例 #1
0
        public async Task <R4UDeck> Inspect(R4UDeck deck, InspectionOptions options)
        {
            Log.Debug("Starting...");
            var keyCards      = deck.Ratios.Keys.Where(c => ((!c.Images?.Any()) ?? false) && String.IsNullOrWhiteSpace(c.CachedImagePath));
            var inspectedDeck = deck.Clone();

            foreach (var card in keyCards)
            {
                Log.Information("{serial} has no image URL nor a cached image. This deck cannot be exported without an image. Do you want to supply an image instead? [Y/N] (Default is N)", card.Serial);
                if (ConsoleUtils.Prompted(options.IsNonInteractive, false))
                {
                    if (inspectedDeck.ReplaceCard(card, await AddImageFromConsole(card, options)))
                    {
                        Log.Information("Checking for other missing images (if any)...");
                    }
                    else
                    {
                        return(R4UDeck.Empty);
                    }
                }
                else
                {
                    Log.Information("Selected No; inspection failed.");
                    return(R4UDeck.Empty);
                }
            }
            Log.Debug("Finished inspection.");
            return(inspectedDeck);
        }
コード例 #2
0
        public async Task <R4UDeck> Inspect(R4UDeck deck, InspectionOptions options)
        {
            var allEmptyTranslations = deck.Ratios.Keys.Where(card => String.IsNullOrWhiteSpace(card.Name.EN))
                                       .Select(card => card.ReleaseID)
                                       .Distinct();

            if (allEmptyTranslations.Any())
            {
                Log.Warning("The following sets (based on Release ID) do not have proper English translations: {allEmptyTranslations}", allEmptyTranslations.ToList());
                Log.Warning("This may result in a deck generator with only Japanese text.");
                Log.Warning("Do you wish to continue? [Y/N] (Default is N)");
                if (ConsoleUtils.Prompted(options.IsNonInteractive, options.NoWarning))
                {
                    return(deck);
                }
                else
                {
                    Log.Information("Operation cancelled.");
                    Log.Information("If you need to add card data from other sources, use this command: {command}", "wstools parse link_url");
                    Log.Information("For more information, please see: {url}", new Uri("https://github.com/ronelm2000/wsmtools"));
                    return(R4UDeck.Empty);
                }
            }
            else
            {
                await Task.CompletedTask; //placebo way to stop warning about async/await
                return(deck);
            }
        }
コード例 #3
0
        public async Task <R4UDeck> Inspect(R4UDeck deck, InspectionOptions options)
        {
            Log.Information("Starting...");
            var imageFolder = Path.Get(_imageCachePath);

            try
            {
                foreach (var card in deck.Ratios.Keys)
                {
                    try
                    {
                        var serialImage = imageFolder
                                          .Files($"{card.Serial.Replace('-', '_').AsFileNameFriendly()}.*", true)
                                          .WhereExtensionIs(".png", ".jpeg", ".jpg", "jfif")
                                          .First();
                        var relativeFileName = _imageCachePath + serialImage.FileName;
                        serialImage = await InspectImage(serialImage, relativeFileName);

                        if (serialImage != null)
                        {
                            Log.Information($"Using cached image: {serialImage}");
//                            card.CachedImagePath = serialImage.FullPath;
                        }
                    } catch (InvalidOperationException)
                    {
                        // Do nothing.
                    }
                }
            } catch (System.IO.DirectoryNotFoundException)
            {
                // Do nothing.
            }
            return(deck);
        }
コード例 #4
0
        public async Task Export(R4UDeck deck, IExportInfo info)
        {
            Log.Information("Serializing: {name}", deck.Name);

            /*
             * using (var db = _database())
             * {
             *  Log.Information("Replacing all foils with non-foils...");
             *  foreach (var card in deck.Ratios.Keys)
             *      if (card.IsFoil) deck.ReplaceCard(card, await db.FindNonFoil(card));
             * }
             */

            Log.Information("Creating deck.cod...");
            var cckDeck = new CockatriceDeck();

            cckDeck.DeckName      = deck.Name;
            cckDeck.Comments      = deck.Remarks;
            cckDeck.Ratios        = new CockatriceDeckRatio();
            cckDeck.Ratios.Ratios = deck.Ratios.Select(Translate).ToList();

            var resultDeck = Path.CreateDirectory(info.Destination).Combine($"{deck.Name?.AsFileNameFriendly() ?? "deck"}.cod");

            resultDeck.Open(s => _serializer.Serialize(s, cckDeck),
                            System.IO.FileMode.Create,
                            System.IO.FileAccess.Write,
                            System.IO.FileShare.ReadWrite
                            );
            Log.Information($"Saved: {resultDeck.FullPath}");
            await Task.CompletedTask;
        }
コード例 #5
0
        public async Task Export(R4UDeck deck, IExportInfo info)
        {
            Log.Information("Exporting as Deck JSON.");
            var jsonFilename = Path.CreateDirectory(info.Destination).Combine($"deck_{deck.Name.AsFileNameFriendly()}.json");

            await Export(deck, info, jsonFilename);
        }
コード例 #6
0
        public async Task <R4UDeck> Parse(string sourceUrlOrFile)
        {
            var        filePath = Path.Get(sourceUrlOrFile);
            SimpleDeck deckJSON = null;

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

            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.R4UCards.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");
                        throw new DeckParsingException($"This card is missing in your local card db: {serial}");
                    }
                    else
                    {
                        deck.Ratios[card] = deckJSON.Ratios[serial];
                    }
                }
            }
            return(deck);
        }
コード例 #7
0
        public async Task Export(R4UDeck deck, IExportInfo info, Path jsonFilename)
        {
            var simplifiedDeck = new
            {
                Name    = deck.Name,
                Remarks = deck.Remarks,
                Ratios  = deck.AsSimpleDictionary()
            };

            jsonFilename.Open(
                async s => await JsonSerializer.SerializeAsync(s, simplifiedDeck, options: _defaultOptions),
                System.IO.FileMode.Create,
                System.IO.FileAccess.Write,
                System.IO.FileShare.ReadWrite
                );
            Log.Information($"Done: {jsonFilename.FullPath}");

            if (!String.IsNullOrWhiteSpace(info?.OutCommand))
            {
                await ExecuteCommandAsync(info.OutCommand, jsonFilename);
            }
        }
コード例 #8
0
ファイル: DeckLogParser.cs プロジェクト: unsiga25/r4utools
        public async Task <R4UDeck> Parse(string sourceUrlOrFile)
        {
            var document = await sourceUrlOrFile.WithHTMLHeaders().GetHTMLAsync();

            //var deckView = document.QuerySelector(".deckview");
            //var cardControllers = deckView.QuerySelectorAll(".card-controller-inner");
            var deckID = urlMatcher.Match(sourceUrlOrFile).Groups[2];

            Log.Information("Parsing ID: {deckID}", deckID);
            var response = await $"{deckLogApiUrlPrefix}{deckID}" //
                           .WithReferrer(sourceUrlOrFile)         //
                           .PostJsonAsync(null);
            var json = JsonConvert.DeserializeObject <dynamic>(await response.Content.ReadAsStringAsync());
            //var json = JsonConverter.CreateDefault().Deserialize<dynamic>(new JsonReader(await response.Content.ReadAsStreamAsync()));
            var newDeck        = new R4UDeck();
            var missingSerials = new List <string>();

            newDeck.Name    = json.title.ToString();
            newDeck.Remarks = json.memo.ToString();
            using (var db = _database())
            {
                List <dynamic> items = new List <dynamic>();
                items.AddRange(json.list);
                items.AddRange(json.sub_list);
                foreach (var cardJSON in items)
                {
                    string serial = cardJSON.card_number.ToString();
                    serial = serial.Replace('+', '+');
                    if (serial == null)
                    {
                        Log.Warning("serial is null for some reason!");
                    }
                    var card = await db.R4UCards.FindAsync(serial);

                    int quantity = cardJSON.num;
                    if (card != null)
                    {
                        Log.Debug("Adding: {card} [{quantity}]", card?.Serial, quantity);
                        if (newDeck.Ratios.TryGetValue(card, out int oldVal))
                        {
                            newDeck.Ratios[card] = oldVal + quantity;
                        }
                        else
                        {
                            newDeck.Ratios.Add(card, quantity);
                        }
                    }
                    else
                    {
                        missingSerials.Add(serial);
                        //throw new DeckParsingException($"MISSING_SERIAL_{serial}");
                        Log.Warning("Serial has been effectively skipped because it's not found on the local db: [{serial}]", serial);
                    }
                }
            }
            if (missingSerials.Count > 0)
            {
                throw new DeckParsingException($"The following serials are missing from the DB:\n{missingSerials.ConcatAsString("\n")}");
            }
            else
            {
                Log.Debug($"Result Deck: {JsonConvert.SerializeObject(newDeck.AsSimpleDictionary())}");
                return(newDeck);
            }
        }
コード例 #9
0
 public Task Export(R4UDeck deck, IExportInfo info)
 {
     return(Task.CompletedTask);
 }