2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
This commit is contained in:
Ahmed Zamil 2020-04-27 08:32:10 +03:00
parent 836a1fdeae
commit 443623d8df
16 changed files with 207 additions and 147 deletions

View File

@ -36,6 +36,9 @@ namespace Esyur.Stores.EntityCore
{
public class EntityResource : IResource
{
[NotMapped]
internal int _PrimaryId;
public event DestroyedEvent OnDestroy;
public event PropertyChangedEventHandler PropertyChanged;

View File

@ -45,7 +45,9 @@ namespace Esyur.Stores.EntityCore
public event DestroyedEvent OnDestroy;
struct TypeInfo
Dictionary<Type, Dictionary<int, WeakReference>> DB = new Dictionary<Type, Dictionary<int, WeakReference>>();
internal struct TypeInfo
{
public string Name;
public IEntityType Type;
@ -53,55 +55,57 @@ namespace Esyur.Stores.EntityCore
}
Dictionary<string, TypeInfo> TypesByName = new Dictionary<string, TypeInfo>();
Dictionary<Type, TypeInfo> TypesByType = new Dictionary<Type, TypeInfo>();
/*
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var extension = optionsBuilder.Options.FindExtension<EsyurExtension>()
?? new EsyurExtension();
internal Dictionary<Type, TypeInfo> TypesByType = new Dictionary<Type, TypeInfo>();
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);
//optionsBuilder.UseLazyLoadingProxies();
base.OnConfiguring(optionsBuilder);
}
*/
/*
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//modelBuilder.Entity<Series>().ToTable("Series");
//modelBuilder.Entity<Episode>().ToTable("Episodes").;
//modelBuilder.Ignore<Entit>
// modelBuilder.Entity<Series>(x=>x.Property(p=>p.Instance).HasConversion(v=>v.Managers.)
Console.WriteLine("OnModelCreating");
//modelBuilder.Entity()
base.OnModelCreating(modelBuilder);
}*/
bool Loaded;
public async AsyncReply<IResource> Get(string path)
{
var p = path.Split('/');
var ti = TypesByName[p[0]];
var id = Convert.ToInt32(p[1]);
return DbContext.Find(ti.Type.ClrType, id) as IResource;
return DbContextProvider().Find(ti.Type.ClrType, id) as IResource;
}
public async AsyncReply<bool> Put(IResource resource)
{
if (resource is EntityStore)
return false;
var type = ResourceProxy.GetBaseType(resource);//.GetType().;
var eid = (resource as EntityResource)._PrimaryId;// (int)resource.Instance.Variables["eid"];
if (DB[type].ContainsKey(eid))
DB[type].Remove(eid);
DB[type].Add(eid, new WeakReference(resource));
return true;
}
public IResource GetById(Type type, int id)
{
if (!DB[type].ContainsKey(id))
return null;
if (!DB[type][id].IsAlive)
return null;
return DB[type][id].Target as IResource;
}
[Attribute]
public EsyurExtensionOptions Options { get; set; }
public Func<DbContext> DbContextProvider { get; set; }
[Attribute]
public DbContextOptionsBuilder Options { get; set; }
//DbContext dbContext;
[Attribute]
public DbContext DbContext { get; set; }
//[Attribute]
//public DbContext DbContext { get; set; }
public string Link(IResource resource)
{
@ -178,9 +182,15 @@ namespace Esyur.Stores.EntityCore
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{
if (trigger == ResourceTrigger.SystemInitialized && DbContext != null)
if (trigger == ResourceTrigger.Initialize)// SystemInitialized && DbContext != null)
{
var types = DbContext.Model.GetEntityTypes();
if (DbContextProvider == null)
DbContextProvider = () => Activator.CreateInstance(Options.Options.ContextType, Options.Options) as DbContext;
var context = Activator.CreateInstance(Options.Options.ContextType, Options.Options) as DbContext;
var types = context.Model.GetEntityTypes();
foreach (var t in types)
{
var ti = new TypeInfo()
@ -192,6 +202,8 @@ namespace Esyur.Stores.EntityCore
TypesByName.Add(t.ClrType.Name, ti);
TypesByType.Add(t.ClrType, ti);
DB.Add(t.ClrType, new Dictionary<int, WeakReference>());
}
}

View File

@ -11,14 +11,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Marten" Version="3.10.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.1.2" />
<PackageReference Include="Npgsql" Version="4.1.3.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.3" />
<PackageReference Include="System.Collections" Version="4.3.0" />
</ItemGroup>

View File

@ -57,6 +57,7 @@ namespace Esyur.Stores.EntityCore
public EntityStore Store => _store;
public void ApplyServices(IServiceCollection services)
{
services.AddEntityFrameworkProxies();

View File

@ -60,11 +60,11 @@ namespace Esyur.Stores.EntityCore
}
public static DbContextOptionsBuilder UseEsyur(this DbContextOptionsBuilder optionsBuilder,
DbContext context,
//DbContext context,
string name = null,
IResource parent = null,
IPermissionsManager manager = null
IResource parent = null,
IPermissionsManager manager = null,
Func<DbContext> dbContextProvider = null
)
{
var extension = optionsBuilder.Options.FindExtension<EsyurExtensionOptions>();
@ -72,10 +72,10 @@ namespace Esyur.Stores.EntityCore
if (extension == null)
{
var store = Warehouse.New<EntityStore>(name, null, parent, manager);
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider });
extension = new EsyurExtensionOptions(store);
store.Options = extension;
store.DbContext = context;
//store.Options = optionsBuilder;
//store.DbContext = context;
}
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);
@ -86,10 +86,11 @@ namespace Esyur.Stores.EntityCore
public static DbContextOptionsBuilder<TContext> UseEsyur<TContext>(
this DbContextOptionsBuilder<TContext> optionsBuilder,
DbContext context,
//DbContext context,
string name = null,
IResource parent = null,
IPermissionsManager manager = null)
IPermissionsManager manager = null,
Func<DbContext> dbContextProvider = null)
where TContext : DbContext
{
@ -98,10 +99,11 @@ namespace Esyur.Stores.EntityCore
if (extension == null)
{
var store = Warehouse.New<EntityStore>(name, null, parent, manager);
var store = Warehouse.New<EntityStore>(name, null, parent, manager, new { Options = optionsBuilder, DbContextProvider = dbContextProvider });
extension = new EsyurExtensionOptions(store);
store.Options = extension;
store.DbContext = context;
//store.Options = optionsBuilder;
//store.Options = extension;
//store.DbContext = context;
}

View File

@ -24,10 +24,12 @@ SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Esyur.Proxy;
using Esyur.Resource;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
@ -48,40 +50,39 @@ namespace Esyur.Stores.EntityCore
public static object CreateInstance(
IDbContextOptions dbContextOptions,
IEntityType entityType,
ILazyLoader loader,
object[] constructorArguments)
// ILazyLoader loader,
object[] constructorArguments,
DbContext context,
int id = 0
)
{
var options = dbContextOptions.FindExtension<EsyurExtensionOptions>();
var manager = options.Store.Instance.Managers.Count > 0 ? options.Store.Instance.Managers.First() : null;
return CreateInstance2(
options,
entityType,
loader,
constructorArguments);
var cache = options.Store.GetById(entityType.ClrType, id);
if (cache != null)
return cache;
// check if the object exists
var obj = Warehouse.New(entityType.ClrType) as EntityResource;//, "", options.Store, null, manager);
obj._PrimaryId = id;
options.Store.TypesByType[entityType.ClrType].PrimaryKey.SetValue(obj, id);
Warehouse.Put(obj, id.ToString(), options.Store, null, null, 0, manager);
// obj.Instance.IntVal = id;//.Variables.Add("eid", id);
return obj;
}
public static object CreateInstance2(
EsyurExtensionOptions options,
IEntityType entityType,
ILazyLoader loader,
object[] constructorArguments)
{
//var key = entityType.FindPrimaryKey();
//options.AddType(entityType);
var manager = options.Store.Instance.Managers.Count > 0 ? options.Store.Instance.Managers.First() : null;
return Warehouse.New(entityType.ClrType, "", options.Store, null, manager);
}
public EsyurProxyRewrite(EsyurExtensionOptions ext, ProviderConventionSetBuilderDependencies conventionSetBuilderDependencies)
{
_directBindingConvention = new ConstructorBindingConvention(conventionSetBuilderDependencies);
}
public void ProcessModelFinalized(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
@ -108,8 +109,10 @@ namespace Esyur.Stores.EntityCore
{
new DependencyInjectionParameterBinding(typeof(IDbContextOptions), typeof(IDbContextOptions)),
new EntityTypeParameterBinding(),
new DependencyInjectionParameterBinding(typeof(ILazyLoader), typeof(ILazyLoader)),
new ObjectArrayParameterBinding(binding.ParameterBindings)
//new DependencyInjectionParameterBinding(typeof(ILazyLoader), typeof(ILazyLoader)),
new ObjectArrayParameterBinding(binding.ParameterBindings),
new ContextParameterBinding(typeof(DbContext)),
new PropertyParameterBinding(entityType.FindPrimaryKey().Properties.FirstOrDefault())
},
proxyType));
}

