Exemplo n.º 1
0
        private async Task SearchAsyncInternal(ISearchEngine searchEngine, CancellationTokenSource cancellationTokenSource)
        {
            try
            {
                using (TaskItem task = taskManager.Create(Resources.ProxySearching))
                {
                    while (true)
                    {
                        task.UpdateDetails(searchEngine.Status);

                        Uri uri = await searchEngine.GetNext(cancellationTokenSource);

                        if (uri == null || cancellationTokenSource.IsCancellationRequested)
                        {
                            return;
                        }

                        task.UpdateDetails(string.Format(Resources.DownloadingFormat, uri.ToString()));

                        string document = await GetDocumentAsyncOrNull(uri, cancellationTokenSource);

                        if (cancellationTokenSource.IsCancellationRequested)
                        {
                            return;
                        }

                        if (document == null)
                        {
                            continue;
                        }

                        List <Proxy> proxies = await proxyProvider.ParseProxiesAsync(uri, document);

                        if (proxies.Any())
                        {
                            checker.CheckAsync(proxies);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SetException(e);
            }
        }
Exemplo n.º 2
0
        private async Task SearchAsyncInternal(ISearchEngine searchEngine, CancellationTokenSource cancellationTokenSource)
        {
            try
            {
                using (TaskItem task = taskManager.Create(Resources.ProxySearching))
                {
                    while (true)
                    {
                        task.UpdateDetails(searchEngine.Status);

                        Uri uri = await searchEngine.GetNext(cancellationTokenSource);

                        if (uri == null || cancellationTokenSource.IsCancellationRequested)
                            return;

                        task.UpdateDetails(string.Format(Resources.DownloadingFormat, uri.ToString()));

                        string document = await GetDocumentAsyncOrNull(uri, cancellationTokenSource);

                        if (cancellationTokenSource.IsCancellationRequested)
                            return;

                        if (document == null)
                            continue;

                        List<Proxy> proxies = await proxyProvider.ParseProxiesAsync(uri, document);

                        if (proxies.Any())
                            checker.CheckAsync(proxies);
                    }
                }
            }
            catch (Exception e)
            {
                SetException(e);
            }
        }