Beispiel #1
0
        public ISet <string> getContent()
        {
            _progress = ProgressListener.getInstance();
            _progress.startReportingTaskProgress(_friendsCount);

            ISet <string> userIds = new HashSet <string>();

            var now            = DateTime.Now;
            var maxWaitingTime = now.AddMinutes(1);

            while ((userIds.Count < _friendsCount - 2) && DateTime.Now < maxWaitingTime)
            {
                HtmlDocument document = webBrowser.Document;
                var          links    = document.Links;
                foreach (HtmlElement link in links)
                {
                    string id = fetchFriendId(link);
                    if (id != null)
                    {
                        userIds.Add(id);
                    }
                }
                document = null;
                links    = null;
                _progress.reportTaskProgress(userIds.Count);
                Application.DoEvents();
            }
            //_progress.finishReporting(this);
            return(userIds);
        }
        public ISet <string> getContent()
        {
            _progress = ProgressListener.getInstance();
            ISet <string> userIds = new HashSet <string>();

            Stopwatch watch = new Stopwatch();

            watch.Start();
            int   lastChange             = 0;
            int   lastCount              = 0;
            int   millisWithoutChange    = 0;
            int   maxMillisWithoutChange = 3000;
            Regex friendIdPattern        = new Regex("(?<=(page|application)\\.php\\?id\\=)\\d+");

            _progress.startReportingTaskProgress(maxMillisWithoutChange);
            while (millisWithoutChange < maxMillisWithoutChange)
            {
                HtmlDocument document2 = webBrowser.Document;
                var          links     = document2.Links;
                foreach (HtmlElement link in links)
                {
                    addIfIdOrClickIfDynamicLink(link, userIds, friendIdPattern);
                }

                var inputs = document2.GetElementsByTagName("input");
                foreach (HtmlElement input in inputs)
                {
                    var profileid = input.GetAttribute("data-profileid");
                    if (profileid.Length != 0)
                    {
                        userIds.Add(profileid);
                    }
                }
                if (userIds.Count > lastCount)
                {
                    lastCount  = userIds.Count;
                    lastChange = watch.Elapsed.Seconds * 1000 + watch.Elapsed.Milliseconds;
                }
                document2 = null;
                inputs    = null;
                Application.DoEvents();
                millisWithoutChange = watch.Elapsed.Seconds * 1000 + watch.Elapsed.Milliseconds - lastChange;
                if (millisWithoutChange <= maxMillisWithoutChange)
                {
                    _progress.reportTaskProgress(millisWithoutChange);
                }
                else
                {
                    _progress.reportTaskProgress(maxMillisWithoutChange);
                }
            }
            watch.Stop();
            watch = null;
            //_progress.finishReporting(this);
            return(userIds);
        }
        private void downloading_Load(object sender, EventArgs e)
        {
            var pListener = ProgressListener.getInstance();

            pListener.TaskProgressBar    = taskProgress;
            pListener.QueueLV            = queue;
            pListener.TaskProfileId      = currentProfile;
            pListener.TaskTypeLabel      = currentType;
            pListener.TotalProgressBar   = totalProgress;
            pListener.TotalProgressLabel = totalProgressLabel;
            pListener.DoneLV             = completed;
            pListener.EstimatedLabel     = estimated;
            pListener.QueuedProfiles     = queuedProfiles;
        }