Exemple #1
0
        private async Task <int> GetContentsOfDaySeparatelyAsync(DateInfo date, ContentsSet contentsSet, CancellationTokenSource cancel, int sum)
        {
            DebugUtil.Log("Loading: " + date.Title);

            var count = await AvContentApi.GetContentCountAsync(new CountingTarget
            {
                Grouping = ContentGroupingMode.Date,
                Uri      = date.Uri,
                Types    = ContentsSetToTypes(contentsSet),
            }).ConfigureAwait(false);

            DebugUtil.Log(count.NumOfContents + " contents exist.");

            var loops  = count.NumOfContents / CONTENT_LOOP_STEP + (count.NumOfContents % CONTENT_LOOP_STEP == 0 ? 0 : 1);
            var loaded = 0;

            for (var i = 0; i < loops; i++)
            {
                if (loaded + sum > MAX_AUTO_LOAD_THUMBNAILS)
                {
                    break;
                }

                var contents = await GetContentsOfDayAsync(date, i *CONTENT_LOOP_STEP, CONTENT_LOOP_STEP, contentsSet).ConfigureAwait(false);

                if (cancel != null && cancel.IsCancellationRequested)
                {
                    DebugUtil.Log("Loading task cancelled");
                    OnCancelled();
                    break;
                }

                loaded += contents.Count;
                DebugUtil.Log(contents.Count + " contents fetched");

                OnPartLoaded(contents.Select(content => new Thumbnail(content, Udn)).ToList());
            }

            if (loaded < count.NumOfContents)
            {
                var remaining = new RemainingContentsHolder(date, Udn, loaded, count.NumOfContents - loaded);
                var list      = new List <Thumbnail>();
                list.Add(remaining);
                OnPartLoaded(list);
            }

            return(loaded);
        }