mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-09-13 12:43:17 +00:00
AsyncReply
This commit is contained in:
@@ -48,6 +48,7 @@ public class Instance
|
||||
List<ulong?> ages = new();
|
||||
List<DateTime?> modificationDates = new();
|
||||
private ulong instanceAge;
|
||||
private byte hops;
|
||||
private DateTime instanceModificationDate;
|
||||
|
||||
uint id;
|
||||
@@ -389,6 +390,16 @@ public class Instance
|
||||
internal set { instanceAge = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of nodes to reach the original resource.
|
||||
/// </summary>
|
||||
public ulong Hops
|
||||
{
|
||||
get { return hops; }
|
||||
internal set { hops = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Last modification date.
|
||||
/// </summary>
|
||||
@@ -443,7 +454,7 @@ public class Instance
|
||||
/// <returns></returns>
|
||||
public PropertyValue[] Serialize()
|
||||
{
|
||||
List<PropertyValue> props = new List<PropertyValue>();
|
||||
var props = new List<PropertyValue>();
|
||||
|
||||
foreach (var pt in template.Properties)
|
||||
{
|
||||
@@ -459,6 +470,33 @@ public class Instance
|
||||
return props.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export all properties with ResourceProperty attributed as bytes array after a specific age.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Map<byte, PropertyValue> SerializeAfter(ulong age = 0)
|
||||
{
|
||||
var props = new Map<byte, PropertyValue>();
|
||||
|
||||
foreach (var pt in template.Properties)
|
||||
{
|
||||
IResource res;
|
||||
if (resource.TryGetTarget(out res))
|
||||
{
|
||||
if (res.Instance.GetAge(pt.Index) > age)
|
||||
{
|
||||
var rt = pt.PropertyInfo.GetValue(res, null);
|
||||
props.Add(pt.Index,
|
||||
new PropertyValue(rt,
|
||||
ages[pt.Index],
|
||||
modificationDates[pt.Index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Deserialize(byte[] data, uint offset, uint length)
|
||||
{
|
||||
@@ -588,7 +626,7 @@ public class Instance
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args)
|
||||
|
||||
|
@@ -652,75 +652,51 @@ public static class Warehouse
|
||||
|
||||
type = ResourceProxy.GetProxy(type);
|
||||
|
||||
|
||||
/*
|
||||
if (arguments != null)
|
||||
{
|
||||
var constructors = type.GetConstructors(System.Reflection.BindingFlags.Public);
|
||||
|
||||
foreach(var constructor in constructors)
|
||||
{
|
||||
var pi = constructor.GetParameters();
|
||||
if (pi.Length == constructor.le)
|
||||
}
|
||||
|
||||
// cast arguments
|
||||
ParameterInfo[] pi = fi.GetParameters();
|
||||
|
||||
object[] args = new object[pi.Length];
|
||||
|
||||
for (var i = 0; i < pi.Length; i++)
|
||||
{
|
||||
if (pi[i].ParameterType == typeof(DistributedConnection))
|
||||
{
|
||||
args[i] = this;
|
||||
}
|
||||
else if (namedArgs.ContainsKey(pi[i].Name))
|
||||
{
|
||||
args[i] = DC.CastConvert(namedArgs[pi[i].Name], pi[i].ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
constructors[0].
|
||||
}
|
||||
*/
|
||||
var res = Activator.CreateInstance(type) as IResource;
|
||||
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
var ps = Map<string, object>.FromObject(properties);
|
||||
|
||||
foreach (var p in ps)
|
||||
if (properties is Map<byte, object> map)
|
||||
{
|
||||
var template = GetTemplateByType(type);
|
||||
foreach(var kvp in map)
|
||||
template.GetPropertyTemplateByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ps = Map<string, object>.FromObject(properties);
|
||||
|
||||
var pi = type.GetProperty(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (pi != null)
|
||||
foreach (var p in ps)
|
||||
{
|
||||
if (pi.CanWrite)
|
||||
var pi = type.GetProperty(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (pi != null)
|
||||
{
|
||||
try
|
||||
if (pi.CanWrite)
|
||||
{
|
||||
pi.SetValue(res, p.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Global.Log(ex);
|
||||
try
|
||||
{
|
||||
pi.SetValue(res, p.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Global.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var fi = type.GetField(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (fi != null)
|
||||
else
|
||||
{
|
||||
try
|
||||
var fi = type.GetField(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (fi != null)
|
||||
{
|
||||
fi.SetValue(res, p.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Global.Log(ex);
|
||||
try
|
||||
{
|
||||
fi.SetValue(res, p.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Global.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -729,9 +705,6 @@ public static class Warehouse
|
||||
|
||||
if (store != null || parent != null || res is IStore)
|
||||
{
|
||||
//if (!await Put(name, res, store, parent, null, 0, manager, attributes))
|
||||
// return null;
|
||||
|
||||
await Put(name, res, store, parent, null, 0, manager, attributes);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user