예제 #1
0
 private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
 {
     if (!e.IsLoading)
     {
         OnPageLoaded?.Invoke();
     }
 }
예제 #2
0
        public override async Task OnPageLoad()
        {
            await base.OnPageLoad();

            Container.Width           = "200px";
            Container.Height          = "200px";
            Container.BackgroundColor = System.Drawing.Color.Blue;
            Container.OnClicked      += Container_OnClicked;


            OnPageLoaded?.Invoke(this);
        }
예제 #3
0
        private void _load()
        {
            if (raw == "")
            {
                loaded = true;
                return;
            }
            offset = new Vector2();
            lock (buf1)
            {
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(buf1);
                g.Clear(System.Drawing.Color.Transparent);
                //CopyBitmapToTexture();
                try
                {
                    //HtmlRenderer.HtmlRender.Render(g, raw, new System.Drawing.PointF(), new System.Drawing.SizeF(size.X, size.Y));
                    c = new HtmlRenderer.HtmlContainer();
                    c.AvoidImagesLateLoading = false;
                    c.Location   = new System.Drawing.PointF();
                    c.MaxSize    = new System.Drawing.SizeF(size.X, size.Y);
                    c.ImageLoad += new EventHandler <HtmlRenderer.Entities.HtmlImageLoadEventArgs>(c_ImageLoad);
                    c.SetHtml(raw);
                    c.PerformLayout(g);
                    c.PerformPaint(g);
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot display HTML page. Aborting...");

                    g.Clear(System.Drawing.Color.Transparent);
                    CopyBitmapToTexture();

                    loaded = true;
                    return;
                }
                //System.Threading.Thread.Sleep(100);
                lock (buf2)
                {
                    CopyBitmapToTexture();
                    //SetBackground();
                }
            }
            if (OnPageLoaded != null)
            {
                OnPageLoaded.Invoke();
            }
            loaded = true;
        }
예제 #4
0
 public override void OnReceivedError(WebView view, IWebResourceRequest request, WebResourceError error)
 {
     OnPageLoaded?.Invoke(this, false);
 }
예제 #5
0
 public override void OnPageFinished(WebView view, string url)
 {
     OnPageLoaded?.Invoke(this, true);
 }
예제 #6
0
 public void InvokePageLoaded(string url, int status)
 {
     OnPageLoaded?.Invoke(url, status);
 }
예제 #7
0
        private async Task <PageCrawlResult> CrawlNode(PageModel node)
        {
            try
            {
                var response = await _httpClient.GetAsync(node.Url);

                Uri requestUrl = response.RequestMessage.RequestUri;
                requestUrl = new Uri(requestUrl.GetLeftPart(UriPartial.Path));

                if (requestUrl != node.Url)
                {
                    if (requestUrl.Host.Replace("www.", "") != node.Url.Host.Replace("www.", ""))
                    {
                        return(PageCrawlResult.FAILED);
                    }
                    else if (ShouldAddUrl(requestUrl))
                    {
                        var pageModel = new PageModel(requestUrl, node);
                        OnNewLinkAdded?.Invoke(pageModel);
                        _pages.Enqueue(pageModel);
                    }
                    return(PageCrawlResult.FINISHED);
                }

                if (response.IsSuccessStatusCode)
                {
                    var pageContent = await response.Content.ReadAsStringAsync();

                    var pageDocument = new HtmlDocument();

                    pageDocument.LoadHtml(pageContent);

                    OnPageLoaded?.Invoke(node.Url, pageDocument);

                    foreach (HtmlNode link in pageDocument.DocumentNode.SelectNodes("//a[@href]"))
                    {
                        HtmlAttribute att   = link.Attributes["href"];
                        string        value = att.Value;
                        if (value.StartsWith("#") || value.StartsWith("mailto:"))
                        {
                            continue;
                        }

                        string extension = Path.GetExtension(value);
                        if (extension != string.Empty && extension != ".html")
                        {
                            continue;
                        }

                        Uri linkUri;
                        if (!Uri.TryCreate(requestUrl, value, out linkUri))
                        {
                            continue;
                        }

                        if (linkUri.Host != requestUrl.Host)
                        {
                            continue;
                        }

                        linkUri = new Uri(linkUri.GetLeftPart(UriPartial.Path));

                        if (ShouldAddUrl(linkUri))
                        {
                            var pageModel = new PageModel(linkUri, node);
                            OnNewLinkAdded?.Invoke(pageModel);
                            _pages.Enqueue(pageModel);
                        }
                    }
                }
                else if (response.StatusCode.Equals(HttpStatusCode.Moved))
                {
                    string returnURL = response.Headers.GetValues("Location").FirstOrDefault().ToString();
                    Uri    linkUri   = new Uri(new Uri(returnURL).GetLeftPart(UriPartial.Path));

                    if (linkUri.Host != requestUrl.Host)
                    {
                        return(PageCrawlResult.FAILED);
                    }

                    if (ShouldAddUrl(linkUri))
                    {
                        var pageModel = new PageModel(linkUri, node);
                        OnNewLinkAdded?.Invoke(pageModel);
                        _pages.Enqueue(pageModel);
                    }
                }
                return(PageCrawlResult.FINISHED);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(PageCrawlResult.ERROR);
            }
        }