private void DoBeginSearch()
        {
            ProxySearchFeedback feedback = new ProxySearchFeedback();

            using (TaskItem taskItem = Context.Get <ITaskManager>().Create(Properties.Resources.SearchInitialization))
            {
                Engine.Application application = new ProxySearchEngineApplicationFactory().Create(taskItem, feedback);
                Task task = application.SearchAsync(Context.Get <CancellationTokenSource>());
            }
        }
Example #2
0
        private async void CheckProxyAsync(Proxy proxy)
        {
            using (TaskItem task = TaskManager.Create(Properties.Resources.CheckingProxyIfItWorks))
            {
                DisposeInitializationTaskIfRequired();

                await Task.Run(async() =>
                {
                    if (CancellationTokenSource.IsCancellationRequested)
                    {
                        return;
                    }

                    task.UpdateDetails(string.Format(Resources.ProxyCheckingIfAliveFormat, proxy));
                    BanwidthInfo bandwidth = null;

                    if (await Alive(proxy, task, () => bandwidth = new BanwidthInfo()
                    {
                        BeginTime = DateTime.Now
                    }, lenght =>
                    {
                        task.UpdateDetails(string.Format(Resources.ProxyGotFirstResponseFormat, proxy.AddressPort), Tasks.TaskStatus.Progress);
                        bandwidth.FirstTime = DateTime.Now;
                        bandwidth.FirstCount = lenght * 2;
                    }, lenght =>
                    {
                        bandwidth.EndTime = DateTime.Now;
                        bandwidth.EndCount = lenght * 2;
                    }, CancellationTokenSource))
                    {
                        if (CancellationTokenSource.IsCancellationRequested)
                        {
                            return;
                        }

                        task.UpdateDetails(string.Format(Resources.ProxyDeterminingProxyType, proxy.AddressPort), Tasks.TaskStatus.GoodProgress);

                        ProxyDetails proxyDetails = new ProxyDetails(await GetProxyDetails(proxy, task, CancellationTokenSource), UpdateProxyDetails);

                        task.UpdateDetails(string.Format(Resources.ProxyDeterminingLocationFormat, proxy.AddressPort), Tasks.TaskStatus.GoodProgress);

                        IPAddress proxyAddress = proxyDetails.Details.OutgoingIPAddress ?? proxy.Address;

                        CountryInfo countryInfo = await GeoIP.GetLocation(proxyAddress.ToString());

                        ProxyInfo proxyInfo = new ProxyInfo(proxy)
                        {
                            CountryInfo = countryInfo,
                            Details     = proxyDetails
                        };

                        if (bandwidth != null)
                        {
                            HttpDownloaderContainer.BandwidthManager.UpdateBandwidthData(proxyInfo, bandwidth);
                        }

                        proxyInfo.RatingData = await RatingManager.GetRatingDataAsync(proxyInfo);

                        ProxySearchFeedback.OnAliveProxy(proxyInfo);
                    }
                });
            }
        }