Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
 private async Task <bool> SubRoutineExecutor()
 {
     using (SubRoutineComposite.Activate(_sub))
     {
         if (_sub.IsDone)
         {
             _sub.Reset();
         }
         return(await _sub);
     }
 }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
 public SubRoutineExecutor(SubRoutineComposite subroutine)
 {
     _subroutine         = subroutine;
     subroutine.IsActive = true;
 }
Ejemplo n.º 5
0
 public static bool GetSubRoutineMyName(string subRoutineName, out SubRoutineComposite subRoutine)
 {
     subRoutine = GetSubRoutineMyNameInternal(subRoutineName, ProfessionbuddyBot.Instance.Branch);
     return(subRoutine != null);
 }
Ejemplo n.º 6
0
 /// <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));
 }