Turn eval test into normal test case
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / MessageProcessingContext.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.ServiceModel;
5 using System.ServiceModel.Channels;
6
7 namespace System.ServiceModel.Dispatcher 
8 {
9         internal class MessageProcessingContext 
10         {
11                 OperationContext operation_context;
12                 RequestContext request_context;
13                 Message incoming_message;
14
15                 Message reply_message;          
16                 InstanceContext instance_context;               
17                 Exception processingException;
18                 DispatchOperation operation;
19                 UserEventsHandler user_events_handler;          
20
21                 public MessageProcessingContext (OperationContext opCtx)
22                 {
23                         operation_context = opCtx;
24                         request_context = opCtx.RequestContext;
25                         incoming_message = opCtx.IncomingMessage;
26                         user_events_handler = new UserEventsHandler (this);
27                 }
28
29                 public DispatchOperation Operation
30                 {
31                         get { return operation; }
32                         set { operation = value; }
33                 }
34
35                 public Exception ProcessingException
36                 {
37                         get { return processingException; }
38                         set { processingException = value; }
39                 }
40                 
41                 public Message ReplyMessage
42                 {
43                         get { return reply_message; }
44                         set { reply_message = value; }
45                 }
46
47                 public InstanceContext InstanceContext
48                 {
49                         get { return instance_context; }
50                         set { instance_context = value; }
51                 }
52
53                 public Message IncomingMessage
54                 {
55                         get { return incoming_message; }
56                         set { incoming_message = value; }
57                 }
58
59                 public RequestContext RequestContext
60                 {
61                         get { return request_context; }
62                         set { request_context = value; }
63                 }
64
65                 public OperationContext OperationContext
66                 {
67                         get { return operation_context; }
68                         set { operation_context = value; }
69                 }
70
71                 public UserEventsHandler EventsHandler
72                 {
73                         get { return user_events_handler; }
74                         set { user_events_handler = value; }
75                 }
76
77                 public void Reply (IDuplexChannel channel, bool useTimeout)
78                 {
79                         EventsHandler.BeforeSendReply ();
80                         if (useTimeout)
81                                 channel.Send (ReplyMessage, Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
82                         else
83                                 channel.Send (ReplyMessage);
84                 }
85
86                 public void Reply (bool useTimeout)
87                 {
88                         EventsHandler.BeforeSendReply ();
89                         if (useTimeout)
90                                 RequestContext.Reply (ReplyMessage, Operation.Parent.ChannelDispatcher.timeouts.SendTimeout);
91                         else
92                                 RequestContext.Reply (ReplyMessage);
93                 }
94         }
95
96         #region user events implementation
97
98         internal class UserEventsHandler
99         {
100                 MessageProcessingContext request_context;
101                 DispatchRuntime dispatch_runtime;
102                 IClientChannel channel;
103                 object [] msg_inspectors_states;
104                 object [] callcontext_initializers_states;
105
106                 public UserEventsHandler (MessageProcessingContext mrc)
107                 {
108                         request_context = mrc;
109                         dispatch_runtime = mrc.OperationContext.EndpointDispatcher.DispatchRuntime;
110                         msg_inspectors_states = new object [dispatch_runtime.MessageInspectors.Count];
111                         channel = request_context.OperationContext.Channel as IClientChannel;
112                 }
113
114                 public void AfterReceiveRequest ()
115                 {
116                         Message message = request_context.IncomingMessage;
117
118                         for (int i = 0; i < dispatch_runtime.MessageInspectors.Count; ++i)
119                                 msg_inspectors_states [i] = dispatch_runtime.MessageInspectors [i].AfterReceiveRequest (
120                                            ref message, channel, request_context.InstanceContext);
121                         request_context.IncomingMessage = message;
122
123                 }
124
125                 public void BeforeSendReply ()
126                 {
127                         Message toBeChanged = request_context.ReplyMessage;
128                         for (int i = 0; i < dispatch_runtime.MessageInspectors.Count; ++i)
129                                 dispatch_runtime.MessageInspectors [i].BeforeSendReply (ref toBeChanged, msg_inspectors_states [i]);
130                 }
131
132                 public void BeforeInvoke (DispatchOperation operation)
133                 {
134                         callcontext_initializers_states = new object [operation.CallContextInitializers.Count];
135                         for (int i = 0; i < callcontext_initializers_states.Length; ++i)
136                                 callcontext_initializers_states [i] = operation.CallContextInitializers [i].BeforeInvoke (
137                                         request_context.InstanceContext, channel, request_context.IncomingMessage);
138
139                 }
140
141                 public void AfterInvoke (DispatchOperation operation)
142                 {
143                         for (int i = 0; i < callcontext_initializers_states.Length; ++i)
144                                 operation.CallContextInitializers [i].AfterInvoke (callcontext_initializers_states [i]);
145                 }
146         }
147
148         #endregion
149 }