2 // MonoTests.Remoting.ContextHookAttribute.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Ximian, Inc.
10 using System
.Runtime
.Remoting
.Contexts
;
11 using System
.Runtime
.Remoting
.Activation
;
12 using System
.Runtime
.Remoting
.Messaging
;
13 using System
.Runtime
.Remoting
.Proxies
;
14 using System
.Runtime
.Remoting
;
15 using System
.Threading
;
17 namespace MonoTests
.Remoting
19 [Serializable
,AttributeUsage(AttributeTargets
.Class
)]
20 public class ContextHookAttribute
: Attribute
, IContextAttribute
, IContextProperty
, IContributeObjectSink
, IContributeServerContextSink
, IContributeEnvoySink
, IContributeClientContextSink
22 bool newContext
= false;
25 public ContextHookAttribute()
29 public ContextHookAttribute(string idp
, bool newContext
)
32 if (id
!= "") id
+= ".";
33 id
+= "d" + CallSeq
.CommonDomainId
;
34 this.newContext
= newContext
;
37 public override object TypeId
40 get { return "ContextHook"; }
43 bool IContextAttribute
.IsContextOK(Context ctx
, IConstructionCallMessage ctor
)
45 CallSeq
.Add("ContextHookAttribute(" + id
+ ").IsContextOK");
49 public bool IsNewContextOK(Context ctx
)
51 CallSeq
.Add("ContextHookAttribute(" + id
+ ").IsNewContextOK");
55 public void Freeze(Context ctx
)
57 CallSeq
.Add("ContextHookAttribute(" + id
+ ").Freeze");
62 get { return "ContextHook(" + id + ")"; }
66 void IContextAttribute
.GetPropertiesForNewContext(IConstructionCallMessage ctor
)
68 CallSeq
.Add("IContextAttribute(" + id
+ ").GetPropertiesForNewContext");
69 ctor
.ContextProperties
.Add(this);
72 IMessageSink IContributeObjectSink
.GetObjectSink(MarshalByRefObject o
, IMessageSink next
)
74 CallSeq
.Add("IContributeObjectSink(" + id
+ ").GetObjectSink");
75 return new GenericMessageSink(o
,next
,"ObjectSink(" + id
+ ")");
78 IMessageSink IContributeServerContextSink
.GetServerContextSink(IMessageSink next
)
80 CallSeq
.Add("IContributeServerContextSink(" + id
+ ").GetServerContextSink");
81 return new GenericMessageSink(null,next
,"ServerContextSink(" + id
+ ")");
84 IMessageSink IContributeEnvoySink
.GetEnvoySink(MarshalByRefObject obj
, IMessageSink nextSink
)
86 CallSeq
.Add("IContributeEnvoySink(" + id
+ ").GetEnvoySink");
87 return new GenericMessageSink(obj
,nextSink
,"EnvoySink(" + id
+ ")");
90 IMessageSink IContributeClientContextSink
.GetClientContextSink (IMessageSink nextSink
)
92 CallSeq
.Add("IContributeClientContextSink(" + id
+ ").GetClientContextSink");
93 return new GenericMessageSink(null,nextSink
,"ClientContextSink(" + id
+ ")");
98 class GenericMessageSink
: IMessageSink
103 public GenericMessageSink(MarshalByRefObject obj
, IMessageSink nextSink
, string type
)
109 public IMessageSink NextSink
111 get { return _next; }
114 public IMessage
SyncProcessMessage(IMessage imCall
)
116 CallSeq
.Add("--> " + _type
+ " SyncProcessMessage " + imCall
.Properties
["__MethodName"]);
117 IMessage ret
= _next
.SyncProcessMessage(imCall
);
118 CallSeq
.Add("<-- " + _type
+ " SyncProcessMessage " + imCall
.Properties
["__MethodName"]);
122 public IMessageCtrl
AsyncProcessMessage(IMessage im
, IMessageSink ims
)
124 CallSeq
.Add("--> " + _type
+ " AsyncProcessMessage " + im
.Properties
["__MethodName"]);
125 IMessageCtrl ret
= _next
.AsyncProcessMessage(im
, ims
);
126 CallSeq
.Add("<-- " + _type
+ " AsyncProcessMessage " + im
.Properties
["__MethodName"]);
132 class GenericDynamicSink
: IDynamicMessageSink
136 public GenericDynamicSink (string name
)
141 void IDynamicMessageSink
.ProcessMessageFinish(IMessage replyMsg
, bool bCliSide
, bool bAsync
)
143 CallSeq
.Add("<-> " + _name
+ " DynamicSink Finish " + replyMsg
.Properties
["__MethodName"] + " client:" + bCliSide
);
146 void IDynamicMessageSink
.ProcessMessageStart(IMessage replyMsg
, bool bCliSide
, bool bAsync
)
148 CallSeq
.Add("<-> " + _name
+ " DynamicSink Start " + replyMsg
.Properties
["__MethodName"] + " client:" + bCliSide
);
152 public class DynProperty
: IDynamicProperty
, IContributeDynamicSink
155 public DynProperty (string name
)
162 get { return _name; }
165 public IDynamicMessageSink
GetDynamicSink()
167 CallSeq
.Add("IContributeDynamicSink(" + _name
+ ").GetDynamicSink");
168 return new GenericDynamicSink(_name
);