mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
TemplateType.Wrapper Removed
This commit is contained in:
parent
77f7d1d545
commit
522f23212d
@ -172,7 +172,7 @@ namespace Esiur.Data
|
||||
(RepresentationTypeIdentifier.Resource) => typeof(IResource),
|
||||
(RepresentationTypeIdentifier.Record) => typeof(IRecord),
|
||||
(RepresentationTypeIdentifier.TypedRecord) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Record)?.DefinedType,
|
||||
(RepresentationTypeIdentifier.TypedResource) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Unspecified)?.DefinedType,
|
||||
(RepresentationTypeIdentifier.TypedResource) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Resource)?.DefinedType,
|
||||
(RepresentationTypeIdentifier.Enum) => Warehouse.GetTemplateByClassId((Guid)GUID, TemplateType.Enum)?.DefinedType,
|
||||
|
||||
_ => null
|
||||
|
@ -122,7 +122,7 @@ public static class TemplateGenerator
|
||||
string name;
|
||||
|
||||
if (representationType.Identifier == RepresentationTypeIdentifier.TypedResource)// == DataType.Resource)
|
||||
name = templates.First(x => x.ClassId == representationType.GUID && (x.Type == TemplateType.Resource || x.Type == TemplateType.Wrapper)).ClassName;
|
||||
name = templates.First(x => x.ClassId == representationType.GUID && (x.Type == TemplateType.Resource)).ClassName;
|
||||
else if (representationType.Identifier == RepresentationTypeIdentifier.TypedRecord)
|
||||
name = templates.First(x => x.ClassId == representationType.GUID && x.Type == TemplateType.Record).ClassName;
|
||||
else if (representationType.Identifier == RepresentationTypeIdentifier.Enum)
|
||||
|
@ -866,13 +866,6 @@ public class Instance
|
||||
/// </summary>
|
||||
public AutoList<IPermissionsManager, Instance> Managers => managers;
|
||||
|
||||
|
||||
public void CallMeTest(Instance ins, int? val) =>
|
||||
ins.EmitResourceEventByIndex(201, val);
|
||||
|
||||
public void CallMeTest2(Instance instance, object issuer, Func<Session, bool> receivers, int? val) =>
|
||||
instance.EmitCustomResourceEventByIndex(issuer, receivers, 201, val);
|
||||
|
||||
/// <summary>
|
||||
/// Create new instance.
|
||||
/// </summary>
|
||||
@ -911,16 +904,14 @@ public class Instance
|
||||
modificationDates.Add(DateTime.MinValue);
|
||||
}
|
||||
|
||||
|
||||
// connect events
|
||||
if (!(resource is DistributedResource))
|
||||
{
|
||||
|
||||
Type t = ResourceProxy.GetBaseType(resource);
|
||||
|
||||
#if NETSTANDARD
|
||||
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
|
||||
#else
|
||||
var events = t.GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
#endif
|
||||
|
||||
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
var emitEventByIndexMethod = GetType().GetMethod("EmitResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
var emitCustomEventByIndexMethod = GetType().GetMethod("EmitCustomResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
@ -980,41 +971,10 @@ public class Instance
|
||||
|
||||
var proxyDelegate = dm.CreateDelegate(evt.EventInfo.EventHandlerType, this);
|
||||
|
||||
//CustomResourceEventHandler<object> proxyDelegate = (issuer, receivers, args) => EmitCustomResourceEvent(issuer, receivers, evt, args);
|
||||
evt.EventInfo.AddEventHandler(resource, proxyDelegate);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
else if (evt.EventHandlerType == typeof(CustomUsersEventHanlder))
|
||||
{
|
||||
var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true);
|
||||
if (ca.Length == 0)
|
||||
continue;
|
||||
|
||||
CustomUsersEventHanlder proxyDelegate = (users, args) => EmitResourceEvent(evt.Name, users, null, args);
|
||||
evt.AddEventHandler(resource, proxyDelegate);
|
||||
}
|
||||
else if (evt.EventHandlerType == typeof(CustomConnectionsEventHanlder))
|
||||
{
|
||||
var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true);
|
||||
if (ca.Length == 0)
|
||||
continue;
|
||||
|
||||
CustomConnectionsEventHanlder proxyDelegate = (connections, args) => EmitResourceEvent(evt.Name, null, connections, args);
|
||||
evt.AddEventHandler(resource, proxyDelegate);
|
||||
}
|
||||
else if (evt.EventHandlerType == typeof(CustomReceiversEventHanlder))
|
||||
{
|
||||
var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true);
|
||||
if (ca.Length == 0)
|
||||
continue;
|
||||
|
||||
CustomReceiversEventHanlder proxyDelegate = (users, connections, args) => EmitResourceEvent(evt.Name, users, connections, args);
|
||||
evt.AddEventHandler(resource, proxyDelegate);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ using System.Text;
|
||||
namespace Esiur.Resource.Template;
|
||||
public enum TemplateType : byte
|
||||
{
|
||||
Unspecified,
|
||||
Resource,
|
||||
Record,
|
||||
Wrapper,
|
||||
Enum
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ public class TypeTemplate
|
||||
};
|
||||
|
||||
getDependenciesFunc(template, list);
|
||||
return list.ToArray();
|
||||
return list.Distinct().ToArray();
|
||||
}
|
||||
|
||||
|
||||
@ -394,12 +394,12 @@ public class TypeTemplate
|
||||
|
||||
}
|
||||
|
||||
public bool IsWrapper { get; private set; }
|
||||
|
||||
public TypeTemplate(Type type, bool addToWarehouse = false)
|
||||
{
|
||||
if (Codec.InheritsClass(type, typeof(DistributedResource)))
|
||||
templateType = TemplateType.Wrapper;
|
||||
else if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
|
||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
templateType = TemplateType.Resource;
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
templateType = TemplateType.Record;
|
||||
@ -408,6 +408,8 @@ public class TypeTemplate
|
||||
else
|
||||
throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource.");
|
||||
|
||||
IsWrapper = Codec.InheritsClass(type, typeof(DistributedResource));
|
||||
|
||||
//if (isRecord && isResource)
|
||||
// throw new Exception("Type can't have both IResource and IRecord interfaces");
|
||||
|
||||
@ -457,8 +459,7 @@ public class TypeTemplate
|
||||
}
|
||||
}
|
||||
|
||||
if (templateType == TemplateType.Resource
|
||||
|| templateType == TemplateType.Wrapper)
|
||||
if (templateType == TemplateType.Resource)
|
||||
{
|
||||
if (hierarchy.ContainsKey(MemberTypes.Method))
|
||||
{
|
||||
|
@ -57,10 +57,10 @@ public static class Warehouse
|
||||
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> templates
|
||||
= new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>()
|
||||
{
|
||||
[TemplateType.Unspecified] = new KeyList<Guid, TypeTemplate>(),
|
||||
//[TemplateType.Unspecified] = new KeyList<Guid, TypeTemplate>(),
|
||||
[TemplateType.Resource] = new KeyList<Guid, TypeTemplate>(),
|
||||
[TemplateType.Record] = new KeyList<Guid, TypeTemplate>(),
|
||||
[TemplateType.Wrapper] = new KeyList<Guid, TypeTemplate>(),
|
||||
//[TemplateType.Wrapper] = new KeyList<Guid, TypeTemplate>(),
|
||||
[TemplateType.Enum] = new KeyList<Guid, TypeTemplate>(),
|
||||
};
|
||||
|
||||
@ -753,6 +753,9 @@ public static class Warehouse
|
||||
/// <param name="template">Resource template.</param>
|
||||
public static void PutTemplate(TypeTemplate template)
|
||||
{
|
||||
if (templates[template.Type].ContainsKey(template.ClassId))
|
||||
throw new Exception($"Template with same class Id already exists. {templates[template.Type][template.ClassId].ClassName} -> {template.ClassName}");
|
||||
|
||||
templates[template.Type][template.ClassId] = template;
|
||||
}
|
||||
|
||||
@ -765,10 +768,12 @@ public static class Warehouse
|
||||
public static TypeTemplate GetTemplateByType(Type type)
|
||||
{
|
||||
|
||||
TemplateType templateType = TemplateType.Unspecified;
|
||||
//TemplateType templateType = TemplateType.Unspecified;
|
||||
|
||||
if (Codec.InheritsClass(type, typeof(DistributedResource)))
|
||||
templateType = TemplateType.Wrapper;
|
||||
//if (Codec.InheritsClass(type, typeof(DistributedResource)))
|
||||
// templateType = TemplateType.Wrapper;
|
||||
|
||||
TemplateType templateType;
|
||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
templateType = TemplateType.Resource;
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
@ -801,32 +806,33 @@ public static class Warehouse
|
||||
/// </summary>
|
||||
/// <param name="classId">Class Id.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
public static TypeTemplate GetTemplateByClassId(Guid classId, TemplateType templateType = TemplateType.Unspecified)
|
||||
public static TypeTemplate GetTemplateByClassId(Guid classId, TemplateType? templateType = null)
|
||||
{
|
||||
if (templateType == TemplateType.Unspecified)
|
||||
if (templateType == null)
|
||||
{
|
||||
// look in resources
|
||||
// look into resources
|
||||
var template = templates[TemplateType.Resource][classId];
|
||||
if (template != null)
|
||||
return template;
|
||||
|
||||
// look in records
|
||||
// look into records
|
||||
template = templates[TemplateType.Record][classId];
|
||||
if (template != null)
|
||||
return template;
|
||||
|
||||
// look in enums
|
||||
// look into enums
|
||||
template = templates[TemplateType.Enum][classId];
|
||||
if (template != null)
|
||||
return template;
|
||||
//if (template != null)
|
||||
|
||||
|
||||
// look in wrappers
|
||||
template = templates[TemplateType.Wrapper][classId];
|
||||
return template;
|
||||
//// look in wrappers
|
||||
//template = templates[TemplateType.Wrapper][classId];
|
||||
//return template;
|
||||
}
|
||||
else
|
||||
return templates[templateType][classId];
|
||||
return templates[templateType.Value][classId];
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -834,27 +840,32 @@ public static class Warehouse
|
||||
/// </summary>
|
||||
/// <param name="className">Class name.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
public static TypeTemplate GetTemplateByClassName(string className, TemplateType templateType = TemplateType.Unspecified)
|
||||
public static TypeTemplate GetTemplateByClassName(string className, TemplateType? templateType = null)
|
||||
{
|
||||
if (templateType == TemplateType.Unspecified)
|
||||
if (templateType == null)
|
||||
{
|
||||
// look in resources
|
||||
// look into resources
|
||||
var template = templates[TemplateType.Resource].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
if (template != null)
|
||||
return template;
|
||||
|
||||
// look in records
|
||||
// look into records
|
||||
template = templates[TemplateType.Record].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
if (template != null)
|
||||
return template;
|
||||
|
||||
// look in wrappers
|
||||
template = templates[TemplateType.Wrapper].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
// look into enums
|
||||
template = templates[TemplateType.Enum].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
//if (template != null)
|
||||
return template;
|
||||
|
||||
//// look in wrappers
|
||||
//template = templates[TemplateType.Wrapper].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
//return template;
|
||||
}
|
||||
else
|
||||
{
|
||||
return templates[templateType].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
return templates[templateType.Value].Values.FirstOrDefault(x => x.ClassName == className);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ namespace Test
|
||||
var temp = await con.Call("temp");
|
||||
Console.WriteLine("Temp: " + temp.GetHashCode());
|
||||
|
||||
var template = await con.GetTemplateByClassName("Test.MyResource");
|
||||
//var template = await con.GetTemplateByClassName("Test.MyResource");
|
||||
|
||||
|
||||
TestObjectProps(local, remote);
|
||||
|
Loading…
x
Reference in New Issue
Block a user