Reintroduce ProtoBuf and use it for inventory caching too. ZeroFormatter wasn't working out.
This commit is contained in:
@@ -27,58 +27,34 @@
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using ZeroFormatter;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace OpenMetaverse
|
||||
{
|
||||
[ZeroFormattable]
|
||||
public class InventoryNode
|
||||
[Serializable]
|
||||
[ProtoContract(SkipConstructor=true)]
|
||||
public class InventoryNode : ISerializable
|
||||
{
|
||||
[Index(0)]
|
||||
private InventoryBase data;
|
||||
[Index(1)]
|
||||
private InventoryNode parent;
|
||||
[Index(3)]
|
||||
private UUID parentID; //used for de-seralization
|
||||
[Index(4)]
|
||||
private InventoryNodeDictionary nodes;
|
||||
[Index(5)]
|
||||
private bool needsUpdate = true;
|
||||
[IgnoreFormat]
|
||||
private object tag;
|
||||
|
||||
/// <summary></summary>
|
||||
public InventoryBase Data
|
||||
{
|
||||
get => data;
|
||||
set => data = value;
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public InventoryBase Data { get; set; }
|
||||
|
||||
/// <summary>User data</summary>
|
||||
public object Tag
|
||||
{
|
||||
get => tag;
|
||||
set => tag = value;
|
||||
}
|
||||
[ProtoMember(2)]
|
||||
public InventoryNode Parent { get; set; }
|
||||
|
||||
/// <summary></summary>
|
||||
public InventoryNode Parent
|
||||
{
|
||||
get => parent;
|
||||
set => parent = value;
|
||||
}
|
||||
[ProtoMember(3)]
|
||||
public UUID ParentID { get; }
|
||||
|
||||
/// <summary></summary>
|
||||
public UUID ParentID => parentID;
|
||||
|
||||
/// <summary></summary>
|
||||
[ProtoMember(4)]
|
||||
public InventoryNodeDictionary Nodes
|
||||
{
|
||||
get { return nodes ?? (nodes = new InventoryNodeDictionary(this)); }
|
||||
get => nodes ?? (nodes = new InventoryNodeDictionary(this));
|
||||
set => nodes = value;
|
||||
}
|
||||
|
||||
public System.DateTime ModifyTime
|
||||
[ProtoMember(5)]
|
||||
public DateTime ModifyTime
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -86,7 +62,7 @@ namespace OpenMetaverse
|
||||
{
|
||||
return item.CreationDate;
|
||||
}
|
||||
DateTime newest = default(DateTime); //.MinValue;
|
||||
DateTime newest = default; //.MinValue;
|
||||
if (Data is InventoryFolder)
|
||||
{
|
||||
foreach (var node in Nodes.Values)
|
||||
@@ -99,29 +75,17 @@ namespace OpenMetaverse
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
Nodes.Sort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For inventory folder nodes specifies weather the folder needs to be
|
||||
/// refreshed from the server
|
||||
/// </summary>
|
||||
public bool NeedsUpdate
|
||||
{
|
||||
get { return needsUpdate; }
|
||||
set { needsUpdate = value; }
|
||||
}
|
||||
|
||||
public InventoryNode()
|
||||
{
|
||||
}
|
||||
[ProtoMember(6)]
|
||||
public bool NeedsUpdate { get; set; }
|
||||
|
||||
/// <param name="data"></param>
|
||||
public InventoryNode(InventoryBase data)
|
||||
{
|
||||
this.data = data;
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,8 +93,8 @@ namespace OpenMetaverse
|
||||
/// </summary>
|
||||
public InventoryNode(InventoryBase data, InventoryNode parent)
|
||||
{
|
||||
this.data = data;
|
||||
this.parent = parent;
|
||||
this.Data = data;
|
||||
this.Parent = parent;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
@@ -138,15 +102,20 @@ namespace OpenMetaverse
|
||||
lock (parent.Nodes.SyncRoot) parent.Nodes.Add(data.UUID, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
Nodes.Sort();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialization handler for the InventoryNode Class
|
||||
/// </summary>
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
|
||||
{
|
||||
info.AddValue("Parent", parent?.Data.UUID ?? UUID.Zero, typeof(UUID));
|
||||
info.AddValue("Type", data.GetType(), typeof(Type));
|
||||
data.GetObjectData(info, ctxt);
|
||||
info.AddValue("Parent", Parent?.Data.UUID ?? UUID.Zero, typeof(UUID));
|
||||
info.AddValue("Type", Data.GetType(), typeof(Type));
|
||||
Data.GetObjectData(info, ctxt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,12 +123,12 @@ namespace OpenMetaverse
|
||||
/// </summary>
|
||||
public InventoryNode(SerializationInfo info, StreamingContext ctxt)
|
||||
{
|
||||
parentID = (UUID)info.GetValue("Parent", typeof(UUID));
|
||||
ParentID = (UUID)info.GetValue("Parent", typeof(UUID));
|
||||
Type type = (Type)info.GetValue("Type", typeof(Type));
|
||||
|
||||
// Construct a new inventory object based on the Type stored in Type
|
||||
System.Reflection.ConstructorInfo ctr = type.GetConstructor(new Type[] {typeof(SerializationInfo),typeof(StreamingContext)});
|
||||
data = (InventoryBase) ctr.Invoke(new Object[] { info, ctxt });
|
||||
System.Reflection.ConstructorInfo ctr = type.GetConstructor(new[] {typeof(SerializationInfo),typeof(StreamingContext)});
|
||||
Data = (InventoryBase) ctr?.Invoke(new object[] { info, ctxt });
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
Reference in New Issue
Block a user