From ed846f11f17b7497c9a0bcf599fcb6431504c18e Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Thu, 2 Feb 2012 18:06:34 -0800 Subject: OpenSim tests do not always create an EventManager so calls to trigger events during tests must check for null EventManager --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 9b660b6..9fb11d3 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2729,7 +2729,9 @@ namespace OpenSim.Region.Framework.Scenes if (ParentGroup == null) return; - ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); + // When running OpenSim tests, EventManager can be null. Maybe tests should create an EventManager. + if(ParentGroup.Scene.EventManager != null) + ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); ParentGroup.QueueForUpdateCheck(); @@ -2763,7 +2765,9 @@ namespace OpenSim.Region.Framework.Scenes if (ParentGroup == null) return; - ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); + // When running OpenSim tests, EventManager can be null. Maybe tests should create an EventManager. + if (ParentGroup.Scene.EventManager != null) + ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); // This was pulled from SceneViewer. Attachments always receive full updates. // I could not verify if this is a requirement but this maintains existing behavior -- cgit v1.1 From 61adf36339f15fcbcc16d96ff7089f03edf72c10 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Thu, 2 Feb 2012 18:19:22 -0800 Subject: Commenting out new event until I can fix OpenSim tests. Currently, testing objects does not create a Scene or EventManager so triggering events crashes some tests --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 9fb11d3..27bcc09 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2729,9 +2729,9 @@ namespace OpenSim.Region.Framework.Scenes if (ParentGroup == null) return; - // When running OpenSim tests, EventManager can be null. Maybe tests should create an EventManager. - if(ParentGroup.Scene.EventManager != null) - ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); + // When running OpenSim tests, Scene (and EventManager can be null). + // Need to fix tests before we can trigger this here + // ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); ParentGroup.QueueForUpdateCheck(); @@ -2765,9 +2765,9 @@ namespace OpenSim.Region.Framework.Scenes if (ParentGroup == null) return; - // When running OpenSim tests, EventManager can be null. Maybe tests should create an EventManager. - if (ParentGroup.Scene.EventManager != null) - ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); + // When running OpenSim tests, Scene (and EventManager can be null). + // Need to fix tests before we can trigger this here + // ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this); // This was pulled from SceneViewer. Attachments always receive full updates. // I could not verify if this is a requirement but this maintains existing behavior -- cgit v1.1 From 1a18948935eb6dcb65fb7a75b241ede9d42af055 Mon Sep 17 00:00:00 2001 From: Snoopy Pfeffer Date: Fri, 3 Feb 2012 23:04:18 +0100 Subject: Corrected console help texts for "save iar" --- .../CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index 150d913..09b4ba6 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs @@ -122,7 +122,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver scene.AddCommand( this, "save iar", - "save iar [-h|--home=] [--noassets] [] [--v|-verbose]", + "save iar [-p|--profile=] [--noassets] [] [-c|--creators] [-v|--verbose]", "Save user inventory archive (IAR).", " is the user's first name." + Environment.NewLine + " is the user's last name." + Environment.NewLine @@ -408,7 +408,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (mainParams.Count < 6) { m_log.Error( - "[INVENTORY ARCHIVER]: usage is save iar [--p|-profile=] [--noassets] []"); + "[INVENTORY ARCHIVER]: usage is save iar [-p|--profile=] [--noassets] [] [-c|--creators] [-v|--verbose]"); return; } -- cgit v1.1 From f17066b7bf27c22448d883e0af9d20a42f671b62 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 22:21:54 +0000 Subject: Change LandDataSerializer deserialization so that in the future it won't care about extra elements or element order. This brings it into line with other deserializations such as object and will improve future backward compatibility. --- OpenSim/Framework/LandData.cs | 2 +- .../Serialization/External/LandDataSerializer.cs | 237 +++++++++++++++------ .../External/UserInventoryItemSerializer.cs | 3 +- .../External/UserProfileSerializer.cs | 5 +- .../Serialization/Tests/LandDataSerializerTests.cs | 37 +++- 5 files changed, 209 insertions(+), 75 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/LandData.cs b/OpenSim/Framework/LandData.cs index 58a80ef..f6271ef 100644 --- a/OpenSim/Framework/LandData.cs +++ b/OpenSim/Framework/LandData.cs @@ -34,7 +34,7 @@ using OpenMetaverse; namespace OpenSim.Framework { - public struct LandAccessEntry + public class LandAccessEntry { public UUID AgentID; public int Expires; diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index 3ae9a8e..bf6c4e5 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -28,8 +28,10 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text; using System.Xml; +using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -40,8 +42,152 @@ namespace OpenSim.Framework.Serialization.External /// public class LandDataSerializer { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); + private delegate void LandDataProcessor(LandData landData, XmlTextReader reader); + private static Dictionary m_ldProcessors + = new Dictionary(); + + private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader); + private static Dictionary m_laeProcessors + = new Dictionary(); + + static LandDataSerializer() + { + // LandData processors + m_ldProcessors.Add( + "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area"))); + m_ldProcessors.Add( + "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID"))); + m_ldProcessors.Add( + "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID"))); + m_ldProcessors.Add( + "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category"))); + m_ldProcessors.Add( + "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate"))); + m_ldProcessors.Add( + "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice"))); + m_ldProcessors.Add( + "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID"))); + m_ldProcessors.Add( + "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID"))); + m_ldProcessors.Add( + "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned"))); + m_ldProcessors.Add( + "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap"))); + m_ldProcessors.Add( + "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description")); + m_ldProcessors.Add( + "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags"))); + m_ldProcessors.Add( + "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType"))); + m_ldProcessors.Add( + "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name")); + m_ldProcessors.Add( + "Status", (ld, xtr) => ld.Status = (ParcelStatus)Convert.ToSByte(xtr.ReadElementString("Status"))); + m_ldProcessors.Add( + "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID"))); + m_ldProcessors.Add( + "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale"))); + m_ldProcessors.Add( + "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID"))); + m_ldProcessors.Add( + "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL")); + m_ldProcessors.Add( + "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL")); + + m_ldProcessors.Add( + "ParcelAccessList", ProcessParcelAccessList); + + m_ldProcessors.Add( + "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))); + m_ldProcessors.Add( + "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice"))); + m_ldProcessors.Add( + "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"))); + m_ldProcessors.Add( + "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID"))); + m_ldProcessors.Add( + "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation"))); + m_ldProcessors.Add( + "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt"))); + + // No longer used here // + // m_ldProcessors.Add("Dwell", (landData, xtr) => return); + + m_ldProcessors.Add( + "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime"))); + + // LandAccessEntryProcessors + m_laeProcessors.Add( + "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID"))); + m_laeProcessors.Add( + "Time", (lae, xtr) => + { + // We really don't care about temp vs perm here and this + // would break on old oars. Assume all bans are perm + xtr.ReadElementString("Time"); + lae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); + } + ); + m_laeProcessors.Add( + "AccessList", (lae, xtr) => lae.Flags = (AccessList)Convert.ToUInt32(xtr.ReadElementString("AccessList"))); + } + + public static void ProcessParcelAccessList(LandData ld, XmlTextReader xtr) + { + if (!xtr.IsEmptyElement) + { + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + LandAccessEntry lae = new LandAccessEntry(); + + xtr.ReadStartElement("ParcelAccessEntry"); + + string nodeName = string.Empty; + while (xtr.NodeType != XmlNodeType.EndElement) + { + nodeName = xtr.Name; + +// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName); + + LandAccessEntryProcessor p = null; + if (m_laeProcessors.TryGetValue(xtr.Name, out p)) + { +// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName); + + try + { + p(lae, xtr); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); + + if (xtr.NodeType == XmlNodeType.EndElement) + xtr.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + xtr.ReadOuterXml(); // ignore + } + } + + xtr.ReadEndElement(); + + ld.ParcelAccessList.Add(lae); + } + } + + xtr.Read(); + } + /// /// Reify/deserialize landData /// @@ -63,72 +209,43 @@ namespace OpenSim.Framework.Serialization.External { LandData landData = new LandData(); - StringReader sr = new StringReader(serializedLandData); - XmlTextReader xtr = new XmlTextReader(sr); - - xtr.ReadStartElement("LandData"); - - landData.Area = Convert.ToInt32( xtr.ReadElementString("Area")); - landData.AuctionID = Convert.ToUInt32( xtr.ReadElementString("AuctionID")); - landData.AuthBuyerID = UUID.Parse( xtr.ReadElementString("AuthBuyerID")); - landData.Category = (ParcelCategory)Convert.ToSByte( xtr.ReadElementString("Category")); - landData.ClaimDate = Convert.ToInt32( xtr.ReadElementString("ClaimDate")); - landData.ClaimPrice = Convert.ToInt32( xtr.ReadElementString("ClaimPrice")); - landData.GlobalID = UUID.Parse( xtr.ReadElementString("GlobalID")); - landData.GroupID = UUID.Parse( xtr.ReadElementString("GroupID")); - landData.IsGroupOwned = Convert.ToBoolean( xtr.ReadElementString("IsGroupOwned")); - landData.Bitmap = Convert.FromBase64String( xtr.ReadElementString("Bitmap")); - landData.Description = xtr.ReadElementString("Description"); - landData.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags")); - landData.LandingType = Convert.ToByte( xtr.ReadElementString("LandingType")); - landData.Name = xtr.ReadElementString("Name"); - landData.Status = (ParcelStatus)Convert.ToSByte( xtr.ReadElementString("Status")); - landData.LocalID = Convert.ToInt32( xtr.ReadElementString("LocalID")); - landData.MediaAutoScale = Convert.ToByte( xtr.ReadElementString("MediaAutoScale")); - landData.MediaID = UUID.Parse( xtr.ReadElementString("MediaID")); - landData.MediaURL = xtr.ReadElementString("MediaURL"); - landData.MusicURL = xtr.ReadElementString("MusicURL"); - landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); - - landData.ParcelAccessList = new List(); - xtr.Read(); - if (xtr.Name != "ParcelAccessList") - throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name)); - - if (!xtr.IsEmptyElement) + using (XmlTextReader reader = new XmlTextReader(new StringReader(serializedLandData))) { - while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) - { - LandAccessEntry pae = new LandAccessEntry(); + reader.ReadStartElement("LandData"); - xtr.ReadStartElement("ParcelAccessEntry"); - pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); - // We really don't care about temp vs perm here and this - // would break on old oars. Assume all bans are perm - xtr.ReadElementString("Time"); - pae.Expires = 0; // Convert.ToUint( xtr.ReadElementString("Time")); - pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); - xtr.ReadEndElement(); + string nodeName = string.Empty; + while (reader.NodeType != XmlNodeType.EndElement) + { + nodeName = reader.Name; - landData.ParcelAccessList.Add(pae); - } - } - xtr.Read(); +// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName); - landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); - landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); - landData.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice")); - landData.SnapshotID = UUID.Parse( xtr.ReadElementString("SnapshotID")); - landData.UserLocation = Vector3.Parse( xtr.ReadElementString("UserLocation")); - landData.UserLookAt = Vector3.Parse( xtr.ReadElementString("UserLookAt")); - // No longer used here - xtr.ReadElementString("Dwell"); - landData.OtherCleanTime = Convert.ToInt32( xtr.ReadElementString("OtherCleanTime")); + LandDataProcessor p = null; + if (m_ldProcessors.TryGetValue(reader.Name, out p)) + { + try + { + p(landData, reader); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); - xtr.ReadEndElement(); + if (reader.NodeType == XmlNodeType.EndElement) + reader.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + reader.ReadOuterXml(); // ignore + } + } - xtr.Close(); - sr.Close(); + reader.ReadEndElement(); + } return landData; } diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index f138437..5d986d5 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -41,8 +41,7 @@ namespace OpenSim.Framework.Serialization.External { /// /// Serialize and deserialize user inventory items as an external format. - /// - /// XXX: Please do not use yet. + /// public class UserInventoryItemSerializer { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); diff --git a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs index f50b49a..c685a15 100644 --- a/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserProfileSerializer.cs @@ -33,8 +33,11 @@ using OpenSim.Framework; namespace OpenSim.Framework.Serialization.External { /// - /// Serialize and deserialize region settings as an external format. + /// Serialize and deserialize user profiles as an external format. /// + /// + /// Currently UNUSED. + /// public class UserProfileSerializer { public const int MAJOR_VERSION = 0; diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index 3607ce8..11a3a0a 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -27,11 +27,12 @@ using System; using System.Collections.Generic; -using OpenSim.Framework; -using OpenSim.Framework.Serialization.External; using OpenMetaverse; using OpenMetaverse.StructuredData; using NUnit.Framework; +using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; +using OpenSim.Tests.Common; namespace OpenSim.Framework.Serialization.Tests { @@ -92,6 +93,8 @@ namespace OpenSim.Framework.Serialization.Tests [Test] public void LandDataSerializerSerializeTest() { + TestHelpers.InMethod(); + string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n"); Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); @@ -112,20 +115,32 @@ namespace OpenSim.Framework.Serialization.Tests /// Test the LandDataSerializer.Deserialize() method /// [Test] - public void TestLandDataSerializerDeserializeFromStringTest() + public void TestLandDataDeserializeNoAccessLists() + { + TestHelpers.InMethod(); + log4net.Config.XmlConfigurator.Configure(); + + LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); + Assert.That(ld != null, "Deserialize(string) returned null"); + Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); + Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + } + + [Test] + public void TestLandDataDeserializeWithAccessLists() { - LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized); - Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); - Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); - Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); - LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); - Assert.That(reifiedLandDataWithParcelAccessList != null, + LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList); + Assert.That(ld != null, "Deserialize(string) returned null (pre-serialized with parcel access list)"); - Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID, + Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)"); - Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name, + Assert.That(ld.Name == this.landWithParcelAccessList.Name, "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)"); + Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2)); + Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c"))); } } } -- cgit v1.1 From 623426421132fdc41d9de006fb55aedc660d5362 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 22:45:50 +0000 Subject: Refactor common deserialization processor code to generic method ExternalRepresentationUtils.ExecuteReadProcessors() --- .../External/ExternalRepresentationUtils.cs | 53 +++++++++++++++- .../Serialization/External/LandDataSerializer.cs | 74 ++-------------------- .../External/UserInventoryItemSerializer.cs | 33 ++-------- 3 files changed, 62 insertions(+), 98 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 7447ac2..39a9f37 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -24,11 +24,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Xml; - +using log4net; using OpenMetaverse; using OpenSim.Services.Interfaces; @@ -39,6 +41,55 @@ namespace OpenSim.Framework.Serialization.External /// public class ExternalRepresentationUtils { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + /// + /// Populate a node with data read from xml using a dictinoary of processors + /// + /// + /// + /// A + /// + /// + /// A + /// + public static void ExecuteReadProcessors( + NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) + { + string nodeName = string.Empty; + while (xtr.NodeType != XmlNodeType.EndElement) + { + nodeName = xtr.Name; + +// m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName); + + Action p = null; + if (processors.TryGetValue(xtr.Name, out p)) + { +// m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName); + + try + { + p(nodeToFill, xtr); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", + nodeName, e.Message, e.StackTrace); + + if (xtr.NodeType == XmlNodeType.EndElement) + xtr.Read(); + } + } + else + { + // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); + xtr.ReadOuterXml(); // ignore + } + } + } + /// /// Takes a XML representation of a SceneObjectPart and returns another XML representation /// with creator data added to it. diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index bf6c4e5..a12877a 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -46,13 +46,11 @@ namespace OpenSim.Framework.Serialization.External protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); - private delegate void LandDataProcessor(LandData landData, XmlTextReader reader); - private static Dictionary m_ldProcessors - = new Dictionary(); + private static Dictionary> m_ldProcessors + = new Dictionary>(); - private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader); - private static Dictionary m_laeProcessors - = new Dictionary(); + private static Dictionary> m_laeProcessors + = new Dictionary>(); static LandDataSerializer() { @@ -146,38 +144,7 @@ namespace OpenSim.Framework.Serialization.External xtr.ReadStartElement("ParcelAccessEntry"); - string nodeName = string.Empty; - while (xtr.NodeType != XmlNodeType.EndElement) - { - nodeName = xtr.Name; - -// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName); - - LandAccessEntryProcessor p = null; - if (m_laeProcessors.TryGetValue(xtr.Name, out p)) - { -// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName); - - try - { - p(lae, xtr); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); - - if (xtr.NodeType == XmlNodeType.EndElement) - xtr.Read(); - } - } - else - { - // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); - xtr.ReadOuterXml(); // ignore - } - } + ExternalRepresentationUtils.ExecuteReadProcessors(lae, m_laeProcessors, xtr); xtr.ReadEndElement(); @@ -213,36 +180,7 @@ namespace OpenSim.Framework.Serialization.External { reader.ReadStartElement("LandData"); - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - -// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName); - - LandDataProcessor p = null; - if (m_ldProcessors.TryGetValue(reader.Name, out p)) - { - try - { - p(landData, reader); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); - - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { - // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName); - reader.ReadOuterXml(); // ignore - } - } + ExternalRepresentationUtils.ExecuteReadProcessors(landData, m_ldProcessors, reader); reader.ReadEndElement(); } diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs index 5d986d5..f6fdc4b 100644 --- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs +++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs @@ -46,8 +46,8 @@ namespace OpenSim.Framework.Serialization.External { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader); - private static Dictionary m_InventoryItemXmlProcessors = new Dictionary(); + private static Dictionary> m_InventoryItemXmlProcessors + = new Dictionary>(); #region InventoryItemBase Processor initialization static UserInventoryItemSerializer() @@ -204,39 +204,14 @@ namespace OpenSim.Framework.Serialization.External { reader.ReadStartElement("InventoryItem"); - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - InventoryItemXmlProcessor p = null; - if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p)) - { - //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); - try - { - p(item, reader); - } - catch (Exception e) - { - m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e); - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { - // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName); - reader.ReadOuterXml(); // ignore - } - - } + ExternalRepresentationUtils.ExecuteReadProcessors( + item, m_InventoryItemXmlProcessors, reader); reader.ReadEndElement(); // InventoryItem } //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); return item; - } public static string Serialize(InventoryItemBase inventoryItem, Dictionary options, IUserAccountService userAccountService) -- cgit v1.1 From ce34b359ad0254b6b4f460e2740e1a1ed30c456b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 23:04:26 +0000 Subject: Extend m_avatars lock in NpcModule.CreateNPC over both creation of NPC scene presence and population of m_avatars. This is required to stop a race where the SensorRepeat module can detect an NPC avatar before m_avatars is populated. Extending the lock is the easiest to understand solution rather than getting complicated with null checks. Hopefully resolves http://opensimulator.org/mantis/view.php?id=5872 --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3831d7a..6a48b89 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -140,24 +140,26 @@ namespace OpenSim.Region.OptionalModules.World.NPC // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); // } - scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); - scene.AddNewClient(npcAvatar, PresenceType.Npc); - - ScenePresence sp; - if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + lock (m_avatars) { - m_log.DebugFormat( - "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); + scene.AddNewClient(npcAvatar, PresenceType.Npc); - sp.CompleteMovement(npcAvatar, false); - } - else - { - m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); - } + ScenePresence sp; + if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) + { + m_log.DebugFormat( + "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + + sp.CompleteMovement(npcAvatar, false); + } + else + { + m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); + } - lock (m_avatars) m_avatars.Add(npcAvatar.AgentId, npcAvatar); + } m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); -- cgit v1.1