private static async Task DoFetch(Random rng, IUserInfo userInfo, DownloadForm downloadWindow, CancellationToken cancellationToken)
        {
            List <IVideoInfo> videos = new List <IVideoInfo>();

            while (true)
            {
                downloadWindow.AddStatusMessage("Fetching " + userInfo.ToString() + "...");

                try {
                    FetchReturnValue fetchReturnValue;
                    int Offset = 0;
                    do
                    {
                        try {
                            await Task.Delay(rng.Next(55000, 95000), cancellationToken);
                        } catch (Exception) { }
                        if (cancellationToken.IsCancellationRequested)
                        {
                            break;
                        }
                        fetchReturnValue = await userInfo.Fetch(Offset, true);

                        Offset += fetchReturnValue.VideoCountThisFetch;
                        if (fetchReturnValue.Success)
                        {
                            videos.AddRange(fetchReturnValue.Videos);
                        }
                    } while (fetchReturnValue.Success && fetchReturnValue.HasMore);
                    break;
                } catch (Exception ex) {
                    downloadWindow.AddStatusMessage("Error during " + userInfo.ToString() + ": " + ex.ToString());
                    break;
                }
            }

            if (!cancellationToken.IsCancellationRequested)
            {
                try {
                    await Task.Delay(rng.Next(55000, 95000), cancellationToken);
                } catch (Exception) { }
            }
            downloadWindow.AddStatusMessage("Fetched " + videos.Count + " items from " + userInfo.ToString() + ".");
            DownloadFetched(videos, downloadWindow);
        }
Example #2
0
        private static async Task <FetchReturnValue> Fetch(IUserInfo userInfo, int offset, bool flat)
        {
            FetchReturnValue frv = await userInfo.Fetch(offset, flat);

            userInfo.LastRefreshedOn = DateTime.UtcNow;

            if (!frv.Success)
            {
                return(frv);
            }

            if (userInfo.Persistable)
            {
                UserInfoPersister.AddOrUpdate(userInfo);
                UserInfoPersister.Save();
            }

            return(frv);
        }