1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.;
15 namespace Castle
.Facilities
.WcfIntegration
.Internal
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
20 using System
.ServiceModel
;
22 using Castle
.MicroKernel
;
24 internal static class WcfUtils
26 public static bool IsHosted(IWcfServiceModel serviceModel
)
28 return serviceModel
.IsHosted
;
31 public static IEnumerable
<T
> FindDependencies
<T
>(IDictionary dependencies
)
33 return FindDependencies
<T
>(dependencies
, null);
36 public static IEnumerable
<T
> FindDependencies
<T
>(IDictionary dependencies
,
39 foreach (object dependency
in dependencies
.Values
)
43 T candidate
= (T
)dependency
;
45 if (test
== null || test(candidate
))
47 yield return candidate
;
53 public static IEnumerable
<T
> FindDependencies
<T
>(ICollection
<T
> dependencies
)
55 return FindDependencies
<T
>(dependencies
, null);
58 public static IEnumerable
<T
> FindDependencies
<T
>(ICollection
<T
> dependencies
,
61 foreach (object dependency
in dependencies
)
65 T candidate
= (T
)dependency
;
67 if (test
== null || test(candidate
))
69 yield return candidate
;
75 public static ICollection
<IHandler
> FindBehaviors
<T
>(IKernel kernel
, WcfBehaviorScope scope
)
77 List
<IHandler
> handlers
= new List
<IHandler
>();
78 foreach (IHandler handler
in kernel
.GetAssignableHandlers(typeof(T
)))
80 ComponentModel model
= handler
.ComponentModel
;
81 if (model
.Configuration
!= null)
83 string scopeAttrib
= model
.Configuration
.Attributes
[WcfConstants
.BehaviorScopeKey
];
84 if (string.IsNullOrEmpty(scopeAttrib
) ||
85 scopeAttrib
.Equals(scope
.ToString(), StringComparison
.InvariantCultureIgnoreCase
))
87 handlers
.Add(handler
);
94 public static bool IsCommunicationObjectReady(ICommunicationObject comm
)
98 case CommunicationState
.Closed
:
99 case CommunicationState
.Closing
:
100 case CommunicationState
.Faulted
:
106 public static void ReleaseCommunicationObject(ICommunicationObject comm
)
110 if (comm
.State
!= CommunicationState
.Faulted
)
116 catch (CommunicationException
)
120 catch (TimeoutException
)