ContextAttribute与ContextBoundObject应用开发
来源:互联网 发布:Python help 编辑:程序博客网 时间:2024/06/06 09:22
这两天因开发的需要,需要分析和构建针对ContextAttribute极其ContextBoundContext相关的拦截器的内容,所以今天一上班就开发分析ContextAttribute与ContextBoundContext之间的应用关系,在查看了相关网友的资源后开始了我的分析之路。
首先:我建立了一个ContextAttribute的子类和一个普通的Attribute子类,分别附加在ContextBoundContext子类和普通子类上。代码如下:
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;
namespace ContextDemo
{
public class DemoContextAttribute : ContextAttribute
{
public DemoContextAttribute()
: base("DemoContextAttribute")
{
Console.WriteLine("Call 'DemoContextAttribute' - 'Constructor' ");
}
}
public class NonContextAttribute : Attribute
{
public NonContextAttribute()
{
Console.WriteLine("Call 'NonContextAttribute' - 'Constructor' ");
}
}
[DemoContext]
[NonContext]
public class DemoContextBoundObject : ContextBoundObject
{
public DemoContextBoundObject()
{
Console.WriteLine("Call 'DemoContextBoundObject' - 'Constructor' ");
}
}
[DemoContext]
[NonContext]
public class NonContextBoundObject
{
public NonContextBoundObject()
{
Console.WriteLine("Call 'NonContextBoundObject' - 'Constructor' ");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Begin Main ");
DemoContextBoundObject dcbo = new DemoContextBoundObject();
NonContextBoundObject ncbo = new NonContextBoundObject();
Console.WriteLine("End Main ");
Console.Read();
}
}
}
执行的结果如下:
这里可以看出,只有继承于ContextAttribute的子类在ContextBoundObject上使用才会进行构造。其实都没有进行调用。
然后:我将ContextAttribute之下的虚方法都进行了一次继承并且添加相应的查看信息来分析各个方法的调用顺序,代码如下:
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;
namespace ContextDemo {
public class DemoContextAttribute : ContextAttribute {
public DemoContextAttribute()
: base("DemoContextAttribute") {
Console.WriteLine("Call 'DemoContextAttribute' - 'Constructor' ");
}
public override void Freeze(Context newContext) {
Console.WriteLine("Call 'DemoContextAttribute' - 'Freeze' ");
}
public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg) {
Console.WriteLine("Call 'DemoContextAttribute' - 'GetPropertiesForNewContext' ");
base.GetPropertiesForNewContext(ctorMsg);
}
public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) {
Console.WriteLine("Call 'DemoContextAttribute' - 'IsContextOK' ");
return false;
}
public override bool IsNewContextOK(Context newCtx) {
Console.WriteLine("Call 'DemoContextAttribute' - 'IsNewContextOK' ");
return base.IsNewContextOK(newCtx);
}
}
[DemoContext]
public class DemoContextBoundObject : ContextBoundObject {
public DemoContextBoundObject() {
Console.WriteLine("Call 'DemoContextBoundObject' - 'Constructor' ");
}
}
class Program {
static void Main(string[] args) {
Console.WriteLine("Begin Main ");
new DemoContextBoundObject();
Console.WriteLine("End Main ");
Console.Read();
}
}
}
执行的结果显示如下:
这里可能以看出在执行的过程中,先建立与ContextBoundObject相关的ContextAttribute对象。并且向ContextAttribute对象询间IsContextOK,环境怎么样还可以吗。这里我先从这个IsContextOK开始进行分析。
这里通过修改代码查看运行的结果发现IsContextOk返回的结果为False,表示对当前环境有点不满意啊,将这里的IsContextOK直接返回True会是什么情况呢。修改代码执行显示结果如下:
Console.WriteLine("Call 'DemoContextAttribute' - 'IsContextOK' ");
return true;
}
看来这个方式就是用来确认当前环境是否满足要求的,如果满足则不执行。这里可以查看一下这一部分的过程:
CRL先询问当前环境是否满足要求,如果满足则不继续执行,如果不满足则先初始化新环境的GetPropertiesForNewContext,再将其Freeze,再询问IsNewContextOK如果没有问题则成功,如果在这里返回false,将引发一个Remoting的异常。
- ContextAttribute与ContextBoundObject应用开发
- C# 多线程Synchronization和ContextBoundObject应用
- ContextBoundObject:MethodWatcher
- hadoop应用与开发
- DM642开发与应用
- Sql开发与应用
- ContextBoundObject:代码暗处有玄机
- ContextBoundObject 上下文对象的用法
- Flash 组件应用与开发
- STRUTS的开发与应用
- DB2数据库开发与应用:
- HLA的开发与应用
- Ajax与企业级应用开发
- C语言程序设计与应用开发
- 开发与应用之我见
- Ajax与企业级应用开发
- ArcGIS应用与开发资料
- 数据库设计与应用开发
- 图像编码杂谈(1)----什么是windows图像
- 软件项目开发典型风险一览-过程篇
- 使命召唤5安装完毕,程序正常运行,但却无法玩
- Button基础
- 启动UClinux后的一些打印信息
- ContextAttribute与ContextBoundObject应用开发
- Crinkler 05.09.09: Version 1.2 released
- __init的含义
- 关闭Socket
- 整吗
- 类与类之间的关系
- 继承CStatic 平面坐标形式显示数据序列
- java 中回调函数
- 偷偷老去的80后的我们