View File

@ -50,12 +50,12 @@
<ItemGroup>
<PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Interactive.Async" Version="3.2.0" />
<PackageReference Include="System.Interactive.Async" Version="4.1.1" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Net.NetworkInformation" Version="4.3.0" />
<PackageReference Include="System.Net.Security" Version="4.3.1" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
<PackageReference Include="System.Net.Security" Version="4.3.2" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
</Project>

View File

@ -416,7 +416,7 @@ namespace Esyur.Net.IIP
parent.children.Remove(child);
child.parents.Remove(parent);
// parent.Instance.Children.Remove(child);
// parent.Instance.Children.Remove(child);
});
});
}
@ -460,6 +460,7 @@ namespace Esyur.Net.IIP
// unsubscribe
r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
r.Instance.CustomResourceEventOccurred -= Instance_CustomEventOccurred;
r.Instance.ResourceModified -= Instance_PropertyModified;
r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
// r.Instance.Children.OnAdd -= Children_OnAdd;
@ -501,6 +502,7 @@ namespace Esyur.Net.IIP
// subscribe
r.Instance.ResourceEventOccurred += Instance_EventOccurred;
r.Instance.CustomResourceEventOccurred += Instance_CustomEventOccurred;
r.Instance.ResourceModified += Instance_PropertyModified;
r.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
//r.Instance.Children.OnAdd += Children_OnAdd;
@ -581,6 +583,7 @@ namespace Esyur.Net.IIP
var r = res as IResource;
// unsubscribe
r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
r.Instance.CustomResourceEventOccurred -= Instance_CustomEventOccurred;
r.Instance.ResourceModified -= Instance_PropertyModified;
r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
//r.Instance.Children.OnAdd -= Children_OnAdd;
@ -590,6 +593,7 @@ namespace Esyur.Net.IIP
// subscribe
r.Instance.ResourceEventOccurred += Instance_EventOccurred;
r.Instance.CustomResourceEventOccurred += Instance_CustomEventOccurred;
r.Instance.ResourceModified += Instance_PropertyModified;
r.Instance.ResourceDestroyed += Instance_ResourceDestroyed;
//r.Instance.Children.OnAdd += Children_OnAdd;
@ -619,6 +623,7 @@ namespace Esyur.Net.IIP
{
var r = res as IResource;
r.Instance.ResourceEventOccurred -= Instance_EventOccurred;
r.Instance.CustomResourceEventOccurred -= Instance_CustomEventOccurred;
r.Instance.ResourceModified -= Instance_PropertyModified;
r.Instance.ResourceDestroyed -= Instance_ResourceDestroyed;
@ -1207,7 +1212,7 @@ namespace Esyur.Net.IIP
.AddUInt8((byte)DataType.Void)
.Done();
}
catch(Exception ex)
catch (Exception ex)
{
SendError(ErrorType.Exception, callback, 0, ex.ToString());
}
@ -1231,7 +1236,7 @@ namespace Esyur.Net.IIP
//SendParams((byte)0x90, callback, Codec.Compose(res, this));
}
else if (rt is AsyncReply)// Codec.ImplementsInterface(rt.GetType(), typeof(IAsyncReply<>)))// rt.GetType().GetTypeInfo().IsGenericType
//&& rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
//&& rt.GetType().GetGenericTypeDefinition() == typeof(IAsyncReply<>))
{
(rt as AsyncReply).Then(res =>
{
@ -1306,18 +1311,18 @@ namespace Esyur.Net.IIP
else
{
// function not found on a distributed object
}
// function not found on a distributed object
}
}
else
{
#if NETSTANDARD
var fi = r.GetType().GetTypeInfo().GetMethod(ft.Name);
var fi = r.GetType().GetTypeInfo().GetMethod(ft.Name);
#else
var fi = r.GetType().GetMethod(ft.Name);
#endif
if (fi != null)
if (fi != null)
{
if (r.Instance.Applicable(session, ActionType.Execute, ft) == Ruling.Denied)
{
@ -1326,8 +1331,8 @@ namespace Esyur.Net.IIP
return;
}
// cast arguments
ParameterInfo[] pi = fi.GetParameters();
// cast arguments
ParameterInfo[] pi = fi.GetParameters();
object[] args = new object[pi.Length];
@ -1379,34 +1384,34 @@ namespace Esyur.Net.IIP
(rt as Task).ContinueWith(t =>
{
#if NETSTANDARD
var res = t.GetType().GetTypeInfo().GetProperty("Result").GetValue(t);
var res = t.GetType().GetTypeInfo().GetProperty("Result").GetValue(t);
#else
var res = t.GetType().GetProperty("Result").GetValue(t);
#endif
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
.AddUInt8Array(Codec.Compose(res, this))
.Done();
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
.AddUInt8Array(Codec.Compose(res, this))
.Done();
});
}
else if (rt is AsyncReply)
else if (rt is AsyncReply)
{
(rt as AsyncReply).Then(res =>
{
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
.AddUInt8Array(Codec.Compose(res, this))
.Done();
SendReply(IIPPacket.IIPPacketAction.InvokeFunctionNamedArguments, callback)
.AddUInt8Array(Codec.Compose(res, this))
.Done();
}).Error(ex =>
{
SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message);
}).Progress((pt, pv, pm) =>
{
SendProgress(callback, pv, pm);
}).Chunk(v =>
{
SendChunk(callback, v);
});
}).Error(ex =>
{
SendError(ErrorType.Exception, callback, (ushort)ex.Code, ex.Message);
}).Progress((pt, pv, pm) =>
{
SendProgress(callback, pv, pm);
}).Chunk(v =>
{
SendChunk(callback, v);
});
}
else
{
@ -1417,14 +1422,14 @@ namespace Esyur.Net.IIP
}
else
{
// ft found, fi not found, this should never happen
}
// ft found, fi not found, this should never happen
}
}
}
else
{
// no function at this index
}
// no function at this index
}
});
}
else
@ -1843,7 +1848,7 @@ namespace Esyur.Net.IIP
{
//if (filter != null)
// ar = ar?.Where(filter).ToArray();
// ar = ar?.Where(filter).ToArray();
// MISSING: should dispatch the unused resources.
if (ar?.Length > 0)
@ -2139,7 +2144,7 @@ namespace Esyur.Net.IIP
Codec.ParseResourceArray(content, 0, (uint)content.Length, this)
.Then(resources => reply.Trigger(resources));
}).Error(ex=>reply.TriggerError(ex));
}).Error(ex => reply.TriggerError(ex));
return reply;
}
@ -2210,26 +2215,15 @@ namespace Esyur.Net.IIP
// private void Instance_EventOccurred(IResource resource, string name, string[] users, DistributedConnection[] connections, object[] args)
private void Instance_EventOccurred(IResource resource, object issuer, Session[] receivers, string name, object[] args)
private void Instance_CustomEventOccurred(IResource resource, object issuer, Func<Session, bool> receivers, string name, object[] args)
{
var et = resource.Instance.Template.GetEventTemplateByName(name);
if (et == null)
return;
/*
if (users != null)
if (!users.Contains(RemoteUsername))
return;
if (connections != null)
if (!connections.Contains(this))
return;
*/
if (receivers != null)
if (!receivers.Contains(this.session))
return;
if (!receivers(this.session))
return;
if (resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, et, issuer) == Ruling.Denied)
return;
@ -2241,5 +2235,24 @@ namespace Esyur.Net.IIP
.AddUInt8Array(Codec.ComposeVarArray(args, this, true))
.Done();
}
private void Instance_EventOccurred(IResource resource, string name, object[] args)
{
var et = resource.Instance.Template.GetEventTemplateByName(name);
if (et == null)
return;
if (resource.Instance.Applicable(this.session, ActionType.ReceiveEvent, et, null) == Ruling.Denied)
return;
// compose the packet
SendEvent(IIPPacket.IIPPacketEvent.EventOccurred)
.AddUInt32(resource.Instance.Id)
.AddUInt8((byte)et.Index)
.AddUInt8Array(Codec.ComposeVarArray(args, this, true))
.Done();
}
}
}

