Exemplo n.º 1
0
        } // method: newInterpreter

        public string evalXMLString(TextReader message)
        {
            XmlDocumentLineInfo xdoc = new XmlDocumentLineInfo("evalXMLString: " + message, true);

            try
            {
                //readerSettings.ValidationEventHandler += new ValidationEventHandler(LLSDXmlSchemaValidationHandler);
                XmlReader reader = new XmlTextReader(message);
                xdoc.Load(reader);
            }
            catch (Exception e)
            {
                throw e;
            }
            if (xdoc.DocumentElement == null)
            {
                return("no document");
            }
            return(EvaluateXmlDocument(xdoc.DocumentElement.OuterXml));
        }
Exemplo n.º 2
0
        public static void LoadAssetFile(string s)
        {
            try
            {
                XmlDocument doc = new XmlDocumentLineInfo();
                doc.Load(s);
                foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                {
                    string nodename = node.Name.ToLower();
                    if (nodename == "alias")
                    {
                        string type = GetAttribValue(node, "type", String.Empty);
                        string to = GetAttribValue(node, "to", String.Empty);
                        string from = GetAttribValue(node, "from", String.Empty);
                        AssetType atype = GetAssetType(type);
                        if (!String.IsNullOrEmpty(from))
                        {
                            string file = from;
                            // only add Hanson .csv files 
                            file = file.Replace(">", "");
                            if (!file.EndsWith(".csv"))
                            {
                                continue;
                            }
                            if (file.Contains("&"))
                            {
                                DLRConsole.DebugWriteLine("ERROR ASSETNAME {0}", file);
                            }
                            AddAssetAlias(file, to, atype);
                        }
                        else
                        {
                           foreach (XmlNode fnode in node.ChildNodes)
                           {
                               string file = fnode.InnerText;
                               file = file.Replace(">", "");
                               // only add Hanson .csv files 
                               if (!file.EndsWith(".csv"))
                               {
                                   continue;                                   
                               }
                               if (file.Contains("&"))
                               {
                                   DLRConsole.DebugWriteLine("ERROR ASSETNAME {0}", file);
                               }
                               AddAssetAlias(file, to, atype);                               
                           } 
                        }
                        continue;
                    }
                    if (nodename == "asset")
                    {
                        string type = GetAttribValue(node, "type", String.Empty);
                        string to = GetAttribValue(node, "name", String.Empty);
                        string from = GetAttribValue(node, "uuid", String.Empty);
                        AssetType atype = GetAssetType(type);
                        SimAsset A = FindOrCreateAsset(UUID.Parse(from), atype);
                        A.Name = to;
                        foreach (XmlNode fnode in node.ChildNodes)
                        {
                            if (fnode.Name == "name") A.Name = fnode.InnerText;
                            if (fnode.Name == "meaning") A.AddType(fnode.InnerText);
                        }

                        continue;
                    }
                }
            }
            catch (Exception exception)
            {
                DLRConsole.DebugWriteLine("ERROR {0}", exception);
            }

        }
