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 FindDependency
<T
>(IDictionary dependencies
,
29 return FindDependency
<T
>(dependencies
, null, out match
);
32 public static bool FindDependency
<T
>(IDictionary dependencies
,
33 Predicate
<T
> test
, out T match
)
37 foreach (object dependency
in dependencies
.Values
)
41 T candidate
= (T
)dependency
;
43 if (test
== null || test(candidate
))
53 public static bool FindDependency
<T
>(ICollection
<T
> dependencies
,
56 return FindDependency
<T
>(dependencies
, null, out match
);
59 public static bool FindDependency
<T
>(ICollection
<T
> dependencies
,
60 Predicate
<T
> test
, out T match
)
64 foreach (object dependency
in dependencies
)
68 T candidate
= (T
)dependency
;
70 if (test
== null || test(candidate
))
80 public static ICollection
<IHandler
> FindBehaviors
<T
>(IKernel kernel
, WcfBehaviorScope scope
)
82 List
<IHandler
> handlers
= new List
<IHandler
>();
83 foreach (IHandler handler
in kernel
.GetAssignableHandlers(typeof(T
)))
85 ComponentModel model
= handler
.ComponentModel
;
86 if (model
.Configuration
!= null)
88 string scopeAttrib
= model
.Configuration
.Attributes
[WcfConstants
.BehaviorScopeKey
];
89 if (string.IsNullOrEmpty(scopeAttrib
) ||
90 scopeAttrib
.Equals(scope
.ToString(), StringComparison
.InvariantCultureIgnoreCase
))
92 handlers
.Add(handler
);
99 public static bool IsCommunicationObjectReady(ICommunicationObject comm
)
103 case CommunicationState
.Closed
:
104 case CommunicationState
.Closing
:
105 case CommunicationState
.Faulted
:
111 public static void ReleaseCommunicationObject(ICommunicationObject comm
)
115 if (comm
.State
!= CommunicationState
.Faulted
)
121 catch (CommunicationException
)
125 catch (TimeoutException
)