View File

@ -20,5 +20,8 @@ namespace Esyur.Net.IIP
{
this.Method = method;
}
public static implicit operator DistributedPropertyContext(Func<DistributedConnection, object> method)
=> new DistributedPropertyContext(method);
}
}

View File

@ -214,7 +214,7 @@ namespace Esyur.Net.IIP
{
var et = Instance.Template.GetEventTemplateByIndex(index);
events[index]?.Invoke(this, args);
Instance.EmitResourceEvent(null, null, et.Name, args);
Instance.EmitResourceEvent(et.Name, args);
}
public AsyncReply<object> _InvokeByNamedArguments(byte index, Structure namedArgs)

View File

@ -140,11 +140,7 @@ namespace Esyur.Net.IIP
protected override void ClientDisconnected(DistributedConnection sender)
{
sender.Destroy();
Warehouse.Remove(sender);
//Console.WriteLine("DistributedConnection Client Disconnected");
}
}
}

View File

@ -29,6 +29,11 @@ namespace Esyur.Proxy
public static Type GetBaseType(Type type)
{
if (type.Assembly.IsDynamic)
return type.GetTypeInfo().BaseType;
else
return type;
if (type.FullName.Contains("Esyur.Proxy.T"))
#if NETSTANDARD
return type.GetTypeInfo().BaseType;

View File

@ -44,5 +44,7 @@ namespace Esyur.Resource
get;
set;
}
}
}

