public async Task LoadAsync(string url)
        {
            if (!IsReady())
            {
                throw new InvalidOperationException();
            }

            // navigate and handle LoadCompleted
            var navigationTcs = new TaskCompletionSource <bool>();

            System.Windows.Navigation.LoadCompletedEventHandler handler = (s, e) =>
                                                                          navigationTcs.TrySetResult(true);

            _browser.LoadCompleted += handler;
            try
            {
                _browser.Navigate(url);
                await navigationTcs.Task;
            }
            finally
            {
                _browser.LoadCompleted -= handler;
            }

            // make the content editable to check if WebBrowser shortcuts work well
            dynamic doc = _browser.Document;

            doc.body.firstChild.contentEditable = true;
            _events.FireLoaded();
        }
Example #2
0
        internal void RetornoXml(WebBrowser webBrowser, string retornoXmlString)
        {
            var stw = new StreamWriter(_path + @"\tmp.xml");

            stw.WriteLine(retornoXmlString);
            stw.Close();
            webBrowser.Navigate(_path + @"\tmp.xml");
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();

            System.Windows.Controls.WebBrowser browser = new System.Windows.Controls.WebBrowser();
            // you can put any other uri here, or better make browser field and navigate to desired uri on some event
            browser.Navigate(new Uri("http://www.blic.rs/"));
            grdBrowserHost.Children.Add(browser);
        }
Example #4
0
 private void UpdateLink()
 {
     System.Windows.Controls.WebBrowser _webBrowser = new System.Windows.Controls.WebBrowser();
     _webBrowser.Navigated += _webBrowser_Navigated;
     if (Uri.IsWellFormedUriString(wnd.siteTB.Text, UriKind.Absolute))
     {
         _webBrowser.Navigate(wnd.siteTB.Text);
         wnd.updateLinkBT.Content = "Updating...";
     }
     else
     {
         wnd.updateLinkBT.Content = "Invalid Link";
     }
 }
Example #5
0
        public override string HttpGet(string url, Encoding enc)
        {
            LoadCompleted = false;

            browser.Navigate(url);

            while (LoadCompleted == false)
            {
                System.Threading.Thread.Sleep(100);
            }
//            browser.com
            dynamic doc  = browser.Document;
            dynamic body = doc.body;



            return(body.innerHTML);
        }
Example #6
0
            public SiteManagerCompletedEventArgs Navigate(Uri url, int wait = 0)
            {
                SiteManagerCompletedEventArgs result = new SiteManagerCompletedEventArgs() { ResponseUri = url };
                bool done = false;
                System.Windows.Controls.WebBrowser wb = null;

                Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,
                    new Action(() =>
                    {
                        PutControl(wb = new System.Windows.Controls.WebBrowser());

                        wb.Navigated += (s, e) =>
                        {
                            result.ResponseUri = e.Uri;
                            HideScriptErrors(s as System.Windows.Controls.WebBrowser, true);
                        };

                        wb.LoadCompleted += (s, e) =>
                        {
                            result.ResponseUri = e.Uri;
                            done = true;
                        };

                        wb.Navigate(url);
                    }));

                #region Wait (done and pause) or 30 sec
                DateTime endTime = DateTime.Now.AddSeconds(30);
                while (!done && (DateTime.Now < endTime))
                    Thread.Sleep(100);

                if (done)
                    Wait(wait);
                #endregion

                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(() =>
                    {
                        try
                        {
                            mshtml.HTMLDocument doc = wb.Document as mshtml.HTMLDocument;
                            if (doc != null && doc.documentElement != null)
                                result.Content = doc.documentElement.innerHTML;
                        }
                        catch (Exception ex)
                        {
                            Helpers.Old.Log.Add(ex, "SiteManagerIE.Navigate().GetHTML()");
                        }
                        finally
                        {
                            RemoveControl(wb);
                            wb = null;
                            GC.Collect();
                        }
                    }));

                return result;
            }
Example #7
0
        public void GetSession()
        {
            if (string.IsNullOrWhiteSpace(Token)) GetToken();
            if (string.IsNullOrWhiteSpace(ApiSig)) GetApiSig();

            var browser = new System.Windows.Controls.WebBrowser();
            browser.Navigate("http://www.last.fm/api/auth/?api_key="
                + ApiKey + "&token="
                + Token);
            var logWindow = new LogInWindow(browser);
            logWindow.ShowDialog();

            var Params = new RequestParameters { { "token", Token }, { "api_sig", ApiSig },
            { "api_key", ApiKey }};

            object lfmSession = new Session { ApiKey = ApiKey, ApiSec = ApiSec, ApiSig = ApiSig, Token = Token, Name = Name, Key = Key };
            AutomaticGetObject("auth.getsession", Params, ref lfmSession, "session");
            var lastSession = lfmSession as Session;
            if (lastSession != null)
            {
                Key = lastSession.Key;
                Name = lastSession.Name;
            }
        }
Example #8
0
        //***********************************************************************************************************************************************************************************************************

        /// <summary>
        /// Connect to the Spotify Web API
        /// </summary>
        /// <param name="timeout_ms">Connection timeout in ms</param>
        /// <param name="forceReauthenticate">if true, force the user to reauthenticate to the player application</param>
        /// <returns>true on connection success, otherwise false</returns>
        /// see: https://johnnycrazy.github.io/SpotifyAPI-NET/SpotifyWebAPI/auth/#implicitgrantauth
        /// Use https://developer.spotify.com/dashboard/ to get a Client ID
        /// It should be noted, "http://*****:*****@"(\?|\&|#)([^=]+)\=([^&]+)"); // Extract the fields from the returned URL
                                MatchCollection matches = regex.Matches(urlFinal);
                                foreach (Match match in matches)
                                {
                                    if (match.Value.Contains("access_token"))
                                    {
                                        accessToken = match.Value.Replace("#access_token=", "");
                                    }
                                    else if (match.Value.Contains("token_type"))
                                    {
                                        tokenType = match.Value.Replace("&token_type=", "");
                                    }
                                    else if (match.Value.Contains("expires_in"))
                                    {
                                        ConnectionTokenExpirationTime = new TimeSpan(0, 0, int.Parse(match.Value.Replace("&expires_in=", "")));
                                    }
                                }

                                _spotifyWeb = new SpotifyWebAPI()
                                {
                                    TokenType = tokenType, AccessToken = accessToken
                                };
                                waitForAuthFinish.Set();        // Signal that the authentication finished

                                authWindowClosedByProgram = true;
                                authWindow.Close();
                            }
                            else
                            {
                                authWindow.WindowState = WindowState.Normal;
                                userInteractionWaiting = true;
                            }
                        };

                        authWindow.Closed += (sender, args) =>
                        {
                            waitForWindowClosed.Set();
                            if (!authWindowClosedByProgram)
                            {
                                waitForAuthFinish.Set();
                            }
                        };

                        webBrowser.Navigate(url);       // Navigate to spotifys login page to begin authentication. If credentials exist, you are redirected to an URL containing the access_token.
                        authWindow.ShowDialog();
                    }));
                    newThread.SetApartmentState(ApartmentState.STA);
                    newThread.Start();

                    waitForAuthFinish.WaitOne(timeout_ms);
                    if (userInteractionWaiting)
                    {
                        waitForWindowClosed.WaitOne(); waitForAuthFinish.WaitOne(timeout_ms);
                    }
                }
            });

            if (_spotifyWeb == null)
            {
                IsConnected = false; return(false);
            }
            else
            {
                _wasConnectionTokenExpiredEventRaised = false; IsConnected = true; return(true);
            }
        }