/// <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"); InfoBoxLabel.ScrollToEnd(); //Take address from address bar. WebSite WebSite = new WebSite(SiteAdressTextBox.Text); //Verify correctness of web address Parser.ValidateWebAddress(WebSite.WebSiteAddress.ToString()); InfoBoxLabel.AppendText("Adres internetowy został zweryfikowany...\n"); InfoBoxLabel.ScrollToEnd(); //When there is internet connection. if (Connections.HasInternetConnection()) { InfoBoxLabel.AppendText("Wykryto połączenie internetowe...\n"); InfoBoxLabel.ScrollToEnd(); //Check if website is available (can I ping it?) if (WebSite.IsWebSiteAvailable(WebSite.WebSiteAddress) == true) { //If there was response from website... InfoBoxLabel.AppendText("Nawiązano połączenie ze stroną...\n"); InfoBoxLabel.ScrollToEnd(); //Get Source Code of website (HTML document only)... WebSite.GetWebsiteSourceCode(); //...and inform user about success InfoBoxLabel.AppendText("Kod strony pobrano pomyślnie...\n"); InfoBoxLabel.ScrollToEnd(); //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.ListOfDistinctMatches.Count; if (Cells > 0) { //Prepare GRID layout to further display MakeGrid(Cells); //Take all links and fill grid with it's content FillGrid(Cells); //Enable second button DownloadAllButon.IsEnabled = true; } } //Can't ping website else { //Inform user about failure InfoBoxLabel.AppendText("Brak odpowiedzi od serwera\n"); InfoBoxLabel.ScrollToEnd(); //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"); InfoBoxLabel.ScrollToEnd(); } }
/// <summary> /// Inform user about completed download /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CompletedOneImage(object sender, AsyncCompletedEventArgs e) { InfoBoxLabel.AppendText("Plik został pobrany...\n"); InfoBoxLabel.ScrollToEnd(); //throw new NotImplementedException(); }