/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public virtual ERunStatus Run(Bullet bullet) { //run all the child tasks TaskFinished = true; for (int i = 0; i < ChildTasks.Count; i++) { //is the child task finished running? if (!ChildTasks[i].TaskFinished) { //Run the child task... ERunStatus childStaus = ChildTasks[i].Run(bullet); if (childStaus == ERunStatus.Stop) { //The child task is paused, so it is not finished TaskFinished = false; return(childStaus); } else if (childStaus == ERunStatus.Continue) { //child task needs to do some more work TaskFinished = false; } } } return(TaskFinished ? ERunStatus.End : ERunStatus.Continue); }
/// <summary> /// Run this task and all subtasks against a bullet /// This is called once a frame during runtime. /// </summary> /// <returns>ERunStatus: whether this task is done, paused, or still running</returns> /// <param name="bullet">The bullet to update this task against.</param> public override ERunStatus Run(Bullet bullet) { //run the action until we hit the limit while (RepeatNum < RepeatNumMax) { ERunStatus runStatus = base.Run(bullet); //What was the return value from running all teh child actions? switch (runStatus) { case ERunStatus.End: { //The actions completed successfully, initialize everything and run it again RepeatNum++; //reset all the child tasks foreach (BulletMLTask task in ChildTasks) { task.InitTask(bullet); } } break; case ERunStatus.Stop: { //Something in the child tasks paused this action return(runStatus); } default: { //One of the child tasks needs to keep running next frame return(ERunStatus.Continue); } } } //if it gets here, all the child tasks have been run the correct number of times TaskFinished = true; return(ERunStatus.End); }
/// <summary> /// Updates the run status, the audit table, and sends a status update event /// </summary> /// <param name="newStatus"></param> /// <param name="message"></param> /// <param name="exception"></param> /// <returns></returns> public async Task <bool> SetRunStatus(ERunStatus newStatus, string message, Exception exception, CancellationToken cancellationToken) { try { RunStatus = newStatus; if (!string.IsNullOrEmpty(message)) { Message = message; } if (exception != null) { // pull out the full details of the exception. var properties = exception.GetType().GetProperties(); var fields = properties .Select(property => new { property.Name, Value = property.GetValue(exception, null) }) .Select(x => string.Format( "{0} = {1}", x.Name, x.Value != null ? x.Value.ToString() : string.Empty )); ExceptionDetails = string.Join("\n", fields); } if (RunStatus == ERunStatus.Abended || RunStatus == ERunStatus.Finished || RunStatus == ERunStatus.FinishedErrors || RunStatus == ERunStatus.Cancelled) { EndTime = DateTime.Now; OnFinish?.Invoke(this); } if (_auditConnection != null) { LastUpdateTime = DateTime.Now; try { await _auditConnection.UpdateAudit(this, cancellationToken); } catch (Exception ex) { RunStatus = ERunStatus.Abended; Message = Message ?? "" + "\n" + $"An error occurred when updating the audit table of connection {_auditConnection.Name}. {ex.Message}"; return(false); } } OnStatusUpdate?.Invoke(this); return(true); } catch (Exception ex) { RunStatus = ERunStatus.Abended; Message = Message ?? "" + "\n" + $"An error occurred when updating run status. {ex.Message}"; return(false); } }