Пример #1
0
        /// <summary>
        /// Recursively evaluates the template nodes returned from the bot
        /// </summary>
        /// <param name="node">the node to evaluate</param>
        /// <param name="query">the query that produced this 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 string</returns>
        private string processNode(XmlNode node, SubQuery query, Request request, Result result, User user)
        {
            // check for timeout (to avoid infinite loops)
            if (request.StartedOn.AddMilliseconds(request.bot.TimeOut) < DateTime.Now)
            {
                request.bot.writeToLog("WARNING! Request timeout. User: "******" raw input: \"" + request.rawInput + "\" processing template: \"" + query.Template + "\"");
                request.hasTimedOut = true;
                return(string.Empty);
            }

            StringBuilder newInnerText = new StringBuilder();

            if (node.HasChildNodes)
            {
                // recursively check
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    childNode.InnerText = this.processNode(childNode, query, request, result, user);
                }
            }

            // process the node itself
            AIMLTagHandler tagHandler = null;

            switch (node.Name.ToLower())
            {
            case "bot":
                tagHandler = new AIMLTagHandlers.bot(this, user, query, request, result, node);
                break;

            case "condition":
                tagHandler = new AIMLTagHandlers.condition(this, user, query, request, result, node);
                break;

            case "date":
                tagHandler = new AIMLTagHandlers.date(this, user, query, request, result, node);
                break;

            case "formal":
                tagHandler = new AIMLTagHandlers.formal(this, user, query, request, result, node);
                break;

            case "gender":
                tagHandler = new AIMLTagHandlers.gender(this, user, query, request, result, node);
                break;

            case "get":
                tagHandler = new AIMLTagHandlers.get(this, user, query, request, result, node);
                break;

            case "gossip":
                tagHandler = new AIMLTagHandlers.gossip(this, user, query, request, result, node);
                break;

            case "id":
                tagHandler = new AIMLTagHandlers.id(this, user, query, request, result, node);
                break;

            case "input":
                tagHandler = new AIMLTagHandlers.input(this, user, query, request, result, node);
                break;

            case "javascript":
                tagHandler = new AIMLTagHandlers.javascript(this, user, query, request, result, node);
                break;

            case "learn":
                tagHandler = new AIMLTagHandlers.learn(this, user, query, request, result, node);
                break;

            case "lowercase":
                tagHandler = new AIMLTagHandlers.lowercase(this, user, query, request, result, node);
                break;

            case "person":
                tagHandler = new AIMLTagHandlers.person(this, user, query, request, result, node);
                break;

            case "person2":
                tagHandler = new AIMLTagHandlers.person2(this, user, query, request, result, node);
                break;

            case "random":
                tagHandler = new AIMLTagHandlers.random(this, user, query, request, result, node);
                break;

            case "sentence":
                tagHandler = new AIMLTagHandlers.sentence(this, user, query, request, result, node);
                break;

            case "set":
                tagHandler = new AIMLTagHandlers.set(this, user, query, request, result, node);
                break;

            case "size":
                tagHandler = new AIMLTagHandlers.size(this, user, query, request, result, node);
                break;

            case "sr":
                tagHandler = new AIMLTagHandlers.sr(this, user, query, request, result, node);
                break;

            case "srai":
                tagHandler = new AIMLTagHandlers.srai(this, user, query, request, result, node);
                break;

            case "star":
                tagHandler = new AIMLTagHandlers.star(this, user, query, request, result, node);
                break;

            case "system":
                tagHandler = new AIMLTagHandlers.system(this, user, query, request, result, node);
                break;

            case "that":
                tagHandler = new AIMLTagHandlers.that(this, user, query, request, result, node);
                break;

            case "thatstar":
                tagHandler = new AIMLTagHandlers.thatstar(this, user, query, request, result, node);
                break;

            case "think":
                tagHandler = new AIMLTagHandlers.think(this, user, query, request, result, node);
                break;

            case "topicstar":
                tagHandler = new AIMLTagHandlers.topicstar(this, user, query, request, result, node);
                break;

            case "uppercase":
                tagHandler = new AIMLTagHandlers.uppercase(this, user, query, request, result, node);
                break;

            case "version":
                tagHandler = new AIMLTagHandlers.version(this, user, query, request, result, node);
                break;

            default:
                tagHandler = this.getBespokeTags(user, query, request, result, node);
                break;
            }
            if (object.Equals(null, tagHandler))
            {
                return(node.InnerText);
            }
            else
            {
                return(tagHandler.Transform());
            }
        }
