예제 #1
0
        private async void Trigger(object sender, ElapsedEventArgs e)
        {
            var current = nextToPop_;

            if (!nextToPop_.Next.Equals(TimeSpan.Zero))
            {
                var s = await ScheduleDBModel.FromDB(nextToPop_.Id, database_);

                s.When += s.Interval;
                await s.AddOrUpdate(database_);
            }
            else
            {
                await database_.Database.DeleteAsync <ScheduleDBModel_>(current.Id);
            }
            if (App.IsUserWorking)
            {
                await Schedule(current.Workout, DateTime.Now + TimeSpan.FromMinutes(5));
                await ReloadSchedule();

                return;
            }
            await ReloadSchedule();
            await PushWorkout(current);
        }
예제 #2
0
        public async Task ChangeScheduleState(int id, bool isActive)
        {
            var schedule = await ScheduleDBModel.FromDB(id, database_);

            schedule.IsActive = isActive;
            await schedule.AddOrUpdate(database_);

            await ReloadSchedule();
        }
예제 #3
0
        private async Task <Notification> CreateLocalNotification(ScheduleDBModel model)
        {
            var workout = await database_.GetWorkout(model.WorkoutId, model.WorkoutType);

            return(new Notification
            {
                Id = model.Id,
                Next = model.Interval,
                TriggerTime = model.When,
                Workout = workout
            });
        }
예제 #4
0
        public async Task EditSchedule(int id, IWorkout workout, DateTime when, TimeSpan interval)
        {
            var schedule = await ScheduleDBModel.FromDB(id, database_);

            schedule.WorkoutId   = workout.Id;
            schedule.WorkoutType = workout.WorkoutType;
            schedule.When        = when;
            schedule.Interval    = interval;
            await schedule.AddOrUpdate(database_);

            await ReloadSchedule();
        }
예제 #5
0
        private async Task UpdateList()
        {
            var items = await ScheduleDBModel.FromDB(database_).ConfigureAwait(false);

            notifs_.Clear();
            foreach (var s in items)
            {
                notifs_.Add(new NotificationSchedulesManager
                {
                    Id          = s.Id,
                    IsOn        = s.IsActive,
                    Next        = s.Interval,
                    Workout     = await database_.GetWorkout(s.WorkoutId, s.WorkoutType).ConfigureAwait(false),
                    TriggerTime = s.When
                });
            }
        }
예제 #6
0
        private async Task ReloadSchedule()
        {
            timer_.Stop();
            var items = await ScheduleDBModel.FromDB(database_).ConfigureAwait(false);

            var next = (from i in items
                        where i.IsActive && i.When > DateTime.Now
                        orderby i.When ascending
                        select i).FirstOrDefault();

            if (next != null)
            {
                ScheduleNotification(await CreateLocalNotification(next));
            }
            else
            {
                nextToPop_ = null;
            }
        }
예제 #7
0
        private async Task ClearAndUpdateOverdue()
        {
            var overdue = (await ScheduleDBModel.FromDB(database_))
                          .Where(s => s.Interval == TimeSpan.Zero)
                          .ToList();
            var toClear  = overdue.Where(s => s.Interval == TimeSpan.Zero);
            var toUpdate = overdue.Except(toClear);

            foreach (var t in toClear)
            {
                await t.Delete(database_);
            }
            foreach (var s in toUpdate)
            {
                while (s.When < DateTime.Now)
                {
                    s.When += s.Interval;
                }
                await s.AddOrUpdate(database_);
            }
        }