public static FromOriginalXmlFormat ( UUID fromUserInventoryItemID, string xmlData ) : SceneObjectGroup | ||
fromUserInventoryItemID | UUID | |
xmlData | string | |
리턴 | SceneObjectGroup |
public static void LoadPrimsFromXml(IScene scene, string fileName, bool newIDS, Vector3 loadOffset) { XmlDocument doc = new XmlDocument(); if (fileName.StartsWith("http:") || File.Exists(fileName)) { XmlTextReader reader = new XmlTextReader(fileName) { WhitespaceHandling = WhitespaceHandling.None }; doc.Load(reader); reader.Close(); XmlNode rootNode = doc.FirstChild; foreach (XmlNode aPrimNode in rootNode.ChildNodes) { SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(aPrimNode.OuterXml, scene); if (group == null) { return; } group.IsDeleted = false; group.m_isLoaded = true; foreach (SceneObjectPart part in group.ChildrenList) { part.IsLoading = false; } scene.SceneGraph.AddPrimToScene(group); } } else { throw new Exception("Could not open file " + fileName + " for reading"); } }
public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset) { XmlDocument doc = new XmlDocument(); XmlNode rootNode; if (fileName.StartsWith("http:") || File.Exists(fileName)) { XmlTextReader reader = new XmlTextReader(fileName); reader.WhitespaceHandling = WhitespaceHandling.None; doc.Load(reader); reader.Close(); 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); } } else { throw new Exception("Could not open file " + fileName + " for reading"); } }
public static bool TryFromXml(string xml, out CoalescedSceneObjects coa) { // m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml); coa = null; 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(); coa.Add(SceneObjectSerializer.FromOriginalXmlFormat(soXml)); } } 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); }
/// <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); }
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); }
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); }