public void OnEndImpulse(ImpulseHandle handle)
 {
     if (Enabled.Contains((ImpulseType)Convert.ChangeType(handle.Impulse, typeof(ImpulseType))))
     {
         writer.WriteLine("- {0} {1}:\n  ({2}, {3})", handle.Impulse, handle.GetHashCode(), handle.Source, handle.Data);
     }
 }
        /// <summary>
        /// Will be executed frequently to check whether this task/subtree is ready to run.
        /// </summary>
        /// <returns>Returns true if the task/subtree is ready and can be started; otherwise, false.</returns>
        public override bool CheckConditions()
        {
            if (active != null)
            {
                return(true);
            }

            do
            {
                if (impulses.Count == 0)
                {
                    active = null;
                    return(false);
                }

                active = impulses[0];
                impulses.Remove(active);
                string sourceName = sourceVariable;
                if (sourceName.Length > 0)
                {
                    Context.Variables[sourceName] = active.Source;
                }
                string dataName = dataVariable;
                if (dataName.Length > 0)
                {
                    Context.Variables[dataName] = active.Data;
                }
            } while (!Subtask.CheckConditions());

            return(true);
        }
        /// <summary>
        /// IImpulseHandler implementation. Will be executed when an impulse becomes active.
        /// </summary>
        /// <param name="handle">The impulse handle</param>
        public void OnBeginImpulse(ImpulseHandle handle)
        {
            impulses.Add(handle);

            if (impulses.Count > 256)
            {
                Context.Log.Warning("A DuringImpulse Task is accumulating a lot of unhandled impulses of type {0}", impulse);
            }
        }
        /// <summary>
        /// IImpulseHandler implementation. Will be executed when an impulse becomes active.
        /// </summary>
        /// <param name="handle">The impulse handle</param>
        public void OnBeginImpulse(ImpulseHandle handle)
        {
            for (int i = 0; i < impulses.Count; i++)
            {
                if (impulses[i].Impulse.Equals(handle.Impulse) &&
                    impulses[i].Source.Equals(handle.Source) &&
                    impulses[i].Data.Equals(handle.Data))
                {
                    impulses[i] = handle; // replace old identical impulse with new one... is this okay? :/
                    return;
                }
            }

            impulses.Add(handle);

            if (impulses.Count > 256)
            {
                Context.Log.Warning("An OnImpulse Task is accumulating a lot of unhandled impulses of type {0}", impulse);
            }
        }
 /// <summary>
 /// IImpulseHandler implementation. Will be executed when an impulse becomes inactive.
 /// </summary>
 /// <param name="handle">The impulse handle</param>
 public void OnEndImpulse(ImpulseHandle handle)
 {
     impulses.Remove(handle);
 }
 /// <summary>
 /// Will be executed when the task is stopped or has finished.
 /// </summary>
 public override void End()
 {
     base.End();
     active = null;
 }
 /// <summary>
 /// IImpulseHandler implementation. Will be executed when an impulse becomes inactive.
 /// </summary>
 /// <param name="handle">The impulse handle</param>
 public void OnEndImpulse(ImpulseHandle handle)
 {
 }