2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.ServiceModel / System.ServiceModel / InstanceContext.cs
blob92eae066cdf6088d13ce97f21ba6ecc896f57a5e
1 //
2 // InstanceContext.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Collections.Generic;
30 using System.ServiceModel.Channels;
31 using System.ServiceModel.Dispatcher;
33 namespace System.ServiceModel
35 [MonoTODO]
36 public sealed class InstanceContext : CommunicationObject,
37 IExtensibleObject<InstanceContext>
39 ServiceHostBase host;
40 object implementation;
41 int manual_flow_limit;
42 InstanceBehavior _behavior;
43 bool is_user_instance_provider;
44 bool is_user_context_provider;
46 static InstanceContextIdleCallback idle_callback = new InstanceContextIdleCallback(NotifyIdle);
48 public InstanceContext (object implementation)
49 : this (null, implementation)
53 public InstanceContext (ServiceHostBase host)
54 : this (host, null)
58 public InstanceContext (ServiceHostBase host,
59 object implementation) : this(host, implementation, true)
62 internal InstanceContext(ServiceHostBase host,
63 object implementation, bool userContextProvider)
65 this.host = host;
66 this.implementation = implementation;
67 is_user_context_provider = userContextProvider;
70 internal bool IsUserProvidedInstance {
71 get {
72 return is_user_instance_provider;
76 internal bool IsUserProvidedContext {
77 get {
78 return is_user_context_provider;
82 internal InstanceBehavior Behavior {
83 get {
84 return _behavior;
86 set {
87 _behavior = value;
91 protected internal override TimeSpan DefaultCloseTimeout {
92 get { return host.DefaultCloseTimeout; }
95 protected internal override TimeSpan DefaultOpenTimeout {
96 get { return host.DefaultOpenTimeout; }
99 public IExtensionCollection<InstanceContext> Extensions {
100 get { throw new NotImplementedException (); }
103 public ServiceHostBase Host {
104 get { return host; }
107 public ICollection<IChannel> IncomingChannels {
108 get { throw new NotImplementedException (); }
111 public int ManualFlowControlLimit {
112 get { return manual_flow_limit; }
113 set { manual_flow_limit = value; }
116 public ICollection<IChannel> OutgoingChannels {
117 get { throw new NotImplementedException (); }
120 public object GetServiceInstance ()
122 return GetServiceInstance (null);
125 public object GetServiceInstance (Message message)
127 if (implementation == null && Behavior != null) {
128 implementation = Behavior.GetServiceInstance (this, message, ref is_user_instance_provider);
130 return implementation;
133 public int IncrementManualFlowControlLimit (int incrementBy)
135 throw new NotImplementedException ();
138 internal void CloseIfIdle () {
139 if (Behavior.InstanceContextProvider != null && !IsUserProvidedContext) {
140 if (!Behavior.InstanceContextProvider.IsIdle (this)) {
141 Behavior.InstanceContextProvider.NotifyIdle (IdleCallback, this);
143 else {
144 if (State != CommunicationState.Closed)
145 Close ();
150 static void NotifyIdle (InstanceContext ctx) {
151 ctx.CloseIfIdle ();
154 internal InstanceContextIdleCallback IdleCallback {
155 get {
156 return idle_callback;
160 public void ReleaseServiceInstance ()
162 Behavior.ReleaseServiceInstance (this, implementation);
163 implementation = null;
166 protected override void OnAbort ()
170 [MonoTODO]
171 protected override void OnFaulted ()
173 base.OnFaulted ();
176 [MonoTODO]
177 protected override void OnClosed ()
179 base.OnClosed ();
182 [MonoTODO]
183 protected override void OnOpened ()
185 base.OnOpened ();
188 protected override void OnOpening ()
190 base.OnOpening ();
191 if (Behavior != null)
192 Behavior.Initialize (this);
195 protected override IAsyncResult OnBeginOpen (
196 TimeSpan timeout, AsyncCallback callback, object state)
198 throw new NotImplementedException ();
201 protected override void OnEndOpen (IAsyncResult result)
205 protected override void OnOpen (TimeSpan timeout)
209 protected override IAsyncResult OnBeginClose (
210 TimeSpan timeout, AsyncCallback callback, object state)
212 throw new NotImplementedException ();
215 protected override void OnEndClose (IAsyncResult result)
219 protected override void OnClose (TimeSpan timeout)