private void DownloadCards_Click(object sender, RoutedEventArgs e)
 {
     DownloadCards inputWindow = new DownloadCards(this);
     inputWindow.Show();
     //SolforgeDatabaseDownloader downloader = new SolforgeDatabaseDownloader();
     //List<CardDefinition> cardList;
     //cardList = downloader.getCardFromWebSite();
     //SolforgeDatabase.SaveDefinitionFromList(cardList);
 }
        public List<CardDefinition> getCardFromWebSite(bool DoDownloadImage, DownloadCards statusDisplay)
        {
            m_DoDownloadImage = DoDownloadImage;
            List<CardDefinition> cardList;
            cardList = new List<CardDefinition>();
            List<String> cardNameList;
            cardNameList = new List<String>();
            HtmlDocument document = new HtmlDocument();
            HtmlDocument cardDetailHtml = new HtmlDocument();
            HtmlDocument cardImageHtml = new HtmlDocument();
            HtmlNodeCollection collection;
            bool cardFound;
            int CardCounter = 0;
            int currPage = 1;
            String alternate, sourcePage, cardName;
            cardName = "";
            do
            {
                sourcePage = GetSourcePage(m_URLAddress + "&page=" + currPage.ToString());
                cardFound = false;
                document.LoadHtml(sourcePage);
                collection = document.DocumentNode.SelectNodes("//div[@class='card_meta mobile']");
                foreach(HtmlNode cardNode in collection)
                {
                    HtmlDocument cardHtml = new HtmlDocument();
                    cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", "")));
                    cardDetailHtml.LoadHtml(cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']")[0].InnerHtml);
                    alternate = "";
                    if (cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']") != null)
                    {
                        alternate = cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']")[0].InnerText;
                    }

                    cardName = cardHtml.DocumentNode.SelectNodes("//h6")[0].InnerText;
                    if (cardNameList.Contains(cardName) || alternate == "(Alternate Art)")
                    {
                        CardCounter = CardCounter + 1;
                        cardFound = true;
                        continue;
                    }
                    cardNameList.Add(cardName);
                    cardList.Add(ExtractCardFromHtml(cardNode));
                    if (m_DoDownloadImage == true)
                    {
                        cardImageHtml.LoadHtml(cardHtml.DocumentNode.SelectNodes("//div[@class='cardart owl-carousel']")[0].InnerHtml);
                        DownloadImage(cardImageHtml);
                    }
                    cardFound = true;
                    CardCounter = CardCounter + 1;
                }
                currPage = currPage + 1;
                statusDisplay.labelStstusUpdate("Downloading Level 1 ", cardName);
            }
            while ((CardCounter % 12) == 0 && cardFound == true);

            CardCounter = 0;
            currPage = 1;
            do
            {
                sourcePage = GetSourcePage(m_URLAddressDetail + "2" + "&page=" + currPage.ToString());
                cardFound = false;
                document.LoadHtml(sourcePage);
                collection = document.DocumentNode.SelectNodes("//div[@class='card_meta mobile']");
                foreach (HtmlNode cardNode in collection)
                {
                    HtmlDocument cardHtml = new HtmlDocument();
                    cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", "")));
                    cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']");
                    alternate = "";
                    if (cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']") != null)
                    {
                        alternate = cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']")[0].InnerText;
                    }
                    if (alternate == "(Alternate Art)")
                    {
                        CardCounter = CardCounter + 1;
                        cardFound = true;
                        continue;
                    }
                    cardName = cardHtml.DocumentNode.SelectNodes("//h6")[0].InnerText.Trim();
                    CardDefinition cardToComplete = cardList.Find(x => x.Name == cardName);
                    completeCardWithLevelDependentValue(cardNode, cardToComplete);
                    cardFound = true;
                    CardCounter = CardCounter + 1;
                }
                currPage = currPage + 1;
                statusDisplay.labelStstusUpdate("Downloading Level 2 " , cardName);
            }
            while ((CardCounter % 12) == 0 && cardFound == true);

            CardCounter = 0;
            currPage = 1;
            do
            {
                sourcePage = GetSourcePage(m_URLAddressDetail + "3" + "&page=" + currPage.ToString());
                cardFound = false;
                document.LoadHtml(sourcePage);
                collection = document.DocumentNode.SelectNodes("//div[@class='card_meta mobile']");
                foreach (HtmlNode cardNode in collection)
                {
                    HtmlDocument cardHtml = new HtmlDocument();
                    cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", "")));
                    cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']");
                    alternate = "";
                    if (cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']") != null)
                    {
                        alternate = cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']")[0].InnerText;
                    }
                    if (alternate == "(Alternate Art)")
                    {
                        CardCounter = CardCounter + 1;
                        cardFound = true;
                        continue;
                    }
                    cardName = cardHtml.DocumentNode.SelectNodes("//h6")[0].InnerText.Trim();
                    CardDefinition cardToComplete = cardList.Find(x => x.Name == cardName);
                    completeCardWithLevelDependentValue(cardNode, cardToComplete);
                    cardFound = true;
                    CardCounter = CardCounter + 1;
                }
                currPage = currPage + 1;
                statusDisplay.labelStstusUpdate("Downloading Level 3 " , cardName);
            }
            while ((CardCounter % 12) == 0 && cardFound == true);

            CardCounter = 0;
            currPage = 1;
            do
            {
                sourcePage = GetSourcePage(m_URLAddressDetail + "4" + "&page=" + currPage.ToString());
                cardFound = false;
                document.LoadHtml(sourcePage);
                collection = document.DocumentNode.SelectNodes("//div[@class='card_meta mobile']");
                foreach (HtmlNode cardNode in collection)
                {
                    HtmlDocument cardHtml = new HtmlDocument();
                    cardHtml.LoadHtml((cardNode.InnerHtml.Replace("<br />", "").Replace("<br>", "").Replace("\t", "")));
                    cardHtml.DocumentNode.SelectNodes("//div[@class='mobiletrigger']");
                    alternate = "";
                    if (cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']") != null)
                    {
                        alternate = cardHtml.DocumentNode.SelectNodes("//span[@class='alternate_art']")[0].InnerText;
                    }
                    if (alternate == "(Alternate Art)")
                    {
                        CardCounter = CardCounter + 1;
                        cardFound = true;
                        continue;
                    }
                    cardName = cardHtml.DocumentNode.SelectNodes("//h6")[0].InnerText.Trim();
                    CardDefinition cardToComplete = cardList.Find(x => x.Name == cardName);
                    completeCardWithLevelDependentValue(cardNode, cardToComplete);
                    cardFound = true;
                    CardCounter = CardCounter + 1;
                    statusDisplay.labelStstusUpdate("Downloading Level 4 " , cardName);
                }
                currPage = currPage + 1;
            }
            while ((CardCounter % 12) == 0 && cardFound == true);

            return cardList;
        }