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();
                }
            });
        }
Exemplo n.º 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();
                                                           }
                                                       });
        }
Exemplo n.º 4
0
        public Application(ISearchEngine searchEngine,
                           IProxyChecker checker,
                           IHttpDownloaderContainer httpDownloaderContainer,
                           IGeoIP geoIP = null,
                           IProxyProvider proxyProvider = null,
                           ITaskManager taskManager = null)
        {
            this.searchEngine = searchEngine;
            this.checker = checker;
            this.httpDownloaderContainer = httpDownloaderContainer;

            this.proxyProvider = proxyProvider ?? new ProxyProvider();
            this.geoIP = geoIP ?? new TurnOffGeoIP();
            this.taskManager = taskManager ?? new TaskManager();
        }
Exemplo n.º 5
0
        public Application(ISearchEngine searchEngine,
                           IProxyChecker checker,
                           IHttpDownloaderContainer httpDownloaderContainer,
                           IGeoIP geoIP = null,
                           IRatingManager ratingManager = null,
                           IProxyProvider proxyProvider = null,
                           ITaskManager taskManager     = null)
        {
            this.searchEngine            = searchEngine;
            this.checker                 = checker;
            this.httpDownloaderContainer = httpDownloaderContainer;

            this.proxyProvider = proxyProvider ?? new ProxyProvider();
            this.geoIP         = geoIP ?? new TurnOffGeoIP();
            this.taskManager   = taskManager ?? new TaskManager();
            this.ratingManager = ratingManager ?? new DisabledRatingManager();
        }
Exemplo n.º 6
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)
            {
            }
        }