Exemplo n.º 1
0
        private void BatDauLoadTinNhan()
        {
            //web.Reload();
            divLoadMore = (GeckoAnchorElement)web.Document.SelectFirst("//a[@class='touchable primary']");
            tm_XuLyTinNhan.Start();
            while (divLoadMore != null)
            {
                Application.DoEvents();
                isDangXuLyTinNhan = true;
                divLoadMore.Click();
                divLoadMore = (GeckoAnchorElement)web.Document.SelectFirst("//a[@class='touchable primary']");
                while (isDangXuLyTinNhan)
                {
                    Application.DoEvents();
                }
            }


            btnLoadTinNhan.Text = "Tải tin nhắn";
            isDangXuLyTinNhan   = false;
            divLoadMore         = null;
            TrangThaiDangTai(true);
            tm_XuLyTinNhan.Stop();

            ComponentFactory.Krypton.Toolkit.KryptonMessageBox.Show("Đã load hết nội dung tin nhắn!");
        }
Exemplo n.º 2
0
 private void frmLogin2_FormClosing(object sender, FormClosingEventArgs e)
 {
     isDangXuLyTinNhan = false;
     divLoadMore       = null;
     tm_XoaNoiDung.Stop();
     tm_XuLyTinNhan.Stop();
     Application.Exit();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Dom单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void On_DomClick(object sender, DomMouseEventArgs e)
        {
            //屏蔽页面点击事件
            e.PreventDefault();
            e.StopPropagation();

            var ele = e.CurrentTarget.CastToGeckoElement();

            ele = e.Target.CastToGeckoElement();
            GeckoHtmlElement geckoHtmlElement = (GeckoHtmlElement)ele;
            string           searchElement    = geckoHtmlElement.OuterHtml;

            if (!searchElement.Contains("firefinder-match-red"))
            {
                //在datagridview中显示选中行的内容
                GeckoHtmlElement[] geckoHtmlEle = new GeckoHtmlElement[1];
                geckoHtmlEle[0] = geckoHtmlElement;

                if (geckofxType.Equals(GeckofxWebbrowerType.General))
                {
                    InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle);
                }
                else if (geckofxType.Equals(GeckofxWebbrowerType.ListDetails))
                {
                    InsertDataGridRow(dgv, geckoWebBrowser, geckoHtmlEle);
                }
                else if (geckofxType.Equals(GeckofxWebbrowerType.UrlModel))
                {
                    try
                    {
                        GeckoAnchorElement d   = (GeckoAnchorElement)geckoHtmlElement;
                        string             URL = d.Href;

                        InsertDataGridRow(GeckofxWebbrowerType.UrlModel, dgv, geckoWebBrowser, geckoHtmlEle);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("请获取链接!");
                        return;
                    }
                }

                ruleStyle.AddClass("firefinder-match-red", ele);
            }
            else
            {
                //在浏览器中标记红圈
                ruleStyle.RemoveClass("firefinder-match-red", ele);
            }
        }
Exemplo n.º 4
0
        public static string GetUrlByElementParent(Object objElement)
        {
            string           URL;
            GeckoHtmlElement element = (GeckoHtmlElement)objElement;

            try
            {
                GeckoAnchorElement d = (GeckoAnchorElement)element.Parent;
                URL = d.Href;
            }
            catch (Exception)
            {
                URL = null;
            }
            return(URL);
        }
Exemplo n.º 5
0
        /// <summary>
        /// When you receive a OnBrowserClick and have determined that nothing was clicked on that the c# needs to pay attention to,
        /// pass it on to this method. It will either let the browser handle it normally, or redirect it to the operating system
        /// so that it can open the file or external website itself.
        /// </summary>
        public void HandleLinkClick(GeckoAnchorElement anchor, DomEventArgs eventArgs, string workingDirectoryForFileLinks)
        {
            Debug.Assert(!InvokeRequired);
            if (anchor.Href.ToLower().StartsWith("http"))             //will cover https also
            {
                Process.Start(anchor.Href);
                eventArgs.Handled = true;
                return;
            }
            if (anchor.Href.ToLower().StartsWith("file"))
            //links to files are handled externally if we can tell they aren't html/javascript related
            {
                // TODO: at this point spaces in the file name will cause the link to fail.
                // That seems to be a problem in the DomEventArgs.Target.CastToGeckoElement() method.
                var href = anchor.Href;

                var path = href.Replace("file:///", "");

                if (new List <string>(new[] { ".pdf", ".odt", ".doc", ".docx", ".txt" }).Contains(Path.GetExtension(path).ToLower()))
                {
                    eventArgs.Handled = true;
                    Process.Start(new ProcessStartInfo()
                    {
                        FileName         = path,
                        WorkingDirectory = workingDirectoryForFileLinks
                    });
                    return;
                }
                eventArgs.Handled = false;                 //let gecko handle it
                return;
            }
            else if (anchor.Href.ToLower().StartsWith("mailto"))
            {
                eventArgs.Handled = true;
                Process.Start(anchor.Href);                 //let the system open the email program
                Debug.WriteLine("Opening email program " + anchor.Href);
            }
            else
            {
                ErrorReport.NotifyUserOfProblem("Bloom did not understand this link: " + anchor.Href);
                eventArgs.Handled = true;
            }
        }
        public void AddVoiceActions(GeckoDocument document, string tagName)
        {
            foreach (GeckoElement element in document.GetElementsByTagName(tagName))
            {
                VoiceAction action = new VoiceAction();
                action.label = element.TextContent.Trim();

                if (tagName == "button")
                {
                    action.task += () =>
                    {
                        GeckoButtonElement button = new GeckoButtonElement(element.DomObject);
                        button.Click();
                    };
                }

                if (tagName == "a")
                {
                    action.task += () =>
                    {
                        GeckoAnchorElement anchor = new GeckoAnchorElement(element.DomObject);
                        anchor.Click();
                    };
                }

                if (tagName == "iframe")
                {
                    action.task += () =>
                    {
                        GeckoButtonElement iframe = new GeckoButtonElement(element.DomObject);
                        iframe.Click();
                    };
                }
                actions.Add(action);
            }
        }