View File

@ -20,6 +20,8 @@ namespace Esyur.Resource
{
string name;
// public int IntVal { get; set; }
WeakReference<IResource> resource;
IStore store;
ResourceTemplate template;
@ -27,11 +29,15 @@ namespace Esyur.Resource
public delegate void ResourceModifiedEvent(IResource resource, string propertyName, object newValue);
public delegate void ResourceEventOccurredEvent(IResource resource, object issuer, Session[] receivers, string eventName, object[] args);
public delegate void ResourceEventOccurredEvent(IResource resource, string eventName, object[] args);
public delegate void CustomResourceEventOccurredEvent(IResource resource, object issuer, Func<Session, bool> receivers, string eventName, object[] args);
public delegate void ResourceDestroyedEvent(IResource resource);
public event ResourceModifiedEvent ResourceModified;
public event ResourceEventOccurredEvent ResourceEventOccurred;
public event CustomResourceEventOccurredEvent CustomResourceEventOccurred;
public event ResourceDestroyedEvent ResourceDestroyed;
bool loading = false;
@ -582,13 +588,21 @@ namespace Esyur.Resource
// internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args)
internal void EmitResourceEvent(object issuer, Session[] receivers, string name, object[] args)
internal void EmitCustomResourceEvent(object issuer, Func<Session, bool> receivers, string name, object[] args)
{
IResource res;
if (this.resource.TryGetTarget(out res))
{
CustomResourceEventOccurred?.Invoke(res, issuer, receivers, name, args);
}
}
ResourceEventOccurred?.Invoke(res, issuer, receivers, name, args);
internal void EmitResourceEvent(string name, object[] args)
{
IResource res;
if (this.resource.TryGetTarget(out res))
{
ResourceEventOccurred?.Invoke(res, name, args);
}
}
@ -891,7 +905,7 @@ namespace Esyur.Resource
// if (ca.Length == 0)
// continue;
ResourceEventHanlder proxyDelegate = (args) => EmitResourceEvent(null, null, evt.Name, args);
ResourceEventHanlder proxyDelegate = (args) => EmitResourceEvent(evt.Name, args);
evt.Info.AddEventHandler(resource, proxyDelegate);
}
@ -901,7 +915,7 @@ namespace Esyur.Resource
//if (ca.Length == 0)
// continue;
CustomResourceEventHanlder proxyDelegate = (issuer, receivers, args) => EmitResourceEvent(issuer, receivers, evt.Name, args);
CustomResourceEventHanlder proxyDelegate = (issuer, receivers, args) => EmitCustomResourceEvent(issuer, receivers, evt.Name, args);
evt.Info.AddEventHandler(resource, proxyDelegate);
}

