private static bool IsConditionalNodeActive <T>(IConditionalNode <T> node) where T : ParserRuleContext { if (node == null || (node.Result == null)) { throw new NotImplementedException("IsConditionalNodeActive"); } if (node.Result is bool) { return((bool)node.Result); } // TODO handle other data types. throw new NotImplementedException("IsConditionalNodeActive"); }
/// <summary> /// Evaluates the pre and post conditions of the node. /// </summary> public static void EvaluateNode(IConditionalNode node) { // // Here is where we do the actual work of calling the // conditions. // // First, set the node into the FeatureCallContext so the // conditions can know // GuidanceCallContext.Current.DefaultConditionTarget = node as INode; // // Then, check the preconditions. // Note: We do not automatically set the result of // precondition calculation for Fork/Join/Decision/Merge // to enable them full latitude in state management // if (!EvaluateBindings(node.Preconditions)) { //if (!(node is Fork) && // !(node is Join) && // !(node is Decision) && // !(node is Merge)) if (TraceStateChanges && node.State != NodeState.Blocked) { tracer.Verbose(Resources.GuidanceConditionsEvaluator_TraceBlockState, currentExtensionInstance.InstanceName, node.Name); } node.SetState(NodeState.Blocked, false); } else { NodeState postConditionsState = NodeState.Enabled; if (currentExtensionInstance != null) { if ((currentExtensionInstance.GuidanceWorkflow != null) && ((GuidanceWorkflow)currentExtensionInstance.GuidanceWorkflow).IgnorePostConditions) { postConditionsState = NodeState.Enabled; } else { postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled; } } else if (GuidanceConditionsEvaluator.Current != null && GuidanceConditionsEvaluator.Current.guidanceManager != null && GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension != null) { if ((GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension.GuidanceWorkflow != null) && ((GuidanceWorkflow)GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension.GuidanceWorkflow).IgnorePostConditions) { postConditionsState = NodeState.Enabled; } else { postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled; } } else { postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled; } // // Same rule for post condtions, let the "big guys" // calculate state for themselves // //if (!(node is Fork) && // !(node is Join) && // !(node is Decision) && // !(node is Merge)) if (TraceStateChanges && node.State != postConditionsState) { tracer.Verbose(Resources.GuidanceConditionsEvaluator_TraceStateToPostConditions + postConditionsState.ToString() + @" '{0}.{1}'.", currentExtensionInstance.InstanceName, node.Name); } node.SetState(postConditionsState, false); } }
internal static bool HasIncompleteChildren <T>(this IConditionalNode <T> node) where T : ParserRuleContext { var lastChild = node.ChildBlocks.LastOrDefault(); return(lastChild != null && !lastChild.IsComplete); }