Пример #2
0
 /// <summary>
 /// Recursively evaluates the template nodes returned from the bot
 /// </summary>
 /// <param name="node">the node to evaluate</param>
 /// <param name="query">the query that produced this 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 string</returns>
 private string processNode(XmlNode node, SubQuery query, Request request, Result result, User user)
 {
     // check for timeout (to avoid infinite loops)
     if (request.StartedOn.AddMilliseconds(request.bot.TimeOut) < DateTime.Now)
     {
         request.bot.writeToLog("WARNING! Request timeout. User: "******" raw input: \"" + request.rawInput + "\" processing template: \""+query.Template+"\"");
         request.hasTimedOut = true;
         return string.Empty;
     }
                 
     // process the node
     string tagName = node.Name.ToLower();
     if (tagName == "template")
     {
         StringBuilder templateResult = new StringBuilder();
         if (node.HasChildNodes)
         {
             // recursively check
             foreach (XmlNode childNode in node.ChildNodes)
             {
                 templateResult.Append(this.processNode(childNode, query, request, result, user));
             }
         }
         return templateResult.ToString();
     }
     else
     {
         AIMLTagHandler tagHandler = null;
         tagHandler = this.getBespokeTags(user, query, request, result, node);
         if (object.Equals(null, tagHandler))
         {
             switch (tagName)
             {
                 case "bot":
                     tagHandler = new AIMLTagHandlers.bot(this, user, query, request, result, node);
                     break;
                 case "condition":
                      tagHandler = new AIMLTagHandlers.Condition(this, user, query, request, result, node);
                     break;
                 case "date":
                     tagHandler = new AIMLTagHandlers.date(this, user, query, request, result, node);
                     break;
                 case "formal":
                     tagHandler = new AIMLTagHandlers.formal(this, user, query, request, result, node);
                     break;
                 case "gender":
                     tagHandler = new AIMLTagHandlers.gender(this, user, query, request, result, node);
                     break;
                 case "get":
                     tagHandler = new AIMLTagHandlers.get(this, user, query, request, result, node);
                     break;
                 case "gossip":
                     tagHandler = new AIMLTagHandlers.gossip(this, user, query, request, result, node);
                     break;
                 case "id":
                     tagHandler = new AIMLTagHandlers.id(this, user, query, request, result, node);
                     break;
                 case "input":
                     tagHandler = new AIMLTagHandlers.input(this, user, query, request, result, node);
                     break;
                 case "javascript":
                     tagHandler = new AIMLTagHandlers.javascript(this, user, query, request, result, node);
                     break;
                 case "learn":
                     tagHandler = new AIMLTagHandlers.learn(this, user, query, request, result, node);
                     break;
                 case "lowercase":
                     tagHandler = new AIMLTagHandlers.lowercase(this, user, query, request, result, node);
                     break;
                 case "person":
                     tagHandler = new AIMLTagHandlers.person(this, user, query, request, result, node);
                     break;
                 case "person2":
                     tagHandler = new AIMLTagHandlers.person2(this, user, query, request, result, node);
                     break;
                 case "random":
                     tagHandler = new AIMLTagHandlers.random(this, user, query, request, result, node);
                     break;
                 case "sentence":
                     tagHandler = new AIMLTagHandlers.sentence(this, user, query, request, result, node);
                     break;
                 case "set":
                     tagHandler = new AIMLTagHandlers.set(this, user, query, request, result, node);
                     break;
                 case "size":
                     tagHandler = new AIMLTagHandlers.size(this, user, query, request, result, node);
                     break;
                 case "sr":
                     tagHandler = new AIMLTagHandlers.sr(this, user, query, request, result, node);
                     break;
                 case "srai":
                     tagHandler = new AIMLTagHandlers.srai(this, user, query, request, result, node);
                     break;
                 case "star":
                     tagHandler = new AIMLTagHandlers.star(this, user, query, request, result, node);
                     break;
                 case "system":
                     tagHandler = new AIMLTagHandlers.system(this, user, query, request, result, node);
                     break;
                 case "that":
                     tagHandler = new AIMLTagHandlers.that(this, user, query, request, result, node);
                     break;
                 case "thatstar":
                     tagHandler = new AIMLTagHandlers.thatstar(this, user, query, request, result, node);
                     break;
                 case "think":
                     tagHandler = new AIMLTagHandlers.think(this, user, query, request, result, node);
                     break;
                 case "topicstar":
                     tagHandler = new AIMLTagHandlers.topicstar(this, user, query, request, result, node);
                     break;
                 case "uppercase":
                     tagHandler = new AIMLTagHandlers.uppercase(this, user, query, request, result, node);
                     break;
                 case "version":
                     tagHandler = new AIMLTagHandlers.version(this, user, query, request, result, node);
                     break;
                 default:
                     tagHandler = null;
                     break;
             }
         }
         if (object.Equals(null, tagHandler))
         {
             return node.InnerText;
         }
         else
         {
             if (tagHandler.isRecursive)
             {
                 if (node.HasChildNodes)
                 {
                     // recursively check
                     foreach (XmlNode childNode in node.ChildNodes)
                     {
                         if (childNode.NodeType != XmlNodeType.Text)
                         {
                             childNode.InnerXml = this.processNode(childNode, query, request, result, user);
                         }
                     }
                 }
                 return tagHandler.Transform();
             }
             else
             {
                 string resultNodeInnerXML = tagHandler.Transform();
                 XmlNode resultNode = AIMLTagHandler.getNode("<node>" + resultNodeInnerXML + "</node>");
                 if (resultNode.HasChildNodes)
                 {
                     StringBuilder recursiveResult = new StringBuilder();
                     // recursively check
                     foreach (XmlNode childNode in resultNode.ChildNodes)
                     {
                         recursiveResult.Append(this.processNode(childNode, query, request, result, user));
                     }
                     return recursiveResult.ToString();
                 }
                 else
                 {
                     return resultNode.InnerXml;
                 }
             }
         }
     }
 }