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
.ManagedExtensions
20 using Castle
.Core
.Configuration
;
22 using Castle
.MicroKernel
;
24 using Castle
.ManagementExtensions
;
25 using Castle
.ManagementExtensions
.Remote
.Server
;
27 using Castle
.Facilities
.ManagedExtensions
.Server
;
30 /// Summary description for ManagementExtensionsServerFacility.
32 public class ManagementExtensionsServerFacility
: IFacility
34 private IKernel _kernel
;
35 private MServer _mserver
;
36 private MConnectorServer _serverConn
;
38 public ManagementExtensionsServerFacility()
42 public MServer MServer
44 get { return _mserver; }
47 public void Init(IKernel kernel
, IConfiguration config
)
51 _mserver
= MServerFactory
.CreateServer( "castle.domain", false );
54 MConnectorServerFactory
.CreateServer(
55 "provider:http:binary:test.rem", null, _mserver
);
57 _kernel
.ComponentModelBuilder
.AddContributor(
58 new ManagementExtensionModelServerInspector() );
60 _kernel
.ComponentCreated
+= new ComponentInstanceDelegate(OnComponentCreated
);
61 _kernel
.ComponentDestroyed
+= new ComponentInstanceDelegate(OnComponentDestroyed
);
64 public void Terminate()
66 _serverConn
.Dispose();
69 private void OnComponentCreated(ComponentModel model
, object instance
)
71 if (model
.ExtendedProperties
.Contains( ManagementConstants
.ComponentIsNaturalManageable
))
73 _mserver
.RegisterManagedObject( instance
, new ManagedObjectName( model
.Name
) );
75 else if (model
.ExtendedProperties
.Contains( ManagementConstants
.ComponentIsNonNaturalManageable
))
77 DefaultMDynamicSupport
dynamic =
78 new DefaultMDynamicSupport(
80 model
.Configuration
.Children
["management"]);
82 _mserver
.RegisterManagedObject( dynamic, new ManagedObjectName( model
.Name
) );
86 private void OnComponentDestroyed(ComponentModel model
, object instance
)
88 if (model
.ExtendedProperties
.Contains( ManagementConstants
.ComponentIsNaturalManageable
)
89 || model
.ExtendedProperties
.Contains( ManagementConstants
.ComponentIsNonNaturalManageable
))
91 _mserver
.UnregisterManagedObject( new ManagedObjectName( model
.Name
) );