Beispiel #1
0
        public void Setup(FileInfo?loadFrom, FileInfo cache, CommandLineArgs cla)
        {
            System.Diagnostics.Debug.Assert(cache != null);
            CacheFile = cache;

            //assume that the data is up to date (this will be overridden by the value in the XML if we have a prior install)
            //If we have no prior install then the app has no shows and is by definition up-to-date
            latestMovieUpdateTime = new UpdateTimeTracker();
            latestTvUpdateTime    = new UpdateTimeTracker();

            LastErrorMessage = string.Empty;

            LoadOk = loadFrom is null || (CachePersistor.LoadMovieCache(loadFrom, this) && CachePersistor.LoadTvCache(loadFrom, this));
        }
Beispiel #2
0
        public static IEnumerable <ChangesListItem> GetChangesMovies(this TMDbClient client, CancellationToken cts, UpdateTimeTracker latestUpdateTime)
        {
            //We need to ask for updates in blocks of 7 days
            //We'll keep asking until we get to a date within 7 days of today
            //(up to a maximum of 52 - if you are this far behind then you may need multiple refreshes)

            List <ChangesListItem> updatesResponses = new List <ChangesListItem>();
            bool moreUpdates       = true;
            int  numberOfCallsMade = 0;

            for (DateTime time = latestUpdateTime.LastSuccessfulServerUpdateDateTime();
                 time <= DateTime.Now;
                 time = time.AddDays(14)
                 )
            {
                int maxPage = 1;
                for (int currentPage = 0; currentPage <= maxPage; currentPage++)
                {
                    if (cts.IsCancellationRequested)
                    {
                        throw new CancelledException();
                    }
                    SearchContainer <ChangesListItem>?response = client.GetMoviesChangesAsync(page: currentPage, startDate: time, cancellationToken: cts).Result;
                    numberOfCallsMade++;
                    maxPage = response.TotalPages;
                    updatesResponses.AddRange(response.Results);
                    if (numberOfCallsMade > MAX_NUMBER_OF_CALLS)
                    {
                        throw new TooManyCallsException();
                    }
                }
            }

            latestUpdateTime.RegisterServerUpdate(DateTime.Now.ToUnixTime());

            return(updatesResponses);
        }