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); }
public async Task ChangeScheduleState(int id, bool isActive) { var schedule = await ScheduleDBModel.FromDB(id, database_); schedule.IsActive = isActive; await schedule.AddOrUpdate(database_); await ReloadSchedule(); }
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 }); }
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(); }
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 }); } }
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; } }
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_); } }