コード例 #1
0
ファイル: Application.cs プロジェクト: hepper/proxysearcher
        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);
            }
        }
コード例 #2
0
        protected override void OnActivate()
        {
            base.OnActivate();

            _proxyConfig = _transportService.GetProxyConfig() as TLProxyConfig76;
            if (_proxyConfig != null)
            {
                _isEnabled   = _proxyConfig.IsEnabled.Value;
                _useForCalls = _proxyConfig.UseForCalls.Value;

                var now = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now);
                Items.Clear();
                for (var i = 0; i < _proxyConfig.Items.Count; i++)
                {
                    var item = _proxyConfig.Items[i];
                    item.IsSelected = i == _proxyConfig.SelectedIndex.Value;
                    Items.Add(item);

                    if (CheckProxy(item))
                    {
                        item.Status = ProxyStatus.Connecting;
                        item.Ping   = null;
                        _proxyChecker.CheckAsync(item, 10.0,
                                                 (proxyItem, ping) => Execute.BeginOnUIThread(() =>
                        {
                            proxyItem.Proxy.CheckTime = now;
                            proxyItem.Proxy.Ping      = ping;
                            proxyItem.Proxy.Status    = item.Ping != null ? ProxyStatus.Available : ProxyStatus.Unavailable;

                            Set(_proxyConfig);
                        }));
                    }
                }
            }

            _transportService.TransportConnected  += OnTransportConnected;
            _transportService.TransportConnecting += OnTransportConnecting;
        }