示例#1
0
        public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
        {
            UrlType urlType = ((WebSpiderResource)parentSpider).addingUrlType;

            if (
                !(urlType == UrlType.Img && this.downloadImagesFromExternalSite)
                &&
                !(urlType != UrlType.Img && this.downloadResourceFromExternalSite)
                )
            {
                string tempbase = context.BaseLocation;
                int    i;

                if ((i = tempbase.LastIndexOf("/")) >= 0)
                {
                    tempbase = tempbase.Substring(0, i + 1);
                }

                if (!location.OriginalString.StartsWith(tempbase))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
        {
            UrlType urlType = ((WebSpiderResource)parentSpider).addingUrlType;
            
            if (
            !(urlType == UrlType.Img && this.downloadImagesFromExternalSite)
                &&
            !(urlType != UrlType.Img && this.downloadResourceFromExternalSite)
                )
            {
                string tempbase = context.BaseLocation;
                int i;

                if ((i = tempbase.LastIndexOf("/")) >= 0)
                {
                    tempbase = tempbase.Substring(0, i + 1);
                }

                if (!location.OriginalString.StartsWith(tempbase))
                {
                    return false;
                }
            }

            return true;
        }
示例#3
0
 protected internal virtual void OnResourceCompleted(ISpiderResource spider)
 {
     if (ResourceCompleted != null)
     {
         ResourceCompleted(this, spider);
     }
 }
示例#4
0
        public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
        {
            string ext = Path.GetExtension(location.Segments[location.Segments.Length - 1]).ToLower();

            int index = Array.IndexOf <string>(this.extensionsToExclude, ext);

            return(index < 0);
        }
示例#5
0
        public virtual IAsyncRetriver BeginLookup()
        {
            ISpiderResource resourceSpider = factory.CreateSpider(this.context, null, this.context.BaseLocation);

            context.AddURIToVisit(new Uri(this.context.BaseLocation), resourceSpider);

            return(resourceSpider.BeginReceive());
        }
        public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
        {
            string ext = Path.GetExtension(location.Segments[location.Segments.Length-1]).ToLower();

            int index = Array.IndexOf<string>(this.extensionsToExclude, ext);

            return index < 0;
        }
示例#7
0
 public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
 {
     if (this.maxDepth > 0 && parentSpider.Depth >= this.maxDepth)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
示例#8
0
 public bool Accept(Uri location, SpiderContext context, ISpiderResource parentSpider)
 {
     if (this.maxDepth > 0 && parentSpider.Depth >= this.maxDepth)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
        public bool Accept(Uri uri, SpiderContext context, ISpiderResource parentSpider)
        {
            string fileName = uri.Segments[uri.Segments.Length - 1];

            for (int i = 0; i < namesToExclude.Length; i++)
            {
                if (fileName.IndexOf(namesToExclude[i]) >= 0)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#10
0
        public bool Accept(Uri uri, SpiderContext context, ISpiderResource parentSpider)
        {
            string fileName = uri.Segments[uri.Segments.Length - 1];

            for (int i = 0; i < namesToExclude.Length; i++)
            {
                if (fileName.IndexOf(namesToExclude[i]) >= 0)
                {
                    return false;
                }
            }

            return true;
        }
示例#11
0
 private void UpdateDepth()
 {
     if (this.parent == null)
     {
         this.depth = 0;
     }
     else
     {
         ISpiderResource tmpParent = this.parent;
         while (tmpParent != null)
         {
             this.depth++;
             tmpParent = tmpParent.ParentResource;
         }
     }
 }
示例#12
0
        public void NotifyCompletion(ISpiderResource spider)
        {
            lock (completedResources)
            {
                if (!completedResources.Contains(spider))
                {
                    completedResources.Add(spider);
                }
            }

            OnResourceCompleted(spider);

            if (completedResources.Count == VisitedLocations.Count)
            {
                OnCompleted();
            }
        }
示例#13
0
        public WebSpiderResource(SpiderContext context, ISpiderResource parent, string location)
        {
            this.context = context;
            this.location = location;
            this.parent = parent;

            UpdateDepth();

            string localFile = GetLocalFile();

            download = DownloadManager.Instance.Add(
                    ResourceLocation.FromURL(this.Location),
                    null,
                    localFile,
                    1,
                    false);

            download.StateChanged += new EventHandler(download_StateChanged);
        }
示例#14
0
        public WebSpiderResource(SpiderContext context, ISpiderResource parent, string location)
        {
            this.context  = context;
            this.location = location;
            this.parent   = parent;

            UpdateDepth();

            string localFile = GetLocalFile();

            download = DownloadManager.Instance.Add(
                ResourceLocation.FromURL(this.Location),
                null,
                localFile,
                1,
                false);

            download.StateChanged += new EventHandler(download_StateChanged);
        }
示例#15
0
        public bool AddURIToVisit(Uri uri, ISpiderResource parentSpider)
        {
            if (ShouldAdd(uri, parentSpider))
            {
                lock (visitedLocations)
                {
                    if (visitedLocations.Contains(uri))
                    {
                        return(false);
                    }

                    visitedLocations.Add(uri);

                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
示例#16
0
        private bool ShouldAdd(Uri location, ISpiderResource parentSpider)
        {
            #region Aborted
            if (aborted)
            {
                return(false);
            }
            #endregion

            #region Naming rules
            for (int j = 0; j < namingRules.Count; j++)
            {
                if (!namingRules[j].Accept(location, this, parentSpider))
                {
                    return(false);
                }
            }
            #endregion

            return(true);
        }
示例#17
0
 protected internal virtual void OnResourceCompleted(ISpiderResource spider)
 {
     if (ResourceCompleted != null)
     {
         ResourceCompleted(this, spider);
     }
 }
 public ISpiderResource CreateSpider(SpiderContext cntx, ISpiderResource parent, string location)
 {
     return(new WebSpiderResource(cntx, parent, location));
 }
 public ISpiderResource CreateSpider(SpiderContext cntx, ISpiderResource parent, string location)
 {
     return new WebSpiderResource(cntx, parent, location);
 }
 internal DownloaderAsyncRetrive(ISpiderResource resource, Downloader d)
 {
     this.downloader = d;
     this.resource   = resource;
 }
示例#21
0
        public bool AddURIToVisit(Uri uri, ISpiderResource parentSpider)
        {
            if (ShouldAdd(uri, parentSpider))
            {
                lock (visitedLocations)
                {
                    if (visitedLocations.Contains(uri))
                    {
                        return false;
                    }

                    visitedLocations.Add(uri);

                    return true;
                }
            }
            else
            {
                return false;
            }
        }
示例#22
0
        public void NotifyCompletion(ISpiderResource spider)
        {
            lock (completedResources)
            {
                if (!completedResources.Contains(spider))
                {
                    completedResources.Add(spider);
                }
            }

            OnResourceCompleted(spider);

            if (completedResources.Count == VisitedLocations.Count)
            {
                OnCompleted();
            }
        }
示例#23
0
        private bool ShouldAdd(Uri location, ISpiderResource parentSpider)
        {
            #region Aborted
            if (aborted)
            {
                return false;
            }
            #endregion

            #region Naming rules
            for (int j = 0; j < namingRules.Count; j++)
            {
                if (!namingRules[j].Accept(location, this, parentSpider)) return false;
            }
            #endregion

            return true;
        }
示例#24
0
 internal DownloaderAsyncRetrive(ISpiderResource resource, Downloader d)
 {
     this.downloader = d;
     this.resource = resource;
 }