Esempio n. 1
0
        public void UpdateUserActivity(UserActivity userActivity)
        {
            var recentlyWatchedEpisodeUrls = new HashSet <string>();

            this.WebAccessor.NavigateTo(Config.Page.History.Url);
            const string loadMoreXPath = Config.Page.History.ElementLoadMoreLinkXPath;
            int          pageCount     = 0;

            do
            {
                BotDetectionMitigation.RandomizedWait();
                Trace.TraceInformation("[UpdateUserActivity] page count = {0}", ++pageCount);
            }while (pageCount < Config.Task.UpdateUserActivity.MaxPageCount && this.WebAccessor.ElementExists(loadMoreXPath) && this.WebAccessor.Click(loadMoreXPath));

            var watchedVideoLinks = this.WebAccessor.Driver.FindElementsByXPath(Config.Page.History.ElementWatchedVideoLinksXPath);

            for (int i = 0; i < watchedVideoLinks.Count; i++)
            {
                var watchedVideoUrl = watchedVideoLinks[i].GetAttribute("href");
                Trace.TraceInformation("[UpdateUserActivity] processing {0} of {1} [{2}]", i + 1, watchedVideoLinks.Count, watchedVideoUrl);
                recentlyWatchedEpisodeUrls.Add(watchedVideoUrl);
            }

            userActivity.AddWatchedEpisodesMostRecentFirst(recentlyWatchedEpisodeUrls);
        }