mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
Handle
This commit is contained in:
@@ -44,7 +44,7 @@ public abstract class PacketFilter : IResource
|
|||||||
public event DestroyedEvent OnDestroy;
|
public event DestroyedEvent OnDestroy;
|
||||||
|
|
||||||
|
|
||||||
public abstract AsyncReply<bool> Handle(ResourceOperation trigger);
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
|
|
||||||
public abstract bool Execute(Packet packet);
|
public abstract bool Execute(Packet packet);
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ public class PacketServer : IResource
|
|||||||
OnDestroy?.Invoke(this);
|
OnDestroy?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
if (trigger == ResourceOperation.Initialize)
|
if (operation == ResourceOperation.Initialize)
|
||||||
{
|
{
|
||||||
foreach (var src in sources)
|
foreach (var src in sources)
|
||||||
{
|
{
|
||||||
@@ -77,12 +77,12 @@ public class PacketServer : IResource
|
|||||||
src.Open();
|
src.Open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
foreach (var src in sources)
|
foreach (var src in sources)
|
||||||
src.Close();
|
src.Close();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemReload)
|
else if (operation == ResourceOperation.SystemReloading)
|
||||||
{
|
{
|
||||||
foreach (var src in sources)
|
foreach (var src in sources)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ public abstract class PacketSource : IResource
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
|
|
||||||
|
|
||||||
|
|
||||||
public abstract bool RawMode
|
public abstract bool RawMode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using System.Text;
|
|||||||
namespace Esiur.Net.Http;
|
namespace Esiur.Net.Http;
|
||||||
public class EpOverHttp : HttpFilter
|
public class EpOverHttp : HttpFilter
|
||||||
{
|
{
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
EntryPoint EntryPoint { get; set; }
|
EntryPoint EntryPoint { get; set; }
|
||||||
|
|
||||||
public override AsyncReply<bool> Execute(HttpConnection sender)
|
public override AsyncReply<bool> Execute(HttpConnection sender)
|
||||||
@@ -30,7 +30,7 @@ public class EpOverHttp : HttpFilter
|
|||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public override AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ using Esiur.Core;
|
|||||||
using Esiur.Protocol;
|
using Esiur.Protocol;
|
||||||
|
|
||||||
namespace Esiur.Net.Http;
|
namespace Esiur.Net.Http;
|
||||||
|
|
||||||
public class EpOvwerWebsocket : HttpFilter
|
public class EpOvwerWebsocket : HttpFilter
|
||||||
{
|
{
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public EpServer Server
|
public EpServer Server
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -72,7 +73,7 @@ public class EpOvwerWebsocket : HttpFilter
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public override AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public abstract class HttpFilter : IResource
|
|||||||
}
|
}
|
||||||
|
|
||||||
public event DestroyedEvent OnDestroy;
|
public event DestroyedEvent OnDestroy;
|
||||||
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public virtual void SessionModified(HTTPSession session, string key, object oldValue, object newValue)
|
public virtual void SessionModified(HTTPSession session, string key, object oldValue, object newValue)
|
||||||
|
|||||||
@@ -139,14 +139,14 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public virtual string IP
|
public virtual string IP
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public virtual ushort Port
|
public virtual ushort Port
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -154,21 +154,21 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public virtual uint MaxPost
|
public virtual uint MaxPost
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public virtual bool SSL
|
public virtual bool SSL
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public virtual string Certificate
|
public virtual string Certificate
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -291,10 +291,10 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public async AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public async AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (trigger == ResourceOperation.Initialize)
|
if (operation == ResourceOperation.Initialize)
|
||||||
{
|
{
|
||||||
//var ip = (IPAddress)Instance.Attributes["ip"];
|
//var ip = (IPAddress)Instance.Attributes["ip"];
|
||||||
//var port = (int)Instance.Attributes["port"];
|
//var port = (int)Instance.Attributes["port"];
|
||||||
@@ -318,16 +318,16 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
|
|||||||
|
|
||||||
Start(listener);
|
Start(listener);
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemReload)
|
else if (operation == ResourceOperation.SystemReloading)
|
||||||
{
|
{
|
||||||
await Trigger(ResourceOperation.Terminate);
|
await Handle(ResourceOperation.Terminate);
|
||||||
await Trigger(ResourceOperation.Initialize);
|
await Handle(ResourceOperation.Initialize);
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemInitialized)
|
else if (operation == ResourceOperation.SystemReady)
|
||||||
{
|
{
|
||||||
filters = await Instance.Children<HttpFilter>();
|
filters = await Instance.Children<HttpFilter>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public abstract class NetworkServer<TConnection> : IDestructible where TConnecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public uint Timeout
|
public uint Timeout
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -144,7 +144,7 @@ public abstract class NetworkServer<TConnection> : IDestructible where TConnecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public uint Clock
|
public uint Clock
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public abstract class TcpFilter : IResource
|
|||||||
public event DestroyedEvent OnDestroy;
|
public event DestroyedEvent OnDestroy;
|
||||||
|
|
||||||
|
|
||||||
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
|
|
||||||
public virtual bool Connected(TcpConnection sender)
|
public virtual bool Connected(TcpConnection sender)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ namespace Esiur.Net.Tcp;
|
|||||||
public class TcpServer : NetworkServer<TcpConnection>, IResource
|
public class TcpServer : NetworkServer<TcpConnection>, IResource
|
||||||
{
|
{
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string IP
|
public string IP
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public ushort Port
|
public ushort Port
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -66,9 +66,9 @@ public class TcpServer : NetworkServer<TcpConnection>, IResource
|
|||||||
|
|
||||||
TcpFilter[] filters = null;
|
TcpFilter[] filters = null;
|
||||||
|
|
||||||
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;
|
TcpSocket listener;
|
||||||
|
|
||||||
@@ -82,16 +82,16 @@ public class TcpServer : NetworkServer<TcpConnection>, IResource
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemReload)
|
else if (operation == ResourceOperation.SystemReloading)
|
||||||
{
|
{
|
||||||
Trigger(ResourceOperation.Terminate);
|
Handle(ResourceOperation.Terminate);
|
||||||
Trigger(ResourceOperation.Initialize);
|
Handle(ResourceOperation.Initialize);
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemInitialized)
|
else if (operation == ResourceOperation.SystemReady)
|
||||||
{
|
{
|
||||||
Instance.Children<TcpFilter>().Then(x => filters = x);
|
Instance.Children<TcpFilter>().Then(x => filters = x);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ public abstract class UdpFilter : IResource
|
|||||||
|
|
||||||
public event DestroyedEvent OnDestroy;
|
public event DestroyedEvent OnDestroy;
|
||||||
|
|
||||||
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
|
|
||||||
|
|
||||||
public abstract bool Execute(byte[] data, IPEndPoint sender);
|
public abstract bool Execute(byte[] data, IPEndPoint sender);
|
||||||
|
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ public class UdpServer : IResource
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
string IP
|
string IP
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
ushort Port
|
ushort Port
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -177,9 +177,9 @@ public class UdpServer : IResource
|
|||||||
OnDestroy?.Invoke(this);
|
OnDestroy?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async AsyncReply<bool> IResource.Trigger(ResourceOperation trigger)
|
public async AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
if (trigger == ResourceOperation.Initialize)
|
if (operation == ResourceOperation.Initialize)
|
||||||
{
|
{
|
||||||
var address = IP == null ? IPAddress.Any : IPAddress.Parse(IP);
|
var address = IP == null ? IPAddress.Any : IPAddress.Parse(IP);
|
||||||
|
|
||||||
@@ -188,12 +188,12 @@ public class UdpServer : IResource
|
|||||||
receiver = new Thread(Receiving);
|
receiver = new Thread(Receiving);
|
||||||
receiver.Start();
|
receiver.Start();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
if (receiver != null)
|
if (receiver != null)
|
||||||
receiver.Abort();
|
receiver.Abort();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemInitialized)
|
else if (operation == ResourceOperation.SystemReady)
|
||||||
{
|
{
|
||||||
filters = await Instance.Children<UdpFilter>();
|
filters = await Instance.Children<UdpFilter>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,30 +145,28 @@ public partial class EpConnection : NetworkConnection, IStore
|
|||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public uint KeepAliveTime { get; set; } = 10;
|
public uint KeepAliveTime { get; set; } = 10;
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public ExceptionLevel ExceptionLevel { get; set; }
|
public ExceptionLevel ExceptionLevel { get; set; }
|
||||||
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
|
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//[Attribute]
|
//[Attribute]
|
||||||
//public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
|
||||||
public bool AutoReconnect { get; set; } = false;
|
public bool AutoReconnect { get; set; } = false;
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public uint ReconnectInterval { get; set; } = 5;
|
public uint ReconnectInterval { get; set; } = 5;
|
||||||
|
|
||||||
//[Attribute]
|
//[Attribute]
|
||||||
//public string Username { get; set; }
|
//public string Username { get; set; }
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public bool UseWebSocket { get; set; }
|
public bool UseWebSocket { get; set; }
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public bool SecureWebSocket { get; set; }
|
public bool SecureWebSocket { get; set; }
|
||||||
|
|
||||||
//[Attribute]
|
//[Attribute]
|
||||||
@@ -1694,25 +1692,55 @@ public partial class EpConnection : NetworkConnection, IStore
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="trigger">Resource trigger.</param>
|
/// <param name="trigger">Resource trigger.</param>
|
||||||
/// <returns></returns>
|
/// <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
|
// @TODO: Need a better way to check for initiator or responder
|
||||||
if (this.Server != null)
|
if (this.Server != null)
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
|
|
||||||
|
|
||||||
var host = Instance.Name.Split(':');
|
var host = Instance.Name.Split(':');
|
||||||
|
|
||||||
var address = host[0];
|
var address = host[0];
|
||||||
var port = host.Length > 1 ? ushort.Parse(host[1]) : (ushort)10518;
|
var port = host.Length > 1 ? ushort.Parse(host[1]) : (ushort)10518;
|
||||||
|
|
||||||
// assign domain from hostname if not provided
|
// 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;
|
_remoteDomain = address;
|
||||||
|
|
||||||
return Connect(null, address, port, _remoteDomain);
|
return Connect(null, address, port, _remoteDomain);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Esiur.Data;
|
using Esiur.Data;
|
||||||
using Esiur.Net.Packets;
|
using Esiur.Net.Packets;
|
||||||
using Esiur.Resource;
|
using Esiur.Resource;
|
||||||
|
using Esiur.Security.Authority;
|
||||||
using Esiur.Security.Membership;
|
using Esiur.Security.Membership;
|
||||||
using Esiur.Security.Permissions;
|
using Esiur.Security.Permissions;
|
||||||
using System;
|
using System;
|
||||||
@@ -10,24 +11,24 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Esiur.Protocol;
|
namespace Esiur.Protocol;
|
||||||
|
|
||||||
public class EpConnectionContext : ResourceContext
|
public class EpConnectionContext : IResourceContext
|
||||||
{
|
{
|
||||||
public EpConnectionContext()
|
//public EpConnectionContext()
|
||||||
: base(0, new Map<string, object>(), null, null)
|
// : base(0, new Map<string, object>(), null, null)
|
||||||
{
|
//{
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
public override void Build()
|
//public override void Build()
|
||||||
{
|
//{
|
||||||
Attributes["AutoConnect"] = AutoReconnect;
|
// Attributes["AutoConnect"] = AutoReconnect;
|
||||||
Attributes["ReconnectInterval"] = ReconnectInterval;
|
// Attributes["ReconnectInterval"] = ReconnectInterval;
|
||||||
Attributes["UseWebSocket"] = UseWebSocket;
|
// Attributes["UseWebSocket"] = UseWebSocket;
|
||||||
Attributes["SecureWebSocket"] = SecureWebSocket;
|
// Attributes["SecureWebSocket"] = SecureWebSocket;
|
||||||
Attributes["Domain"] = SecureWebSocket;
|
// Attributes["Domain"] = SecureWebSocket;
|
||||||
Attributes["AuthenticationProtocol"] = SecureWebSocket;
|
// Attributes["AuthenticationProtocol"] = SecureWebSocket;
|
||||||
Attributes["Identity"] = SecureWebSocket;
|
// Attributes["Identity"] = SecureWebSocket;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public ExceptionLevel ExceptionLevel { get; set; }
|
public ExceptionLevel ExceptionLevel { get; set; }
|
||||||
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
|
= 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 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 Identity { get; set; }
|
||||||
public string AuthenticationProtocol { get; set; }
|
public string AuthenticationProtocol { get; set; } = "hash";
|
||||||
|
|
||||||
public bool AutoReconnect { get; set; } = false;
|
public bool AutoReconnect { get; set; } = false;
|
||||||
|
|
||||||
@@ -55,4 +57,10 @@ public class EpConnectionContext : ResourceContext
|
|||||||
//public ulong TokenIndex { get; set; }
|
//public ulong TokenIndex { get; set; }
|
||||||
|
|
||||||
public string Domain { 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>
|
/// </summary>
|
||||||
/// <param name="trigger"></param>
|
/// <param name="trigger"></param>
|
||||||
/// <returns></returns>
|
/// <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.Instance.PropertyModified += (x) =>
|
||||||
this.PropertyChanged?.Invoke(this, new ResourcePropertyChangedEventArgs(x.Name));
|
this.PropertyChanged?.Invoke(this, new ResourcePropertyChangedEventArgs(x.Name));
|
||||||
|
|||||||
@@ -46,17 +46,17 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string IP
|
public string IP
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string[] AllowedAuthenticationProviders { get; set; }
|
public string[] AllowedAuthenticationProviders { get; set; }
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public bool AllowUnauthorizedAccess { get; set; }
|
public bool AllowUnauthorizedAccess { get; set; }
|
||||||
|
|
||||||
//IMembership membership;
|
//IMembership membership;
|
||||||
@@ -88,14 +88,14 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
|||||||
// connection.ProcessAuthorization(indication.Results);
|
// connection.ProcessAuthorization(indication.Results);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public EntryPoint EntryPoint
|
public EntryPoint EntryPoint
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public ushort Port
|
public ushort Port
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -103,7 +103,7 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
|||||||
} = 10518;
|
} = 10518;
|
||||||
|
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public ExceptionLevel ExceptionLevel { get; set; }
|
public ExceptionLevel ExceptionLevel { get; set; }
|
||||||
= ExceptionLevel.Code
|
= ExceptionLevel.Code
|
||||||
| ExceptionLevel.Source
|
| 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;
|
TcpSocket listener;
|
||||||
|
|
||||||
@@ -137,14 +138,14 @@ public class EpServer : NetworkServer<EpConnection>, IResource
|
|||||||
|
|
||||||
Start(listener);
|
Start(listener);
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.SystemReload)
|
else if (operation == ResourceOperation.SystemReloading)
|
||||||
{
|
{
|
||||||
Trigger(ResourceOperation.Terminate);
|
Handle(ResourceOperation.Terminate);
|
||||||
Trigger(ResourceOperation.Initialize);
|
Handle(ResourceOperation.Initialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
|
|||||||
@@ -111,9 +111,9 @@ namespace Esiur.Proxy
|
|||||||
code.AppendLine("public virtual event DestroyedEvent? OnDestroy;");
|
code.AppendLine("public virtual event DestroyedEvent? OnDestroy;");
|
||||||
code.AppendLine("public virtual void Destroy() { OnDestroy?.Invoke(this); }");
|
code.AppendLine("public virtual void Destroy() { OnDestroy?.Invoke(this); }");
|
||||||
|
|
||||||
if (!ci.HasTrigger)
|
if (!ci.HasHandle)
|
||||||
{
|
{
|
||||||
code.AppendLine("public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger) => new AsyncReply<bool>(true);");
|
code.AppendLine("public virtual AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null) => new AsyncReply<bool>(true);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,11 +181,13 @@ namespace Esiur.Proxy
|
|||||||
ResourceClassInfo? classInfo = null;
|
ResourceClassInfo? classInfo = null;
|
||||||
if (hasResource)
|
if (hasResource)
|
||||||
{
|
{
|
||||||
bool hasTrigger = cds.Members
|
bool hasHandle = cds.Members
|
||||||
.OfType<MethodDeclarationSyntax>()
|
.OfType<MethodDeclarationSyntax>()
|
||||||
.Select(m => ctx.SemanticModel.GetDeclaredSymbol(m) as IMethodSymbol)
|
.Select(m => ctx.SemanticModel.GetDeclaredSymbol(m) as IMethodSymbol)
|
||||||
.Where(s => s is not null)
|
.Where(s => s is not null)
|
||||||
.Any(s => s!.Name == "Trigger" && s.Parameters.Length == 1 && s.Parameters[0].Type.ToDisplayString() == "Esiur.Resource.ResourceTrigger");
|
.Any(s => s!.Name == "Handle" && s.Parameters.Length == 2
|
||||||
|
&& s.Parameters[0].Type.ToDisplayString() == "Esiur.Resource.ResourceOperation"
|
||||||
|
&& s.Parameters[1].Type.ToDisplayString() == "Esiur.Resource.IResourceContext");
|
||||||
|
|
||||||
var exportedFields = cds.Members
|
var exportedFields = cds.Members
|
||||||
.OfType<FieldDeclarationSyntax>()
|
.OfType<FieldDeclarationSyntax>()
|
||||||
@@ -208,7 +210,7 @@ namespace Esiur.Proxy
|
|||||||
cls,
|
cls,
|
||||||
exportedFields,
|
exportedFields,
|
||||||
hasInterface,
|
hasInterface,
|
||||||
hasTrigger
|
hasHandle
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +230,7 @@ namespace Esiur.Proxy
|
|||||||
{
|
{
|
||||||
Fields = mergedFields,
|
Fields = mergedFields,
|
||||||
HasInterface = existing.HasInterface || item.HasInterface,
|
HasInterface = existing.HasInterface || item.HasInterface,
|
||||||
HasTrigger = existing.HasTrigger || item.HasTrigger
|
HasHandle = existing.HasHandle || item.HasHandle
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -337,7 +339,7 @@ namespace Esiur.Proxy
|
|||||||
|
|
||||||
public ResourceClassInfo(string key, string name ,
|
public ResourceClassInfo(string key, string name ,
|
||||||
ClassDeclarationSyntax classDeclaration,
|
ClassDeclarationSyntax classDeclaration,
|
||||||
ITypeSymbol classSymbol, List<IFieldSymbol> fileds, bool hasInterface, bool hasTrigger)
|
ITypeSymbol classSymbol, List<IFieldSymbol> fileds, bool hasInterface, bool hasHandle)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
Name = name;
|
Name = name;
|
||||||
@@ -345,7 +347,7 @@ namespace Esiur.Proxy
|
|||||||
ClassSymbol = classSymbol;
|
ClassSymbol = classSymbol;
|
||||||
Fields = fileds;
|
Fields = fileds;
|
||||||
HasInterface = hasInterface;
|
HasInterface = hasInterface;
|
||||||
HasTrigger = hasTrigger;
|
HasHandle = hasHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Key;
|
public string Key;
|
||||||
@@ -354,7 +356,7 @@ namespace Esiur.Proxy
|
|||||||
public ITypeSymbol ClassSymbol;
|
public ITypeSymbol ClassSymbol;
|
||||||
public List<IFieldSymbol> Fields;
|
public List<IFieldSymbol> Fields;
|
||||||
public bool HasInterface;
|
public bool HasInterface;
|
||||||
public bool HasTrigger;
|
public bool HasHandle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,10 +218,14 @@ public static class TypeDefGenerator
|
|||||||
throw new Exception("Invalid EP URL");
|
throw new Exception("Invalid EP URL");
|
||||||
|
|
||||||
var path = urlRegex.Split(url);
|
var path = urlRegex.Split(url);
|
||||||
var con = Warehouse.Default.Get<EpConnection>(path[1] + "://" + path[2], new ResourceContext(0,
|
var con = Warehouse.Default.Get<EpConnection>(path[1] + "://" + path[2], new EpConnectionContext()
|
||||||
new Map<string, object> { ["username"] = username, ["password"] = password }, null, null)
|
{
|
||||||
// !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) ? new { Username = username, Password = password } : null
|
Identity = username
|
||||||
).Wait(20000);
|
}).Wait(10000);
|
||||||
|
|
||||||
|
//ResourceContext(0,
|
||||||
|
// new Map<string, object> { ["username"] = username, ["password"] = password }, null, null)
|
||||||
|
// ).Wait(20000);
|
||||||
|
|
||||||
if (con == null)
|
if (con == null)
|
||||||
throw new Exception("Can't connect to server");
|
throw new Exception("Can't connect to server");
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ public delegate bool QueryFilter<T>(T value);
|
|||||||
|
|
||||||
public interface IResource : IDestructible
|
public interface IResource : IDestructible
|
||||||
{
|
{
|
||||||
AsyncReply<bool> Handle(ResourceOperation trigger);
|
AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext? context = null);
|
||||||
AsyncReply<bool> Initialize(ResourceContext resourceContext);
|
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Esiur.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Resource
|
||||||
|
{
|
||||||
|
public interface IResourceContext
|
||||||
|
{
|
||||||
|
public Map<string, object> Attributes { get; }
|
||||||
|
public Map<string, object> Properties { get; }
|
||||||
|
public ulong Age { get; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,9 +38,9 @@ public class Resource : IResource
|
|||||||
OnDestroy?.Invoke(this);
|
OnDestroy?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public virtual AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
if (trigger == ResourceOperation.Initialize)
|
if (operation == ResourceOperation.Initialize)
|
||||||
return new AsyncReply<bool>(this.Create());
|
return new AsyncReply<bool>(this.Create());
|
||||||
else
|
else
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Esiur.Resource
|
namespace Esiur.Resource
|
||||||
{
|
{
|
||||||
public class ResourceContext
|
public class ResourceContext:IResourceContext
|
||||||
{
|
{
|
||||||
public ulong Age { get; }
|
public ulong Age { get; }
|
||||||
public Map<string, object> Attributes { get; }
|
public Map<string, object> Attributes { get; }
|
||||||
@@ -23,9 +23,9 @@ namespace Esiur.Resource
|
|||||||
PermissionsManager = permissionsManager;
|
PermissionsManager = permissionsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Build()
|
//public virtual void Build()
|
||||||
{
|
//{
|
||||||
// update the context based on the current state of the resource and its environment
|
// // update the context based on the current state of the resource and its environment
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ public abstract class Store<T> : IStore where T : IResource
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
|
|
||||||
|
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
|
||||||
|
|
||||||
|
|
||||||
//public async AsyncReply<T> New(string name = null, object attributes = null, object properties = null)
|
//public async AsyncReply<T> New(string name = null, object attributes = null, object properties = null)
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class Warehouse
|
|||||||
public event StoreEvent StoreConnected;
|
public event StoreEvent StoreConnected;
|
||||||
public event StoreEvent StoreDisconnected;
|
public event StoreEvent StoreDisconnected;
|
||||||
|
|
||||||
public delegate AsyncReply<IStore> ProtocolInstance(string name, ResourceContext resourceContext);
|
public delegate AsyncReply<IStore> ProtocolInstance(string name, IResourceContext resourceContext);
|
||||||
|
|
||||||
public KeyList<string, ProtocolInstance> Protocols { get; } = new KeyList<string, ProtocolInstance>();
|
public KeyList<string, ProtocolInstance> Protocols { get; } = new KeyList<string, ProtocolInstance>();
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ public class Warehouse
|
|||||||
//IResource r;
|
//IResource r;
|
||||||
//if (rk.Value.TryGetTarget(out r))
|
//if (rk.Value.TryGetTarget(out r))
|
||||||
//{
|
//{
|
||||||
var rt = await r.Trigger(ResourceOperation.Initialize);
|
var rt = await r.Handle(ResourceOperation.Initialize);
|
||||||
//if (!rt)
|
//if (!rt)
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ public class Warehouse
|
|||||||
|
|
||||||
foreach (var r in resSnap)
|
foreach (var r in resSnap)
|
||||||
{
|
{
|
||||||
var rt = await r.Trigger(ResourceOperation.SystemInitialized);
|
var rt = await r.Handle(ResourceOperation.SystemReady);
|
||||||
if (!rt)
|
if (!rt)
|
||||||
{
|
{
|
||||||
Global.Log("Warehouse", LogType.Warning, $"Resource failed at SystemInitialized {r.Instance.Name} [{r.Instance.Definition.Name}]");
|
Global.Log("Warehouse", LogType.Warning, $"Resource failed at SystemInitialized {r.Instance.Name} [{r.Instance.Definition.Name}]");
|
||||||
@@ -267,13 +267,13 @@ public class Warehouse
|
|||||||
if (resource.TryGetTarget(out r))
|
if (resource.TryGetTarget(out r))
|
||||||
{
|
{
|
||||||
if (!(r is IStore))
|
if (!(r is IStore))
|
||||||
bag.Add(r.Trigger(ResourceOperation.Terminate));
|
bag.Add(r.Handle(ResourceOperation.Terminate));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var store in _stores)
|
foreach (var store in _stores)
|
||||||
bag.Add(store.Key.Trigger(ResourceOperation.Terminate));
|
bag.Add(store.Key.Handle(ResourceOperation.Terminate));
|
||||||
|
|
||||||
|
|
||||||
foreach (var resource in _resources.Values)
|
foreach (var resource in _resources.Values)
|
||||||
@@ -282,13 +282,13 @@ public class Warehouse
|
|||||||
if (resource.TryGetTarget(out r))
|
if (resource.TryGetTarget(out r))
|
||||||
{
|
{
|
||||||
if (!(r is IStore))
|
if (!(r is IStore))
|
||||||
bag.Add(r.Trigger(ResourceOperation.SystemTerminated));
|
bag.Add(r.Handle(ResourceOperation.SystemTerminated));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var store in _stores)
|
foreach (var store in _stores)
|
||||||
bag.Add(store.Key.Trigger(ResourceOperation.SystemTerminated));
|
bag.Add(store.Key.Handle(ResourceOperation.SystemTerminated));
|
||||||
|
|
||||||
bag.Seal();
|
bag.Seal();
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ public class Warehouse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns>Resource instance.</returns>
|
/// <returns>Resource instance.</returns>
|
||||||
public async AsyncReply<T> Get<T>(string path, ResourceContext resourceContext = null)
|
public async AsyncReply<T> Get<T>(string path, IResourceContext resourceContext = null)
|
||||||
where T : IResource
|
where T : IResource
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ public class Warehouse
|
|||||||
/// <param name="resource">Resource instance.</param>
|
/// <param name="resource">Resource instance.</param>
|
||||||
/// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param>
|
/// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param>
|
||||||
/// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param>
|
/// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param>
|
||||||
public async AsyncReply<T> Put<T>(string path, T resource, ResourceContext resourceContext = null) where T : IResource
|
public async AsyncReply<T> Put<T>(string path, T resource, IResourceContext resourceContext = null) where T : IResource
|
||||||
{
|
{
|
||||||
if (resource.Instance != null)
|
if (resource.Instance != null)
|
||||||
throw new Exception("Resource already initialized.");
|
throw new Exception("Resource already initialized.");
|
||||||
@@ -448,9 +448,9 @@ public class Warehouse
|
|||||||
|
|
||||||
if (_warehouseIsOpen)
|
if (_warehouseIsOpen)
|
||||||
{
|
{
|
||||||
await resource.Handle(ResourceOperation.Initialize);
|
await resource.Handle(ResourceOperation.Initialize, resourceContext);
|
||||||
if (resource is IStore)
|
if (resource is IStore)
|
||||||
await resource.Handle(ResourceOperation.Open);
|
await resource.Handle(ResourceOperation.Open, resourceContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource is IStore)
|
if (resource is IStore)
|
||||||
@@ -551,13 +551,13 @@ public class Warehouse
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async AsyncReply<IResource> New(Type type, string path, ResourceContext resourceContext)
|
public async AsyncReply<IResource> New(Type type, string path, IResourceContext resourceContext)
|
||||||
{
|
{
|
||||||
var res = Create(type, resourceContext?.Properties);
|
var res = Create(type, resourceContext?.Properties);
|
||||||
return await Put(path, res, resourceContext);
|
return await Put(path, res, resourceContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async AsyncReply<T> New<T>(string path, ResourceContext resourceContext = null)
|
public async AsyncReply<T> New<T>(string path, IResourceContext resourceContext = null)
|
||||||
where T : IResource
|
where T : IResource
|
||||||
{
|
{
|
||||||
return (T)(await New(typeof(T), path, resourceContext));
|
return (T)(await New(typeof(T), path, resourceContext));
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ public class MemoryStore : IStore
|
|||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
|
||||||
{
|
{
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class TemporaryStore : IStore
|
|||||||
return new AsyncReply<IResource>(null);
|
return new AsyncReply<IResource>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
{
|
{
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class EntityStore : IStore
|
|||||||
Dictionary<string, EntityTypeInfo> TypesByName = new Dictionary<string, EntityTypeInfo>();
|
Dictionary<string, EntityTypeInfo> TypesByName = new Dictionary<string, EntityTypeInfo>();
|
||||||
internal Dictionary<Type, EntityTypeInfo> TypesByType = new Dictionary<Type, EntityTypeInfo>();
|
internal Dictionary<Type, EntityTypeInfo> TypesByType = new Dictionary<Type, EntityTypeInfo>();
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public Func<DbContext> Getter { get; set; }
|
public Func<DbContext> Getter { get; set; }
|
||||||
|
|
||||||
|
|
||||||
@@ -223,9 +223,9 @@ public class EntityStore : IStore
|
|||||||
|
|
||||||
internal DbContextOptions Options { get; set; }
|
internal DbContextOptions Options { get; set; }
|
||||||
|
|
||||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext? context = null)
|
||||||
{
|
{
|
||||||
if (trigger == ResourceOperation.Initialize)// SystemInitialized && DbContext != null)
|
if (operation == ResourceOperation.Initialize)// SystemInitialized && DbContext != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Getter == null)
|
if (Getter == null)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class MongoDBStore : IStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public AsyncReply<bool> Remove(IResource resource)
|
public AsyncReply<bool> Remove(IResource resource)
|
||||||
{
|
{
|
||||||
var objectId = resource.Instance.Variables["objectId"].ToString();
|
var objectId = resource.Instance.Variables["objectId"].ToString();
|
||||||
var filter = Builders<BsonDocument>.Filter.Eq("_id", new BsonObjectId(new ObjectId(objectId)));
|
var filter = Builders<BsonDocument>.Filter.Eq("_id", new BsonObjectId(new ObjectId(objectId)));
|
||||||
@@ -515,16 +515,16 @@ public class MongoDBStore : IStore
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string Connection { get; set; }
|
public string Connection { get; set; }
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string Collection { get; set; }
|
public string Collection { get; set; }
|
||||||
[Attribute]
|
//[Attribute]
|
||||||
public string Database { get; set; }
|
public string Database { get; set; }
|
||||||
public AsyncReply<bool> Trigger(ResourceOperation trigger)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (trigger == ResourceOperation.Initialize)
|
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
|
||||||
|
{
|
||||||
|
if (operation == ResourceOperation.Initialize)
|
||||||
{
|
{
|
||||||
|
|
||||||
var collectionName = Collection ?? "resources";
|
var collectionName = Collection ?? "resources";
|
||||||
@@ -574,7 +574,7 @@ public class MongoDBStore : IStore
|
|||||||
|
|
||||||
return new AsyncReply<bool>(true);
|
return new AsyncReply<bool>(true);
|
||||||
}
|
}
|
||||||
else if (trigger == ResourceOperation.Terminate)
|
else if (operation == ResourceOperation.Terminate)
|
||||||
{
|
{
|
||||||
// save all resources
|
// save all resources
|
||||||
foreach (var resource in resources.Values)
|
foreach (var resource in resources.Values)
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class Program
|
|||||||
var auth = new ClientAuthenticationProvider();
|
var auth = new ClientAuthenticationProvider();
|
||||||
wh.RegisterAuthenticationProvider(auth);
|
wh.RegisterAuthenticationProvider(auth);
|
||||||
|
|
||||||
var con = await new Warehouse().Get<EpConnection>("EP://localhost", new EpConnectionContext
|
var con = await wh.Get<EpConnection>("EP://localhost", new EpConnectionContext
|
||||||
{
|
{
|
||||||
AutoReconnect = true,
|
AutoReconnect = true,
|
||||||
Identity = "tester",
|
Identity = "tester",
|
||||||
|
|||||||
Reference in New Issue
Block a user