Exemplo n.º 1
0
        private void updateImagesWork(object sender, DoWorkEventArgs e)
        {
            CardCollection cardCollection = new CardCollection();

            // A way to log which images where not found correctly
            // You dont need to port this but it could be helpfull
            String fileName = AuditLog.logPath + "Images Updated.txt";

            AuditLog.clear("Images Updated.txt");

            BackgroundWorker worker = (BackgroundWorker)sender;
            int setCount            = 0;

            setCount++;
            int cardCount = 1;

            // So this method only gets images of cards we have
            // You can do it this way or not
            // This does 'decouple' cards.json and card set images, which i think makes sense
            List <WixossCard> cardList = WixCardService.getAllCards();

            // call Worker_ProgressChanged with the second parameter being e.UserState
            worker.ReportProgress(cardList.Count, "Card Set Count");
            worker.ReportProgress(setCount, "Card Set Value");

            // Loop thru all cards we have and check if we have the image
            // Propbably should of been a for loop
            foreach (var wixCard in cardList)
            {
                cardCount++;
                // Check if we dont have the card's image
                if (!File.Exists(wixCard.CardImagePath))
                {
                    // Start an 'internal' browser
                    using (WebClient client = new WebClient())
                    {
                        // Build the file path based on set and 'card id'
                        String newFilePath = CardCollection.setImages + "\\" + wixCard.Id + ".jpg";

                        // make sure the card has an image url
                        // this is probably bad if it doesnt...
                        if (wixCard.ImageUrl != null)
                        {
                            String urlName = wixCard.ImageUrl;

                            // Download file async (non-thread blocking aka download many images as once)
                            client.DownloadFileAsync(new Uri(urlName), newFilePath, wixCard);

                            // on complete run 'Client_DownloadFileCompleted'
                            client.DownloadFileCompleted += Client_DownloadFileCompleted;
                        }
                    }
                }
                worker.ReportProgress(cardCount, "Card Value");
            }

            Process.Start("notepad.exe", fileName);
        }
Exemplo n.º 2
0
        // Method to get cards
        private void updateCardsWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;
            int setCount            = 0;

            // Loop thru cardSets
            foreach (var cardSet in cardSets)
            {
                setCount++;

                // Get a hashmap of all the sets card
                // Key: Card URL
                // Value: Number of cards (This only really matters for decks)
                Dictionary <String, int> cardList = cardMaker.GetCardsFromUrl(cardSet.Value);
                List <WixossCard>        setCards = new List <WixossCard>();

                worker.ReportProgress(cardList.Values.Count, "Card Set Count");
                worker.ReportProgress(setCount, "Card Set Value");
                int cardCount = 0;

                // Loop thru all cards in the set
                foreach (var cardItem in cardList)
                {
                    cardCount++;
                    worker.ReportProgress(cardCount, "Card Value");

                    // Get card from url
                    WixossCard theCard = cardMaker.GetCardFromUrl(cardItem.Key);

                    // Create or update the card to sql lite db
                    WixCardService.CreateOrUpdate(theCard);
                }

                worker.ReportProgress(-1, "Set: " + cardSet + " updated");
            }
            worker.ReportProgress(setCount + 1, "Card Set Value");
        }