make some use of frozendicionaries on xml processors

This commit is contained in:
UbitUmarov
2024-05-08 19:14:32 +01:00
parent 5330c8fcca
commit 1736b6a8a0
5 changed files with 95 additions and 130 deletions

View File

@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Frozen;
using System.Diagnostics;
using System.IO;
using System.Reflection;
@@ -53,7 +54,7 @@ namespace OpenSim.Framework.Serialization.External
/// <param name="xtr"></param>
/// <returns>true on successful, false if there were any processing failures</returns>
public static bool ExecuteReadProcessors<NodeType>(
NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlReader>> processors, XmlReader xtr)
NodeType nodeToFill, FrozenDictionary<string, Action<NodeType, XmlReader>> processors, XmlReader xtr)
{
return ExecuteReadProcessors(
nodeToFill,
@@ -77,7 +78,7 @@ namespace OpenSim.Framework.Serialization.External
/// <returns>true on successful, false if there were any processing failures</returns>
public static bool ExecuteReadProcessors<NodeType>(
NodeType nodeToFill,
Dictionary<string, Action<NodeType, XmlReader>> processors,
FrozenDictionary<string, Action<NodeType, XmlReader>> processors,
XmlReader xtr,
Action<NodeType, string, Exception> parseExceptionAction)
{

View File

@@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -40,107 +41,66 @@ namespace OpenSim.Framework.Serialization.External
/// </summary>
public class LandDataSerializer
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static Dictionary<string, Action<LandData, XmlReader>> m_ldProcessors
= new Dictionary<string, Action<LandData, XmlReader>>();
private static readonly FrozenDictionary<string, Action<LandData, XmlReader>> m_ldProcessors
= new Dictionary<string, Action<LandData, XmlReader>>()
{
{ "Area", (ld, xtr) => ld.Area = Convert.ToInt32(xtr.ReadElementString("Area")) },
{ "AuctionID", (ld, xtr) => ld.AuctionID = Convert.ToUInt32(xtr.ReadElementString("AuctionID")) },
{ "AuthBuyerID", (ld, xtr) => ld.AuthBuyerID = UUID.Parse(xtr.ReadElementString("AuthBuyerID"))},
{ "Category", (ld, xtr) => ld.Category = (ParcelCategory)Convert.ToSByte(xtr.ReadElementString("Category")) },
{ "ClaimDate", (ld, xtr) => ld.ClaimDate = Convert.ToInt32(xtr.ReadElementString("ClaimDate")) },
{ "ClaimPrice", (ld, xtr) => ld.ClaimPrice = Convert.ToInt32(xtr.ReadElementString("ClaimPrice")) },
{ "GlobalID", (ld, xtr) => ld.GlobalID = UUID.Parse(xtr.ReadElementString("GlobalID")) },
{ "GroupID", (ld, xtr) => ld.GroupID = UUID.Parse(xtr.ReadElementString("GroupID")) },
{ "IsGroupOwned", (ld, xtr) => ld.IsGroupOwned = Convert.ToBoolean(xtr.ReadElementString("IsGroupOwned")) },
{ "Bitmap", (ld, xtr) => ld.Bitmap = Convert.FromBase64String(xtr.ReadElementString("Bitmap")) },
{ "Description", (ld, xtr) => ld.Description = xtr.ReadElementString("Description") },
{ "Flags", (ld, xtr) => ld.Flags = Convert.ToUInt32(xtr.ReadElementString("Flags")) },
{ "LandingType", (ld, xtr) => ld.LandingType = Convert.ToByte(xtr.ReadElementString("LandingType")) },
{ "Name", (ld, xtr) => ld.Name = xtr.ReadElementString("Name") },
{ "Status", (ld, xtr) => ld.Status = (ParcelStatus) Convert.ToSByte(xtr.ReadElementString("Status")) },
{ "LocalID", (ld, xtr) => ld.LocalID = Convert.ToInt32(xtr.ReadElementString("LocalID")) },
{ "MediaAutoScale", (ld, xtr) => ld.MediaAutoScale = Convert.ToByte(xtr.ReadElementString("MediaAutoScale")) },
{ "MediaID", (ld, xtr) => ld.MediaID = UUID.Parse(xtr.ReadElementString("MediaID")) },
{ "MediaURL", (ld, xtr) => ld.MediaURL = xtr.ReadElementString("MediaURL") },
{ "MusicURL", (ld, xtr) => ld.MusicURL = xtr.ReadElementString("MusicURL") },
{ "OwnerID", (ld, xtr) => ld.OwnerID = UUID.Parse(xtr.ReadElementString("OwnerID")) },
private static Dictionary<string, Action<LandAccessEntry, XmlReader>> m_laeProcessors
= new Dictionary<string, Action<LandAccessEntry, XmlReader>>();
{ "ParcelAccessList", ProcessParcelAccessList },
{ "Environment", ProcessParcelEnvironment },
{ "PassHours", (ld, xtr) => ld.PassHours = Convert.ToSingle(xtr.ReadElementString("PassHours"))},
{ "PassPrice", (ld, xtr) => ld.PassPrice = Convert.ToInt32(xtr.ReadElementString("PassPrice"))},
{ "SalePrice", (ld, xtr) => ld.SalePrice = Convert.ToInt32(xtr.ReadElementString("SalePrice"))},
{ "SnapshotID", (ld, xtr) => ld.SnapshotID = UUID.Parse(xtr.ReadElementString("SnapshotID"))},
{ "UserLocation", (ld, xtr) => ld.UserLocation = Vector3.Parse(xtr.ReadElementString("UserLocation"))},
{ "UserLookAt", (ld, xtr) => ld.UserLookAt = Vector3.Parse(xtr.ReadElementString("UserLookAt"))},
{ "OtherCleanTime", (ld, xtr) => ld.OtherCleanTime = Convert.ToInt32(xtr.ReadElementString("OtherCleanTime")) },
{ "SeeAVs", (ld, xtr) => ld.SeeAVs = xtr.ReadElementString("SeeAVs") == "1" },
{ "AnyAVSnds", (ld, xtr) => ld.AnyAVSounds = xtr.ReadElementString("AnyAVSnds") == "1" },
{ "GrpAVSnds", (ld, xtr) => ld.GroupAVSounds = xtr.ReadElementString("GrpAVSnds") == "1" },
}.ToFrozenDictionary();
private static readonly FrozenDictionary<string, Action<LandAccessEntry, XmlReader>> m_laeProcessors
= new Dictionary<string, Action<LandAccessEntry, XmlReader>>()
{
{ "AgentID", (lae, xtr) => lae.AgentID = UUID.Parse(xtr.ReadElementString("AgentID")) },
{ "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"));
} },
{ "AccessList", (lae, xtr) => lae.Flags = (AccessList) Convert.ToUInt32(xtr.ReadElementString("AccessList")) }
}.ToFrozenDictionary();
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(
"OwnerID", (ld, xtr) => ld.OwnerID = UUID.Parse(xtr.ReadElementString("OwnerID")));
m_ldProcessors.Add(
"ParcelAccessList", ProcessParcelAccessList);
m_ldProcessors.Add(
"Environment", ProcessParcelEnvironment);
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")));
m_ldProcessors.Add(
"SeeAVs", (ld, xtr) => ld.SeeAVs = xtr.ReadElementString("SeeAVs") == "1");
m_ldProcessors.Add(
"AnyAVSnds", (ld, xtr) => ld.AnyAVSounds = xtr.ReadElementString("AnyAVSnds") == "1");
m_ldProcessors.Add(
"GrpAVSnds", (ld, xtr) => ld.GroupAVSounds = xtr.ReadElementString("GrpAVSnds") == "1");
// 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 ProcessParcelEnvironment(LandData ld, XmlReader xtr)

