mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-03-31 10:28:21 +00:00
No templates anymore
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
using Esiur.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)]
|
||||
public class ClassIdAttribute : Attribute
|
||||
{
|
||||
public UUID ClassId { get; private set; }
|
||||
|
||||
public ClassIdAttribute(string classId)
|
||||
{
|
||||
var data = DC.FromHex(classId, null);
|
||||
ClassId = new UUID(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,18 @@ namespace Esiur.Resource;
|
||||
|
||||
public class CustomEventOccurredInfo
|
||||
{
|
||||
public readonly EventDef EventTemplate;
|
||||
public readonly EventDef EventDef;
|
||||
public readonly IResource Resource;
|
||||
public readonly object Value;
|
||||
public readonly object Issuer;
|
||||
public readonly Func<Session, bool> Receivers;
|
||||
|
||||
public string Name => EventTemplate.Name;
|
||||
public string Name => EventDef.Name;
|
||||
|
||||
public CustomEventOccurredInfo(IResource resource, EventDef eventTemplate, Func<Session, bool> receivers, object issuer, object value)
|
||||
public CustomEventOccurredInfo(IResource resource, EventDef eventDef, Func<Session, bool> receivers, object issuer, object value)
|
||||
{
|
||||
Resource = resource;
|
||||
EventTemplate = eventTemplate;
|
||||
EventDef = eventDef;
|
||||
Receivers = receivers;
|
||||
Issuer = issuer;
|
||||
Value = value;
|
||||
|
||||
@@ -70,8 +70,8 @@ public interface IStore : IResource
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecord(IResource resource, string propertyName, ulong fromAge, ulong toAge);
|
||||
//AsyncReply<PropertyValue[]> GetPropertyRecordByDate(IResource resource, string propertyName, DateTime fromDate, DateTime toDate);
|
||||
|
||||
//AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge);
|
||||
// AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
//AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge);
|
||||
// AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
|
||||
//AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ namespace Esiur.Resource;
|
||||
public struct PropertyModificationInfo
|
||||
{
|
||||
public readonly IResource Resource;
|
||||
public readonly PropertyDef PropertyTemplate;
|
||||
public string Name => PropertyTemplate.Name;
|
||||
public readonly PropertyDef PropertyDef;
|
||||
public string Name => PropertyDef.Name;
|
||||
public readonly ulong Age;
|
||||
public object Value;
|
||||
|
||||
public PropertyModificationInfo(IResource resource, PropertyDef propertyTemplate, object value, ulong age)
|
||||
public PropertyModificationInfo(IResource resource, PropertyDef propertyDef, object value, ulong age)
|
||||
{
|
||||
Resource = resource;
|
||||
PropertyTemplate = propertyTemplate;
|
||||
PropertyDef = propertyDef;
|
||||
Age = age;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
19
Esiur/Resource/TypeIdAttribute.cs
Normal file
19
Esiur/Resource/TypeIdAttribute.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Esiur.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)]
|
||||
public class TypeIdAttribute : Attribute
|
||||
{
|
||||
public UUID Id { get; private set; }
|
||||
|
||||
public TypeIdAttribute(string id)
|
||||
{
|
||||
var data = DC.FromHex(id, null);
|
||||
Id = new UUID(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,12 +515,12 @@ public class Warehouse
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a TypeDef by type from the typeDefs warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse.
|
||||
/// </summary>
|
||||
/// <param name="type">.Net type.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
public TypeDef GetTypeDefByType(Type type)
|
||||
/// <summary>
|
||||
/// Get a TypeDef by type from the warehouse. If not in the warehouse, a new TypeDef is created and added to the warehouse.
|
||||
/// </summary>
|
||||
/// <param name="type">.Net type.</param>
|
||||
/// <returns>Resource TypeDef.</returns>
|
||||
public TypeDef GetTypeDefByType(Type type)
|
||||
{
|
||||
if (!(type.IsClass || type.IsEnum))
|
||||
return null;
|
||||
@@ -531,61 +531,61 @@ public class Warehouse
|
||||
|| baseType == typeof(IRecord))
|
||||
return null;
|
||||
|
||||
TypeDefKind schemaKind;
|
||||
TypeDefKind typeDefKind;
|
||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
schemaKind = TypeDefKind.Resource;
|
||||
typeDefKind = TypeDefKind.Resource;
|
||||
else if (Codec.ImplementsInterface(type, typeof(IRecord)))
|
||||
schemaKind = TypeDefKind.Record;
|
||||
typeDefKind = TypeDefKind.Record;
|
||||
else if (type.IsEnum)
|
||||
schemaKind = TypeDefKind.Enum;
|
||||
typeDefKind = TypeDefKind.Enum;
|
||||
else
|
||||
return null;
|
||||
|
||||
var schema = typeDefs[schemaKind].Values.FirstOrDefault(x => x.DefinedType == baseType);
|
||||
if (schema != null)
|
||||
return schema;
|
||||
var typeDef = typeDefs[typeDefKind].Values.FirstOrDefault(x => x.DefinedType == baseType);
|
||||
if (typeDef != null)
|
||||
return typeDef;
|
||||
|
||||
// create new template for type
|
||||
schema = new TypeDef(baseType, this);
|
||||
TypeDef.GetDependencies(schema, this);
|
||||
// create new TypeDef for type
|
||||
typeDef = new TypeDef(baseType, this);
|
||||
TypeDef.GetDependencies(typeDef, this);
|
||||
|
||||
return schema;
|
||||
return typeDef;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a schema by class Id from the templates warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse.
|
||||
/// Get a TypeDef by TypeId from the warehouse. If not in the warehouse, a new TypeDef is created and added to the warehouse.
|
||||
/// </summary>
|
||||
/// <param name="classId">Class Id.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
public TypeDef GetTypeDefById(UUID typeId, TypeDefKind? templateType = null)
|
||||
/// <param name="typeId">typeId.</param>
|
||||
/// <returns>TypeDef.</returns>
|
||||
public TypeDef GetTypeDefById(UUID typeId, TypeDefKind? typeDefKind = null)
|
||||
{
|
||||
if (templateType == null)
|
||||
if (typeDefKind == null)
|
||||
{
|
||||
// look into resources
|
||||
var template = typeDefs[TypeDefKind.Resource][typeId];
|
||||
if (template != null)
|
||||
return template;
|
||||
var typeDef = typeDefs[TypeDefKind.Resource][typeId];
|
||||
if (typeDef != null)
|
||||
return typeDef;
|
||||
|
||||
// look into records
|
||||
template = typeDefs[TypeDefKind.Record][typeId];
|
||||
if (template != null)
|
||||
return template;
|
||||
typeDef = typeDefs[TypeDefKind.Record][typeId];
|
||||
if (typeDef != null)
|
||||
return typeDef;
|
||||
|
||||
// look into enums
|
||||
template = typeDefs[TypeDefKind.Enum][typeId];
|
||||
return template;
|
||||
typeDef = typeDefs[TypeDefKind.Enum][typeId];
|
||||
return typeDef;
|
||||
|
||||
}
|
||||
else
|
||||
return typeDefs[templateType.Value][typeId];
|
||||
return typeDefs[typeDefKind.Value][typeId];
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a template by class name from the templates warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse.
|
||||
/// Get a TypeDef by type name . If not in the warehouse, a new TypeDef is created and added to the warehouse.
|
||||
/// </summary>
|
||||
/// <param name="className">Class name.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
/// <param name="typeName">Class full name.</param>
|
||||
/// <returns>TypeDef.</returns>
|
||||
public TypeDef GetTypeDefByName(string typeName, TypeDefKind? typeDefKind = null)
|
||||
{
|
||||
if (typeDefKind == null)
|
||||
|
||||
Reference in New Issue
Block a user