Esempio n. 1
0
        public DMS.JobProgressInfo GetProgressInfo(DMS.Job job)
        {
            // Downcast der Job- Referenz in eine Referenz vom Typ PageDownloadJob
            PickLinksJob pJob = job as PickLinksJob;

            Debug.Assert(pJob != null);

            DMS.JobProgressInfo pinfo = new DMS.JobProgressInfo(pJob.JobId, pJob.JobState);
            return(pinfo);
        }
Esempio n. 2
0
        public void doIt(DMS.Job currentJob)
        {
#if (DEBUG)
            Debug.Assert(System.Text.RegularExpressions.Regex.IsMatch("href   =\"http://www.mkoit.de\"", HRefRegEx));
            Debug.Assert(System.Text.RegularExpressions.Regex.IsMatch("href = http://www.mkoit.de", HRefRegEx));
            Debug.Assert(System.Text.RegularExpressions.Regex.IsMatch("href=http://www.mkoit.de", HRefRegEx));

            Debug.Assert(System.Text.RegularExpressions.Regex.IsMatch("href=\"http://www.mkoit.de\"", HRefRegEx));

            //Debug.Assert(!System.Text.RegularExpressions.Regex.IsMatch("href=\"https:/www.mkoit.de\"", HRefRegEx));
#endif


            // Downcast in PickLinksJob
            PickLinksJob pJob = currentJob as PickLinksJob;
            Debug.Assert(pJob != null);

            int NewDeept = pJob.ActDeept - 1;

            // Alle Urls aus dem HTML- Text extrahieren
            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(
                HRefRegEx,
                RegexOptions.IgnoreCase | RegexOptions.Compiled);

            MatchCollection mc = regEx.Matches(pJob.HtmlText);
            Debug.WriteLine("PC: Deept= " + pJob.ActDeept + " JobId= " + pJob.JobId + " #Urls = " + mc.Count);

            // Iteration durch alle Treffer des regulären Ausdrucks
            foreach (System.Text.RegularExpressions.Match match in mc)
            {
                // Für jede Url einen neuen PageDownload Job erzeugen
                Debug.Assert(pageDownloadQueue != null);

                string Url;
                if (GetInternetLink(match.Captures[0].Value, out Url))
                {
                    PageDownloadJob downloadJob = new PageDownloadJob();

                    // Job wird nach der Fertigstellung automatisch entfernt
                    downloadJob.OneWay = true;
                    downloadJob.JobId  = pageDownloadQueue.NewJobId();
                    downloadJob.Url    = Url;

                    downloadJob.ActDeept = NewDeept;

                    // Rückkopplung: Herunterladen der Seite, auf die der Link aus der aktuellen verweist
                    pageDownloadQueue.pushJob(downloadJob);
                }
            }

            pJob.SetFinished();
        }
Esempio n. 3
0
        public void doIt(DMS.Job currentJob)
        {
            // Downcast der Job- Referenz in eine Referenz vom Typ PageDownloadJob
            PageDownloadJob downloadJob = currentJob as PageDownloadJob;

            Debug.Assert(downloadJob != null);
            Debug.WriteLine("PD: Deept= " + downloadJob.ActDeept + " JobId= " + downloadJob.JobId + " Url=" + downloadJob.Url);

            try
            {
                // Prüfen, ob die max. Tiefe beim crawlen erreicht wurde
                if (downloadJob.ActDeept <= 0)
                {
                    if (EventEndOfCrawl != null)
                    {
                        lock (Visited)
                        {
                            EventEndOfCrawl(
                                new PageDownloadJobProgressInfo(
                                    downloadJob.Url,
                                    Visited.Count,
                                    downloadJob.JobId,
                                    downloadJob.JobState));
                        }
                    }
                    return;
                }

                // Prüfen, ob Seite bereits besucht wurde
                if (Visited.Any(r => r == downloadJob.Url))
                {
                    return;
                }

                // Seite herunterladen
                System.Net.WebRequest  request  = null;
                System.Net.WebResponse response = null;

                System.Net.NetworkCredential cred = new NetworkCredential(
                    //System.Security.Principal.WindowsIdentity.GetCurrent().Name,
                    "Administrator",
                    "schulung");

                //System.Net.WebProxy myProxy = new System.Net.WebProxy("http://10.7.252.34:80", true);
                //myProxy.Credentials = cred;


                request = System.Net.WebRequest.Create(downloadJob.Url);
                //request.Proxy = myProxy;
                response = request.GetResponse();

                // Seite als besucht verzeichnen
                Visited.Add(downloadJob.Url);

                // Inhalt der Seite auslesen

                System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
                string HtmlText = reader.ReadToEnd();

                // Neuen PickLinJob in die Queue von PickLinks stellen
                PickLinksJob pickJob = new PickLinksJob();

                // Job wird nach der Fertigstellung automatisch entfernt
                pickJob.OneWay   = true;
                pickJob.JobId    = pickLinksBp.NewJobId();
                pickJob.HtmlText = HtmlText;
                pickJob.ActDeept = downloadJob.ActDeept;

                pickLinksBp.pushJob(pickJob);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Fehler beim Herunterladen: " + ex.Message);
            }
            finally
            {
                downloadJob.SetFinished();
            }
        }