private async Task Run()
        {
            while (true)
            {
                try {
                    await Task.Delay(3000, CancelToken);
                } catch (Exception) { }

                if (CancelToken.IsCancellationRequested)
                {
                    return;
                }

                try {
                    IUserInfo earliestUserInfo = null;
                    lock (ContainerLock) {
                        foreach (IUserInfo u in UserInfos)
                        {
                            if (u.AutoDownload && (earliestUserInfo == null || u.LastRefreshedOn < earliestUserInfo.LastRefreshedOn))
                            {
                                earliestUserInfo = u;
                            }
                        }
                    }

                    if (earliestUserInfo != null)
                    {
                        DateTime earliestStartTime = earliestUserInfo.LastRefreshedOn.AddHours(7.0);
                        DateTime now = DateTime.UtcNow;
                        if (earliestStartTime <= now)
                        {
                            try {
                                await DoFetch(RNG, earliestUserInfo, Form, CancelToken);
                            } finally {
                                if (!CancelToken.IsCancellationRequested)
                                {
                                    earliestUserInfo.LastRefreshedOn = now;
                                    if (earliestUserInfo.Persistable)
                                    {
                                        UserInfoPersister.AddOrUpdate(earliestUserInfo);
                                        UserInfoPersister.Save();
                                    }
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                    Form.AddStatusMessage("Error during fetch: " + ex.ToString());
                }
            }
        }
Esempio n. 2
0
        private void checkBoxAutoDownload_CheckedChanged(object sender, EventArgs e)
        {
            IUserInfo u = comboBoxKnownUsers.SelectedItem as IUserInfo;

            if (u != null)
            {
                if (u.AutoDownload != checkBoxAutoDownload.Checked)
                {
                    u.AutoDownload = checkBoxAutoDownload.Checked;
                    if (u.Persistable)
                    {
                        UserInfoPersister.AddOrUpdate(u);
                        UserInfoPersister.Save();
                    }
                }
            }
        }
Esempio n. 3
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);
        }