public SavedTaskExecutor(int id, DiscordClient client, SavedTaskInfo task, SharedData data, DatabaseContextBuilder dbb) { this.Id = id; this.client = client; this.TaskInfo = task; this.shared = data; this.dbb = dbb; }
public static async Task ScheduleAsync(SharedData shared, DatabaseContextBuilder dbb, DiscordClient client, SavedTaskInfo task) { SavedTaskExecutor texec = null; try { using (DatabaseContext db = dbb.CreateContext()) { if (task is SendMessageTaskInfo) { var dbtask = DatabaseReminder.FromSavedTaskInfo(task); db.Reminders.Add(dbtask); await db.SaveChangesAsync(); texec = new SavedTaskExecutor(dbtask.Id, client, task, shared, dbb); } else { var dbtask = DatabaseSavedTask.FromSavedTaskInfo(task); db.SavedTasks.Add(dbtask); await db.SaveChangesAsync(); texec = new SavedTaskExecutor(dbtask.Id, client, task, shared, dbb); } } texec.Schedule(); } catch (Exception e) { await texec?.UnscheduleAsync(); shared.LogProvider.Log(LogLevel.Warning, e); throw; } }