AOP的两个应用:实体集更新(DateEntityListUpdate)、延迟加载(LazyLoad)(上)
2010-09-30 21:02:56 来源:WEB开发网EntityListUpdatableSink类
//*******************************************************************
// 模块:用于处理属性修改后的消息接收器
// 日期:2009-9-19 14:24:12
// 作者:Faib
// 版权:Copyright Faib Studio 2009
// 官网:http://www.faib.net.cn
// 邮箱:faib920@126.com
// 备注:
//*******************************************************************
using System;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
namespace FaibClass.Data.Aspect
{
/// <summary>
/// 用于处理属性修改后的消息接收器。
/// </summary>
internal class EntityListUpdatableSink : IMessageSink
{
private IMessageSink m_nextSink;
private MarshalByRefObject m_target;
private static object syncRoot = new object();
public EntityListUpdatableSink(MarshalByRefObject target, IMessageSink nextSink)
{
lock (syncRoot)
{
m_target = target;
m_nextSink = nextSink;
}
}
public IMessage SyncProcessMessage(IMessage msg)
{
IMethodReturnMessage returnedMessage;
HandleMessage(msg, false, out returnedMessage);
return returnedMessage;
}
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
{
IMethodReturnMessage returnedMessage;
HandleMessage(msg, true, out returnedMessage);
return m_nextSink.AsyncProcessMessage(msg, replySink);
}
public IMessageSink NextSink
{
get { return m_nextSink; }
}
private void HandleMessage(IMessage msg, bool IsAsync, out IMethodReturnMessage returnedMessage)
{
returnedMessage = null;
if (!IsAsync)
{
if (msg is IMethodCallMessage)
{
IMethodCallMessage mcm = (IMethodCallMessage)msg;
bool isFill = (bool)m_target.GetType().GetProperty("InnerIsFill", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(m_target, null);
bool isProperty = !isFill && ((mcm.MethodName.Length > 4 &&
mcm.MethodName.Substring(0, 4) == "set_" && mcm.MethodName != "set_InnerIsFill" &&
mcm.MethodName != "set_InnerDataState" &&
mcm.MethodName != "set_InnerData") || mcm.MethodName == "FieldSetter");
object oldvalue = null, newvalue = null;
MemberInfo minfo = null;
string propertyName = string.Empty;
//取原来的值
if (isProperty)
{
if (mcm.MethodName == "FieldSetter")
propertyName = mcm.InArgs[1].ToString();
else
propertyName = mcm.MethodName.Replace("set_", "");
minfo = Utility.GetMember(m_target.GetType(), propertyName);
if (minfo == null)
isProperty = false;
else if (minfo.IsDefined(typeof(DataColumnAttribute), true))
oldvalue = Utility.GetMemberValue(m_target, minfo, propertyName);
}
returnedMessage = (IMethodReturnMessage)m_nextSink.SyncProcessMessage(msg);
if (isProperty)
{
//新的值
newvalue = Utility.GetMemberValue(m_target, minfo, propertyName);
if (!newvalue.Equals(oldvalue))
{
//调用内部方法添加修改了的列
m_target.GetType().InvokeMember("AddUpdateColumn", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, m_target, new object[] { mcm.MethodName.Replace("set_", "") });
}
}
}
else
{
returnedMessage = (IMethodReturnMessage)m_nextSink.SyncProcessMessage(msg);
}
}
else
{
returnedMessage = null;
}
}
}
}
- ››应用云平台的可用性——从新浪SAE看云平台设计
- ››应用程序的配置管理Poco
- ››AOP的两个应用:实体集更新(DateEntityListUpdate...
- ››AOP的两个应用:实体集更新(DateEntityListUpdate...
- ››应用WebSphere MQ V6 来构建企业信息总线的行业示...
- ››应用 Python 解决一些实际问题
- ››应用JScript和XML自定义无刷新多级联动菜单
- ››应用:C/C++获取本机IP地址
- ››应用程序开发者偏好苹果也关注Android
- ››AOP 的利器:ASM 3.0 介绍
- ››应用软件视频会议中的几个常见问题
- ››应用 RSA 实现 EMF 的开发
更多精彩
赞助商链接