Exemple #1
0
        private static async Task <string> ImportFromMtgGoldfish(string url, IReporter reporter)
        {
            var web = new HtmlWeb();

            reporter.Report("Unraveling skeins...");
            HtmlDocument doc = await web.LoadFromWebAsync(url);

            var decklistBuilder = new StringBuilder();

            HtmlNodeCollection nodes     = doc.DocumentNode.SelectNodes("//table[@class='deck-view-deck-table']/tr");
            List <HtmlNode>    deckNodes = nodes.TakeWhile(node => !node.OuterHtml.Contains("Cards Total")).ToList();

            if (nodes == null || !nodes.Any())
            {
                throw new InvalidOperationException("Could not find a valid deck at the URL. Make sure the link provided is pointing to the root of the deck.");
            }

            reporter.StartProgress();

            for (var i = 0; i < deckNodes.Count; i++)
            {
                await Task.Delay(1);

                reporter.Progress(i, 0, deckNodes.Count);
                reporter.Report($"Bifurcating the furcate {i}/{deckNodes.Count}");

                HtmlNode node = deckNodes[i];
                try
                {
                    HtmlNodeCollection qtyNodes  = node.SelectNodes(".//td[@class='deck-col-qty']");
                    HtmlNodeCollection nameNodes = node.SelectNodes(".//td[@class='deck-col-card']");

                    if (qtyNodes?.Count != 1 || nameNodes?.Count != 1)
                    {
                        continue;
                    }

                    int    qty  = int.Parse(qtyNodes[0].InnerText.Trim());
                    string name = HttpUtility.HtmlDecode(nameNodes[0].InnerText.Trim());
                    var    line = new SearchLine(name, qty);
                    decklistBuilder.AppendLine(line.ToString());
                }
                catch (Exception)
                {
                    reporter.Report($"Failed to import node #{i} from {url}", true);
                }
            }

            reporter.StopProgress();
            return(decklistBuilder.ToString());
        }
Exemple #2
0
        private static async Task <string> ImportFromStreamdecker(string url, IReporter reporter)
        {
            var web = new HtmlWeb();

            reporter.Report("Unraveling skeins...");
            HtmlDocument doc = await web.LoadFromWebAsync(url);

            var decklistBuilder = new StringBuilder();

            HtmlNodeCollection activeTabNodes = doc.DocumentNode.SelectNodes("//div[@class='display-card-list']");

            if (activeTabNodes == null || activeTabNodes.Count != 1)
            {
                throw new InvalidOperationException("Could not find a valid deck at the URL. Make sure the link provided is pointing to the root of the deck.");
            }

            HtmlNodeCollection cardNodes = activeTabNodes.Single().SelectNodes(".//div[@class='card-container']/div[@class='column-wrapper']/div/a[@class='cardLink']");

            reporter.StartProgress();
            var cardIndex = 0;
            var qty       = 1;

            while (cardIndex < cardNodes.Count)
            {
                try
                {
                    string name = cardNodes[cardIndex].Attributes.Single(a => a.Name == "data-card-name").Value;
                    qty = 1;

                    while (cardIndex + qty < cardNodes.Count && cardNodes[cardIndex + qty].Attributes.Single(a => a.Name == "data-card-name").Value == name)
                    {
                        qty++;
                    }

                    cardIndex += qty;
                    name       = HttpUtility.HtmlDecode(name.Trim());
                    var line = new SearchLine(name, qty);
                    decklistBuilder.AppendLine(line.ToString());
                }
                catch (Exception)
                {
                    reporter.Report($"Failed to import all or part of node #{cardIndex} from {url}", true);
                    cardIndex += qty;
                }
            }

            reporter.StopProgress();
            return(decklistBuilder.ToString());
        }
Exemple #3
0
        private static async Task <string> ImportFromTappedOut(string url, IReporter reporter)
        {
            var web = new HtmlWeb();

            reporter.Report("Unraveling skeins...");
            HtmlDocument doc = await web.LoadFromWebAsync(url);

            var decklistBuilder = new StringBuilder();

            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//ul[@class='boardlist']/li/a"); // Looking for data-name in span from these nodes

            if (nodes == null || !nodes.Any())
            {
                throw new InvalidOperationException("Could not find a valid deck at the URL. Make sure the link provided is pointing to the root of the deck.");
            }

            for (var i = 0; i < nodes.Count; i++)
            {
                await Task.Delay(1);

                reporter.Progress(i, 0, nodes.Count);
                reporter.Report($"Bifurcating the furcate {i}/{nodes.Count}");

                try
                {
                    HtmlNode node = nodes[i];
                    string   name = HttpUtility.HtmlDecode(node.Attributes.Single(a => a.Name == "data-name").Value.Trim());
                    int      qty  = int.Parse(node.Attributes.Single(a => a.Name == "data-qty").Value);
                    var      line = new SearchLine(name, qty);
                    decklistBuilder.AppendLine(line.ToString());
                }
                catch (Exception)
                {
                    reporter.Report($"Failed to import node #{i} from {url}", true);
                }
            }

            return(decklistBuilder.ToString());
        }