Adapts a static string content as an IResource
Inheritance: AbstractResource
示例#1
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>());
        }
        protected virtual void LoadPatches() {
            patches = new List<IMvcPatch>();
            var patchIocFile = TargetFileSystem.ReadXml("ioc/patches.config", null,
                                                        new ReadXmlOptions{Merge = true});
            if (patchIocFile == null){
                patchIocFile = "<configuration />";
            }
            try{
                var patchIocResource = new StaticContentResource(patchIocFile);
                if (null != patchIocFile){

                    var container = new WindsorContainer(new XmlInterpreter(patchIocResource));
                    try{
                        foreach (var patch in container.ResolveAll<IMvcPatch>()){
                            patch.FileSystem = FileSystem;
                            patch.Manager = this;
                            patch.Identity = new SimplePackageIdentity(patch.Code);
                            patches.Add(patch);
                        }
                    }
                    finally{
                        container.Dispose();
                    }
                }
            }catch(Exception ex){
                throw new Exception("error in config:\r\n"+patchIocFile,ex);
            }
        }
		/// <summary>
		/// Registers the javascript.
		/// </summary>
		/// <param name="combiner">The combiner.</param>
		/// <param name="key">The key.</param>
		/// <param name="resourceRegistry">The resource registry.</param>
		/// <param name="javascriptHash">The javascript hash.</param>
		private void RegisterJavascript(CombinerConfig combiner, string key, IStaticResourceRegistry resourceRegistry, long javascriptHash)
		{
			if (combiner.JavascriptFiles.Count < 1) return;

			var script = CombineJSFileContent(combiner.JavascriptFiles);

			if (ScriptBuilder.Minify)
				script = ScriptBuilder.CompressJavascript(script);

			var staticContentResource = new StaticContentResource(script);

			resourceRegistry.RegisterCustomResource(key, null, javascriptHash.ToString(), staticContentResource,
													"application/x-javascript", DateTime.Now);
		}
		/// <summary>
		/// Registers the CSS.
		/// </summary>
		/// <param name="combiner">The combiner.</param>
		/// <param name="resourceRegistry">The resource registry.</param>
		/// <param name="cssKey">The CSS key.</param>
		/// <param name="cssHash">The CSS hash.</param>
		private void RegisterCss(CombinerConfig combiner, IStaticResourceRegistry resourceRegistry, string cssKey, long cssHash)
		{
			if (combiner.CssFiles.Count < 1) return;

			var css = CombineCssFileContent(combiner);

			if (ScriptBuilder.Minify)
				css = ScriptBuilder.CompressCSS(css);

			var cssResource = new StaticContentResource(css);

			resourceRegistry.RegisterCustomResource(cssKey, null, cssHash.ToString(), cssResource,
													"text/css", DateTime.Now);
		}