Reads the configuration from a XmlFile. Sample structure: <configuration> <facilities> <facility id="myfacility"> </facility> </facilities> <components> <component id="component1"> </component> </components> </configuration>
Inheritance: AbstractInterpreter
        public Full_test_of_load_balancer_and_failover()
        {
            var interpreter = new XmlInterpreter(@"LoadBalancer\BusWithLoadBalancer.config");
            container = new WindsorContainer(interpreter);
            container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());

            container.Register(
                Component.For<MsmqLoadBalancer>()
                    .DependsOn(new
                    {
                        threadCount = 1,
                        endpoint = new Uri(loadBalancerQueue),
                        secondaryLoadBalancer = TestQueueUri2.Uri,
                   		transactional = TransactionalOptions.FigureItOut
                 }),
                Component.For<MsmqSecondaryLoadBalancer>()
                    .DependsOn(new
                    {
                        threadCount = 1,
                        endpoint = TestQueueUri2.Uri,
                        primaryLoadBalancer = new Uri(loadBalancerQueue),
                        transactional = TransactionalOptions.FigureItOut
                    })
                );
        }
		public void ProperDeserialization()
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter(new ConfigResource());
			interpreter.ProcessResource(interpreter.Source, store);

			Assert.AreEqual(2, store.GetFacilities().Length);
			Assert.AreEqual(3, store.GetComponents().Length);

			IConfiguration config = store.GetFacilityConfiguration("testidengine");
			IConfiguration childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value", childItem.Value);

			config = store.GetFacilityConfiguration("testidengine2");
			Assert.IsNotNull(config);
			Assert.AreEqual("value within CDATA section", config.Value);

			config = store.GetComponentConfiguration("testidcomponent1");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value1", childItem.Value);

			config = store.GetComponentConfiguration("testidcomponent2");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value2", childItem.Value);
		}
		public void ProperDeserialization()
		{
			var store = new DefaultConfigurationStore();
			var interpreter = new XmlInterpreter(new ConfigResource());
			IKernel kernel = new DefaultKernel();
			interpreter.ProcessResource(interpreter.Source, store, kernel);

			Assert.AreEqual(2, store.GetFacilities().Length);
			Assert.AreEqual(4, store.GetComponents().Length);

			var config = store.GetFacilityConfiguration(typeof(NoopFacility).FullName);
			var childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value", childItem.Value);

			config = store.GetFacilityConfiguration(typeof(Noop2Facility).FullName);
			Assert.IsNotNull(config);
			Assert.AreEqual("value within CDATA section", config.Value);

			config = store.GetComponentConfiguration("testidcomponent1");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value1", childItem.Value);

			config = store.GetComponentConfiguration("testidcomponent2");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value2", childItem.Value);
		}
示例#4
0
        public OGDotNetApp()
        {
            //Can't read default config directly if we're untrusted http://social.msdn.microsoft.com/Forums/en-US/clr/thread/1e14f665-10a3-426b-a75d-4e66354c5522
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            var section = config.Sections["castle"];
            var configXml = section.SectionInformation.GetRawXml();
            var resource = new StaticContentResource(configXml);
            var xmlInterpreter = new XmlInterpreter(resource);
            _container = new WindsorContainer(xmlInterpreter);

            FromAssembly.Containing<RemoteEngineContextFactory>().Install(_container, new DefaultConfigurationStore());

            _container.Register();

            //Give all of the windows the opportunity to pick up context
            var windowStyle = new Style(typeof(Window));

            windowStyle.Setters.Add(new Setter(OGContextProperty, new Binding("OGContext") { Source = this }));
            windowStyle.Setters.Add(new Setter(OGContextFactoryProperty, new Binding("OGContextFactory") { Source = this }));

            FrameworkElement.StyleProperty.OverrideMetadata(typeof(Window),
                new FrameworkPropertyMetadata { DefaultValue = windowStyle }
                );
            FreezeDetector.HookUp(Dispatcher, _container.Resolve<ILogger>());
        }
