Пример #1
0
 public int LoadSysVarHtml(Stream content)
 {
     var sysvars = GetSysVars();
     var doc = new XmlDocumentLineInfo().ReadNode(XmlReader.Create(content));
     if (doc == null) return -1;
     if (doc.Name == "html") doc = doc.FirstChild;
     if (doc == null) return -1;
     if (doc.Name == "head") doc = doc.NextSibling;
     if (doc == null) return -1;
     if (doc.Name == "body") doc = doc.FirstChild;
     if (doc == null) return -1;
     if (doc.Name == "table") doc = doc.FirstChild;
     if (doc == null) return -1;
     int lineCount = 0;
     while (doc != null && doc.Name == "tr")
     {
         var fc = doc.FirstChild;
         if (fc.Name == "td")
         {
             string svname = fc.InnerText;
             var sc = fc.NextSibling;
             string svalue = sc.InnerText;
             bool found = false;
             foreach (var s in ScriptManager.FindMatchingSysvars(sysvars, svname, true, true))
             {
                 found = true;
                 lineCount++;
                 s.Value = svalue;
             }
             if (!found) Failure("Cant set: " + svname + "  " + svalue);
         }
         doc = doc.NextSibling;
     }
     return lineCount;
 }
Пример #2
0
 public void SetOwnerDocument(XmlDocumentLineInfo newDoc)
 {
     var prev = OwnerDocument as XmlDocumentLineInfo;
     if (prev != newDoc)
     {
         _docLineInfo = newDoc;
     }
 }
Пример #3
0
 internal LineInfoElementImpl(string prefix, string localname, string nsURI, XmlDocumentLineInfo doc)
     : base(XmlDocumentLineInfo.Intern(prefix), XmlDocumentLineInfo.Intern(localname), XmlDocumentLineInfo.Intern(nsURI), doc.FileDoc)
 {
     var lvar = doc as XmlDocumentLineInfo;
     if (lvar != null)
     {
         _docLineInfo = lvar;
         lvar.CheckNode(this);
     }
     //((XmlDocumentLineInfo)doc).IncrementElementCount();
 }
Пример #4
0
 public void SetOwnerDocument(XmlDocumentLineInfo newDoc)
 {
     var prev = OwnerDocument as XmlDocumentLineInfo;
     if (prev != newDoc)
     {
         _docLineInfo = newDoc;
     }
     foreach (var v in ChildNodes)
     {
         XmlDocumentLineInfo.DropDocument(v as XmlSourceLineInfo, newDoc);
     }
 }
Пример #5
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));
        }
Пример #6
0
        //private static int depth = 0;
        public override Unifiable RecurseChildren()
        {
            try
            {
                ResetValues(true);
                isRecursive = true;
                Unifiable f = Recurse();
                //depth++;

                /* int d = request.GetCurrentDepth();
                 * if (d > 30)
                 * {
                 *   writeToLogWarn("WARNING Depth pretty deep " + f + " returning empty");
                 *   return Unifiable.Empty;
                 * }
                 * if (depth > 30)
                 * {
                 *   writeToLogWarn("WARNING Depth pretty deep " + f + " returning empty");
                 *   return Unifiable.Empty;
                 * }*/
                var tn = templateNode;
                foreach (var cn in tn.ChildNodes)
                {
                }
                string  s    = Unifiable.ToVMString(f);
                XmlNode node =
                    new XmlDocumentLineInfo(s, false).ReadNode(
                        XmlDocumentLineInfo.CreateXmlTextReader(new StringReader(s)));
                bool templateSucceeded;
                bool createdOutput;
                templateInfo        = GetTemplateInfo();
                request.LastHandler = Proc.TagHandling.proccessResponse(query, request, result, (XmlNode)node, templateInfo.Guard, out createdOutput,
                                                                        out templateSucceeded, this, templateInfo, ReadOnly, true);
                return(Unifiable.Empty);
            }
            finally
            {
                //   depth--;
            }
        }
Пример #7
0
 public XmlAttributeLineInfo(string prefix, string name, string uri, XmlDocumentLineInfo doc)
     : base(XmlDocumentLineInfo.Intern(prefix), XmlDocumentLineInfo.Intern(name), XmlDocumentLineInfo.Intern(uri), doc.FileDoc)
 {
     docLineInfo = doc;
 }
Пример #8
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);
            }

        }
Пример #9
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>");
            }
        }
Пример #10
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);
            }
        }
        public int LoadSysVarHtml(Stream content)
        {
            var sysvars = GetSysVars();
            var doc     = new XmlDocumentLineInfo().ReadNode(XmlReader.Create(content));

            if (doc == null)
            {
                return(-1);
            }
            if (doc.Name == "html")
            {
                doc = doc.FirstChild;
            }
            if (doc == null)
            {
                return(-1);
            }
            if (doc.Name == "head")
            {
                doc = doc.NextSibling;
            }
            if (doc == null)
            {
                return(-1);
            }
            if (doc.Name == "body")
            {
                doc = doc.FirstChild;
            }
            if (doc == null)
            {
                return(-1);
            }
            if (doc.Name == "table")
            {
                doc = doc.FirstChild;
            }
            if (doc == null)
            {
                return(-1);
            }
            int lineCount = 0;

            while (doc != null && doc.Name == "tr")
            {
                var fc = doc.FirstChild;
                if (fc.Name == "td")
                {
                    string svname = fc.InnerText;
                    var    sc     = fc.NextSibling;
                    string svalue = sc.InnerText;
                    bool   found  = false;
                    foreach (var s in ScriptManager.FindMatchingSysvars(sysvars, svname, true, true))
                    {
                        found = true;
                        lineCount++;
                        s.Value = svalue;
                    }
                    if (!found)
                    {
                        Failure("Cant set: " + svname + "  " + svalue);
                    }
                }
                doc = doc.NextSibling;
            }
            return(lineCount);
        }
Пример #12
0
 public XmlTextLineInfo(string text, XmlDocumentLineInfo info)
     : base(XmlDocumentLineInfo.Intern(text), info.FileDoc)
 {
     _docLineInfo = info;
 }
Пример #13
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>";
            }
        }
Пример #14
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);
        }