Exemplo n.º 7
0
        private void tm_XuLyTinNhan_Tick(object sender, EventArgs e)
        {
            Application.DoEvents();

            try
            {
                GeckoHtmlElement nodeRoot = (Gecko.GeckoHtmlElement)web.Document.SelectFirst("//div[@class='voice acw abt'][last()]");
                if (nodeRoot == null)
                {
                    isDangXuLyTinNhan = false;
                    return;
                }

                GeckoHtmlElement divMsg = web2.Document.CreateHtmlElement("div");

                string html = "";

                var user = nodeRoot.GetElementsByTagName("strong").Where(n => n.GetAttribute("class") == "actor").FirstOrDefault();
                if (user != null)
                {
                    html += "<div class='user'><b>" + user.TextContent + "</b>";
                    var timeSpan = nodeRoot.GetElementsByTagName("abbr").FirstOrDefault();
                    if (timeSpan != null)
                    {
                        html += "<span class='time'>(" + timeSpan.TextContent + ")</span>";
                    }
                    html += "</div>";
                }

                var mess = nodeRoot.GetElementsByTagName("div").Where(n => n.GetAttribute("data-sigil") == "message-text");

                bool isTiepTuc = true;

                foreach (GeckoHtmlElement m in mess)
                {
                    Application.DoEvents();
                    isTiepTuc = true;
                    if (chkImgOffline.Checked)
                    {
                        var arrImg = m.GetElementsByTagName("img");
                        foreach (GeckoImageElement _img in arrImg)
                        {
                            string strBase64 = ImageToBase64(_img);
                            if (strBase64 != "")
                            {
                                _img.SetAttribute("src", "data:image/png;base64," + strBase64);
                            }
                        }
                    }

                    Regex  r         = new Regex("timestamp&quot;:(.*?),", RegexOptions.Multiline);
                    Match  mt        = r.Match(m.OuterHtml);
                    string _str_time = "";
                    if (mt.Success)
                    {
                        DateTime tSS = SecondToDateTime(mt.Groups[1].Value.ToString());
                        _str_time = tSS.ToString("HH:mm");
                        if (txtDenLuc.Checked && tSS < txtDenLuc.Value)
                        {
                            isTiepTuc = false;
                        }
                    }

                    if (chkTaiTextDuyNhat.Checked)
                    {
                        if (m.TextContent.Trim() != "")
                        {
                            html += "<div class='msg'><span class='time2'>" + _str_time + "</span>" + m.TextContent + "</div>";
                        }
                    }
                    else
                    {
                        html += "<div class='msg'><span class='time2'>" + _str_time + "</span>" + m.InnerHtml + "</div>";
                    }
                }

                divMsg.InnerHtml = "<div>" + html + "</div>";

                web2.Document.Body.InsertBefore(divMsg, web2.Document.Body.ChildNodes[0]);


                nodeRoot.ParentNode.RemoveChild(nodeRoot);

                if (!isTiepTuc)
                {
                    btnLoadTinNhan.Text = "Tải tin nhắn";
                    isDangXuLyTinNhan   = false;
                    divLoadMore         = null;
                    TrangThaiDangTai(true);
                    tm_XuLyTinNhan.Stop();
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Dom双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void On_DomDoubleClick(object sender, DomMouseEventArgs e)
        {
            //屏蔽页面点击事件
            e.PreventDefault();
            e.StopPropagation();

            var ele = e.CurrentTarget.CastToGeckoElement();

            ele = e.Target.CastToGeckoElement();
            GeckoHtmlElement geckoHtmlElement = (GeckoHtmlElement)ele;

            //短xpath
            var xpath1 = xpathHelper.GetSmallXpath(ele);

            //var xpath2 = xpathHelper.GetXpath(ele);
            if (xpath1.Contains("tr"))
            {
                string demo = xpath1.Substring(xpath1.IndexOf("tr"));
                try
                {
                    demo = demo.Substring(0, demo.IndexOf("/"));
                }
                catch (Exception)
                {
                }
                xpath1 = xpath1.Replace(demo, "tr");
            }
            else if (xpath1.Contains("li"))
            {
                string demo = xpath1.Substring(xpath1.IndexOf("li"));
                try
                {
                    demo = demo.Substring(0, demo.IndexOf("/"));
                }
                catch (Exception)
                {
                }
                xpath1 = xpath1.Replace(demo, "li");
            }

            if (string.IsNullOrWhiteSpace(xpath1))
            {
                return;
            }
            var xresult  = geckoWebBrowser.DomDocument.EvaluateXPath(xpath1);
            var nodes    = xresult.GetNodes();
            var elements = nodes.Select(x => x as GeckoElement).ToArray();


            if (geckofxType.Equals(GeckofxWebbrowerType.General))
            {
            }
            else if (geckofxType.Equals(GeckofxWebbrowerType.ListDetails))
            {
            }
            else if (geckofxType.Equals(GeckofxWebbrowerType.UrlModel))
            {
                foreach (var item in elements)
                {
                    try
                    {
                        GeckoAnchorElement d   = (GeckoAnchorElement)geckoHtmlElement;
                        string             URL = d.Href;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("链接列表有问题,请检查!");
                        return;
                    }
                }
            }

            ruleStyle.AddClass("firefinder-match-red", elements);
            InsertDataGridRow(GeckofxWebbrowerType.UrlModel, dgv, geckoWebBrowser, elements);
        }