Ejemplo n.º 1
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var iterable = _iterable.Compose(
                input,
                parentPath);

            if (!iterable.IsSuccess)
            {
                throw new NotImplementedException("handle possible problems");
            }

            if (iterable.Value is JArray array)
            {
                var results = new List <JToken>();

                foreach (var jToken in array)
                {
                    var scopedInput = GetScopedInput(
                        input,
                        jToken);

                    var conditionResult = _condition.Evaluate(
                        scopedInput);

                    if (!conditionResult.IsSuccess)
                    {
                        throw new NotImplementedException("handle possible problems");
                    }

                    if (conditionResult.Value)
                    {
                        results.Add(jToken);
                    }
                }

                return(new CorrectComposition(
                           new JArray(results.ToArray())));
            }
            else
            {
                var scopedInput = GetScopedInput(
                    input,
                    iterable.Value);

                var conditionResult = _condition.Evaluate(
                    scopedInput);


                if (!conditionResult.IsSuccess)
                {
                    throw new NotImplementedException("handle possible problems");
                }

                return(new CorrectComposition(
                           new JArray(iterable.Value)));
            }
        }
        public Option <PickIndexElementComposition> Compose(
            JObject input,
            Path parentPath,
            int index)
        {
            var conditionResult = _condition.Evaluate(
                input);

            if (!conditionResult.IsSuccess)
            {
                return(new PickIndexElementComposition.Failure(
                           index,
                           new PickIndexElementCompositionFailed(
                               innerErrors: conditionResult.Errors)));
            }

            if (!conditionResult.Value)
            {
                return(Option <PickIndexElementComposition> .None);
            }

            var composition = _valueComposer.Compose(
                input,
                parentPath);

            if (composition.GetDecimal().IsInteger(out var value))
            {
                return(new PickIndexElementComposition.Success(
                           index,
                           new[] { value }));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 3
0
        public Option <ElementComposition> Compose(
            JObject input,
            Path parentPath,
            int index)
        {
            var conditionResult = _condition.Evaluate(
                input);

            if (!conditionResult.IsSuccess)
            {
                return(ConditionFailure(
                           parentPath,
                           index,
                           conditionResult));
            }

            if (!conditionResult.Value)
            {
                return(Option <ElementComposition> .None);
            }

            return(_elementComposer.Compose(
                       input,
                       parentPath,
                       index));
        }
Ejemplo n.º 4
0
 public void Execute()
 {
     if (_condition.Evaluate())
     {
         _command.Start();
     }
 }
Ejemplo n.º 5
0
    public bool React()
    {
        if (!Condition.Evaluate())
        {
            return(false);
        }

        // Go through all the Reactions and call their React function.
        for (int i = 0; i < reactions.Length; i++)
        {
            // The DelayedReaction hides the Reaction.React function.
            // Note again this is mainly done for demonstration purposes.
            DelayedReaction delayedReaction = reactions[i] as DelayedReaction;

            if (delayedReaction)
            {
                delayedReaction.React(GameObject);
            }
            else
            {
                reactions[i].React(GameObject);
            }
        }
        return(true);
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Check if the user meets audience conditions to be in experiment or not
        /// </summary>
        /// <param name="config">ProjectConfig Configuration for the project</param>
        /// <param name="experiment">Experiment Entity representing the experiment</param>
        /// <param name="userAttributes">Attributes of the user. Defaults to empty attributes array if not provided</param>
        /// <returns>true if the user meets audience conditions to be in experiment, false otherwise.</returns>
        public static bool IsUserInExperiment(ProjectConfig config, Experiment experiment, UserAttributes userAttributes, ILogger logger)
        {
            if (userAttributes == null)
            {
                userAttributes = new UserAttributes();
            }

            ICondition expConditions = null;

            if (experiment.AudienceConditionsList != null)
            {
                expConditions = experiment.AudienceConditionsList;
                logger.Log(LogLevel.DEBUG, $@"Evaluating audiences for experiment ""{experiment.Key}"": {experiment.AudienceConditionsString}");
            }
            else
            {
                expConditions = experiment.AudienceIdsList;
                logger.Log(LogLevel.DEBUG, $@"Evaluating audiences for experiment ""{experiment.Key}"": {experiment.AudienceIdsString}");
            }

            // If there are no audiences, return true because that means ALL users are included in the experiment.
            if (expConditions == null)
            {
                return(true);
            }

            var result     = expConditions.Evaluate(config, userAttributes, logger).GetValueOrDefault();
            var resultText = result.ToString().ToUpper();

            logger.Log(LogLevel.INFO, $@"Audiences for experiment ""{experiment.Key}"" collectively evaluated to {resultText}");
            return(result);
        }
Ejemplo n.º 7
0
 public virtual bool Evaluate(IDelegateExecution execution)
 {
     if (Condition != null)
     {
         return(Condition.Evaluate(execution, execution));
     }
     throw new InvalidOperationException("Condtional event must have a condition!");
 }
Ejemplo n.º 8
0
        public ConditionResult Evaluate(JObject input)
        {
            var innerResult = _innerCondition.Evaluate(
                input);

            return(innerResult.Select(
                       (success) => new ConditionResult.Success(!success.Value),
                       (failure) => failure));
        }
Ejemplo n.º 9
0
        private void OnPreviewInvoke(object sender, PreviewInvokeEventArgs e)
        {
            ICondition condition = Condition;

            if (condition != null)
            {
                e.Cancelling = !condition.Evaluate();
            }
        }
Ejemplo n.º 10
0
 public bool Evaluate()
 {
     if (srchById.Evaluate() && srchByName.Evaluate())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// <see cref="IInstruction.Execute" />
 /// </summary>
 public void Execute()
 {
     if (_ifCondition.Evaluate())
     {
         _ifInstruction.Execute();
     }
     else if (_elseInstruction != null)
     {
         _elseInstruction.Execute();
     }
 }
Ejemplo n.º 12
0
        public void Execute()
        {
            if (!_condition.Evaluate())
            {
                return;
            }

            foreach (IOperation op in _operations)
            {
                op.Execute();
            }
        }
Ejemplo n.º 13
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var conditionResult = _condition.Evaluate(input);

            return(conditionResult.Value
                ? _ifComposer.Compose(
                       input,
                       parentPath)
                : _elseComposer.Compose(
                       input,
                       parentPath));
        }
Ejemplo n.º 14
0
        public void Execute()
        {
            IEnumerable <IOperation> operations = _condition.Evaluate() ? _operationsThen : _operationsElse;

            if (operations == null)
            {
                return;
            }

            foreach (IOperation op in operations)
            {
                op.Execute();
            }
        }
Ejemplo n.º 15
0
        public Composition Compose(
            JObject input,
            Path parentPath)
        {
            var condition = _condition.Evaluate(
                input);

            if (condition.IsSuccess)
            {
                return(new CorrectComposition(
                           new JValue(condition.Value)));
            }

            return(new IncorrectComposition(
                       parentPath,
                       condition.Errors));
        }
Ejemplo n.º 16
0
        public ConditionResult Evaluate(JObject input)
        {
            var leftResult = _left.Evaluate(
                input);

            return(leftResult.Select(
                       (leftSuccess) =>
            {
                if (leftSuccess.Value)
                {
                    return new ConditionResult.Success(true);
                }

                return _right.Evaluate(
                    input);
            },
                       (failure) => failure));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Check if the user meets audience conditions to be in experiment or not
        /// </summary>
        /// <param name="config">ProjectConfig Configuration for the project</param>
        /// <param name="experiment">Experiment Entity representing the experiment</param>
        /// <param name="userAttributes">Attributes of the user. Defaults to empty attributes array if not provided</param>
        /// <param name="loggingKeyType">It can be either experiment or rule.</param>
        /// <param name="loggingKey">In case loggingKeyType is experiment it will be experiment key or else it will be rule number.</param>
        /// <returns>true if the user meets audience conditions to be in experiment, false otherwise.</returns>
        public static Result <bool> DoesUserMeetAudienceConditions(ProjectConfig config,
                                                                   Experiment experiment,
                                                                   UserAttributes userAttributes,
                                                                   string loggingKeyType,
                                                                   string loggingKey,
                                                                   ILogger logger)
        {
            var reasons = new DecisionReasons();

            if (userAttributes == null)
            {
                userAttributes = new UserAttributes();
            }

            ICondition expConditions = null;

            if (experiment.AudienceConditionsList != null)
            {
                expConditions = experiment.AudienceConditionsList;
                logger.Log(LogLevel.DEBUG, $@"Evaluating audiences for {loggingKeyType} ""{loggingKey}"": {experiment.AudienceConditionsString}.");
            }
            else
            {
                expConditions = experiment.AudienceIdsList;
                logger.Log(LogLevel.DEBUG, $@"Evaluating audiences for {loggingKeyType} ""{loggingKey}"": {experiment.AudienceIdsString}.");
            }

            // If there are no audiences, return true because that means ALL users are included in the experiment.
            if (expConditions == null)
            {
                return(Result <bool> .NewResult(true, reasons));
            }

            var result     = expConditions.Evaluate(config, userAttributes, logger).GetValueOrDefault();
            var resultText = result.ToString().ToUpper();

            logger.Log(LogLevel.INFO, reasons.AddInfo($@"Audiences for {loggingKeyType} ""{loggingKey}"" collectively evaluated to {resultText}"));
            return(Result <bool> .NewResult(result, reasons));
        }
Ejemplo n.º 18
0
        public Option <PropertyComposition> Compose(
            JObject input,
            Path parentPath)
        {
            var conditionResult = _condition.Evaluate(
                input);

            if (!conditionResult.IsSuccess)
            {
                return(ConditionFailure(
                           parentPath,
                           conditionResult));
            }

            if (!conditionResult.Value)
            {
                return(Option <PropertyComposition> .None);
            }

            return(_propertyComposer.Compose(
                       input,
                       parentPath));
        }
Ejemplo n.º 19
0
 public bool Evaluate(ConditionSettings settings, params string[] replacements)
 {
     return(!_condition.Evaluate(settings, replacements));
 }
Ejemplo n.º 20
0
 bool ITransition.IsTriggered(FTrigger trigger)
 {
     return(this._trigger == trigger && (_condition == null || _condition.Evaluate()));
 }
Ejemplo n.º 21
0
 public virtual bool Evaluate(IInstanceResolver resolver, object context)
 {
     return(evaluation.Evaluate(context));
 }
 protected override bool Condition(T instance)
 {
     return(_condition.Evaluate(instance));
 }
Ejemplo n.º 23
0
 /// <summary>Evaluates the condition</summary>
 public override bool Evaluate()
 {
     return(m_cond1.Evaluate() && m_cond2.Evaluate());
 }
Ejemplo n.º 24
0
 public override bool Evaluate(Facts facts)
 {
     return(_condition.Evaluate(facts));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Evalutes the Condition against the Question's answer.
 /// </summary>
 /// <param name="actor">The Screenplay Actor.</param>
 /// <returns></returns>
 public bool Evaluate(IActor actor)
 {
     _answer = actor.AsksFor(Question);
     return(Condition.Evaluate(_answer));
 }
Ejemplo n.º 26
0
 /// <summary>Evaluates the condition</summary>
 public override bool Evaluate()
 {
     return(!m_cond.Evaluate());
 }
Ejemplo n.º 27
0
 public override bool Evaluate <T>(T context)
 {
     return(_condition.Evaluate(context));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// <see cref="ICondition.Evaluate" />
 /// </summary>
 public bool Evaluate()
 {
     return(!_condition.Evaluate());
 }