internal AIMLTagHandler GetTagHandler(User user, SubQuery query, Request request, Result result, XmlNode node, AIMLTagHandler parentTagHandlerU) { AltBot targetBot = user.bot; AIMLTagHandler tag = targetBot.GetTagHandler(node, query, request, result, user, true); if (query != null) { query.CurrentTagHandlerU = tag; } if (query != null) { query.CurrentNode = node; } if (tag == null) { writeToLog("NULL TAG " + node.OuterXml); } if (tag != null) { tag.SetParent(parentTagHandlerU); if (query != null) { query.LastTagHandlerU = parentTagHandlerU ?? tag; } TemplateInfo ti = tag.templateInfo; if (ti == null && query != null) { ti = query.CurrentTemplate; } if (ti == null && parentTagHandlerU != null) { ti = parentTagHandlerU.GetTemplateInfo(); } if (ti != null) { tag.templateInfo = ti; } else { // writeToLog("DEBUG9 Missing templateInfo " + node.OuterXml); } } return(tag); }
/// <summary> /// Recursively evaluates the template nodes returned from the Proccessor /// </summary> /// <param name="node">the node to evaluate</param> /// <param name="query">the query that produced targetBot node</param> /// <param name="request">the request from the user</param> /// <param name="result">the result to be sent to the user</param> /// <param name="user">the user who originated the request</param> /// <returns>the output Unifiable</returns> public string processNodeVV(XmlNode node, SubQuery query, Request request, Result result, User user, AIMLTagHandler parentHandlerU, bool protectChild, bool copyParent, AIMLTagHandler tagHandlerU, out bool childSuccess) { AltBot TargetBot = tagHandlerU.bot; if (request != null) { TargetBot = request.TargetBot; } childSuccess = true; if (node == null) { string whyError = "ERROR null NODE " + tagHandlerU; writeToLog(whyError); throw new ChatSignalOverBudget(request, whyError); } if (node.NodeType == XmlNodeType.Text) { childSuccess = true; if (tagHandlerU != null) { tagHandlerU.QueryHasSuceeded = true; } string s = StaticAIMLUtils.Trim(StaticAIMLUtils.TextNodeValue(node)); if (!String.IsNullOrEmpty(s)) { return(StaticAIMLUtils.ValueText(s)); } //return s; } if (tagHandlerU == null) { string whyError = "ERROR null THND " + node; childSuccess = false; writeToLog(whyError); } bool isTraced = (request != null && (request.IsTraced || !request.GraphsAcceptingUserInput)) || (query != null && query.IsTraced); // check for timeout (to avoid infinite loops) bool overBudget = false; if (request != null && request.IsComplete(result)) { object gn = request.Graph; if (query != null) { gn = query.Graph; } string s = StaticAIMLUtils.SafeFormat("WARNING! Request " + request.WhyComplete + ". User: {0} raw input: {3} \"{1}\" processing {2} templates: \"{4}\"", request.Requester.UserID, Unifiable.DescribeUnifiable(request.rawInput), (query == null ? "-NOQUERY-" : query.Templates.Count.ToString()), gn, node); if (isTraced) { request.writeToLog(s); } overBudget = true; if (!request.IsToplevelRequest) { throw new ChatSignalOverBudget(request, s); } } // process the node if (ReferenceEquals(null, tagHandlerU)) { childSuccess = true; if (node.NodeType == XmlNodeType.Comment) { return(Unifiable.Empty); } if (node.NodeType == XmlNodeType.Text) { string s = StaticAIMLUtils.Trim(StaticAIMLUtils.TextNodeValue(node)); if (String.IsNullOrEmpty(s)) { return(Unifiable.Empty); } return(s); } // ReSharper disable ConditionIsAlwaysTrueOrFalse OutputDelegate del = (request != null) ? request.writeToLog : writeToLog; // ReSharper restore ConditionIsAlwaysTrueOrFalse if (overBudget) { return(Unifiable.Empty); } string nodeInner = node.InnerXml; TargetBot.EvalAiml(node, request, del ?? TextPatternUtils.DEVNULL); return(node.InnerXml); } XmlNode oldNode = node; bool wasReadonlyNode = oldNode.IsReadOnly; // copy the node!?! if (protectChild) { copyParent = true; LineInfoElementImpl newnode = StaticAIMLUtils.CopyNode(node, copyParent); newnode.ReadOnly = false; node = newnode; } if (overBudget) { tagHandlerU.Dispose(); tagHandlerU = null; childSuccess = true; return(Unifiable.Empty); } tagHandlerU.SetParent(parentHandlerU); //if (parent!=null) parent.AddChild(tagHandler); Unifiable cp = tagHandlerU.Transform(); if (Unifiable.IsNullOrEmpty(cp) && (!tagHandlerU.QueryHasSuceeded || tagHandlerU.QueryHasFailed)) { bool needsOneMoreTry = !request.SuspendSearchLimits && (request.IsToplevelRequest /*|| result.ParentRequest.IsToplevelRequest*/); if (isTraced || needsOneMoreTry) { //writeDebugLine("ERROR: Try Again since NULL " + tagHandler); bool wsl = request.SuspendSearchLimits; try { request.SuspendSearchLimits = true; cp = tagHandlerU.Transform(); if (Unifiable.IsNull(cp)) { childSuccess = false; return(tagHandlerU.GetTemplateNodeInnerText()); } if (false && Unifiable.IsNullOrEmpty(cp)) { // trace the next line to see why AIMLTagHandler handlerU = tagHandlerU; TargetBot.TraceTest("ERROR: Try Again since NULL " + handlerU, () => { cp = handlerU.Transform(); }); } } finally { request.SuspendSearchLimits = wsl; } } } if (tagHandlerU.QueryHasFailed) { childSuccess = false; return(tagHandlerU.FAIL); } childSuccess = !tagHandlerU.QueryHasFailed; if (!childSuccess) { } var st = StaticAIMLUtils.IsSilentTag(node); var ine = Unifiable.IsNullOrEmpty(cp); if (!ine || st) { childSuccess = true; return(cp); } if (Unifiable.IsNull(cp)) { cp = tagHandlerU.GetTemplateNodeInnerText(); if (tagHandlerU.QueryHasSuceeded) { childSuccess = true; return(cp); } return(cp); } return(cp); }