/// <summary>
        /// Detects cloudflare protection type for a specific website.
        /// </summary>
        /// <param name="httpClient">HttpClient to use in detection process.</param>
        /// <param name="httpClientHandler">HttpClientHandler of the HttpClient.</param>
        /// <param name="targetUri">The uri of the website.</param>
        /// <param name="requireHttps">Https is required.</param>
        public static async Task <DetectResult> Detect(HttpClient httpClient, HttpClientHandler httpClientHandler, Uri targetUri, bool requireHttps = false)
        {
            DetectResult result = default(DetectResult);

            await _locker.LockAsync(async() =>
            {
                var cloudflareHandler = new CloudflareHandler(httpClientHandler);

                result = await Detect(httpClient, cloudflareHandler, targetUri, requireHttps);

                //cloudflareHandler.Dispose();
            });

            return(result);
        }
 public async Task DoTest()
 {
     await _locker.LockAsync(async() =>
     {
         // [asyn] calls can be used within this block
         // to handle a resource by one thread.
     });
 }
Exemplo n.º 3
0
        public async Task <IEnumerable <DAL.Client> > GetAll()
        {
            IEnumerable <DAL.Client> result = Enumerable.Empty <DAL.Client>();
            await _locker.LockAsync(async() =>
            {
                result = await _clientRepository.GetAllAsync();
            });

            return(result);
        }
Exemplo n.º 4
0
        public async Task <DAL.Manager> FindAsync(Guid managerId)
        {
            DAL.Manager result = new DAL.Manager();
            await _locker.LockAsync(async() =>
            {
                result = await _managerRepository.FindAsync(managerId);
            });

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Solves cloudflare challenge protecting a specific website.
        /// </summary>
        /// <param name="siteUrl">Uri of the website.</param>
        /// <param name="userAgent">The user-agent which will be used to solve the challenge.</param>
        /// <param name="proxy">Proxy to use while solving the challenge.</param>
        /// <param name="cancellationToken">CancellationToken to contol solving operation cancelling.</param>
        public async Task <SolveResult> Solve(Uri siteUrl, string userAgent, [Optional] IWebProxy proxy, [Optional] CancellationToken cancellationToken)
        {
            SolveResult result = default(SolveResult);

            await _locker.LockAsync(async() =>
            {
                this.userAgent    = userAgent;
                cloudflareHandler = new CloudflareHandler(userAgent);
                cloudflareHandler.HttpClientHandler.Proxy = proxy;
                httpClient             = new HttpClient(cloudflareHandler);
                this.siteUrl           = siteUrl;
                this.cancellationToken = cancellationToken;

                result = await Solve();

                httpClient.Dispose();
                captchaDetectResults.Clear();
            });

            return(result);
        }
Exemplo n.º 6
0
        public async Task <FlareSolverrResponse> Solve(HttpRequestMessage request)
        {
            FlareSolverrResponse result = null;

            await Locker.LockAsync(async() =>
            {
                HttpResponseMessage response;
                try
                {
                    _httpClient = new HttpClient();
                    response    = await _httpClient.PostAsync(_flareSolverrUri, GenerateFlareSolverrRequest(request));
                }
                catch (HttpRequestException e)
                {
                    throw new FlareSolverrException("Error connecting to FlareSolverr server: " + e);
                }
                catch (Exception e)
                {
                    throw new FlareSolverrException(e.ToString());
                }
                finally
                {
                    _httpClient.Dispose();
                }

                var resContent = await response.Content.ReadAsStringAsync();
                try
                {
                    result = JsonConvert.DeserializeObject <FlareSolverrResponse>(resContent);
                }
                catch (Exception)
                {
                    throw new FlareSolverrException("Error parsing response, check FlareSolverr version. Response: " + resContent);
                }

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new FlareSolverrException(result.Message);
                }
            });

            return(result);
        }
        private async Task GetAuthToken(DelegateResult <HttpResponseMessage> result, int retryCount)
        {
            if (_accessToken.Value != null && (int)DateTime.UtcNow.Subtract(_accessToken.Updated).TotalSeconds < _accessToken.ExpiresIn / 2)
            {
                return;
            }

            await _getTokenLocker.LockAsync(async() =>
            {
                if (_accessToken.Value != null && (int)DateTime.UtcNow.Subtract(_accessToken.Updated).TotalSeconds < _accessToken.ExpiresIn / 2)
                {
                    return;
                }

                await this.ActualizeToken(new ClientCredentialsTokenRequest
                {
                    ClientId     = _clientConfiguration.ClientId,
                    ClientSecret = _clientConfiguration.ClientSecret,
                    GrantType    = OidcConstants.GrantTypes.ClientCredentials
                });
            });
        }
        public async Task <LoginResponse> LoginAsync(P360LoginData p360LoginData)
        {
            LoginResponse loginResponse = null;

            if (Enum.TryParse <LoginMode>(p360LoginData.LoginMode, out LoginMode loginMode))
            {
                var service = new P360WebReference.ViewStarServiceSoapClient(EndpointConfiguration.ViewStarServiceSoap, p360LoginData.Url);

                await _locker.LockAsync(async() =>
                {
                    loginResponse = await service.LoginAsync(
                        p360LoginData.Username,
                        p360LoginData.Password,
                        p360LoginData.Group,
                        loginMode);
                    // This is a work-around due to P360 issue whereas simultaneous logins to not release licenses
                    await Task.Delay(TimeSpan.FromMilliseconds(_p360ServiceData.CurrentValue.TimeBetweenP360LoginsInMs));
                });
            }

            return(loginResponse);
        }