mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
a
This commit is contained in:
+19
-10
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
#nullable enable
|
||||
@@ -368,13 +369,21 @@ namespace Esiur.Data
|
||||
|| type.IsEnum)
|
||||
{
|
||||
|
||||
var typeDef = warehouse.GetLocalTypeDefByType(type);
|
||||
var remoteAttr = type.GetCustomAttribute<RemoteAttribute>();
|
||||
|
||||
if (typeDef == null)
|
||||
throw new Exception("Unregistered type: " + type.FullName + ".");
|
||||
if (remoteAttr != null)
|
||||
{
|
||||
var typeDef = warehouse.GetRemoteTypeDefByName(remoteAttr.Domains, remoteAttr.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var typeDef = warehouse.GetLocalTypeDefByType(type);
|
||||
|
||||
return new TruTypeDef(nullable, typeDef);
|
||||
if (typeDef == null)
|
||||
throw new Exception("Unregistered type: " + type.FullName + ".");
|
||||
|
||||
return new TruTypeDef(nullable, typeDef);
|
||||
}
|
||||
}
|
||||
else if (type.IsGenericType)
|
||||
{
|
||||
@@ -392,10 +401,10 @@ namespace Esiur.Data
|
||||
else
|
||||
{
|
||||
var subType = FromType(args[0], warehouse);
|
||||
|
||||
|
||||
if (subType == null) // unrecongnized type
|
||||
throw new Exception("Unrecognized type: " + args[0].FullName);
|
||||
|
||||
|
||||
return new TruComposite(TruIdentifier.TypedList, nullable,
|
||||
new Tru[] { subType }, type);
|
||||
|
||||
@@ -867,9 +876,9 @@ namespace Esiur.Data
|
||||
{
|
||||
var td = connection.Instance.Warehouse.GetLocalTypeDefById(typeDefId);
|
||||
|
||||
if ( td == null)
|
||||
if (td == null)
|
||||
throw new Exception("TypeDef not found.");
|
||||
|
||||
|
||||
return new ParseResult<TruTypeDef>(
|
||||
new TruTypeDef(nullable, td),
|
||||
offset - oOffset);
|
||||
@@ -900,7 +909,7 @@ namespace Esiur.Data
|
||||
|
||||
if (runtimeType != null && runtimeType.IsValueType && nullable)
|
||||
{
|
||||
//if (runtimeType.IsValueType)// && Nullable.GetUnderlyingType(runtimeType) == null)
|
||||
//if (runtimeType.IsValueType)// && Nullable.GetUnderlyingType(runtimeType) == null)
|
||||
runtimeType = typeof(Nullable<>).MakeGenericType(runtimeType);
|
||||
}
|
||||
|
||||
@@ -911,7 +920,7 @@ namespace Esiur.Data
|
||||
}
|
||||
else
|
||||
{
|
||||
var runtimeType = nullable ? Tru.NullableTypesMapping[identifier]
|
||||
var runtimeType = nullable ? Tru.NullableTypesMapping[identifier]
|
||||
: Tru.TypesMapping[identifier];
|
||||
return new ParseResult<TruPrimitive>(
|
||||
new TruPrimitive(identifier, nullable, runtimeType),
|
||||
|
||||
@@ -264,7 +264,8 @@ public class LocalTypeDef:TypeDef
|
||||
else
|
||||
throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource.");
|
||||
|
||||
//IsWrapper = Codec.InheritsClass(type, typeof(EpResource));
|
||||
if (type.GetCustomAttribute<RemoteAttribute>() != null)
|
||||
throw new Exception("Remote types are not supported as local type definitions.");
|
||||
|
||||
type = ResourceProxy.GetBaseType(type);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Esiur.Net.Packets
|
||||
Unsubscribe = 0x3,
|
||||
|
||||
// Request Inquire
|
||||
TypeDefByName = 0x8,
|
||||
TypeDefIdsByNames = 0x8,
|
||||
TypeDefById = 0x9,
|
||||
TypeDefByResourceId = 0xA,
|
||||
Query = 0xB,
|
||||
|
||||
@@ -532,8 +532,8 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
EpRequestUnsubscribe(_packet.CallbackId, dt);
|
||||
break;
|
||||
// Inquire
|
||||
case EpPacketRequest.TypeDefByName:
|
||||
EpRequestTypeDefByName(_packet.CallbackId, dt);
|
||||
case EpPacketRequest.TypeDefIdsByNames:
|
||||
EpRequestTypeDefIdsByNames(_packet.CallbackId, dt);
|
||||
break;
|
||||
case EpPacketRequest.TypeDefById:
|
||||
EpRequestTypeDefById(_packet.CallbackId, dt);
|
||||
@@ -736,7 +736,7 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
}
|
||||
|
||||
SendAuthHeaders(EpAuthPacketMethod.SessionEstablished, localHeaders);
|
||||
|
||||
|
||||
_session.Authenticated = true;
|
||||
_session.LocalIdentity = null;
|
||||
_session.RemoteIdentity = null;
|
||||
@@ -1031,7 +1031,7 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
|
||||
|
||||
|
||||
void AuthenticatonCompleted()
|
||||
async Task AuthenticatonCompleted()
|
||||
{
|
||||
|
||||
if (this.Instance == null)
|
||||
@@ -1062,12 +1062,50 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
{
|
||||
_authenticated = true;
|
||||
Status = EpConnectionStatus.Connected;
|
||||
_openReply?.Trigger(true);
|
||||
_openReply = null;
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
_session.AuthenticationHandler?.Provider?.Login(_session);
|
||||
//Server?.Membership?.Login(_session);
|
||||
|
||||
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
var proxyTypes = Instance.Warehouse.GetProxyTypesByDomain(_remoteDomain);
|
||||
|
||||
var typeDefNames = new List<string>();
|
||||
|
||||
foreach (var kk in proxyTypes)
|
||||
{
|
||||
foreach (var kv in kk.Value)
|
||||
{
|
||||
typeDefNames.Add(kv.Key);
|
||||
}
|
||||
}
|
||||
if (typeDefNames.Count > 0)
|
||||
{
|
||||
GetTypeDefIds(typeDefNames.ToArray()).Then(ids =>
|
||||
{
|
||||
var bag = new AsyncBag<object>();
|
||||
foreach (var id in ids)
|
||||
bag.Add(FetchTypeDef(id, null));
|
||||
|
||||
bag.Seal();
|
||||
|
||||
bag.Then((o) =>
|
||||
{
|
||||
_openReply?.Trigger(true);
|
||||
_openReply = null;
|
||||
});
|
||||
}).Error(ex =>
|
||||
{
|
||||
_openReply.TriggerError(ex);
|
||||
// do nothing, proxies won't work but connection is established
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_openReply?.Trigger(true);
|
||||
_openReply = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//private void ProcessClientAuth(byte[] data)
|
||||
|
||||
@@ -1011,17 +1011,25 @@ partial class EpConnection
|
||||
Instance.Warehouse.Query(resourceLink).Then(queryCallback);
|
||||
}
|
||||
|
||||
void EpRequestTypeDefByName(uint callback, PlainTdu tdu)
|
||||
void EpRequestTypeDefIdsByNames(uint callback, PlainTdu tdu)
|
||||
{
|
||||
var value = Codec.ParseSync(tdu, Instance.Warehouse);
|
||||
|
||||
var className = (string)value;
|
||||
var classNames = (string[])value;
|
||||
|
||||
var typeDef = Instance.Warehouse.GetRemoteTypeDefByName(_remoteDomain, className);
|
||||
var typeDefs = new List<ulong>();
|
||||
|
||||
if (typeDef != null)
|
||||
foreach (var className in classNames)
|
||||
{
|
||||
SendReply(EpPacketReply.Completed, callback, typeDef.Compose(this));
|
||||
//@TODO: need to search in remoteTypeDefs as well
|
||||
var typeDef = Instance.Warehouse.GetLocalTypeDefByName(className);
|
||||
if (typeDef != null)
|
||||
typeDefs.Add(typeDef.Id);
|
||||
}
|
||||
|
||||
if (typeDefs.Count > 0)
|
||||
{
|
||||
SendReply(EpPacketReply.Completed, callback, typeDefs.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2567,6 +2575,18 @@ partial class EpConnection
|
||||
return reply;
|
||||
}
|
||||
|
||||
public AsyncReply<ulong[]> GetTypeDefIds(string[] fullNames)
|
||||
{
|
||||
var reply = new AsyncReply<ulong[]>();
|
||||
|
||||
SendRequest(EpPacketRequest.TypeDefIdsByNames, fullNames)
|
||||
.Then(result =>
|
||||
{
|
||||
reply.Trigger((ulong[])result);
|
||||
}).Error(ex => reply.TriggerError(ex));
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new resource.
|
||||
|
||||
@@ -713,6 +713,11 @@ public class Warehouse
|
||||
}
|
||||
}
|
||||
|
||||
internal KeyList<TypeDefKind, KeyList<string , Type>> GetProxyTypesByDomain(string domain)
|
||||
{
|
||||
return _proxyTypeDefs[domain];
|
||||
}
|
||||
|
||||
public bool TryRegisterRemoteTypeDef(string domain, RemoteTypeDef typeDef)
|
||||
{
|
||||
lock (_typeDefsLock)
|
||||
@@ -843,6 +848,14 @@ public class Warehouse
|
||||
return _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
||||
}
|
||||
|
||||
public TypeDef GetProxyTypeDef(string domain, string typeName, TypeDefKind? typeDefKind = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(domain) || !_remoteTypeDefs.ContainsKey(domain))
|
||||
return null;
|
||||
sdcsdc
|
||||
return _remoteTypeDefs[domain].Values.FirstOrDefault(x => x.Name == typeName);
|
||||
}
|
||||
|
||||
//public TypeDef GetRemoteTypeDefByType(Type type)
|
||||
//{
|
||||
// var remoteAttr = type.GetCustomAttribute<RemoteAttribute>();
|
||||
|
||||
Reference in New Issue
Block a user