public static DAMap FromXml(string rawXml) { DAMap map = new DAMap(); map.ReadXml(rawXml); return(map); }
public void CopyFrom(DAMap other) { // Deep copy string data = null; lock (other) { if (other.CountNamespaces > 0) { data = OSDParser.SerializeLLSDXmlString(other.m_map); } } lock (this) { if (data == null) { Clear(); } else { m_map = (OSDMap)OSDParser.DeserializeLLSDXml(data); } } }
/// <summary> /// Sanitise the map to remove any namespaces or stores that are not OSDMap. /// </summary> /// <param name='map'> /// </param> public static void SanitiseMap(DAMap daMap) { List <string> keysToRemove = null; OSDMap namespacesMap = daMap.m_map; foreach (string key in namespacesMap.Keys) { // Console.WriteLine("Processing ns {0}", key); if (!(namespacesMap[key] is OSDMap)) { if (keysToRemove == null) { keysToRemove = new List <string>(); } keysToRemove.Add(key); } } if (keysToRemove != null) { foreach (string key in keysToRemove) { // Console.WriteLine ("Removing bad ns {0}", key); namespacesMap.Remove(key); } } foreach (OSD nsOsd in namespacesMap.Values) { OSDMap nsOsdMap = (OSDMap)nsOsd; keysToRemove = null; foreach (string key in nsOsdMap.Keys) { if (!(nsOsdMap[key] is OSDMap)) { if (keysToRemove == null) { keysToRemove = new List <string>(); } keysToRemove.Add(key); } } if (keysToRemove != null) { foreach (string key in keysToRemove) { nsOsdMap.Remove(key); } } } }
public void Add(string ns, string objName, object dynObj) { DAMap.ValidateNamespace(ns); lock (this) { if (m_map == null) { m_map = new Dictionary <string, object>(); } m_map.Add(objName, dynObj); } }
// ~SceneObjectPart() // { // Console.WriteLine( // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}", // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId); // m_log.DebugFormat( // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}", // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId); // } #region Constructors /// <summary> /// No arg constructor called by region restore db code /// </summary> public SceneObjectPart() { m_TextureAnimation = Utils.EmptyBytes; m_particleSystem = Utils.EmptyBytes; Rezzed = DateTime.UtcNow; Description = String.Empty; DynAttrs = new DAMap(); // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log m_inventory = new SceneObjectPartInventory(this); }
public void TestSerializeXml2() { TestHelpers.InMethod(); //log4net.Config.XmlConfigurator.Configure(); string rpName = "My Little Pony"; UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000064"); UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000015"); PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); // Vector3 groupPosition = new Vector3(10, 20, 30); // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); // Vector3 offsetPosition = new Vector3(5, 10, 15); SceneObjectPart rp = new SceneObjectPart(); rp.UUID = rpUuid; rp.Name = rpName; rp.CreatorID = rpCreatorId; rp.Shape = shape; string daNamespace = "MyNamespace"; string daStoreName = "MyStore"; string daKey = "foo"; string daValue = "bar"; OSDMap myStore = new OSDMap(); myStore.Add(daKey, daValue); rp.DynAttrs = new DAMap(); rp.DynAttrs.SetStore(daNamespace, daStoreName, myStore); SceneObjectGroup so = new SceneObjectGroup(rp); // Need to add the object to the scene so that the request to get script state succeeds m_scene.AddSceneObject(so); Dictionary<string, object> options = new Dictionary<string, object>(); options["old-guids"] = true; string xml2 = m_serialiserModule.SerializeGroupToXml2(so, options); XmlTextReader xtr = new XmlTextReader(new StringReader(xml2)); xtr.ReadStartElement("SceneObjectGroup"); xtr.ReadStartElement("SceneObjectPart"); UUID uuid = UUID.Zero; string name = null; UUID creatorId = UUID.Zero; DAMap daMap = null; while (xtr.Read() && xtr.Name != "SceneObjectPart") { if (xtr.NodeType != XmlNodeType.Element) continue; switch (xtr.Name) { case "UUID": xtr.ReadStartElement("UUID"); uuid = UUID.Parse(xtr.ReadElementString("Guid")); xtr.ReadEndElement(); break; case "Name": name = xtr.ReadElementContentAsString(); break; case "CreatorID": xtr.ReadStartElement("CreatorID"); creatorId = UUID.Parse(xtr.ReadElementString("Guid")); xtr.ReadEndElement(); break; case "DynAttrs": daMap = new DAMap(); daMap.ReadXml(xtr); break; } } xtr.ReadEndElement(); xtr.ReadStartElement("OtherParts"); xtr.ReadEndElement(); xtr.Close(); // TODO: More checks Assert.That(uuid, Is.EqualTo(rpUuid)); Assert.That(name, Is.EqualTo(rpName)); Assert.That(creatorId, Is.EqualTo(rpCreatorId)); Assert.NotNull(daMap); Assert.AreEqual(daValue, daMap.GetStore(daNamespace, daStoreName)[daKey].AsString()); }
public static DAMap FromXml(string rawXml) { DAMap map = new DAMap(); map.ReadXml(rawXml); return map; }
/// <summary> /// Sanitise the map to remove any namespaces or stores that are not OSDMap. /// </summary> /// <param name='map'> /// </param> public static void SanitiseMap(DAMap daMap) { List<string> keysToRemove = null; OSDMap namespacesMap = daMap.m_map; foreach (string key in namespacesMap.Keys) { // Console.WriteLine("Processing ns {0}", key); if (!(namespacesMap[key] is OSDMap)) { if (keysToRemove == null) keysToRemove = new List<string>(); keysToRemove.Add(key); } } if (keysToRemove != null) { foreach (string key in keysToRemove) { // Console.WriteLine ("Removing bad ns {0}", key); namespacesMap.Remove(key); } } foreach (OSD nsOsd in namespacesMap.Values) { OSDMap nsOsdMap = (OSDMap)nsOsd; keysToRemove = null; foreach (string key in nsOsdMap.Keys) { if (!(nsOsdMap[key] is OSDMap)) { if (keysToRemove == null) keysToRemove = new List<string>(); keysToRemove.Add(key); } } if (keysToRemove != null) foreach (string key in keysToRemove) nsOsdMap.Remove(key); } }
public void CopyFrom(DAMap other) { // Deep copy string data = null; lock (other) { if (other.CountNamespaces > 0) { data = OSDParser.SerializeLLSDXmlString(other.m_map); } } lock (this) { if (data == null) Clear(); else m_map = (OSDMap)OSDParser.DeserializeLLSDXml(data); } }
public void Add(string ns, string objName, object dynObj) { DAMap.ValidateNamespace(ns); m_map.Add(objName, dynObj); }
public void TestSerializeXml() { TestHelpers.InMethod(); //log4net.Config.XmlConfigurator.Configure(); string rpName = "My Little Donkey"; UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000964"); UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000915"); PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); // Vector3 groupPosition = new Vector3(10, 20, 30); // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); // Vector3 offsetPosition = new Vector3(5, 10, 15); SceneObjectPart rp = new SceneObjectPart(); rp.UUID = rpUuid; rp.Name = rpName; rp.CreatorID = rpCreatorId; rp.Shape = shape; string daStoreName = "MyStore"; string daKey = "foo"; string daValue = "bar"; OSDMap myStore = new OSDMap(); myStore.Add(daKey, daValue); rp.DynAttrs = new DAMap(); rp.DynAttrs[daStoreName] = myStore; SceneObjectGroup so = new SceneObjectGroup(rp); // Need to add the object to the scene so that the request to get script state succeeds m_scene.AddSceneObject(so); string xml = SceneObjectSerializer.ToOriginalXmlFormat(so); XmlTextReader xtr = new XmlTextReader(new StringReader(xml)); xtr.ReadStartElement("SceneObjectGroup"); xtr.ReadStartElement("RootPart"); xtr.ReadStartElement("SceneObjectPart"); UUID uuid = UUID.Zero; string name = null; UUID creatorId = UUID.Zero; DAMap daMap = null; while (xtr.Read() && xtr.Name != "SceneObjectPart") { if (xtr.NodeType != XmlNodeType.Element) continue; switch (xtr.Name) { case "UUID": xtr.ReadStartElement("UUID"); try { uuid = UUID.Parse(xtr.ReadElementString("UUID")); xtr.ReadEndElement(); } catch { } // ignore everything but <UUID><UUID>...</UUID></UUID> break; case "Name": name = xtr.ReadElementContentAsString(); break; case "CreatorID": xtr.ReadStartElement("CreatorID"); creatorId = UUID.Parse(xtr.ReadElementString("UUID")); xtr.ReadEndElement(); break; case "DynAttrs": daMap = new DAMap(); daMap.ReadXml(xtr); break; } } xtr.ReadEndElement(); xtr.ReadEndElement(); xtr.ReadStartElement("OtherParts"); xtr.ReadEndElement(); xtr.Close(); // TODO: More checks Assert.That(uuid, Is.EqualTo(rpUuid)); Assert.That(name, Is.EqualTo(rpName)); Assert.That(creatorId, Is.EqualTo(rpCreatorId)); Assert.NotNull(daMap); Assert.AreEqual(daValue, daMap[daStoreName][daKey].AsString()); }