private async Task SendTaskConfirmationRequestAsync(Node owner, RoutineTask task, CancellationToken cancellationToken) { var select = new Select { Text = $"{task.Name} " + $"{Settings.Phraseology.During} " + $"{task.Time.GetValueOrDefault().Name().ToLower()} " + $"{task.Days.GetValueOrDefault().Name().ToLower()}!", Options = new[] { new SelectOption { Text = Settings.Phraseology.Confirm, Value = new PlainText { Text = Settings.Commands.Confirm }, Order = 1 }, new SelectOption { Text = Settings.Phraseology.Cancel, Value = new PlainText { Text = Settings.Phraseology.Cancel }, Order = 2 } } }; await Sender.SendMessageAsync(select, owner, cancellationToken); }
// 2. connect to the data public object ConnectData(int topicId, ref Array Strings, ref bool GetNewValues) { if (_tasks.ContainsKey(topicId)) { // return "rtd task already set"; return(DateTime.Now); } if (Strings.Length < 2) { throw new Exception("input parameters should at least contains interval and function names"); } double interval = Double.Parse((string)Strings.GetValue(0)); string functionName = (string)Strings.GetValue(1); List <string> parameters = new List <string>(); if (Strings.Length > 2) { for (int i = 2; i < Strings.Length; ++i) { parameters.Add((string)Strings.GetValue(i)); } } RoutineTask task = new RoutineTask(interval, functionName, parameters); _tasks.Add(topicId, task); //_timer.Interval = (int)Strings.GetValue(0); _timer.Start(); return(_tasks[topicId].ToString()); }
IEnumerator RunDelayAsync(Action callback, float seconds, RoutineTask task) { yield return(new WaitForSecondsRealtime(seconds)); if (!task.IsDisposed) { callback(); } }
public void RunRoutine(IEnumerator routine) { var task = new RoutineTask(); task.Routine = routine; lock (pendingRoutine) { pendingRoutine.Enqueue(task); hasRoutine = true; } }
private string GetDelayEmoticon(RoutineTask task) { var days = task.Delay.TotalDays; if (task.Days.GetValueOrDefault() == RoutineTaskDaysValue.WeekEnds) { if (days > 35) { return("😢"); } if (days > 28) { return("😞"); } if (days > 21) { return("😳"); } if (days > 14) { return("😧"); } if (days > 7) { return("😮"); } return("😎"); } else { if (days > 28) { return("😢"); } if (days > 21) { return("😞"); } if (days > 14) { return("😳"); } if (days > 7) { return("😧"); } if (days > 2) { return("😮"); } return("😎"); } }
public IDisposable RunDelay(Action callback, float seconds = 5) { var task = new RoutineTask(); task.Routine = RunDelayAsync(callback, seconds, task); lock (pendingRoutine) { pendingRoutine.Enqueue(task); hasRoutine = true; } return(task); }
private async Task <bool> MarkTaskAsCompletedAsync(Node owner, Document content, CancellationToken cancellationToken) { var externalTaskId = RoutineTask.ExtractTaskIdFromCompleteCommand(((PlainText)content)?.Text); long taskId; long.TryParse(externalTaskId, out taskId); var routine = await GetRoutineAsync(owner, false, cancellationToken); var task = routine.Tasks.FirstOrDefault(t => t.Id == taskId); if (task == null) { return(false); } task.LastTime = DateTimeOffset.Now; await SetRoutineAsync(routine, cancellationToken); return(true); }
private async Task <RoutineTask> PrepareTaskToBeDeletedAsync(Node owner, Document content, CancellationToken cancellationToken) { var externalTaskId = RoutineTask.ExtractTaskIdFromDeleteCommand(((PlainText)content)?.Text); long taskId; long.TryParse(externalTaskId, out taskId); var routine = await GetRoutineAsync(owner, false, cancellationToken); var task = routine.Tasks.FirstOrDefault(t => t.Id == taskId); if (task == null) { return(null); } // Put the task to be deleted at the end of the array routine.Tasks = routine.Tasks.Where(t => t != task).Concat(new[] { task }).ToArray(); task.LastTime = DateTimeOffset.Now; await SetRoutineAsync(routine, cancellationToken); return(task); }