Esempio n. 1
0
 public WebPage(string url)
 {
     rootUrl = new Uri(url);
     resourceAddresses = new ConcurrentBag<string>();
     Resources = new ConcurrentDictionary<string, Resource>();
     resourceAddresses.Add(url);
     var root = new Resource(url);
     if(root.StatusCode == HttpStatusCode.OK)
     {
         Html = ASCIIEncoding.ASCII.GetString(root.Data);
         var document = new HtmlDocument();
         document.LoadHtml(Html);
         FillResources(document.DocumentNode);
     }
 }
Esempio n. 2
0
        public WebPage GetResources()
        {
            ParallelOptions op = new ParallelOptions();
            op.MaxDegreeOfParallelism = 40;
            Parallel.ForEach(resourceAddresses, op, addr =>
            {
                try
                {
                    var resource = new Resource(addr);
                    Resources.TryAdd(addr, resource);
                }
                catch { }
            });

            return this;
        }