Beispiel #1
0
        private void Navigate(ScriptingContext arg)
        {
            MLA.Invoke(() =>
            {
                if (browser == null)
                {
                    browser = new NonDialogWebBrowser();
#if !DEBUG
                    browser.Hide();
#endif
                    ClientForm.xInit(browser);
                    browser.DocumentCompleted += browser_DocumentCompleted;
                }

                browser.ObjectForScripting = arg;
                byte[] postData            = null;
                string headers             = null;
                if (arg.RequestContent != null)
                {
                    if (this.UseCookies)
                    {
                        if (arg.RequestContent.HasCookie)
                        {
                            _cookieContainer.Add(arg.RequestUrl, arg.RequestContent.Cookies);
                        }
                        string cookieHeader = arg.RequestContent.Headers[HttpRequestHeader.Cookie];
                        if (!string.IsNullOrEmpty(cookieHeader))
                        {
                            _cookieContainer.SetCookies(arg.RequestUrl, cookieHeader.Replace(';', ','));
                            arg.RequestContent.Headers.Remove(HttpRequestHeader.Cookie);
                        }
                        cookieHeader = _cookieContainer.GetCookieHeader(arg.RequestUrl);
                        if (cookieHeader.Length > 0)
                        {
                            arg.RequestContent.Headers[HttpRequestHeader.Cookie] = cookieHeader.Replace(',', ';');
                        }
                        //WinInetInterop.SaveCookies(_cookieContainer, absoluteUri);
                    }
                    else
                    {
                        arg.RequestContent.Headers[HttpRequestHeader.Cookie] = string.Empty;
                        //WinInetInterop.DeleteCache(WinInetInterop.CacheKind.Cookies);
                    }
                    if (arg.RequestContent.HasBody)
                    {
                        arg.RequestContent.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                        postData = Encoding.UTF8.GetBytes(arg.RequestContent.GetFormString());
                    }
                    headers = arg.RequestContent.GetHeadersString();
                }
                browser.Navigate(arg.RequestUrl, "_self", postData, headers);
            });
            this.STA_WaitSr();
        }
Beispiel #2
0
        public string CurrentInvoke(string js, CurrentInvokeKind kind = CurrentInvokeKind.None)
        {
            this.CheckNavigated();

            ScriptingContext arg    = null;
            string           result = MLA.Invoke(() =>
            {
                arg = (ScriptingContext)browser.ObjectForScripting;
                if (kind == CurrentInvokeKind.Repost)
                {
                    CurrentRepost();
                }
                string callback = ClientForm.xInvoke(browser, js);
                if (kind == CurrentInvokeKind.AjaxEvent)
                {
                    arg.SetAjax(browser, AjaxBlockFlags.Event, "CurrentInvoke");
                }
                return(callback);
            });

            if (arg == null)
            {
                throw new InvalidOperationException("CurrentInvoke NULL arg");
            }
            switch (kind)
            {
            case CurrentInvokeKind.Repost:
                arg.WaitHandle.WaitOne();
                break;

            case CurrentInvokeKind.AjaxEvent:
                arg.WaitAjax(this.SendReceiveTimeout, "CurrentInvoke");
                break;
            }
            return(result);
        }
Beispiel #3
0
        public void CurrentSnapshot(Size size, Guid?fileID = null)
        {
            this.CheckNavigated();

            MLA.Invoke(() => ClientForm.xSnapshot(browser, size, this.SaveFileDirectory, fileID));
        }
Beispiel #4
0
        public string CurrentGetHtml()
        {
            this.CheckNavigated();

            return(MLA.Invoke(() => ClientForm.xGetHtml(browser)));
        }