Exemplo n.º 3
0
        public string EvaluateXmlDocument(string xcmd)
        {
            WriteLine("EvaluateXmlDocument :" + xcmd);

            string response = "<request>\r\n <cmd>" + xcmd + "</cmd>\r\n <response>null</response>\r\n</request>";

            try
            {
                if (xcmd.Contains(".xlsp"))
                {
                    return(XML2Lisp(xcmd));
                }


                int           depth = 0;
                var           xdoc  = new XmlDocumentLineInfo();
                XmlTextReader reader;
                StringReader  stringReader;
                if (xcmd.Contains("http:") || xcmd.Contains(".xml"))
                {
                    // assuming its a file
                    xcmd   = xcmd.Trim();
                    reader = XmlDocumentLineInfo.CreateXmlTextFileReader(xcmd);
                    xdoc.Load(xcmd);
                }
                else
                {
                    // otherwise just use the string
                    stringReader = new System.IO.StringReader(xcmd);
                    reader       = new XmlTextReader(stringReader);
                    xdoc.LoadXml(xcmd);
                }

                Hashtable[] attributeStack = new Hashtable[16];


                string[] strURI  = new String[16];
                string[] strName = new String[16];
                string[] strPath = new String[16];

                string totalResponse = "";
                for (int i = 0; i < 16; i++)
                {
                    attributeStack[i] = new Hashtable();
                }

                while (reader.Read())
                {
                    depth = reader.Depth + 1;
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        //Hashtable attributes = new Hashtable();
                        strURI[depth]  = reader.NamespaceURI;
                        strName[depth] = reader.Name;
                        strPath[depth] = strPath[depth - 1] + "." + strName[depth];
                        if (reader.HasAttributes)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                string attributeName  = reader.Name;
                                string attributeValue = reader.Value;
                                string attributePath  = "";
                                if ((attributeName == "name") && ((strName[depth] == "param") || (strName[depth] == "feeling")))
                                {
                                    // so you can have multiple named params
                                    strPath[depth] = strPath[depth] + "." + attributeValue;
                                }
                                if (depth > 1)
                                {
                                    attributePath = strPath[depth] + "." + attributeName;
                                }
                                else
                                {
                                    attributePath = attributeName;
                                }
                                overwrite2Hash(attributeStack[depth], attributeName, attributeValue);
                                // zero depth contains the fully qualified nested dotted value
                                // i.e. pet-action-plan.action.param.vector.x
                                // i.e. pet-action-plan.action.param.entity.value
                                overwrite2Hash(attributeStack[0], attributePath, attributeValue);
                            }
                        }
                        overwrite2Hash(attributeStack[depth], "ElementName", strName[depth]);
                        overwrite2Hash(attributeStack[depth], "Path", strPath[depth]);
                        xStartElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                        if (reader.IsEmptyElement)
                        {
                            // do whatever EndElement would do
                            response       = xEndElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                            totalResponse += response + "\r\n";
                        }
                        break;
                    //
                    //you can handle other cases here
                    //

                    case XmlNodeType.Text:
                        // Todo
                        WriteLine(" TextNode: depth=" + depth.ToString() + "  path = " + strPath[depth - 1]);;
                        if (reader.Name == "param")
                        {
                            overwrite2Hash(attributeStack[depth], strPath[depth - 1] + ".param." + strName[depth] + ".InnerText", reader.Value);
                            overwrite2Hash(attributeStack[0], strPath[depth - 1] + ".param." + strName[depth] + ".InnerText", reader.Value);
                        }
                        else
                        {
                            overwrite2Hash(attributeStack[depth], strPath[depth - 1] + ".InnerText", reader.Value);
                            overwrite2Hash(attributeStack[0], strPath[depth - 1] + ".InnerText", reader.Value);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        response       = xEndElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                        totalResponse += response + "\r\n";
                        // Todo
                        //depth--;
                        break;

                    default:
                        break;
                    } //switch
                }     //while
                string finalResponse = "<pet-petaverse-msg>\r\n" + totalResponse + "</pet-petaverse-msg>\r\n";
                return(finalResponse);
            } //try
            catch (Exception e)
            {
                WriteLine("error occured: " + e.Message);
                WriteLine("        Stack: " + e.StackTrace.ToString());
                return("<error><response>" + response + "</response><errormsg>" + e.Message.ToString() + "</errormsg> </error>");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Example text: <sapi> <silence msec="100" /> <bookmark mark="anim:hello.csv"/> Hi there </sapi>
        /// </summary>
        /// <param name="text"></param>
        /// <param name="gate"></param>
        public void XmlTalk(string text, OutputDelegate gate)
        {
            if (true)
            {
                //  SendCleanText(text);
                // return;
            }
            try
            {

                if (!text.Trim().StartsWith("<sapi"))
                {
                    text = "<sapi>" + text + "</sapi>";
                    //  Talk(text);
                    //  return;
                }
                // var sr = new StringReader("<xml>" + text + "</xml>");
                String toSay = "";
                HashSet<String> toAnimate = new HashSet<string>();
                // var reader = new XmlTextReader(sr);
                //while (reader.Read())
                {
                    var doc = new XmlDocumentLineInfo("XmlTalk: " + text, false);
                    doc.Load(new XmlTextReader(new StringReader(text)));
                    //reader.MoveToElement();
                    foreach (var n in doc.DocumentElement.ChildNodes)
                    {
                        XmlNode node = (XmlNode) n;
                        if (node == null) continue;
                        string lname = node.Name.ToLower();

                        //XmlNode node = null;
                        if (lname == "sapi")
                        {
                            XmlTalk(node.InnerXml, gate);
                            continue;
                        }
                        if (lname == "silence")
                        {
                            double sleepms = Double.Parse(node.Attributes["msec"].Value);
                            // todo
                            continue;
                        }
                        if (lname == "bookmark")
                        {
                            toSay = toSay.Trim();
                            if (!String.IsNullOrEmpty(toSay))
                                TalkExact(toSay, 0, ChatType.Normal);
                            toSay = String.Empty;
                            toAnimate.Add(node.Attributes["mark"].Value);
                            continue;
                        }
                        if (node.NodeType == XmlNodeType.Text)
                        {
                            toSay += " " + node.InnerText;
                            continue;
                        }
                        toSay += " <parseme>" + node.OuterXml + "</parseme>";
                    }
                }
                toSay = toSay.Trim();
                if (!String.IsNullOrEmpty(toSay))
                    TalkExact(toSay, 0, ChatType.Normal);
                int maxAnims = 2;
                foreach (var animation in toAnimate)
                {
                    if (maxAnims <= 0) return;
                    maxAnims--;
                    DoAnimation(animation);
                }
                return;
            }
            catch (Exception e)
            {
                LogException("XMlTalk " + text, e);
                // example fragment
                // <sapi> <silence msec="100" /> <bookmark mark="anim:hello.csv"/> Hi there </sapi>
                Talk(text);
            }
        }
Exemplo n.º 5
0
        public string EvaluateXmlDocument(string xcmd)
        {
            WriteLine("EvaluateXmlDocument :" + xcmd);

            string response = "<request>\r\n <cmd>" + xcmd + "</cmd>\r\n <response>null</response>\r\n</request>";
            try
            {
                if (xcmd.Contains(".xlsp"))
                {
                    return XML2Lisp(xcmd);
                }


                int depth = 0;
                var xdoc = new XmlDocumentLineInfo();
                XmlTextReader reader;
                StringReader stringReader;
                if (xcmd.Contains("http:") || xcmd.Contains(".xml"))
                {
                    // assuming its a file
                    xcmd = xcmd.Trim();
                    reader = XmlDocumentLineInfo.CreateXmlTextFileReader(xcmd);
                    xdoc.Load(xcmd);
                }
                else
                {
                    // otherwise just use the string
                    stringReader = new System.IO.StringReader(xcmd);
                    reader = new XmlTextReader(stringReader);
                    xdoc.LoadXml(xcmd);
                }

                Hashtable[] attributeStack = new Hashtable[16];


                string[] strURI = new String[16];
                string[] strName = new String[16];
                string[] strPath = new String[16];

                string totalResponse = "";
                for (int i = 0; i < 16; i++) { attributeStack[i] = new Hashtable(); }

                while (reader.Read())
                {
                    depth = reader.Depth + 1;
                    switch (reader.NodeType)
                    {

                        case XmlNodeType.Element:
                            //Hashtable attributes = new Hashtable();
                            strURI[depth] = reader.NamespaceURI;
                            strName[depth] = reader.Name;
                            strPath[depth] = strPath[depth - 1] + "." + strName[depth];
                            if (reader.HasAttributes)
                            {
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);
                                    string attributeName = reader.Name;
                                    string attributeValue = reader.Value;
                                    string attributePath = "";
                                    if ((attributeName == "name") && ((strName[depth] == "param") || (strName[depth] == "feeling")))
                                    {
                                        // so you can have multiple named params
                                        strPath[depth] = strPath[depth] + "." + attributeValue;
                                    }
                                    if (depth > 1)
                                    {
                                        attributePath = strPath[depth] + "." + attributeName;
                                    }
                                    else
                                    {
                                        attributePath = attributeName;
                                    }
                                    overwrite2Hash(attributeStack[depth], attributeName, attributeValue);
                                    // zero depth contains the fully qualified nested dotted value
                                    // i.e. pet-action-plan.action.param.vector.x
                                    // i.e. pet-action-plan.action.param.entity.value
                                    overwrite2Hash(attributeStack[0], attributePath, attributeValue);
                                }
                            }
                            overwrite2Hash(attributeStack[depth], "ElementName", strName[depth]);
                            overwrite2Hash(attributeStack[depth], "Path", strPath[depth]);
                            xStartElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                            if (reader.IsEmptyElement)
                            {
                                // do whatever EndElement would do
                                response = xEndElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                                totalResponse += response + "\r\n";

                            }
                            break;
                        //
                        //you can handle other cases here
                        //

                        case XmlNodeType.Text:
                            // Todo
                            WriteLine(" TextNode: depth=" + depth.ToString() + "  path = " + strPath[depth - 1]); ;
                            if (reader.Name == "param")
                            {
                                overwrite2Hash(attributeStack[depth], strPath[depth - 1] + ".param." + strName[depth] + ".InnerText", reader.Value);
                                overwrite2Hash(attributeStack[0], strPath[depth - 1] + ".param." + strName[depth] + ".InnerText", reader.Value);
                            }
                            else
                            {

                                overwrite2Hash(attributeStack[depth], strPath[depth - 1] + ".InnerText", reader.Value);
                                overwrite2Hash(attributeStack[0], strPath[depth - 1] + ".InnerText", reader.Value);
                            }
                            break;

                        case XmlNodeType.EndElement:
                            response = xEndElement(strURI[depth], strName[depth], attributeStack[depth], depth, attributeStack);
                            totalResponse += response + "\r\n";
                            // Todo
                            //depth--;
                            break;
                        default:
                            break;
                    } //switch
                } //while
                string finalResponse = "<pet-petaverse-msg>\r\n" + totalResponse + "</pet-petaverse-msg>\r\n";
                return finalResponse;
            } //try
            catch (Exception e)
            {
                WriteLine("error occured: " + e.Message);
                WriteLine("        Stack: " + e.StackTrace.ToString());
                return "<error><response>" + response + "</response><errormsg>" + e.Message.ToString() + "</errormsg> </error>";
            }
        }
Exemplo n.º 6
0
        } // method: newInterpreter


        public string evalXMLString(TextReader message)
        {
            XmlDocumentLineInfo xdoc = new XmlDocumentLineInfo("evalXMLString: " + message, true);
            try
            {
                //readerSettings.ValidationEventHandler += new ValidationEventHandler(LLSDXmlSchemaValidationHandler);
                XmlReader reader = new XmlTextReader(message);
                xdoc.Load(reader);
            }
            catch (Exception e)
            {
                throw e;
            }
            if (xdoc.DocumentElement == null) return "no document";
            return EvaluateXmlDocument(xdoc.DocumentElement.OuterXml);
        }