示例#1
0
        public override bool CheckCriteria(IRegistry registry, IRegistryResolver resolver)
        {
            HookInvokeCriteria baseCriteria = ParameterRegistry.Get <HookInvokeCriteria>("base_criteria");
            long targetRepetitions          = ParameterRegistry.Get <long>("target_repetitions");
            long currentRepititions         = ParameterRegistry.Get <long>("current_repetitions");
            bool withoutInterruption        = ParameterRegistry.Get <bool>("without_interruption");

            if (baseCriteria.CheckCriteria(registry, resolver))
            {
                currentRepititions++;
            }
            else if (withoutInterruption)
            {
                currentRepititions = 0;
            }

            bool fire = currentRepititions >= targetRepetitions;

            if (fire)
            {
                currentRepititions = 0;
            }

            ParameterRegistry["current_repetitions"] = currentRepititions;

            return(fire);
        }
示例#2
0
        /// <summary>
        /// Create a not criteria that inverts a certain criteria.
        /// </summary>
        /// <param name="criteria">The criteria to negate.</param>
        public NegateCriteria(HookInvokeCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            ParameterRegistry["criteria"] = criteria;
        }
示例#3
0
        /// <summary>
        /// Invoke this hook only when a certain hook invoke criteria is satisfied.
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public BaseHook On(HookInvokeCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            InvokeCriteria = criteria;

            return(this);
        }
示例#4
0
        /// <summary>
        /// Create a repeat criteria for a certain amount of repeated fires of a base criteria.
        /// </summary>
        /// <param name="repetitions">The number of repetitions that should be </param>
        /// <param name="criteria">The base criteria.</param>
        /// <param name="withoutInterruption">Indicate if the counter should be reset if the base criteria is not met.</param>
        public RepeatCriteria(HookInvokeCriteria criteria, long repetitions, bool withoutInterruption = false)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }
            if (repetitions <= 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(repetitions)} must be > 0.");
            }

            ParameterRegistry["base_criteria"]        = criteria;
            ParameterRegistry["target_repetitions"]   = repetitions;
            ParameterRegistry["current_repetitions"]  = 0L;
            ParameterRegistry["without_interruption"] = withoutInterruption;
        }
示例#5
0
 /// <summary>
 /// Create a combined multi or criteria with another criteria that fires when all of them fire (boolean AND).
 /// </summary>
 /// <param name="criteria">The other criteria.</param>
 /// <returns>A multi or criteria combining this and another criteria with boolean OR.</returns>
 public virtual MultiAndCriteria And(HookInvokeCriteria criteria)
 {
     return(new MultiAndCriteria(this, criteria));
 }
示例#6
0
 /// <summary>
 /// Create a combined multi or criteria with another criteria that fires when either of them fires (boolean OR).
 /// </summary>
 /// <param name="criteria">The other criteria.</param>
 /// <returns>A multi or criteria combining this and another criteria with boolean OR.</returns>
 public virtual MultiOrCriteria Or(HookInvokeCriteria criteria)
 {
     return(new MultiOrCriteria(this, criteria));
 }
示例#7
0
        public override MultiAndCriteria And(HookInvokeCriteria criteria)
        {
            ParameterRegistry.Get <IList <HookInvokeCriteria> >("criterias").Add(criteria);

            return(this);
        }
示例#8
0
 /// <summary>
 /// Check if this criteria functionally equals another criteria.
 /// Note: The base implementation checks for same type and parameter registry.
 /// </summary>
 /// <param name="other">The other criteria.</param>
 /// <returns>A boolean indicating if this criteria functionally equals another criteria.</returns>
 internal virtual bool FunctionallyEquals(HookInvokeCriteria other)
 {
     return(GetType() == other.GetType() && ParameterRegistry.RegistryContentEquals(other.ParameterRegistry));
 }