View File

@@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
@@ -44,34 +45,36 @@ namespace OpenSim.Framework.Serialization.External
/// </summary>
public class UserInventoryItemSerializer
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static Dictionary<string, Action<InventoryItemBase, XmlReader>> m_InventoryItemXmlProcessors
= new Dictionary<string, Action<InventoryItemBase, XmlReader>>();
private static FrozenDictionary<string, Action<InventoryItemBase, XmlReader>> m_InventoryItemXmlProcessors
= new Dictionary<string, Action<InventoryItemBase, XmlReader>>()
{
{ "Name", ProcessName },
{ "ID", ProcessID },
{ "InvType", ProcessInvType },
{ "CreatorUUID", ProcessCreatorUUID },
{ "CreatorID", ProcessCreatorID },
{ "CreatorData", ProcessCreatorData },
{ "CreationDate", ProcessCreationDate },
{ "Owner", ProcessOwner },
{ "Description", ProcessDescription },
{ "AssetType", ProcessAssetType },
{ "AssetID", ProcessAssetID },
{ "SaleType", ProcessSaleType },
{ "SalePrice", ProcessSalePrice },
{ "BasePermissions", ProcessBasePermissions },
{ "CurrentPermissions", ProcessCurrentPermissions },
{ "EveryOnePermissions", ProcessEveryOnePermissions },
{ "NextPermissions", ProcessNextPermissions },
{ "Flags", ProcessFlags },
{ "GroupID", ProcessGroupID },
{ "GroupOwned", ProcessGroupOwned },
}.ToFrozenDictionary();
#region InventoryItemBase Processor initialization
#region InventoryItemBase Processor initialization
static UserInventoryItemSerializer()
{
m_InventoryItemXmlProcessors.Add("Name", ProcessName);
m_InventoryItemXmlProcessors.Add("ID", ProcessID);
m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID);
m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData);
m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType);
m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID);
m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType);
m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice);
m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions);
m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions);
m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions);
m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions);
m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags);
m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID);
m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned);
}
#endregion

