Exemplo n.º 1
0
        private async Task NavigateAndCheck(CancellationToken stop)
        {
            _navigationStart = DateTime.UtcNow;
            var headers = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("User-Agent", "NHM/" + System.Windows.Forms.Application.ProductVersion),
                new KeyValuePair <string, string>("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"),
            };

            WebViewBrowser.NavigationCompleted += Browser_NavigationCompleted;
            WebViewBrowser.Navigate(new Uri(Links.LoginNHM), HttpMethod.Get, null, headers);
            Func <bool> isActive = () => !stop.IsCancellationRequested;

            while (isActive())
            {
                await TaskHelpers.TryDelay(TimeSpan.FromSeconds(1), stop);

                var ok = await CheckForBtc();

                if (!ok.HasValue)
                {
                    continue;
                }

                LoginSuccess = ok;
                Hide();
                return;
            }
        }
Exemplo n.º 2
0
        private void NavigateTo(string url)
        {
            var headers = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("User-Agent", _userAgent),
                new KeyValuePair <string, string>("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"),
            };

            WebViewBrowser.Navigate(new Uri(url), HttpMethod.Get, null, headers);
        }
Exemplo n.º 3
0
        private void LoginBrowser_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var oldIsVisible = e.OldValue as bool?;

            var wasVisible   = oldIsVisible.HasValue && oldIsVisible.Value;
            var wasInvisible = oldIsVisible.HasValue && !oldIsVisible.Value;

            if (wasVisible)
            {
                CancelNavigateAndCheck();
                LoadingPanel.Visibility = Visibility.Visible;
                WebViewGrid.Visibility  = Visibility.Collapsed;
                WebViewBrowser.Navigate("about:blank");
            }
            else if (wasInvisible)
            {
                Logger.Info("LoginBrowser", $"LoginBrowser_IsVisibleChanged e.OldValue={e.OldValue}; e.NewValue={e.NewValue}");
                _ = StartNavigateAndCheck();
            }
            else
            {
                Logger.Error("LoginBrowser", "Unexpected case");
            }
        }