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);
        }
Пример #2
0
        public override void ProcessResource(IResource source, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            // default stuff...
            base.ProcessResource(source, store);

            // custom stuff..auto register all config\*.castle.config files
            var configFilesLocation = SmartLocation.GetLocation("config");

            foreach (var extraConfig in Directory.GetFiles(configFilesLocation, "*.castle.config"))
            {
                try
                {
                    var interpreter = new XmlInterpreter(extraConfig)
                    {
                        Kernel = Kernel
                    };
                    interpreter.ProcessResource(interpreter.Source, store);
                }
                catch (ConfigurationErrorsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Failed to load configuration: " + extraConfig, ex);
                }
            }
        }
Пример #3
0
        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(2, 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 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"];
		}
        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"];
        }
Пример #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);
			configuration = configurationStore.GetFacilityConfiguration("nhibernatefacility").Children["factory"];
			configurationBuilder = new PersistentConfigurationBuilder();
		}
        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, new DefaultKernel());
            configuration        = configurationStore.GetFacilityConfiguration(typeof(NHibernateFacility).FullName).Children["factory"];
            configurationBuilder = new PersistentConfigurationBuilder();
        }
Пример #8
0
        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"];
        }
Пример #9
0
        public void CorrectConfigurationMapping()
        {
            DefaultConfigurationStore store       = new DefaultConfigurationStore();
            XmlInterpreter            interpreter = new XmlInterpreter("sample_config.xml");

            interpreter.ProcessResource(interpreter.Source, store);

            WindsorContainer container = new WindsorContainer(store);

            container.AddFacility("testidengine", new DummyFacility());
        }
Пример #10
0
        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);
        }
Пример #11
0
        public void Test_Embedded()
        {
            var resource = Xml.Embedded("hasResourceIncludes.xml");

            Assert.IsNotNull(resource);
            Assert.AreEqual(resource.FileBasePath, AppDomain.CurrentDomain.BaseDirectory);
            var interpreter = new XmlInterpreter(resource);

            Assert.AreEqual(interpreter.EnvironmentName, null);
            var kernel = new DefaultKernel();

            interpreter.ProcessResource(resource, kernel.ConfigurationStore, kernel);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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());
        }
Пример #15
0
        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);
        }
Пример #16
0
        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)));
        }
Пример #17
0
        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));
        }
Пример #18
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);
            }
        }