public void InitializeAsync(CancellationTokenSource cancellationTokenSource,
                                    ITaskManager taskManager,
                                    IHttpDownloaderContainer httpDownloaderContainer,
                                    IErrorFeedback errorFeedback,
                                    IProxySearchFeedback proxySearchFeedback,
                                    IGeoIP geoIP,
                                    IRatingManager ratingManager)
        {
            this.httpDownloaderContainer = httpDownloaderContainer;
            TaskItem taskItem = taskManager.Create(Resources.ConfigureProviderOfProxyDetails);

            taskItem.UpdateDetails(Resources.DetermineCurrentIPAddress);

            initializatinTask = httpDownloaderContainer.HttpDownloader
                                .GetContentOrNull(MyIPUrl, null, cancellationTokenSource)
                                .ContinueWith(task =>
            {
                try
                {
                    if (task.Result != null)
                    {
                        IPAddress.TryParse(task.Result.Trim(), out myIPAddress);
                    }
                }
                finally
                {
                    taskItem.Dispose();
                }
            });
        }
Example #2
0
        public virtual void InitializeAsync(CancellationTokenSource cancellationTokenSource,
                                            ITaskManager taskManager,
                                            IHttpDownloaderContainer httpDownloaderContainer,
                                            IErrorFeedback errorFeedback,
                                            IProxySearchFeedback proxySearchFeedback,
                                            IGeoIP geoIP,
                                            IRatingManager ratingManager)
        {
            CancellationTokenSource = cancellationTokenSource;
            TaskManager             = taskManager;
            HttpDownloaderContainer = httpDownloaderContainer;
            ErrorFeedback           = errorFeedback;
            ProxySearchFeedback     = proxySearchFeedback;
            GeoIP         = geoIP;
            RatingManager = ratingManager;

            IAsyncInitialization asyncInitialization = DetailsProvider as IAsyncInitialization;

            if (asyncInitialization != null)
            {
                asyncInitialization.InitializeAsync(cancellationTokenSource, taskManager, httpDownloaderContainer, errorFeedback, proxySearchFeedback, geoIP, ratingManager);
            }

            TaskManager.Tasks.CollectionChanged += (sender, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    StartCheckProxiesTaskIfRequired();
                }
            };
        }
        public void InitializeAsync(CancellationTokenSource cancellationTokenSource,
                                    ITaskManager taskManager,
                                    IHttpDownloaderContainer httpDownloaderContainer,
                                    IErrorFeedback errorFeedback,
                                    IProxySearchFeedback proxySearchFeedback,
                                    IGeoIP geoIP)
        {
            this.httpDownloaderContainer = httpDownloaderContainer;
            TaskItem taskItem = taskManager.Create(Resources.ConfigureProviderOfProxyDetails);

            taskItem.UpdateDetails(Resources.DetermineCurrentIPAddress);

            initializatinTask = httpDownloaderContainer.HttpDownloader
                                                       .GetContentOrNull(MyIPUrl, null, cancellationTokenSource)
                                                       .ContinueWith(task =>
                                                       {
                                                           try
                                                           {
                                                               if (task.Result != null)
                                                               {
                                                                   IPAddress.TryParse(task.Result.Trim(), out myIPAddress);
                                                               }
                                                           }
                                                           finally
                                                           {
                                                               taskItem.Dispose();
                                                           }
                                                       });
        }
Example #4
0
        public override void InitializeAsync(CancellationTokenSource cancellationTokenSource,
                                             ITaskManager taskManager,
                                             IHttpDownloaderContainer httpDownloaderContainer,
                                             IErrorFeedback errorFeedback,
                                             IProxySearchFeedback proxySearchFeedback,
                                             IGeoIP geoIP,
                                             IRatingManager ratingManager)
        {
            base.InitializeAsync(cancellationTokenSource, taskManager, httpDownloaderContainer, errorFeedback, proxySearchFeedback, geoIP, ratingManager);

            TaskItem taskItem = taskManager.Create(Resources.ConfiguringProxyChecker);

            try
            {
                taskItem.UpdateDetails(string.Format(Resources.DownloadingFormat, Url));

                initializatinTask = httpDownloaderContainer.HttpDownloader.GetContentOrNull(Url, null, cancellationTokenSource)
                                    .ContinueWith(task =>
                {
                    try
                    {
                        if (task.Result == null)
                        {
                            errorFeedback.SetException(new InvalidOperationException(string.Format(Resources.CannotDownloadContent, Url)));
                            cancellationTokenSource.Cancel();
                        }
                        else
                        {
                            analyzedText = AnalyzeText(task.Result);
                        }
                    }
                    finally
                    {
                        taskItem.Dispose();
                    }
                });
            }
            catch (TaskCanceledException)
            {
            }
        }