mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
Handle
This commit is contained in:
@@ -145,30 +145,28 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
|
||||
// Attributes
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public uint KeepAliveTime { get; set; } = 10;
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public ExceptionLevel ExceptionLevel { get; set; }
|
||||
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
|
||||
|
||||
|
||||
|
||||
//[Attribute]
|
||||
//public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
|
||||
|
||||
|
||||
[Attribute]
|
||||
public bool AutoReconnect { get; set; } = false;
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public uint ReconnectInterval { get; set; } = 5;
|
||||
|
||||
//[Attribute]
|
||||
//public string Username { get; set; }
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public bool UseWebSocket { get; set; }
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public bool SecureWebSocket { get; set; }
|
||||
|
||||
//[Attribute]
|
||||
@@ -1694,25 +1692,55 @@ public partial class EpConnection : NetworkConnection, IStore
|
||||
/// </summary>
|
||||
/// <param name="trigger">Resource trigger.</param>
|
||||
/// <returns></returns>
|
||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
||||
public AsyncReply<bool> Handle(ResourceOperation trigger, IResourceContext context = null)
|
||||
{
|
||||
|
||||
_authPacket = new EpAuthPacket(Instance.Warehouse);
|
||||
_packet = new EpPacket(Instance.Warehouse);
|
||||
|
||||
if (trigger == ResourceOperation.Open)
|
||||
if (trigger == ResourceOperation.Initialize)
|
||||
{
|
||||
_authPacket = new EpAuthPacket(Instance.Warehouse);
|
||||
_packet = new EpPacket(Instance.Warehouse);
|
||||
|
||||
|
||||
}
|
||||
else if (trigger == ResourceOperation.Open)
|
||||
{
|
||||
// @TODO: Need a better way to check for initiator or responder
|
||||
if (this.Server != null)
|
||||
return new AsyncReply<bool>(true);
|
||||
|
||||
|
||||
var host = Instance.Name.Split(':');
|
||||
|
||||
var address = host[0];
|
||||
var port = host.Length > 1 ? ushort.Parse(host[1]) : (ushort)10518;
|
||||
|
||||
// assign domain from hostname if not provided
|
||||
if (_remoteDomain == null)
|
||||
|
||||
|
||||
if (context is EpConnectionContext epContext)
|
||||
{
|
||||
var provider = Instance.Warehouse.GetAuthenticationProvider(epContext.AuthenticationProtocol);
|
||||
|
||||
_remoteDomain = epContext.Domain ?? address;
|
||||
|
||||
Session.AuthenticationHandler = provider.CreateAuthenticationHandler(new AuthenticationContext(){
|
||||
Direction = AuthenticationDirection.Initiator,
|
||||
Domain = _remoteDomain,
|
||||
HostName = address,
|
||||
InitiatorIdentity = epContext.Identity,
|
||||
Mode = epContext.AuthenticationMode,
|
||||
});
|
||||
|
||||
Session.LocalIdentity = epContext.Identity;
|
||||
ReconnectInterval = epContext.ReconnectInterval;
|
||||
ExceptionLevel = epContext.ExceptionLevel;
|
||||
UseWebSocket = epContext.UseWebSocket;
|
||||
SecureWebSocket = epContext.SecureWebSocket;
|
||||
_remoteDomain = epContext.Domain;
|
||||
AutoReconnect = epContext.AutoReconnect;
|
||||
}
|
||||
else if (_remoteDomain == null)
|
||||
_remoteDomain = address;
|
||||
|
||||
return Connect(null, address, port, _remoteDomain);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Net.Packets;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Security.Membership;
|
||||
using Esiur.Security.Permissions;
|
||||
using System;
|
||||
@@ -10,24 +11,24 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Protocol;
|
||||
|
||||
public class EpConnectionContext : ResourceContext
|
||||
public class EpConnectionContext : IResourceContext
|
||||
{
|
||||
public EpConnectionContext()
|
||||
: base(0, new Map<string, object>(), null, null)
|
||||
{
|
||||
//public EpConnectionContext()
|
||||
// : base(0, new Map<string, object>(), null, null)
|
||||
//{
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
public override void Build()
|
||||
{
|
||||
Attributes["AutoConnect"] = AutoReconnect;
|
||||
Attributes["ReconnectInterval"] = ReconnectInterval;
|
||||
Attributes["UseWebSocket"] = UseWebSocket;
|
||||
Attributes["SecureWebSocket"] = SecureWebSocket;
|
||||
Attributes["Domain"] = SecureWebSocket;
|
||||
Attributes["AuthenticationProtocol"] = SecureWebSocket;
|
||||
Attributes["Identity"] = SecureWebSocket;
|
||||
}
|
||||
//public override void Build()
|
||||
//{
|
||||
// Attributes["AutoConnect"] = AutoReconnect;
|
||||
// Attributes["ReconnectInterval"] = ReconnectInterval;
|
||||
// Attributes["UseWebSocket"] = UseWebSocket;
|
||||
// Attributes["SecureWebSocket"] = SecureWebSocket;
|
||||
// Attributes["Domain"] = SecureWebSocket;
|
||||
// Attributes["AuthenticationProtocol"] = SecureWebSocket;
|
||||
// Attributes["Identity"] = SecureWebSocket;
|
||||
//}
|
||||
|
||||
public ExceptionLevel ExceptionLevel { get; set; }
|
||||
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
|
||||
@@ -35,8 +36,9 @@ public class EpConnectionContext : ResourceContext
|
||||
//public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
|
||||
//public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
|
||||
|
||||
public AuthenticationMode AuthenticationMode { get; set; } = AuthenticationMode.None;
|
||||
public string Identity { get; set; }
|
||||
public string AuthenticationProtocol { get; set; }
|
||||
public string AuthenticationProtocol { get; set; } = "hash";
|
||||
|
||||
public bool AutoReconnect { get; set; } = false;
|
||||
|
||||
@@ -55,4 +57,10 @@ public class EpConnectionContext : ResourceContext
|
||||
//public ulong TokenIndex { get; set; }
|
||||
|
||||
public string Domain { get; set; }
|
||||
|
||||
public Map<string, object> Attributes { get; set; }
|
||||
|
||||
public Map<string, object> Properties { get; set; }
|
||||
|
||||
public ulong Age { get; }
|
||||
}
|
||||
|
||||
@@ -475,10 +475,10 @@ public class EpResource : DynamicObject, IResource, INotifyPropertyChanged, IDyn
|
||||
/// </summary>
|
||||
/// <param name="trigger"></param>
|
||||
/// <returns></returns>
|
||||
public AsyncReply<bool> Handle(ResourceOperation trigger)
|
||||
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||
{
|
||||
|
||||
if (trigger == ResourceOperation.Initialize)
|
||||
if (operation == ResourceOperation.Initialize)
|
||||
{
|
||||
this.Instance.PropertyModified += (x) =>
|
||||
this.PropertyChanged?.Invoke(this, new ResourcePropertyChangedEventArgs(x.Name));
|
||||
|
||||
@@ -46,17 +46,17 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
{
|
||||
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public string IP
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public string[] AllowedAuthenticationProviders { get; set; }
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public bool AllowUnauthorizedAccess { get; set; }
|
||||
|
||||
//IMembership membership;
|
||||
@@ -88,14 +88,14 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
// connection.ProcessAuthorization(indication.Results);
|
||||
//}
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public EntryPoint EntryPoint
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public ushort Port
|
||||
{
|
||||
get;
|
||||
@@ -103,7 +103,7 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
} = 10518;
|
||||
|
||||
|
||||
[Attribute]
|
||||
//[Attribute]
|
||||
public ExceptionLevel ExceptionLevel { get; set; }
|
||||
= ExceptionLevel.Code
|
||||
| ExceptionLevel.Source
|
||||
@@ -124,9 +124,10 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
||||
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||
|
||||
{
|
||||
if (trigger == ResourceOperation.Initialize)
|
||||
if (operation == ResourceOperation.Initialize)
|
||||
{
|
||||
TcpSocket listener;
|
||||
|
||||
@@ -137,14 +138,14 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
||||
|
||||
Start(listener);
|
||||
}
|
||||
else if (trigger == ResourceOperation.Terminate)
|
||||
else if (operation == ResourceOperation.Terminate)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
else if (trigger == ResourceOperation.SystemReload)
|
||||
else if (operation == ResourceOperation.SystemReloading)
|
||||
{
|
||||
Trigger(ResourceOperation.Terminate);
|
||||
Trigger(ResourceOperation.Initialize);
|
||||
Handle(ResourceOperation.Terminate);
|
||||
Handle(ResourceOperation.Initialize);
|
||||
}
|
||||
|
||||
return new AsyncReply<bool>(true);
|
||||
|
||||
Reference in New Issue
Block a user