2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2023-07-01 15:32:23 +03:00
parent 7ce0037e40
commit b6f5a8d9dd
12 changed files with 73 additions and 27 deletions

View File

@ -97,7 +97,7 @@ public class AutoList<T, ST> : IEnumerable<T>, ICollection, ICollection<T>
/// Create a new instance of AutoList
/// </summary>
/// <param name="state">State object to be included when an event is raised.</param>
public AutoList(ST state)
public AutoList(ST state = default(ST))
{
State = state;
#if NETSTANDARD

View File

@ -203,14 +203,19 @@ public static class Codec
// Special
[typeof(object[])] = DataSerializer.ListComposer,// DataSerializer.ListComposerFromArray,
[typeof(List<object>)] = DataSerializer.ListComposer,// DataSerializer.ListComposerFromList,
[typeof(VarList<object>)] = DataSerializer.ListComposer,// DataSerializer.ListComposerFromList,
[typeof(IResource[])] = DataSerializer.ResourceListComposer,// (value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(IResource?[])] = DataSerializer.ResourceListComposer,// (value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(List<IResource>)] = DataSerializer.ResourceListComposer, //(value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(List<IResource?>)] = DataSerializer.ResourceListComposer, //(value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(VarList<IResource>)] = DataSerializer.ResourceListComposer, //(value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(VarList<IResource?>)] = DataSerializer.ResourceListComposer, //(value, con) => (TransmissionTypeIdentifier.ResourceList, DC.ToBytes((decimal)value)),
[typeof(IRecord[])] = DataSerializer.RecordListComposer,// (value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(IRecord?[])] = DataSerializer.RecordListComposer,// (value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(List<IRecord>)] = DataSerializer.RecordListComposer, //(value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(List<IRecord?>)] = DataSerializer.RecordListComposer, //(value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(VarList<IRecord>)] = DataSerializer.RecordListComposer, //(value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(VarList<IRecord?>)] = DataSerializer.RecordListComposer, //(value, con) => (TransmissionTypeIdentifier.RecordList, DC.ToBytes((decimal)value)),
[typeof(Map<object, object>)] = DataSerializer.MapComposer,
[typeof(Map<object?, object>)] = DataSerializer.MapComposer,
[typeof(Map<object, object?>)] = DataSerializer.MapComposer,
@ -297,7 +302,7 @@ public static class Codec
else if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(List<>))
if (genericType == typeof(List<>) || genericType == typeof(VarList<>))
{
var args = type.GetGenericArguments();
//if (Composers.ContainsKey(args[0]))

View File

@ -317,6 +317,11 @@ public static class DataSerializer
var resource = (IResource)value;
var rt = new byte[4];
if (resource.Instance == null || resource.Instance.IsDestroyed)
{
return (TransmissionTypeIdentifier.Null, new byte[0]);
}
if (Codec.IsLocalResource(resource, connection))
{
@ -327,9 +332,13 @@ public static class DataSerializer
}
else
{
//rt.Append((value as IResource).Instance.Template.ClassId, (value as IResource).Instance.Id);
connection.cache.Add(value as IResource, DateTime.UtcNow);
Console.WriteLine("Adding to cache " + resource.Instance.Id);
fixed (byte* ptr = rt)
*((uint*)ptr) = resource.Instance.Id;

View File

@ -232,7 +232,7 @@ namespace Esiur.Data
else if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(List<>))
if (genericType == typeof(List<>) || genericType == typeof(VarList<>))
{
var args = type.GetGenericArguments();
if (args[0] == typeof(object))

View File

@ -8,7 +8,7 @@ using System.Text;
namespace Esiur.Data
{
public class VarList<T> : IEnumerable<T>, ICollection, ICollection<T>
public class VarList<T> : IEnumerable<T>, ICollection, ICollection<T>
{
string propertyName;
IResource resource;
@ -21,6 +21,11 @@ namespace Esiur.Data
this.propertyName = propertyName;
}
public VarList()
{
Console.WriteLine("New varlist");
}
public int Count => list.Count;
public bool IsReadOnly => false;

View File

@ -598,6 +598,8 @@ partial class DistributedConnection
{
// reply failed
//SendParams(0x80, r.Instance.Id, r.Instance.Age, r.Instance.Serialize(false, this));
Console.WriteLine("Not found " + resourceId);
SendError(ErrorType.Management, callback, (ushort)ExceptionCode.ResourceNotFound);
}
});

View File

@ -704,6 +704,8 @@ public class Instance
get { return store; }
}
public bool IsDestroyed { get; private set; }
/// <summary>
/// List of children.
/// </summary>
@ -1009,6 +1011,7 @@ public class Instance
private void Resource_OnDestroy(object sender)
{
IsDestroyed = true;
Destroyed?.Invoke((IResource)sender);
}
}

View File

@ -914,6 +914,8 @@ public static class Warehouse
resource.Destroy();
resource.Instance = null;
return true;
}
}