示例#5
0
		protected void Application_Start(Object sender, EventArgs e)
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter(new ConfigResource());
			interpreter.ProcessResource(interpreter.Source, store);

            _container = new WindsorContainer(interpreter);
        }
		public void SetUp()
		{
			var configurationStore = new DefaultConfigurationStore();
			var resource = new AssemblyResource("Castle.Facilities.NHibernateIntegration.Tests/Issues/Facilities117/facility.xml");
			var xmlInterpreter = new XmlInterpreter(resource);
			xmlInterpreter.ProcessResource(resource, configurationStore);
			facilityCfg = configurationStore.GetFacilityConfiguration("nhibernatefacility").Children["factory"];
		}
示例#7
0
文件: BaseTest.cs 项目: atczyc/castle
        public virtual void FixtureSetUp()
        {
            DefaultConfigurationStore store = new DefaultConfigurationStore();
            XmlInterpreter interpreter = new XmlInterpreter(new ConfigResource());
            interpreter.ProcessResource(interpreter.Source, store);

            container = new WindsorContainer(interpreter);
        }
示例#8
0
		public override void OnSetUp()
		{
			var configurationStore = new DefaultConfigurationStore();
			var resource = new AssemblyResource("Castle.Facilities.NHibernateIntegration.Tests/Issues/Facilities116/facility.xml");
			var xmlInterpreter = new XmlInterpreter(resource);
			xmlInterpreter.ProcessResource(resource, configurationStore);
			this.configuration = configurationStore.GetFacilityConfiguration("nhibernatefacility").Children["factory"];
			this.configurationBuilder = new PersistentConfigurationBuilder();
		}
示例#9
0
		public NetBpmContainer(XmlInterpreter interpreter) : base(interpreter)
		{
			Init();
			if (instance != null)
			{
				log.Warn("another NebBpm container is created");
			}
			instance = this;
		}
		public void CorrectConfigurationMapping()
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter(ConfigHelper.ResolveConfigPath("sample_config.xml"));
			interpreter.ProcessResource(interpreter.Source, store);

			WindsorContainer container = new WindsorContainer(store);

			container.AddFacility("testidengine", new DummyFacility());
		}
		public void Init()
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter( new ConfigResource() );
			interpreter.ProcessResource(interpreter.Source, store);
			_container = new PestControlContainer(interpreter);

			_model = (PestControlModel) _container["pestcontrolModel"];
			_engine = (PrevalenceEngine) _container["prevalenceengine"];
		}
		public void CorrectConfigurationMapping()
		{
			var store = new DefaultConfigurationStore();
			var interpreter = new XmlInterpreter(Xml.Embedded("sample_config.xml"));
			IKernel kernel = new DefaultKernel();
			interpreter.ProcessResource(interpreter.Source, store, kernel);

			var container = new WindsorContainer(store);
			var facility = container.Kernel.GetFacilities().OfType<HiperFacility>().Single();
			Assert.IsTrue(facility.Initialized);
		}
示例#13
0
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container.Register(
         Component.For<ISessionProvider>().
             ImplementedBy<SqlLiteSessionProvider>().
             DependsOn(new {dbFile = ConfigurationManager.AppSettings["DBFile"]}).LifeStyle.Singleton);
     //			container.Register(AllTypes.FromAssembly(typeof (BlogRepository).Assembly).
     //				                            Where(t => t.Namespace == "Core.Repositories" && t.IsClass).WithService.DefaultInterface().Configure(c=>c.LifeStyle.Transient));
     container.Register(Component.For<IDb>().ImplementedBy<Db>().LifeStyle.Transient);
     var xmlInterpreter = new XmlInterpreter();
     xmlInterpreter.ProcessResource(new ConfigResource("castle"),store);
 }
		public void ComponentIdGetsLoadedFromTheParsedConfiguration()
		{
			var store = new DefaultConfigurationStore();
			var interpreter = new XmlInterpreter(Xml.Embedded("sample_config_with_spaces.xml"));
			IKernel kernel = new DefaultKernel();
			interpreter.ProcessResource(interpreter.Source, store, kernel);

			var container = new WindsorContainer(store);

			var handler = container.Kernel.GetHandler(typeof(ICalcService));
			Assert.AreEqual(Core.LifestyleType.Transient, handler.ComponentModel.LifestyleType);
		}
 public static void RegisterXml(this IWindsorContainer container,XmlInterpreter interpreter)
 {
     
     if(null==container){
         return;
     }
     if(null==interpreter){
         return;
     }
     log.Info("start process xml");
     interpreter.ProcessResource(interpreter.Source, container.Kernel.ConfigurationStore);
     
     log.Info("end process xml");
 }
 public static void RegisterXml(this IWindsorContainer container)
 {
     log.Info("start load default xml");
     try{
         var i = new XmlInterpreter();
         container.RegisterXml(i);
     }
     catch (ConfigurationErrorsException ex)
     {
         log.Warn("some problems with configuration, in most cases - it was specified",ex);
         return;
     }
     
     log.Info("end load default xml");
 }
