2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-06-13 14:38:43 +00:00
This commit is contained in:
2026-05-26 16:18:57 +03:00
parent e4a54ffbe8
commit a91fc7d262
29 changed files with 206 additions and 148 deletions
+2 -2
View File
@@ -42,9 +42,9 @@ public abstract class PacketFilter : IResource
}
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);
+4 -4
View File
@@ -67,9 +67,9 @@ public class PacketServer : IResource
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)
{
@@ -77,12 +77,12 @@ public class PacketServer : IResource
src.Open();
}
}
else if (trigger == ResourceOperation.Terminate)
else if (operation == ResourceOperation.Terminate)
{
foreach (var src in sources)
src.Close();
}
else if (trigger == ResourceOperation.SystemReload)
else if (operation == ResourceOperation.SystemReloading)
{
foreach (var src in sources)
{
+1 -3
View File
@@ -43,9 +43,7 @@ public abstract class PacketSource : IResource
set;
}
public abstract AsyncReply<bool> Trigger(ResourceOperation trigger);
public abstract AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null);
public abstract bool RawMode
{
+2 -2
View File
@@ -9,7 +9,7 @@ using System.Text;
namespace Esiur.Net.Http;
public class EpOverHttp : HttpFilter
{
[Attribute]
//[Attribute]
EntryPoint EntryPoint { get; set; }
public override AsyncReply<bool> Execute(HttpConnection sender)
@@ -30,7 +30,7 @@ public class EpOverHttp : HttpFilter
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);
}
+3 -2
View File
@@ -33,9 +33,10 @@ using Esiur.Core;
using Esiur.Protocol;
namespace Esiur.Net.Http;
public class EpOvwerWebsocket : HttpFilter
{
[Attribute]
//[Attribute]
public EpServer Server
{
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);
}
+1 -1
View File
@@ -46,7 +46,7 @@ public abstract class HttpFilter : IResource
}
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)
+12 -12
View File
@@ -139,14 +139,14 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
set;
}
[Attribute]
//[Attribute]
public virtual string IP
{
get;
set;
}
[Attribute]
//[Attribute]
public virtual ushort Port
{
get;
@@ -154,21 +154,21 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
}
[Attribute]
//[Attribute]
public virtual uint MaxPost
{
get;
set;
}
[Attribute]
//[Attribute]
public virtual bool SSL
{
get;
set;
}
[Attribute]
//[Attribute]
public virtual string Certificate
{
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 port = (int)Instance.Attributes["port"];
@@ -318,16 +318,16 @@ public class HttpServer : NetworkServer<HttpConnection>, IResource
Start(listener);
}
else if (trigger == ResourceOperation.Terminate)
else if (operation == ResourceOperation.Terminate)
{
Stop();
}
else if (trigger == ResourceOperation.SystemReload)
else if (operation == ResourceOperation.SystemReloading)
{
await Trigger(ResourceOperation.Terminate);
await Trigger(ResourceOperation.Initialize);
await Handle(ResourceOperation.Terminate);
await Handle(ResourceOperation.Initialize);
}
else if (trigger == ResourceOperation.SystemInitialized)
else if (operation == ResourceOperation.SystemReady)
{
filters = await Instance.Children<HttpFilter>();
}
+2 -2
View File
@@ -136,7 +136,7 @@ public abstract class NetworkServer<TConnection> : IDestructible where TConnecti
}
[Attribute]
//[Attribute]
public uint Timeout
{
get;
@@ -144,7 +144,7 @@ public abstract class NetworkServer<TConnection> : IDestructible where TConnecti
}
[Attribute]
//[Attribute]
public uint Clock
{
get;
+1 -1
View File
@@ -46,7 +46,7 @@ public abstract class TcpFilter : IResource
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)
{
+9 -9
View File
@@ -38,13 +38,13 @@ namespace Esiur.Net.Tcp;
public class TcpServer : NetworkServer<TcpConnection>, IResource
{
[Attribute]
//[Attribute]
public string IP
{
get;
set;
}
[Attribute]
//[Attribute]
public ushort Port
{
get;
@@ -66,9 +66,9 @@ public class TcpServer : NetworkServer<TcpConnection>, IResource
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;
@@ -82,16 +82,16 @@ public class TcpServer : NetworkServer<TcpConnection>, IResource
}
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);
}
else if (trigger == ResourceOperation.SystemInitialized)
else if (operation == ResourceOperation.SystemReady)
{
Instance.Children<TcpFilter>().Then(x => filters = x);
}
+2 -1
View File
@@ -47,7 +47,8 @@ public abstract class UdpFilter : IResource
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);
+6 -6
View File
@@ -55,14 +55,14 @@ public class UdpServer : IResource
set;
}
[Attribute]
//[Attribute]
string IP
{
get;
set;
}
[Attribute]
//[Attribute]
ushort Port
{
get;
@@ -177,9 +177,9 @@ public class UdpServer : IResource
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);
@@ -188,12 +188,12 @@ public class UdpServer : IResource
receiver = new Thread(Receiving);
receiver.Start();
}
else if (trigger == ResourceOperation.Terminate)
else if (operation == ResourceOperation.Terminate)
{
if (receiver != null)
receiver.Abort();
}
else if (trigger == ResourceOperation.SystemInitialized)
else if (operation == ResourceOperation.SystemReady)
{
filters = await Instance.Children<UdpFilter>();
}
+42 -14
View File
@@ -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);
+24 -16
View File
@@ -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; }
}
+2 -2
View File
@@ -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));
+13 -12
View File
@@ -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);
+11 -9
View File
@@ -111,9 +111,9 @@ namespace Esiur.Proxy
code.AppendLine("public virtual event DestroyedEvent? OnDestroy;");
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;
if (hasResource)
{
bool hasTrigger = cds.Members
bool hasHandle = cds.Members
.OfType<MethodDeclarationSyntax>()
.Select(m => ctx.SemanticModel.GetDeclaredSymbol(m) as IMethodSymbol)
.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
.OfType<FieldDeclarationSyntax>()
@@ -208,7 +210,7 @@ namespace Esiur.Proxy
cls,
exportedFields,
hasInterface,
hasTrigger
hasHandle
);
}
@@ -228,7 +230,7 @@ namespace Esiur.Proxy
{
Fields = mergedFields,
HasInterface = existing.HasInterface || item.HasInterface,
HasTrigger = existing.HasTrigger || item.HasTrigger
HasHandle = existing.HasHandle || item.HasHandle
};
}
else
@@ -337,7 +339,7 @@ namespace Esiur.Proxy
public ResourceClassInfo(string key, string name ,
ClassDeclarationSyntax classDeclaration,
ITypeSymbol classSymbol, List<IFieldSymbol> fileds, bool hasInterface, bool hasTrigger)
ITypeSymbol classSymbol, List<IFieldSymbol> fileds, bool hasInterface, bool hasHandle)
{
Key = key;
Name = name;
@@ -345,7 +347,7 @@ namespace Esiur.Proxy
ClassSymbol = classSymbol;
Fields = fileds;
HasInterface = hasInterface;
HasTrigger = hasTrigger;
HasHandle = hasHandle;
}
public string Key;
@@ -354,7 +356,7 @@ namespace Esiur.Proxy
public ITypeSymbol ClassSymbol;
public List<IFieldSymbol> Fields;
public bool HasInterface;
public bool HasTrigger;
public bool HasHandle;
}
}
}
+8 -4
View File
@@ -218,10 +218,14 @@ public static class TypeDefGenerator
throw new Exception("Invalid EP URL");
var path = urlRegex.Split(url);
var con = Warehouse.Default.Get<EpConnection>(path[1] + "://" + path[2], new ResourceContext(0,
new Map<string, object> { ["username"] = username, ["password"] = password }, null, null)
// !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) ? new { Username = username, Password = password } : null
).Wait(20000);
var con = Warehouse.Default.Get<EpConnection>(path[1] + "://" + path[2], new EpConnectionContext()
{
Identity = username
}).Wait(10000);
//ResourceContext(0,
// new Map<string, object> { ["username"] = username, ["password"] = password }, null, null)
// ).Wait(20000);
if (con == null)
throw new Exception("Can't connect to server");
+1 -2
View File
@@ -35,8 +35,7 @@ public delegate bool QueryFilter<T>(T value);
public interface IResource : IDestructible
{
AsyncReply<bool> Handle(ResourceOperation trigger);
AsyncReply<bool> Initialize(ResourceContext resourceContext);
AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext? context = null);
[NotMapped]
[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; }
}
}
+2 -2
View File
@@ -38,9 +38,9 @@ public class Resource : IResource
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());
else
return new AsyncReply<bool>(true);
+6 -6
View File
@@ -8,13 +8,13 @@ using System.Text;
namespace Esiur.Resource
{
public class ResourceContext
public class ResourceContext:IResourceContext
{
public ulong Age { get; }
public Map<string, object> Attributes { get; }
public Map<string, object> Properties { get; }
public IPermissionsManager PermissionsManager { get; }
public ResourceContext(ulong age, Map<string, object> attributes, Map<string, object> properties, IPermissionsManager permissionsManager)
{
Age = age;
@@ -23,9 +23,9 @@ namespace Esiur.Resource
PermissionsManager = permissionsManager;
}
public virtual void Build()
{
// update the context based on the current state of the resource and its environment
}
//public virtual void Build()
//{
// // update the context based on the current state of the resource and its environment
//}
}
}
+6 -4
View File
@@ -35,10 +35,12 @@ public abstract class Store<T> : IStore where T : IResource
public abstract bool Record(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime);
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)
//{
+13 -13
View File
@@ -92,7 +92,7 @@ public class Warehouse
public event StoreEvent StoreConnected;
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>();
@@ -226,7 +226,7 @@ public class Warehouse
//IResource r;
//if (rk.Value.TryGetTarget(out r))
//{
var rt = await r.Trigger(ResourceOperation.Initialize);
var rt = await r.Handle(ResourceOperation.Initialize);
//if (!rt)
// return false;
@@ -239,7 +239,7 @@ public class Warehouse
foreach (var r in resSnap)
{
var rt = await r.Trigger(ResourceOperation.SystemInitialized);
var rt = await r.Handle(ResourceOperation.SystemReady);
if (!rt)
{
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 (!(r is IStore))
bag.Add(r.Trigger(ResourceOperation.Terminate));
bag.Add(r.Handle(ResourceOperation.Terminate));
}
}
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)
@@ -282,13 +282,13 @@ public class Warehouse
if (resource.TryGetTarget(out r))
{
if (!(r is IStore))
bag.Add(r.Trigger(ResourceOperation.SystemTerminated));
bag.Add(r.Handle(ResourceOperation.SystemTerminated));
}
}
foreach (var store in _stores)
bag.Add(store.Key.Trigger(ResourceOperation.SystemTerminated));
bag.Add(store.Key.Handle(ResourceOperation.SystemTerminated));
bag.Seal();
@@ -337,7 +337,7 @@ public class Warehouse
/// </summary>
/// <param name="path"></param>
/// <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
{
@@ -385,7 +385,7 @@ public class Warehouse
/// <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="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)
throw new Exception("Resource already initialized.");
@@ -448,9 +448,9 @@ public class Warehouse
if (_warehouseIsOpen)
{
await resource.Handle(ResourceOperation.Initialize);
await resource.Handle(ResourceOperation.Initialize, resourceContext);
if (resource is IStore)
await resource.Handle(ResourceOperation.Open);
await resource.Handle(ResourceOperation.Open, resourceContext);
}
if (resource is IStore)
@@ -551,13 +551,13 @@ public class Warehouse
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);
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
{
return (T)(await New(typeof(T), path, resourceContext));
+2 -3
View File
@@ -67,9 +67,8 @@ public class MemoryStore : IStore
return new AsyncReply<bool>(true);
}
public AsyncReply<bool> Trigger(ResourceOperation trigger)
{
public AsyncReply<bool> Handle(ResourceOperation operation, IResourceContext context = null)
{
return new AsyncReply<bool>(true);
}
+1 -1
View File
@@ -59,7 +59,7 @@ public class TemporaryStore : IStore
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);
}
@@ -54,7 +54,7 @@ public class EntityStore : IStore
Dictionary<string, EntityTypeInfo> TypesByName = new Dictionary<string, EntityTypeInfo>();
internal Dictionary<Type, EntityTypeInfo> TypesByType = new Dictionary<Type, EntityTypeInfo>();
[Attribute]
//[Attribute]
public Func<DbContext> Getter { get; set; }
@@ -223,9 +223,9 @@ public class EntityStore : IStore
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)
+11 -11
View File
@@ -110,7 +110,7 @@ public class MongoDBStore : IStore
}
[Export]
public AsyncReply<bool> Remove(IResource resource)
public AsyncReply<bool> Remove(IResource resource)
{
var objectId = resource.Instance.Variables["objectId"].ToString();
var filter = Builders<BsonDocument>.Filter.Eq("_id", new BsonObjectId(new ObjectId(objectId)));
@@ -515,16 +515,16 @@ public class MongoDBStore : IStore
throw new NotImplementedException();
}
[Attribute]
//[Attribute]
public string Connection { get; set; }
[Attribute]
//[Attribute]
public string Collection { get; set; }
[Attribute]
//[Attribute]
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";
@@ -574,7 +574,7 @@ public class MongoDBStore : IStore
return new AsyncReply<bool>(true);
}
else if (trigger == ResourceOperation.Terminate)
else if (operation == ResourceOperation.Terminate)
{
// save all resources
foreach (var resource in resources.Values)
@@ -855,7 +855,7 @@ public class MongoDBStore : IStore
}
}
public AsyncReply<bool> AddChild(IResource resource, IResource child)
{
@@ -887,9 +887,9 @@ public class MongoDBStore : IStore
throw new NotImplementedException();
}
public AsyncReply<bool> Move(IResource resource, string newPath)
{
throw new NotImplementedException();
+1 -1
View File
@@ -218,7 +218,7 @@ class Program
var auth = new ClientAuthenticationProvider();
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,
Identity = "tester",