Exemplo n.º 1
0
        /// <summary>
        /// Starts searching for the cards.
        /// </summary>
        public void StartSearching()
        {
            if (txtSearchFor.Text.Trim().Length < 1)
            {
                MessageBox.Show("Enter what you want to search for.");
                return;
            }

            int maxResults;
            if (!int.TryParse(txtMaxResults.Text, out maxResults))
            {
                MessageBox.Show("# of Results can not be blank");
                return;
            }

            List<WebImageSearchItem> items = new List<WebImageSearchItem>();
            string[] values = txtSearchFor.Text.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s in values)
            {
                if (s.Trim().Length > 0)
                    items.Add(new WebImageSearchItem(s));
            }

            progressBar.Maximum = items.Count;
            progressBar.Step = 1;
            progressBar.Value = 0;

            if (items.Count > 0)
            {
                lblStatus.Text = "Downloading... Please Wait...";
            }
            else
            {
                lblStatus.Text = "Nothing to search for.";
                return;
            }

            LoadingPanelIsVisible = true;
            loadingSmallPictureBox.Visible = true;

            errors = new List<ImageRecievedCallbackItem>();

            //Get the images
            _WTIM_SearchFor = WebImage.ProcessImageBatchWithThreadPool(items, maxResults, wTIM_SearchForCallback, 5);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Download and save images for a group of cards by matching images with the answer text.         
        /// </summary>
        /// <param name="cards"></param>
        public void DownloadAndSaveImagesForCards(dsLanguageData.CardDataTable cards)
        {
            //If it is already working.
            if (_WTIM_GetForCards != null && _WTIM_GetForCards.IsWorking)
            {
                return;
            }

            List<WebImageSearchItem> searchItems = new List<WebImageSearchItem>();
            LanguageData dataLayer = new LanguageData();
            foreach (dsLanguageData.CardRow card in cards)
            {
                if (!dataLayer.CardHasPicture(card.ID))
                    searchItems.Add(new WebImageSearchItem(card.ID, card.Answer));
            }

            progressBar.Maximum = searchItems.Count;
            progressBar.Step = 1;
            progressBar.Value = 0;

            if (searchItems.Count > 0)
            {
                lblStatus.Text = "Downloading... Please Wait...";
            }
            else
            {
                lblStatus.Text = "All done. No need to get any pictures";

                LoadImagesForCards(cards);

                return;
            }

            LoadingPanelIsVisible = true;
            loadingSmallPictureBox.Visible = true;

            errors = new List<ImageRecievedCallbackItem>();

            _WTIM_GetForCards = WebImage.ProcessImageBatchWithThreadPool(searchItems, wTIM_GetForSelectedCardsCallback, 5);
        }