Ejemplo n.º 1
0
        /// <summary>
        /// Returns true if the step has references all the way to the root.
        /// </summary>
        /// <param name="instance">Instance to check</param>
        /// <param name="checkIfPropertyAccessed">Check if property has been accessed on the instance.</param>
        /// <returns></returns>
        internal bool IsReferencedToRoot(ModelInstance instance, bool checkIfPropertyAccessed)
        {
            // Exit immediately if the instance is not valid for the current step filter
            if (Filter != null && !Filter.IsInstanceOfType(instance))
            {
                return(false);
            }

            // Check if the current property has been accessed on the instance
            if (checkIfPropertyAccessed && !instance.HasBeenAccessed(Property))
            {
                return(false);
            }

            //if there's no previous steps then the step directly applies to the instance
            if (PreviousStep == null)
            {
                return(true);
            }

            //unless the previous step has references the step is not relevant to the instance.
            foreach (ModelReference parentReference in instance.GetInReferences((ModelReferenceProperty)PreviousStep.Property))
            {
                if (PreviousStep.IsReferencedToRoot(parentReference.In, false))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        internal void RunPendingPropertyGetRules(ModelInstance instance, Func<ModelProperty, bool> when)
        {
            // First run all rules for return values associated with properties that have not yet been accessed
            foreach (Rule rule in instance.GetRules()
                    .Where(rule => (rule.InvocationTypes & RuleInvocationType.PropertyGet) > 0 && rule.ReturnValues.Select(p => rule.RootType.Properties[p])
                    .Any(p => when(p) && !instance.HasBeenAccessed(p))))
                rule.Invoke(instance, null);

            // Then run any property get rules that are pending invocation due to changes in the model
            pendingInvocation.RemoveWhere(rule =>
                {
                    if ((rule.InvocationTypes & RuleInvocationType.PropertyGet) > 0 && rule.ReturnValues.Select(p => rule.RootType.Properties[p]).Any(when))
                    {
                        rule.Invoke(instance, null);
                        return true;
                    }
                    return false;
                });
        }
Ejemplo n.º 3
0
        internal void RunPendingPropertyGetRules(ModelInstance instance, Func <ModelProperty, bool> when)
        {
            // First run all rules for return values associated with properties that have not yet been accessed
            foreach (Rule rule in instance.GetRules()
                     .Where(rule => (rule.InvocationTypes & RuleInvocationType.PropertyGet) > 0 && rule.ReturnValues.Select(p => rule.RootType.Properties[p])
                            .Any(p => when(p) && !instance.HasBeenAccessed(p))))
            {
                rule.Invoke(instance, null);
            }

            // Then run any property get rules that are pending invocation due to changes in the model
            pendingInvocation.RemoveWhere(rule =>
            {
                if ((rule.InvocationTypes & RuleInvocationType.PropertyGet) > 0 && rule.ReturnValues.Select(p => rule.RootType.Properties[p]).Any(when))
                {
                    rule.Invoke(instance, null);
                    return(true);
                }
                return(false);
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns true if the step has references all the way to the root.
        /// </summary>
        /// <param name="instance">Instance to check</param>
        /// <param name="checkIfPropertyAccessed">Check if property has been accessed on the instance.</param>
        /// <returns></returns>
        internal bool IsReferencedToRoot(ModelInstance instance, bool checkIfPropertyAccessed)
        {
            // Exit immediately if the instance is not valid for the current step filter
            if (Filter != null && !Filter.IsInstanceOfType(instance))
                return false;

            // Check if the current property has been accessed on the instance
            if (checkIfPropertyAccessed && !instance.HasBeenAccessed(Property))
                return false;

            //if there's no previous steps then the step directly applies to the instance
            if (PreviousStep == null)
                return true;

            //unless the previous step has references the step is not relevant to the instance.
            foreach (ModelReference parentReference in instance.GetInReferences((ModelReferenceProperty)PreviousStep.Property))
            {
                if (PreviousStep.IsReferencedToRoot(parentReference.In, false))
                    return true;
            }

            return false;
        }