5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System
.Collections
.Generic
;
30 using System
.ServiceModel
.Channels
;
31 using System
.ServiceModel
.Dispatcher
;
33 namespace System
.ServiceModel
36 public sealed class InstanceContext
: CommunicationObject
,
37 IExtensibleObject
<InstanceContext
>
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
)
58 public InstanceContext (ServiceHostBase host
,
59 object implementation
) : this(host
, implementation
, true)
62 internal InstanceContext(ServiceHostBase host
,
63 object implementation
, bool userContextProvider
)
66 this.implementation
= implementation
;
67 is_user_context_provider
= userContextProvider
;
70 internal bool IsUserProvidedInstance
{
72 return is_user_instance_provider
;
76 internal bool IsUserProvidedContext
{
78 return is_user_context_provider
;
82 internal InstanceBehavior Behavior
{
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
{
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);
144 if (State
!= CommunicationState
.Closed
)
150 static void NotifyIdle (InstanceContext ctx
) {
154 internal InstanceContextIdleCallback IdleCallback
{
156 return idle_callback
;
160 public void ReleaseServiceInstance ()
162 Behavior
.ReleaseServiceInstance (this, implementation
);
163 implementation
= null;
166 protected override void OnAbort ()
171 protected override void OnFaulted ()
177 protected override void OnClosed ()
183 protected override void OnOpened ()
188 protected override void 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
)