示例#17
0
        public With_fail_over()
        {
            var interpreter = new XmlInterpreter(@"LoadBalancer\BusWithLoadBalancer.config");
            container = new WindsorContainer(interpreter);
            container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());

            container.Register(
                Component.For<MsmqLoadBalancer>()
                    .DependsOn(new
                    {
                        threadCount = 1,
                        endpoint = new Uri(loadBalancerQueue),
                        secondaryLoadBalancer = TestQueueUri2.Uri
                    })
                );
        }
示例#18
0
		public void SetUp() 
		{
			 _container = null;
			 _homeController = null;
			 _state = null;

			// Config by file
//			_container = new WindsorContainer( new XmlInterpreter( new AppDomainConfigSource("castle")),
//				new XmlInterpreter( "test.config" )
//				);

			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter(new ConfigResource());
			interpreter.ProcessResource(interpreter.Source, store);

			_container = new WindsorContainer( interpreter );

			//-- Config by Code for test
//			_container = new WindsorContainer(new DefaultConfigurationStore());
//
//			MutableConfiguration confignode = new MutableConfiguration("facility");
//
//			IConfiguration assembyView = confignode.Children.Add(new MutableConfiguration("assembyView"));
//
//			_container.Kernel.ConfigurationStore.AddFacilityConfiguration("MVCFacility", confignode);
//			_container.AddFacility("MVCFacility", new MVCFacility());
//
//			_container.AddComponent( "state", typeof(IState),typeof(MyApplicationState));
//			_container.AddComponent( "navigator", typeof(INavigator), typeof(DefaultNavigator));
//			_container.AddComponent( "viewManager", typeof(IViewManager), typeof(MockViewManager));
//			_container.AddComponent( "statePersister", typeof(IStatePersister), typeof(MemoryStatePersister));
//
//			// controllers
//			_container.AddComponent( "HomeController", typeof(HomeController) );
//			_container.AddComponent( "AccountController", typeof(AccountController) );
//
//			// components
//			_container.AddComponent( "ServiceA", typeof(IServiceA), typeof(ServiceA));


			_homeController = _container["HomeController"] as HomeController;
			_state = _homeController.State as MyApplicationState;
		}
		public void ProperDeserialization()
		{
			var store = new DefaultConfigurationStore();

			var interpreter = new XmlInterpreter(Xml.Embedded("sample_config_complex.xml"));
			IKernel kernel = new DefaultKernel();
			interpreter.ProcessResource(interpreter.Source, store, kernel);

			Assert.AreEqual(2, store.GetFacilities().Length);
			Assert.AreEqual(2, store.GetComponents().Length);
			Assert.AreEqual(2, store.GetConfigurationForChildContainers().Length);

			var config = store.GetFacilityConfiguration(typeof(DummyFacility).FullName);
			var childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value", childItem.Value);

			config = store.GetFacilityConfiguration(typeof(HiperFacility).FullName);
			Assert.IsNotNull(config);
			Assert.AreEqual("value within CDATA section", config.Value);

			config = store.GetComponentConfiguration("testidcomponent1");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value1", childItem.Value);

			config = store.GetComponentConfiguration("testidcomponent2");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value2", childItem.Value);

			config = store.GetChildContainerConfiguration("child1");
			Assert.IsNotNull(config);
			Assert.AreEqual(config.Attributes["name"], "child1");
			Assert.AreEqual("<configuration />", config.Value);

			config = store.GetChildContainerConfiguration("child2");
			Assert.IsNotNull(config);
			Assert.AreEqual(config.Attributes["name"], "child2");
			Assert.AreEqual("<configuration />", config.Value);
		}
		public void UsingAttributes()
		{
			String xml = 
				"<configuration>" + 
				"	<facilities>" + 
				"		<facility id=\"batchregistration\">" + 
				"			<assemblyBatch name=\"Castle.Facilities.BatchRegistration.Tests\" useAttributes=\"true\" />" + 
				"		</facility>" + 
				"	</facilities>" + 
				"</configuration>";

			XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
			interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);

			_kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );

			Assert.IsTrue( _kernel.HasComponent("comp1") );
			Assert.IsTrue( _kernel.HasComponent("comp2") );
			Assert.IsTrue( _kernel.HasComponent( typeof(Component1) ) );
			Assert.IsTrue( _kernel.HasComponent( typeof(Component2) ) );
		}
		public void ProperDeserialization()
		{
			DefaultConfigurationStore store = new DefaultConfigurationStore();

			XmlInterpreter interpreter = new XmlInterpreter(ConfigHelper.ResolveConfigPath("sample_config.xml"));
			interpreter.ProcessResource(interpreter.Source, store);

			Assert.AreEqual(2, store.GetFacilities().Length);
			Assert.AreEqual(2, store.GetComponents().Length);
			Assert.AreEqual(2, store.GetConfigurationForChildContainers().Length);

			IConfiguration config = store.GetFacilityConfiguration("testidengine");
			IConfiguration childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value", childItem.Value);

			config = store.GetFacilityConfiguration("testidengine2");
			Assert.IsNotNull(config);
			Assert.AreEqual("value within CDATA section", config.Value);

			config = store.GetComponentConfiguration("testidcomponent1");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value1", childItem.Value);

			config = store.GetComponentConfiguration("testidcomponent2");
			childItem = config.Children["item"];
			Assert.IsNotNull(childItem);
			Assert.AreEqual("value2", childItem.Value);

			config = store.GetChildContainerConfiguration("child1");
			Assert.IsNotNull(config);
			Assert.AreEqual(config.Attributes["name"], "child1");
			Assert.AreEqual("<configuration />", config.Value);

			config = store.GetChildContainerConfiguration("child2");
			Assert.IsNotNull(config);
			Assert.AreEqual(config.Attributes["name"], "child2");
			Assert.AreEqual("<configuration />", config.Value);
		}
        protected void ProcessFolder(Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store, 
            Castle.MicroKernel.IKernel kernel,
            string path)
        {
            foreach (var extraConfig in Directory.GetFiles(path, "*.castle.config"))
            {
                try
                {
                    var interpreter = new XmlInterpreter(extraConfig);
                    interpreter.ProcessResource(interpreter.Source, store, kernel);
                }
                catch (ConfigurationErrorsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Failed to load configuration: " + extraConfig, ex);
                }
            }

            Directory.GetDirectories(path).ToList().ForEach(folder => ProcessFolder(store, kernel, folder));
        }
		public void InvalidAssemblyName()
		{
			String xml = 
				"<configuration>" + 
				"	<facilities>" + 
				"		<facility id=\"batchregistration\">" + 
				"			<assemblyBatch name=\"MyCastle.Facilities.BatchRegistration.Tests\" useAttributes=\"false\" >" + 
				"				<include key=\"other\" component=\"Castle.Facilities.BatchRegistration.Tests.Components.OtherComponent\" />" + 
				"			</assemblyBatch>" + 
				"		</facility>" + 
				"	</facilities>" + 
				"</configuration>";

			XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
			interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);

			_kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );
		}
		public void AddFacilities()
		{
			String xml = 
				"<configuration>" + 
				"	<facilities>" + 
				"		<facility id=\"batchregistration\">" + 
				"			<addFacility id=\"facility1\" type=\"Castle.Facilities.BatchRegistration.Tests.Facilities.Facility1, Castle.Facilities.BatchRegistration.Tests\" />" + 
				"			<addFacility id=\"facility2\" type=\"Castle.Facilities.BatchRegistration.Tests.Facilities.Facility2, Castle.Facilities.BatchRegistration.Tests\" />" + 
				"		</facility>" + 
				"	</facilities>" + 
				"</configuration>";

			XmlInterpreter interpreter = new XmlInterpreter( new StaticContentResource(xml) );
			interpreter.ProcessResource( interpreter.Source, _kernel.ConfigurationStore);

			_kernel.AddFacility( "batchregistration", new BatchRegistrationFacility() );

			IFacility[] facilities = _kernel.GetFacilities();
			Assert.AreEqual( 3, facilities.Length );				
		}
