Represents the target of an condition, including the set of properties involved.
Ejemplo n.º 1
0
        /// <summary>
        /// Recursively attaches the current condition to targets in the model.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="steps"></param>
        void AddTarget(ModelInstance target, IEnumerable <ModelStep> steps)
        {
            // Get or create a condition target for the current instance
            ConditionTarget conditionTarget = targets.FirstOrDefault(ct => ct.Target == target);

            if (conditionTarget == null)
            {
                conditionTarget = new ConditionTarget(this, target);
                targets.Add(conditionTarget);
            }

            // Process each step along the path
            foreach (var step in steps)
            {
                // Add the property for the current step
                conditionTarget.AddProperty(step.Property.Name);

                // Stop processing if the current step is a leaf property
                if (step.NextSteps.Count == 0)
                {
                    continue;
                }

                // Recursively process child instances
                foreach (var child in step.GetInstances(target))
                {
                    AddTarget(child, step.NextSteps);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates or removes an condition on the specified target based on the specified condition.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="condition"></param>
        /// <param name="properties"></param>
        public Condition When(string message, object target, Func <bool> condition, params string[] properties)
        {
            // Get the current condition if it exists
            ConditionTarget conditionTarget = ModelInstance.GetModelInstance(target).GetExtension <RuleManager>().GetCondition(this);

            // Add the condition on the target if it does not exist yet
            if (condition())
            {
                // Create a new condition if one does not exist
                if (conditionTarget == null)
                {
                    return(new Condition(this, message, target, properties));
                }

                // Return the existing condition
                else
                {
                    // Update the message if a different message was passed in
                    if (!string.IsNullOrEmpty(message) && message != conditionTarget.Condition.Message)
                    {
                        conditionTarget.Condition.Message = message;
                    }

                    return(conditionTarget.Condition);
                }
            }

            // Destroy the condition if it exists on the target and is no longer valid
            if (conditionTarget != null)
            {
                conditionTarget.Condition.Destroy();
            }

            // Return null to indicate that no condition was created
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Recursively attaches the current condition to targets in the model.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="steps"></param>
        void AddTarget(ModelInstance target, IEnumerable<ModelStep> steps)
        {
            // Get or create a condition target for the current instance
            ConditionTarget conditionTarget = targets.FirstOrDefault(ct => ct.Target == target);
            if (conditionTarget == null)
            {
                conditionTarget = new ConditionTarget(this, target);
                targets.Add(conditionTarget);
            }

            // Process each step along the path
            foreach (var step in steps)
            {
                // Add the property for the current step
                conditionTarget.AddProperty(step.Property.Name);

                // Stop processing if the current step is a leaf property
                if (step.NextSteps.Count == 0)
                    continue;

                // Recursively process child instances
                foreach (var child in step.GetInstances(target))
                    AddTarget(child, step.NextSteps);
            }
        }
Ejemplo n.º 4
0
 internal void SetCondition(ConditionTarget conditionTarget)
 {
     conditions[conditionTarget.Condition.Type.Code] = conditionTarget;
 }
Ejemplo n.º 5
0
 internal void SetCondition(ConditionTarget conditionTarget)
 {
     conditions[conditionTarget.Condition.Type.Code] = conditionTarget;
 }