Ejemplo n.º 1
0
        private IList<Website> GetWebsites()
        {
            Website curWebsite = null;
            IList<Website> websites = new List<Website>();
            string siteSearchWords = Utility.GetAppSetting(Constants.WEBSITES_TO_CHECK);
            string[] sitesSearchWordsArr = siteSearchWords.Split(';');

            foreach(string entry in sitesSearchWordsArr)
            {
                if (!string.IsNullOrEmpty(entry))
                {
                    string siteWord = entry.Replace(JobConstants.NEW_LINE, string.Empty);
                    siteWord = siteWord.Trim();
                    string[] siteSearchWord = siteWord.Split(',');

                    curWebsite = new Website();
                    curWebsite.Name = siteSearchWord[0];
                    curWebsite.SearchString = siteSearchWord[1];

                    websites.Add(curWebsite);
                }
            }

            return websites;
        }
Ejemplo n.º 2
0
        private void VerifySearchWordPresent(Website website)
        {
            string pageContents = string.Empty;
            HttpWebRequest req = null;
            HttpWebResponse resp = null;
            StreamReader rdr = null;
            int searchWordExists = 0;

            try
            {
                Uri url = new Uri(website.Name);

                dispOut.Events.Add(Messages.TESTING_WEBSITE + website.Name
                        + Messages.SEARCH_TERM + website.SearchString + Messages.END_SINGLE_QUOTE);

                req = (HttpWebRequest)HttpWebRequest.Create(url);
                req.Method = WebRequestMethods.Http.Get;
                req.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                resp = (HttpWebResponse)req.GetResponse();
                rdr = new StreamReader(resp.GetResponseStream());
                pageContents = rdr.ReadToEnd();
                searchWordExists = pageContents.ToLower().IndexOf(website.SearchString);

                if (searchWordExists == -1)
                {
                    dispOut.Events.Add(website.Name
                                 + Messages.SEARCH_TERM_NOT_FOUND + website.SearchString + Messages.END_SINGLE_QUOTE);
                }
                else
                    dispOut.Events.Add(Messages.WEBSITE + website.Name
                                        + Messages.SEARCH_TERM_FOUND  + website.SearchString + Messages.END_SINGLE_QUOTE);
            }
            catch (System.Net.WebException ex)
            {
                dispOut.Events.Add(Messages.ERROR_WEBSITE_RESPONSE + website.Name
                       + Messages.ERROR_SEARCH_TERM + website.SearchString + Messages.END_SINGLE_QUOTE_DASH + ex.Message);
            }
            finally
            {
                if (req != null)
                {
                    req = null;
                }

                if (resp != null)
                {
                    resp.Close();
                    resp = null;
                }

                if (rdr != null)
                {
                    rdr.Close();
                    rdr.Dispose();
                    rdr = null;
                }
            }
        }