init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
138
Framework/Entities/EntityHandler.cs
Normal file
138
Framework/Entities/EntityHandler.cs
Normal file
|
@ -0,0 +1,138 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace Kreta.Framework.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Az <see cref="IEntityHandler"/> megvalósítások ősosztálya.
|
||||
/// </summary>
|
||||
public class EntityHandler : IEntityHandler
|
||||
{
|
||||
private static Hashtable m_Handlers = new Hashtable();
|
||||
|
||||
/// <summary>
|
||||
/// Létre van-e hozva az entitáshoz EntityHandler
|
||||
/// </summary>
|
||||
public bool IsCreated { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Létrehoz egy <see cref="IEntityHandler"/> objektumot a
|
||||
/// megadott entitáshoz.
|
||||
/// </summary>
|
||||
/// <param name="entityName">Az entitás neve</param>
|
||||
/// <returns>Az entitáshoz tartozó <see cref="IEntityHandler"/> objektum</returns>
|
||||
public static IEntityHandler Create(Type entityType)
|
||||
{
|
||||
// <<Factory Method>>
|
||||
Type handlertype = null;
|
||||
|
||||
while (handlertype == null && entityType != typeof(Entity))
|
||||
{
|
||||
var entityName = EntityAttributeCache.GetEntityNameFromCache(entityType);
|
||||
if (string.IsNullOrWhiteSpace(entityName))
|
||||
{
|
||||
throw new ArgumentNullException("entityName");
|
||||
}
|
||||
|
||||
handlertype = m_Handlers[entityName.ToLower()] as Type;
|
||||
|
||||
entityType = entityType.BaseType;
|
||||
}
|
||||
|
||||
bool isCreated = true;
|
||||
if (handlertype == null)
|
||||
{
|
||||
isCreated = false;
|
||||
handlertype = typeof(EntityHandler);
|
||||
}
|
||||
|
||||
var entityHandler = (IEntityHandler)Activator.CreateInstance(handlertype, true);
|
||||
entityHandler.IsCreated = isCreated; // van-e lefejlesztve hozzá EntityHandler
|
||||
|
||||
return entityHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inicializálja az entitás esemény kezelőket.
|
||||
/// </summary>
|
||||
internal static void Init()
|
||||
{
|
||||
Hashtable handlers = new Hashtable();
|
||||
var handlertypes = from assembly in AppDomain.CurrentDomain.GetAssemblies()
|
||||
where SDAServer.Instance.IsAssemblyAllowed(assembly)
|
||||
from type in assembly.GetTypes()
|
||||
where (type.IsDefined(typeof(EntityHandlerAttribute), false)) && (typeof(IEntityHandler).IsAssignableFrom(type))
|
||||
select type;
|
||||
|
||||
foreach (var handlertype in handlertypes)
|
||||
{
|
||||
foreach (EntityHandlerAttribute attribute in handlertype.GetCustomAttributes(typeof(EntityHandlerAttribute), false))
|
||||
{
|
||||
string name = attribute.EntityName.ToLower();
|
||||
if (!handlers.ContainsKey(name))
|
||||
{
|
||||
handlers[name] = handlertype;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Kreta.Framework.DataIntegrityException("Egy entitáshoz több Handler-t találtam: " + attribute.EntityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_Handlers = handlers;
|
||||
}
|
||||
|
||||
#region IEntityHandler
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás insert művelete előtt fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void BeforeInsert(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás insert művelete után fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void AfterInsert(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás update művelete előtt fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void BeforeUpdate(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás update művelete után fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void AfterUpdate(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás delete művelete előtt fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void BeforeDelete(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az entitás delete művelete után fut le. Ha a leszármazott nem írja felül, akkor nem csinál semmit.
|
||||
/// </summary>
|
||||
/// <param name="entity">Az entitás</param>
|
||||
public virtual void AfterDelete(Entity entity)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue