Serialize and deserialize scene objects.
예제 #1
0
        public static void SavePrimsToXml(Scene scene, string fileName)
        {
            FileStream   file      = new FileStream(fileName, FileMode.Create);
            StreamWriter stream    = new StreamWriter(file);
            int          primCount = 0;

            stream.WriteLine("<scene>\n");

            List <EntityBase> EntityList = scene.GetEntities();

            foreach (EntityBase ent in EntityList)
            {
                if (ent is SceneObjectGroup)
                {
                    stream.WriteLine(SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)ent));
                    primCount++;
                }
            }
            stream.WriteLine("</scene>\n");
            stream.Close();
            file.Close();
        }
예제 #2
0
        /// <summary>
        /// Deserialize a scene object from the original xml format
        /// </summary>
        /// <param name="serialization"></param>
        /// <returns></returns>
        public static CoalescedObject FromXmlFormat(UUID fromUserInventoryItemID, string xmlData)
        {
            List <SceneObjectGroup> sceneObjects             = new List <SceneObjectGroup>();
            Dictionary <UUID, ItemPermissionBlock> permBlock = new Dictionary <UUID, ItemPermissionBlock>();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlData);
                XmlNodeList parts = doc.GetElementsByTagName("ColObjectMember");

                for (int i = 0; i < parts.Count; i++)
                {
                    SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(fromUserInventoryItemID, parts[i].InnerXml);
                    sceneObjects.Add(group);
                }

                XmlNodeList permissions = doc.GetElementsByTagName("CSOPermission");
                for (int i = 0; i < permissions.Count; i++)
                {
                    StringReader        sr     = new StringReader(permissions[i].InnerXml);
                    XmlTextReader       reader = new XmlTextReader(sr);
                    ItemPermissionBlock perm   = ItemPermissionBlock.FromXml(reader);
                    permBlock.Add(perm.ItemId, perm);
                }

                return(new CoalescedObject(sceneObjects, permBlock));
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[SERIALIZER]: Deserialization of xml failed with {0}.  xml was {1}", e, xmlData);
            }

            //m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Deserialize the first prim in a possibly coalesced scene object from the original xml format
        /// </summary>
        /// <param name="fromUserInventoryItemID"></param>
        /// <param name="xmlData"></param>
        /// <param name="index">Which SOG to return in a coalesced item (typically index=0)</param>
        /// <returns></returns>
        public static SceneObjectPart RootPartXmlObject(UUID fromUserInventoryItemID, string xmlData, int index)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlData);
                XmlNodeList parts = doc.GetElementsByTagName("ColObjectMember");

                if (parts.Count < 1)
                {
                    return(null);
                }
                return(SceneObjectSerializer.RootPartInOriginalXmlFormat(fromUserInventoryItemID, parts[index].InnerXml));
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[SERIALIZER]: Deserialization of root prim xml failed with {0}.  xml was {1}", e, xmlData);
            }

            //m_log.DebugFormat("[SERIALIZER]: Finished deserialization of root prim {0}, {1}ms", Name, System.Environment.TickCount - time);
            return(null);
        }
예제 #4
0
        // Called here only. Should be private?
        public static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max)
        {
            XmlTextWriter writer = new XmlTextWriter(stream);

            int primCount = 0;

            stream.WriteLine("<scene>\n");

            foreach (EntityBase ent in entityList)
            {
                if (ent is SceneObjectGroup)
                {
                    SceneObjectGroup g = (SceneObjectGroup)ent;
                    if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero))
                    {
                        Vector3 pos = g.RootPart.GetWorldPosition();
                        if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z)
                        {
                            continue;
                        }
                        if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z)
                        {
                            continue;
                        }
                    }

                    //stream.WriteLine(SceneObjectSerializer.ToXml2Format(g));
                    SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent, new Dictionary <string, object>());
                    stream.WriteLine();

                    primCount++;
                }
            }

            stream.WriteLine("</scene>\n");
            stream.Flush();
        }
예제 #5
0
        public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
        {
            XmlDocument doc = new XmlDocument();

            doc.XmlResolver = null;
            XmlNode rootNode;

            if (fileName.StartsWith("http:") || File.Exists(fileName))
            {
                using (XmlTextReader reader = new XmlTextReader(fileName))
                {
                    reader.WhitespaceHandling = WhitespaceHandling.None;
                    reader.ProhibitDtd        = true;

                    doc.Load(reader);
                }
                rootNode = doc.FirstChild;
                foreach (XmlNode aPrimNode in rootNode.ChildNodes)
                {
                    SceneObjectGroup obj = SceneObjectSerializer.FromOriginalXmlFormat(aPrimNode.OuterXml);

                    if (newIDS)
                    {
                        obj.ResetIDs();
                    }
                    //if we want this to be a import method then we need new uuids for the object to avoid any clashes
                    //obj.RegenerateFullIDs();

                    scene.AddNewSceneObject(obj, true);
                    obj.InvalidateDeepEffectivePerms();
                }
            }
            else
            {
                throw new Exception("Could not open file " + fileName + " for reading");
            }
        }
