File: ContextHookAttribute.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (171 lines) | stat: -rw-r--r-- 4,615 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// MonoTests.Remoting.ContextHookAttribute.cs
//
// Author: Lluis Sanchez Gual (lluis@ximian.com)
//
// 2003 (C) Copyright, Ximian, Inc.
//

using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting;
using System.Threading;

namespace MonoTests.Remoting
{
	[Serializable,AttributeUsage(AttributeTargets.Class)]
	public class ContextHookAttribute: Attribute, IContextAttribute, IContextProperty, IContributeObjectSink, IContributeServerContextSink, IContributeEnvoySink, IContributeClientContextSink
	{
		bool newContext = false;

		string id = "";
		public ContextHookAttribute()
		{
		}

		public ContextHookAttribute(string idp, bool newContext)
		{
			id = idp;
			if (id != "") id += ".";
			id += "d" + CallSeq.CommonDomainId;
			this.newContext = newContext;
		}

		public override object TypeId
		{

			get { return "ContextHook"; }
		}

		bool IContextAttribute.IsContextOK(Context ctx, IConstructionCallMessage ctor)
		{
			CallSeq.Add("ContextHookAttribute(" + id + ").IsContextOK");
			return !newContext;
		}

		public bool IsNewContextOK(Context ctx)
		{
			CallSeq.Add("ContextHookAttribute(" + id + ").IsNewContextOK");
			return true;
		}

		public void Freeze(Context ctx)
		{
			CallSeq.Add("ContextHookAttribute(" + id + ").Freeze");
		}

		public String Name
		{
			get { return "ContextHook(" + id + ")"; }
		}
	

		void IContextAttribute.GetPropertiesForNewContext(IConstructionCallMessage ctor)
		{
			CallSeq.Add("IContextAttribute(" + id + ").GetPropertiesForNewContext");
			ctor.ContextProperties.Add(this);
		}	

		IMessageSink IContributeObjectSink.GetObjectSink(MarshalByRefObject o, IMessageSink next)
		{
			CallSeq.Add("IContributeObjectSink(" + id + ").GetObjectSink");
			return new GenericMessageSink(o,next,"ObjectSink(" + id + ")");
		}
		
		IMessageSink IContributeServerContextSink.GetServerContextSink(IMessageSink next)
		{
			CallSeq.Add("IContributeServerContextSink(" + id + ").GetServerContextSink");
			return new GenericMessageSink(null,next,"ServerContextSink(" + id + ")");
		}

		IMessageSink IContributeEnvoySink.GetEnvoySink(MarshalByRefObject obj, IMessageSink nextSink)
		{
			CallSeq.Add("IContributeEnvoySink(" + id + ").GetEnvoySink");
			return new GenericMessageSink(obj,nextSink,"EnvoySink(" + id + ")");
		}

		IMessageSink IContributeClientContextSink.GetClientContextSink (IMessageSink nextSink )
		{
			CallSeq.Add("IContributeClientContextSink(" + id + ").GetClientContextSink");
			return new GenericMessageSink(null,nextSink,"ClientContextSink(" + id + ")");
		}
	}

	[Serializable]
	class GenericMessageSink: IMessageSink
	{
		IMessageSink _next;
		string _type;

		public GenericMessageSink(MarshalByRefObject obj, IMessageSink nextSink, string type)
		{
			_type = type;
			_next = nextSink;
		}

		public IMessageSink NextSink 
		{	
			get { return _next; }
		}

		public IMessage SyncProcessMessage(IMessage imCall)
		{
			CallSeq.Add("--> " + _type + " SyncProcessMessage " + imCall.Properties["__MethodName"]);
			IMessage ret = _next.SyncProcessMessage(imCall);
			CallSeq.Add("<-- " + _type + " SyncProcessMessage " + imCall.Properties["__MethodName"]);
			return ret;
		}

		public IMessageCtrl AsyncProcessMessage(IMessage im, IMessageSink ims)
		{
			CallSeq.Add("--> " + _type + " AsyncProcessMessage " + im.Properties["__MethodName"]);
			IMessageCtrl ret = _next.AsyncProcessMessage(im, ims);
			CallSeq.Add("<-- " + _type + " AsyncProcessMessage " + im.Properties["__MethodName"]);
			return ret;
		}
	}

	[Serializable]
	class GenericDynamicSink: IDynamicMessageSink
	{
		string _name;
		
		public GenericDynamicSink (string name)
		{
			_name = name;
		}

		void IDynamicMessageSink.ProcessMessageFinish(IMessage replyMsg, bool bCliSide, bool bAsync)
		{
			CallSeq.Add("<-> " + _name + " DynamicSink Finish " + replyMsg.Properties["__MethodName"] + " client:" + bCliSide);
		}

		void IDynamicMessageSink.ProcessMessageStart(IMessage replyMsg, bool bCliSide, bool bAsync)
		{
			CallSeq.Add("<-> " + _name + " DynamicSink Start " + replyMsg.Properties["__MethodName"] + " client:" + bCliSide);
		}
	}

	public class DynProperty: IDynamicProperty, IContributeDynamicSink
	{
		string _name;
		public DynProperty (string name)
		{
			_name = name;
		}

		public string Name
		{
			get { return _name; }
		}

		public IDynamicMessageSink GetDynamicSink()
		{
			CallSeq.Add("IContributeDynamicSink(" + _name + ").GetDynamicSink");
			return new GenericDynamicSink(_name);
		}
	}
}