|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
using Technewlogic.ObjectLounge.Framework.Transactions;
using Technewlogic.ObjectLounge.Framework.MetaModel;
using Technewlogic.ObjectLounge.Framework.BaseConcerns;
using Technewlogic.ObjectLounge.Framework.Validation;
namespace Technewlogic.ObjectLounge.Framework.Proxy
{
public partial class ProxyGenerator
{
public ProxyGenerator(
ModelSpec modelSpec,
TransactionManager transactionManager)
{
_modelSpec = modelSpec;
_transactionManager = transactionManager;
DynamicProxyAssembly = GenerateAssembly();
foreach (var it in _modelSpec.EntitySpecs.Values)
{
Type proxyType = DynamicProxyAssembly.GetTypes()
.Single(it2 => it2.BaseType == it.ClassType);
it.UpdateTriggerPropertyNames = proxyType
.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(it2 => it2.PropertyType != typeof(EntitySync))
.Where(it2 => !it2.PropertyType.IsSubclassOf(typeof(EntitySync)))
.Select(it2 => it2.Name)
.ToArray();
}
}
private readonly ModelSpec _modelSpec;
private readonly TransactionManager _transactionManager;
public Assembly DynamicProxyAssembly { get; private set; }
public T CreateProxy<T>(
SynchronizationOperation initialSynchronizationOperation)
where T : class, new()
{
return (T)CreateProxy(typeof(T), initialSynchronizationOperation);
}
public IProxy CreateProxy(
Type type,
//EntityCollection entityCollection,
SynchronizationOperation initialSynchronizationOperation)
{
// TODO: Assert, dass die Typen gleich sind von type und origi.
Type proxyType = DynamicProxyAssembly.GetTypes()
.FirstOrDefault(it => it.BaseType == type);
// Zwar dürfte das nicht passieren, wenn der generator von dem ObjectLounge-Framework aus bedient wird. Wird er aber einzeln benutzt, so muss das hier abgefangen werden.
if (proxyType == null)
throw Error.EntityTypeNotRegistered(type);
var transactionDispatcher = new TransactionDispatcher(
_modelSpec,
initialSynchronizationOperation,
_transactionManager,
type);
// TODO: Abfangen, wenn kein parameterloser ctor vorhanden ist
var proxy = (IProxy)Activator.CreateInstance(
proxyType,
new object[] { transactionDispatcher });
transactionDispatcher.Parent = proxy;
return proxy;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.