예제 #6
0
 public static SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
 {
     return(SceneObjectSerializer.FromXml2Format(xmlString));
 }
        public static bool TryFromXmlData(byte[] data, out CoalescedSceneObjects coa)
        {
            // m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;
            try
            {
                int len = data.Length;
                if (len < 32)
                {
                    return(false);
                }
                if (data[len - 1] == 0)
                {
                    --len;
                }
                // Quickly check if this is a coalesced object, without fully parsing the XML
                MemoryStream ms = new MemoryStream(data, 0, len, false);
                StreamReader sr = new StreamReader(ms, Encoding.UTF8);
                using (XmlTextReader reader = new XmlTextReader(sr))
                {
                    reader.MoveToContent(); // skip possible xml declaration

                    if (reader.Name != "CoalescedObject")
                    {
                        return(false);
                    }
                }

                XmlDocument doc = new XmlDocument();
                using (ms = new MemoryStream(data, 0, len, false))
                    doc.Load(ms);

                XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
                if (e == null)
                {
                    return(false);
                }

                coa = new CoalescedSceneObjects(UUID.Zero);

                XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
                int         i      = 0;

                foreach (XmlNode n in groups)
                {
                    SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
                    if (so != null)
                    {
                        coa.Add(so);
                    }
                    else
                    {
                        // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                        // coalesced object fails to load.
                        m_log.WarnFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                            i);
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                m_log.Error("[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of binary xml failed ", e);
                return(false);
            }

            return(true);
        }
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
            //            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;

            try
            {
                // Quickly check if this is a coalesced object, without fully parsing the XML
                using (XmlTextReader reader = new XmlTextReader(new StringReader(xml)))
                {
                    reader.MoveToContent(); // skip possible xml declaration

                    if (reader.Name != "CoalescedObject")
                    {
                        // m_log.DebugFormat(
                        //     "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false",
                        //     reader.Name);

                        return(false);
                    }
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
                if (e == null)
                {
                    return(false);
                }

                coa = new CoalescedSceneObjects(UUID.Zero);

                XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
                int         i      = 0;

                foreach (XmlNode n in groups)
                {
                    SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
                    if (so != null)
                    {
                        coa.Add(so);
                    }
                    else
                    {
                        // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                        // coalesced object fails to load.
                        m_log.WarnFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                            i);
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                m_log.Error("[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed ", e);
                Util.LogFailedXML("[COALESCED SCENE OBJECTS SERIALIZER]:", xml);
                return(false);
            }

            return(true);
        }
예제 #9
0
 public static string SaveGroupToXml2(SceneObjectGroup grp)
 {
     return(SceneObjectSerializer.ToXml2Format(grp));
 }
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
//            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;
            int i = 0;

            using (StringReader sr = new StringReader(xml))
            {
                using (XmlTextReader reader = new XmlTextReader(sr))
                {
                    try
                    {
                        reader.Read();
                        if (reader.Name != "CoalescedObject")
                        {
                            //                        m_log.DebugFormat(
                            //                            "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false",
                            //                            reader.Name);

                            return(false);
                        }

                        coa = new CoalescedSceneObjects(UUID.Zero);
                        reader.Read();

                        while (reader.NodeType != XmlNodeType.EndElement && reader.Name != "CoalescedObject")
                        {
                            if (reader.Name == "SceneObjectGroup")
                            {
                                string soXml = reader.ReadOuterXml();

                                SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(soXml);

                                if (so != null)
                                {
                                    coa.Add(so);
                                }
                                else
                                {
                                    // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                                    // coalesced object fails to load.
                                    m_log.WarnFormat(
                                        "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                                        i);
                                }

                                i++;
                            }
                        }

                        reader.ReadEndElement(); // CoalescedObject
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} {1}",
                            e.Message, e.StackTrace);

                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #11
0
 public static string SaveGroupToOriginalXml(SceneObjectGroup grp)
 {
     return(SceneObjectSerializer.ToOriginalXmlFormat(grp, false));
 }