protected async override Task Run() { if (_sub == null && !SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub)) { PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName); IsDone = true; return; } using (SubRoutineComposite.Activate(_sub)) { try { if (_sub.IsDone) { _sub.Reset(); } await _sub; } finally { IsDone = _sub.IsDone; } } }
private async Task <bool> SubRoutineExecutor() { using (SubRoutineComposite.Activate(_sub)) { if (_sub.IsDone) { _sub.Reset(); } return(await _sub); } }
protected async override Task Run() { try { if (!SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub)) { PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName); return; } _treeHookStub = new ActionRunCoroutine(ctx => SubRoutineExecutor()); TreeHooks.Instance.InsertHook(TreeHookName, 0, _treeHookStub); BotEvents.Profile.OnNewOuterProfileLoaded += ProfileOnOnNewOuterProfileLoaded; BotEvents.OnBotStopped += BotEvents_OnBotStopped; PBLog.Debug("Attached the '{0}' SubRoutine to the {1} TreeHook", SubRoutineName, TreeHookName); } finally { _ranonce = true; } }
public SubRoutineExecutor(SubRoutineComposite subroutine) { _subroutine = subroutine; subroutine.IsActive = true; }
public static bool GetSubRoutineMyName(string subRoutineName, out SubRoutineComposite subRoutine) { subRoutine = GetSubRoutineMyNameInternal(subRoutineName, ProfessionbuddyBot.Instance.Branch); return(subRoutine != null); }
/// <summary> /// Activates the specified sub routine. A subroutine needs to be activated before it can be executed /// </summary> /// <param name="subRoutine">The sub routine.</param> public static IDisposable Activate(SubRoutineComposite subRoutine) { return(new SubRoutineExecutor(subRoutine)); }