Exemplo n.º 1
0
 public void NoConditionSetForNot_IsNotValid()
 {
     Assert.Throws <ValidationException>(() =>
                                         StateMachineBuilder.StateMachine()
                                         .StartAt("Initial")
                                         .State("Initial", StateMachineBuilder.ChoiceState()
                                                .Choice(StateMachineBuilder.Choice()
                                                        .Condition(NotCondition.GetBuilder())
                                                        .Transition(StateMachineBuilder.Next("Terminal")))
                                                .DefaultStateName("Terminal"))
                                         .State("Terminal", StateMachineBuilder.SucceedState())
                                         .Build());
 }
Exemplo n.º 2
0
 /**
  * Represents the logical NOT of a single condition. May be used in a {@link ChoiceState}.
  *
  * @param conditionBuilder The condition to be negated. May be another composite condition or a simple condition.
  * @return Builder used to configure a {@link NotCondition}.
  * @see <a href="https://states-language.net/spec.html#choice-state">https://states-language.net/spec.html#choice-state</a>
  */
 public static NotCondition.Builder Not <T>(IConditionBuilder <T> conditionBuilder) where T : ICondition
 {
     return(NotCondition.GetBuilder().Condition(conditionBuilder));
 }
        public IConditionBuilder<ICondition> DeserializeCondition(JObject node)
        {
            if (node.Property(PropertyNames.VARIABLE) != null)
            {
                if (node.Property(PropertyNames.STRING_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(StringEqualsCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.STRING_EQUALS_PATH) != null)
                {
                    return DeserializeBinaryPathCondition(StringEqualsPathCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.STRING_GREATER_THAN) != null)
                {
                    return DeserializeBinaryCondition(StringGreaterThanCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.STRING_GREATER_THAN_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(StringGreaterThanOrEqualCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.STRING_LESS_THAN) != null)
                {
                    return DeserializeBinaryCondition(StringLessThanCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.STRING_LESS_THAN_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(StringLessThanOrEqualCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.TIMESTAMP_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(TimestampEqualCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.TIMESTAMP_GREATER_THAN) != null)
                {
                    return DeserializeBinaryCondition(TimestampGreaterThanCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.TIMESTAMP_GREATER_THAN_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(TimestampGreaterThanOrEqualCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.TIMESTAMP_LESS_THAN) != null)
                {
                    return DeserializeBinaryCondition(TimestampLessThanCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.TIMESTAMP_LESS_THAN_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(TimestampLessThanOrEqualCondition.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.NUMERIC_EQUALS) != null)
                {
                    if (node.Property(PropertyNames.NUMERIC_EQUALS).Value.Type == JTokenType.Integer)
                    {
                        return DeserializeBinaryCondition(NumericEqualsCondition<long>.GetBuilder(), node);
                    }

                    return DeserializeBinaryCondition(NumericEqualsCondition<decimal>.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.NUMERIC_GREATER_THAN) != null)
                {
                    if (node.Property(PropertyNames.NUMERIC_GREATER_THAN).Value.Type == JTokenType.Integer)
                    {
                        return DeserializeBinaryCondition(NumericGreaterThanCondition<long>.GetBuilder(), node);
                    }

                    return DeserializeBinaryCondition(NumericGreaterThanCondition<decimal>.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.NUMERIC_GREATER_THAN_EQUALS) != null)
                {
                    if (node.Property(PropertyNames.NUMERIC_GREATER_THAN_EQUALS).Value.Type == JTokenType.Integer)
                    {
                        return DeserializeBinaryCondition(NumericGreaterThanOrEqualCondition<long>.GetBuilder(), node);
                    }

                    return DeserializeBinaryCondition(NumericGreaterThanOrEqualCondition<decimal>.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.NUMERIC_LESS_THAN) != null)
                {
                    if (node.Property(PropertyNames.NUMERIC_LESS_THAN).Value.Type == JTokenType.Integer)
                    {
                        return DeserializeBinaryCondition(NumericLessThanCondition<long>.GetBuilder(), node);
                    }

                    return DeserializeBinaryCondition(NumericLessThanCondition<decimal>.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.NUMERIC_LESS_THAN_EQUALS) != null)
                {
                    if (node.Property(PropertyNames.NUMERIC_LESS_THAN_EQUALS).Value.Type == JTokenType.Integer)
                    {
                        return DeserializeBinaryCondition(NumericLessThanOrEqualCondition<long>.GetBuilder(), node);
                    }

                    return DeserializeBinaryCondition(NumericLessThanOrEqualCondition<decimal>.GetBuilder(), node);
                }

                if (node.Property(PropertyNames.BOOLEAN_EQUALS) != null)
                {
                    return DeserializeBinaryCondition(BooleanEqualsCondition.GetBuilder(), node);
                }
            }
            else if (node.Property(PropertyNames.AND) != null)
            {
                var builder = AndCondition.GetBuilder();
                foreach (var inner in node[PropertyNames.AND].Children())
                {
                    builder.Condition(DeserializeCondition((JObject) inner));
                }

                return builder;
            }
            else if (node.Property(PropertyNames.OR) != null)
            {
                var builder = OrCondition.GetBuilder();
                foreach (var inner in node[PropertyNames.OR].Children())
                {
                    builder.Condition(DeserializeCondition((JObject) inner));
                }

                return builder;
            }
            else if (node.Property(PropertyNames.NOT) != null)
            {
                return NotCondition.GetBuilder()
                    .Condition(DeserializeCondition((JObject) node.Property(PropertyNames.NOT).First));
            }

            throw new StatesLanguageException("Condition must be provided");
        }