示例#25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultContainer"/> class.
        /// </summary>
        public DefaultContainer()
            : base()
        {
            // 初始化日志系统的相关组件
            try {
                if (loggerFactory == null) throw new Exception("日志对象没有被初始化");
                IConfigurationInterpreter interpreter = new XmlInterpreter();
                interpreter.ProcessResource(interpreter.Source, Kernel.ConfigurationStore);
                this.Kernel.AddComponentInstance("logger", typeof(ILoggerFactory), loggerFactory);
                logger = loggerFactory.CreateLogger<DefaultContainer>("Framework");
            }
            catch (Exception ex) {
                System.Diagnostics.EventLog.WriteEntry("Framework", "日志启动错误:" + ex.Message, System.Diagnostics.EventLogEntryType.Error);
                throw;
            }

            // 加载服务器端的服务
            try {
                string filename = FileUtility.ConvertToFullPath(@"Uniframework.config");
                logger.Info("开始加载注册表服务");
                this.Kernel.AddComponentInstance("configService", typeof(IConfigurationService), new XMLConfigurationService(filename));

                logger.Info("开始加载嵌入式对象数据库服务");
                AddComponent("ObjectDatabaseService", typeof(IDb4oDatabaseService), typeof(Db4oDatabaseService));

                logger.Info("开始加载事件分发服务");
                AddFacility("eventautowiring", new EventAutoWiringFacility());

                logger.Info("开始加载会话管理服务");
                AddComponent("SessionService", typeof(ISessionService), typeof(SessionService));

                logger.Info("开始加载系统管理服务");
                AddFacility("System.Facility", new SystemFacility());

                logger.Info("开始加载客户端初始化服务");
                AddComponent("InitializeService", typeof(IInitializeService), typeof(InitializeService));

                logger.Info("开始加载远程调用服务");
                AddComponent("DefaultServiceCaller", typeof(IServiceCaller), typeof(DefaultServiceCaller));

                CheckBuiltInService(); // 对远程服务及远程方法进行注入处理

                AbstractExtend[] loadedExtends = LoadFrameworkExtends();

                string[] customServices = LoadFrameworkComponents();

                object[] components = ActivatingComponents();

                WiringEvent();

                foreach (AbstractExtend extend in loadedExtends) {
                    extend.LoadFinished(components);
                }

                logger.Info("开始加载应用服务器网关");
                AddComponent("ServiceGateway", typeof(ServiceGateway));

                systemReady = true;
                logger.Info("应用服务器启动完成");
            }
            catch (Exception ex) {
                logger.Fatal("注册组件时发生错误", ex);
            }
        }
示例#26
0
		public NetBpmWebContainer(XmlInterpreter interpreter) : base(interpreter)
		{
			Init();
		}
		public void ComponentIdGetsLoadedFromTheParsedConfiguration() {
			
			DefaultConfigurationStore store = new DefaultConfigurationStore();
			XmlInterpreter interpreter = new XmlInterpreter(ConfigHelper.ResolveConfigPath("sample_config_with_spaces.xml"));
			interpreter.ProcessResource(interpreter.Source, store);

			WindsorContainer container = new WindsorContainer(store);

			IHandler handler = container.Kernel.GetHandler(typeof(ICalcService));
			Assert.AreEqual(Core.LifestyleType.Transient, handler.ComponentModel.LifestyleType);
		}
示例#28
0
		public MindDumpContainer(XmlInterpreter interpreter) : base(interpreter)
		{
			Init();
		}