ProcessResource() public method

public ProcessResource ( IResource source, IConfigurationStore store ) : void
source IResource
store IConfigurationStore
return void
		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);
		}
Example #3
0
        public virtual void FixtureSetUp()
        {
            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"];
		}
Example #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);
        }
Example #6
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();
		}
		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()
		{
			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 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);
		}
Example #10
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");
 }
Example #13
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 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);
		}
		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 );				
		}
        /// <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);
            }
        }