View File

@ -34,11 +34,11 @@ using System.Threading.Tasks;
namespace Esyur.Resource
{
public delegate void ResourceEventHanlder(params object[] args);
// public delegate void CustomUsersEventHanlder(string[] usernames, params object[] args);
// public delegate void CustomUsersEventHanlder(string[] usernames, params object[] args);
//public delegate void CustomReceiversEventHanlder(DistributedConnection[] connections, params object[] args);
//public delegate void CustomInquirerEventHanlder(object inquirer, params object[] args);
public delegate void CustomResourceEventHanlder(object issuer, Session[] receivers, params object[] args);
public delegate void CustomResourceEventHanlder(object issuer, Func<Session, bool> receivers, params object[] args);// object issuer, Session[] receivers, params object[] args);
// public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args);

View File

@ -115,6 +115,9 @@ namespace Esyur.Resource
/// <returns>True, if no problem occurred.</returns>
public static async AsyncReply<bool> Open()
{
if (warehouseIsOpen)
return false;
warehouseIsOpen = true;
var resSnap = resources.Select(x =>
@ -526,7 +529,7 @@ namespace Esyur.Resource
}
public static IResource New(Type type, string name, IStore store = null, IResource parent = null, IPermissionsManager manager = null, object attributes = null, object properties = null)
public static IResource New(Type type, string name = null, IStore store = null, IResource parent = null, IPermissionsManager manager = null, object attributes = null, object properties = null)
{
type = ResourceProxy.GetProxy(type);
@ -618,12 +621,15 @@ namespace Esyur.Resource
/// <returns>Resource template.</returns>
public static ResourceTemplate GetTemplate(Type type)
{
var baseType = ResourceProxy.GetBaseType(type);
// loaded ?
foreach (var t in templates.Values)
if (t.ClassName == type.FullName)
if (t.ClassName == baseType.FullName)
return t;
var template = new ResourceTemplate(type);
var template = new ResourceTemplate(baseType);
templates.Add(template.ClassId, template);
return template;