internal string[] GetDeckUrls(string html)
        {
            if (string.IsNullOrWhiteSpace(html))
            {
                return(Array.Empty <string>());
            }

            string          htmltext = WebUtility.HtmlDecode(html);
            MatchCollection matches  = _decksRegex.Matches(htmltext);
            ICollection <IPreconstructedDeck> decks = MagicDatabase.GetAllPreconstructedDecks();

            return(matches.OfType <Match>()
                   .Select(m => BaseUrl + m.Groups["url"].Value)
                   .Where(u => decks.All(d => d.Url != u) && !_excludedRegex.IsMatch(u))
                   .ToArray());
        }
示例#2
0
        private IList <PreconstructedDeckViewModel> LoadReferentialData()
        {
            List <PreconstructedDeckViewModel> ret = new List <PreconstructedDeckViewModel>();
            IDictionary <int, CardViewModel>   allCardsViewModel = _magicDatabase.GetAllInfos().ToDictionary(cai => cai.IdGatherer, cai => new CardViewModel(cai));

            foreach (IPreconstructedDeck preconstructedDeck in _magicDatabase.GetAllPreconstructedDecks())
            {
                ICollection <IPreconstructedDeckCardEdition> deckComposition = _magicDatabase.GetPreconstructedDeckCards(preconstructedDeck);
                IEdition edition = _magicDatabase.GetEditionById(preconstructedDeck.IdEdition);

                ret.Add(new PreconstructedDeckViewModel(preconstructedDeck, edition,
                                                        deckComposition.Select(pdce => new KeyValuePair <CardViewModel, int>(allCardsViewModel[pdce.IdGatherer], pdce.Number))));
            }

            ret.Sort((x, y) =>
            {
                //Most recent set first
                if (!x.EditionDate.HasValue)
                {
                    return(y.EditionDate.HasValue ? 1 : 0);
                }
                if (!y.EditionDate.HasValue)
                {
                    return(-1);
                }
                int comp = y.EditionDate.Value.CompareTo(x.EditionDate.Value);
                if (comp == 0)
                {
                    //Alphabet order
                    comp = x.Name.CompareTo(y.Name);
                }


                return(comp);
            });

            return(ret.AsReadOnly());
        }