Esempio n. 1
0
        /// <summary>
        /// Most important method in application
        /// Is responsible for coordinating every class
        /// 1. Prepares field for making web request.
        /// 2. Constantly updates itself in infobox
        /// 3. Creates new instance of WebSite and serves requests
        /// 4. If there is internet connection takes source code and gives it to Parser to find all correct images links
        /// 5. Makes grid to show images
        /// 6. Allows images to be downloaded from WEB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void webRequest(object sender, RoutedEventArgs e)
        {
            //Prepare application windows for new request.
            clearGrid(cells);

            //Inform about start of process.
            InfoBoxLabel.Background = System.Windows.Media.Brushes.White;
            InfoBoxLabel.AppendText("Wysyłam żądanie...\n");

            //Take address from address bar.
            Site webSite = new Site(siteAdressTextBox.Text);

            //Verify correctness of web address
            Parser.validateWebAddress(webSite.webSiteAddress.ToString());
            InfoBoxLabel.AppendText("Adres internetowy został zweryfikowany...\n");

            //When there is internet connection.
            if (Connections.HasInternetConnection())
            {
                InfoBoxLabel.AppendText("Wykryto połączenie internetowe...\n");

                //Check if website is available (can I ping it?)
                if (Connections.isWebSiteAvailable(webSite.webSiteAddress) == true)
                {
                    //If there was response from website...
                    InfoBoxLabel.AppendText("Nawiązano połączenie ze stroną...\n");

                    //Get Source Code of website (HTML document only)...
                    webSite.getWebsiteSourceCode();
                    //...and inform user about success
                    InfoBoxLabel.AppendText("Kod strony pobrano pomyślnie...\n");

                    //Having document, Parse it and tame all image links from it.
                    webSite.RetrieveImageLinks(webSite.webSiteAddress);

                    //Update information about needed cells to dynamically create in GRID
                    cells = FindAllImages.Matches.Count;
                    //Prepare GRID layout to further display
                    makeGrid(cells);
                    //Take all links and fill grid with it's content
                    fillGrid(cells);
                }

                //Can't ping website
                else
                {
                    //Inform user about failure
                    InfoBoxLabel.AppendText("Brak odpowiedzi od serwera\n");
                    //Change box color to draw attention of user
                    InfoBoxLabel.Background = System.Windows.Media.Brushes.Crimson;
                }
            }

            else
            {
                //Very angry color to force user to buy the internet (or correct it's connection)
                InfoBoxLabel.Background = System.Windows.Media.Brushes.Crimson;
                //Short info about "obstacle"
                InfoBoxLabel.AppendText("Brak połączenia internetowego...\n");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Inform user about completed download
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CompletedOneImage(object sender, AsyncCompletedEventArgs e)
 {
     InfoBoxLabel.AppendText("\nPlik został pobrany...\n");
     //throw new NotImplementedException();
 }