Exemplo n.º 1
0
        public async Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = new CancellationToken())
        {
            if (options == null)
            {
                throw new ArgumentException("Options cannot be null.", nameof(options));
            }

            using var listener = new LoopbackHttpListener(Port, _path);
            OpenBrowser.OpenBrowser(options.StartUrl, UserName, Password);

            try
            {
                var result = await listener.WaitForCallbackAsync().ConfigureAwait(false);

                if (string.IsNullOrWhiteSpace(result))
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.UnknownError, Error = "Empty response."
                    });
                }

                return(new BrowserResult {
                    Response = result, ResultType = BrowserResultType.Success
                });
            }
            catch (TaskCanceledException ex)
            {
                return(new BrowserResult {
                    ResultType = BrowserResultType.Timeout, Error = ex.Message
                });
            }
        }
Exemplo n.º 2
0
        public async Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var listener = new LoopbackHttpListener(Port, _path))
            {
                openBrowser.OpenBrowser(options.StartUrl, userName, password);

                try
                {
                    var result = await listener.WaitForCallbackAsync();

                    if (string.IsNullOrWhiteSpace(result))
                    {
                        return(new BrowserResult
                        {
                            ResultType = BrowserResultType.UnknownError, Error = "Empty response."
                        });
                    }

                    return(new BrowserResult {
                        Response = result, ResultType = BrowserResultType.Success
                    });
                }
                catch (TaskCanceledException ex)
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.Timeout, Error = ex.Message
                    });
                }
                catch (Exception ex)
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.UnknownError, Error = ex.Message
                    });
                }
            }
        }