View File

@@ -292,7 +292,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
int nbytes =
await m_udpSocket.ReceiveFromAsync(buf.Data.AsMemory(), SocketFlags.None, workSktAddress, InboundCancellationSource.Token).ConfigureAwait(false);
if (!m_IsRunningInbound)
if (!m_IsRunningInbound || InboundCancellationSource.IsCancellationRequested)
{
FreeUDPBuffer(buf);
return;
@@ -302,7 +302,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
int startTick = Util.EnvironmentTickCount();
buf.RemoteEndPoint = Util.GetEndPoint(workSktAddress);;
buf.RemoteEndPoint = Util.GetEndPoint(workSktAddress);
buf.DataLength = nbytes;
UdpReceives++;

View File

@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Frozen;
using System.Drawing;
using System.IO;
using System.Reflection;
@@ -434,7 +435,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
#region manual serialization
private static readonly Dictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors = new()
private static readonly FrozenDictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors = new Dictionary<string, Action<SceneObjectPart, XmlReader>>()
{
{"AllowedDrop", ProcessAllowedDrop },
{"CreatorID", ProcessCreatorID },
@@ -526,9 +527,9 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
{"SOPAnims", ProcessSOPAnims },
{"SitActRange", ProcessSitActRange }
};
}.ToFrozenDictionary();
private static readonly Dictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors = new()
private static readonly FrozenDictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>()
{
{"AssetID", ProcessTIAssetID },
{"BasePermissions", ProcessTIBasePermissions },
@@ -554,9 +555,9 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
{"PermsMask", ProcessTIPermsMask },
{"Type", ProcessTIType },
{"OwnerChanged", ProcessTIOwnerChanged }
};
}.ToFrozenDictionary();
private static readonly Dictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors = new()
private static readonly FrozenDictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>()
{
{"ProfileCurve", ProcessShpProfileCurve },
{"TextureEntry", ProcessShpTextureEntry },
@@ -608,7 +609,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
{"SculptEntry", ProcessShpSculptEntry },
{"Media", ProcessShpMedia },
{"MatOvrd", ProcessShpMatOvrd }
};
}.ToFrozenDictionary();
#region SOPXmlProcessors
private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader)