public void CreateParser(string configFileName) { IEnumerable <Assembly> plugins; if (!string.IsNullOrEmpty(configFileName)) { var config = SaltarelleConfig.LoadFile(configFileName); plugins = config.LoadPluginsInNoContext(Path.GetDirectoryName(configFileName)); } else { plugins = new Assembly[0]; } var windsorContainer = new WindsorContainer(); ContainerFactory.PrepareWindsorContainer(windsorContainer); foreach (var p in plugins) { windsorContainer.RegisterPluginsFromAssembly(p); } var container = ContainerFactory.CreateContainer(windsorContainer); parser = SaltarelleParserFactory.CreateParserWithPlugins(plugins, container); }
private static ProcessedConfig ProcessConfig(SaltarelleConfig config, IRouteService routes) { ProcessedConfig result; if (_configsCache.TryGetValue(config, out result)) return result; result = new ProcessedConfig(config, routes); _configsCache[config] = result; return result; }
public static void RegisterSaltarelleCoreServices(IWindsorContainer container, SaltarelleConfig saltarelleConfig) { container.Register(Component.For<Saltarelle.IRouteService>().ImplementedBy<Saltarelle.Mvc.MvcRouteService>().LifeStyle.Singleton, Component.For<Saltarelle.IModuleUtils>().ImplementedBy<Saltarelle.Mvc.ModuleUtils>().LifeStyle.Singleton, Component.For<Saltarelle.Ioc.IContainer>().UsingFactoryMethod(() => Saltarelle.CastleWindsor.ContainerFactory.CreateContainer(container)).LifestylePerWebRequest(), Component.For<Saltarelle.IScriptManagerService>().UsingFactoryMethod(() => new Saltarelle.DefaultScriptManagerService(container.Resolve<IRouteService>(), container.Resolve<IModuleUtils>(), saltarelleConfig)).LifeStyle.PerWebRequest, Component.For<Saltarelle.Mvc.SaltarelleController>().LifeStyle.PerWebRequest, Component.For<Saltarelle.UI.ISaltarelleUIService>().ImplementedBy<Saltarelle.UI.DefaultSaltarelleUIService>().LifeStyle.Singleton ); }
private static ProcessedConfig ProcessConfig(SaltarelleConfig config, IRouteService routes) { ProcessedConfig result; if (_configsCache.TryGetValue(config, out result)) { return(result); } result = new ProcessedConfig(config, routes); _configsCache[config] = result; return(result); }
public ProcessedConfig(SaltarelleConfig cfg, IRouteService routes) { if (cfg.Scripts == null) { // Default DebugScripts = true; AddScriptsBeforeCoreScripts = new List<string>().AsReadOnly(); AddScriptsBeforeAssemblyScripts = new List<string>().AsReadOnly(); AddScriptsAfterAssemblyScripts = new List<string>().AsReadOnly(); return; } DebugScripts = cfg.Scripts.Debug; var allScripts = cfg.Scripts.Select(elem => { string url; if (!string.IsNullOrEmpty(elem.Assembly)) { if (string.IsNullOrEmpty(elem.Resource)) throw new ConfigurationErrorsException("Saltarelle configuration: if an assembly is specified for a script, the resource name must also be specified."); if (!string.IsNullOrEmpty(elem.Url)) throw new ConfigurationErrorsException("Saltarelle configuration: if an assembly is specified for a script, the URL may not also be specified."); Assembly asm; try { asm = Assembly.Load(elem.Assembly); } catch (Exception ex) { throw new ConfigurationErrorsException("Saltarelle configuration: The assembly '" + elem.Assembly + "' could not be loaded.", ex); } var res = asm.GetCustomAttributes(typeof(WebResourceAttribute), false).Cast<WebResourceAttribute>().SingleOrDefault(x => x.PublicResourceName == elem.Resource); if (res == null) throw new ConfigurationErrorsException("Saltarelle configuration: The assembly '" + elem.Assembly + "' does not contain a resource named '" + elem.Resource + "'."); url = routes.GetAssemblyResourceUrl(asm, res.PublicResourceName); } else if (!string.IsNullOrEmpty(elem.Url)) { if (VirtualPathUtility.IsAppRelative(elem.Url)) url = VirtualPathUtility.ToAbsolute(elem.Url); else url = elem.Url; } else throw new ConfigurationErrorsException("Saltarelle configuration: script elements must have assembly/resource or url specified."); return new { elem.Position, Url = url }; }).ToList(); AddScriptsBeforeCoreScripts = (from x in allScripts where x.Position == ScriptPosition.BeforeCoreScripts select x.Url).ToList().AsReadOnly(); AddScriptsBeforeAssemblyScripts = (from x in allScripts where x.Position == ScriptPosition.BeforeAssemblyScripts select x.Url).ToList().AsReadOnly(); AddScriptsAfterAssemblyScripts = (from x in allScripts where x.Position == ScriptPosition.AfterAssemblyScripts select x.Url).ToList().AsReadOnly(); }
protected void Application_Start() { var container = new WindsorContainer(); Saltarelle.CastleWindsor.ContainerFactory.PrepareWindsorContainer(container); RegisterSaltarelleCoreServices(container, SaltarelleConfig.GetFromWebConfig()); container.RegisterPluginsFromAssembly(typeof(CopyrightNodeProcessor).Assembly); container.RegisterControlsFromAssembly(typeof(Lesson1Control).Assembly); container.RegisterControlsFromAssembly(typeof(Label).Assembly); container.Register(AllTypes.FromAssemblyContaining <HomeController>().BasedOn <IController>().WithService.Self().LifestylePerWebRequest()); container.Register(Component.For <ILesson7Service>().ImplementedBy <DefaultLesson7Provider>()); RegisterRoutes(RouteTable.Routes); DependencyResolver.SetResolver(container.Resolve, s => (object[])container.ResolveAll(s)); }
public static void RegisterSaltarelleCoreServices(IWindsorContainer container, SaltarelleConfig saltarelleConfig) { container.Register(Component.For <Saltarelle.IRouteService>().ImplementedBy <Saltarelle.Mvc.MvcRouteService>().LifeStyle.Singleton, Component.For <Saltarelle.IModuleUtils>().ImplementedBy <Saltarelle.Mvc.ModuleUtils>().LifeStyle.Singleton, Component.For <Saltarelle.Ioc.IContainer>().UsingFactoryMethod(() => Saltarelle.CastleWindsor.ContainerFactory.CreateContainer(container)).LifestylePerWebRequest(), Component.For <Saltarelle.IScriptManagerService>().UsingFactoryMethod(() => new Saltarelle.DefaultScriptManagerService(container.Resolve <IRouteService>(), container.Resolve <IModuleUtils>(), saltarelleConfig)).LifeStyle.PerWebRequest, Component.For <Saltarelle.Mvc.SaltarelleController>().LifeStyle.PerWebRequest, Component.For <Saltarelle.UI.ISaltarelleUIService>().ImplementedBy <Saltarelle.UI.DefaultSaltarelleUIService>().LifeStyle.Singleton ); }
public ProcessedConfig(SaltarelleConfig cfg, IRouteService routes) { if (cfg.Scripts == null) { // Default DebugScripts = true; AddScriptsBeforeCoreScripts = new List <string>().AsReadOnly(); AddScriptsBeforeAssemblyScripts = new List <string>().AsReadOnly(); AddScriptsAfterAssemblyScripts = new List <string>().AsReadOnly(); return; } DebugScripts = cfg.Scripts.Debug; var allScripts = cfg.Scripts.Select(elem => { string url; if (!string.IsNullOrEmpty(elem.Assembly)) { if (string.IsNullOrEmpty(elem.Resource)) { throw new ConfigurationErrorsException("Saltarelle configuration: if an assembly is specified for a script, the resource name must also be specified."); } if (!string.IsNullOrEmpty(elem.Url)) { throw new ConfigurationErrorsException("Saltarelle configuration: if an assembly is specified for a script, the URL may not also be specified."); } Assembly asm; try { asm = Assembly.Load(elem.Assembly); } catch (Exception ex) { throw new ConfigurationErrorsException("Saltarelle configuration: The assembly '" + elem.Assembly + "' could not be loaded.", ex); } var res = asm.GetCustomAttributes(typeof(WebResourceAttribute), false).Cast <WebResourceAttribute>().SingleOrDefault(x => x.PublicResourceName == elem.Resource); if (res == null) { throw new ConfigurationErrorsException("Saltarelle configuration: The assembly '" + elem.Assembly + "' does not contain a resource named '" + elem.Resource + "'."); } url = routes.GetAssemblyResourceUrl(asm, res.PublicResourceName); } else if (!string.IsNullOrEmpty(elem.Url)) { if (VirtualPathUtility.IsAppRelative(elem.Url)) { url = VirtualPathUtility.ToAbsolute(elem.Url); } else { url = elem.Url; } } else { throw new ConfigurationErrorsException("Saltarelle configuration: script elements must have assembly/resource or url specified."); } return(new { elem.Position, Url = url }); }).ToList(); AddScriptsBeforeCoreScripts = (from x in allScripts where x.Position == ScriptPosition.BeforeCoreScripts select x.Url).ToList().AsReadOnly(); AddScriptsBeforeAssemblyScripts = (from x in allScripts where x.Position == ScriptPosition.BeforeAssemblyScripts select x.Url).ToList().AsReadOnly(); AddScriptsAfterAssemblyScripts = (from x in allScripts where x.Position == ScriptPosition.AfterAssemblyScripts select x.Url).ToList().AsReadOnly(); }
public DefaultScriptManagerService(IRouteService routes, IModuleUtils moduleUtils, SaltarelleConfig config) { this.routes = routes; this.moduleUtils = moduleUtils; var pc = ProcessConfig(config, routes); earlyAdditionalIncludes.AddRange(pc.AddScriptsBeforeCoreScripts); earlyAdditionalIncludes.AddRange((pc.DebugScripts ? Resources.CoreScriptsDebug : Resources.CoreScriptsRelease).Select(s => routes.GetAssemblyResourceUrl(typeof(Resources).Assembly, s))); earlyAdditionalIncludes.AddRange(pc.AddScriptsBeforeAssemblyScripts); lateAdditionalIncludes.AddRange(pc.AddScriptsAfterAssemblyScripts); }
public static void RegisterRoutes(RouteCollection routes) { var config = SaltarelleConfig.GetFromWebConfig(); if (config == null) { throw new ConfigurationErrorsException("The <saltarelle> section is missing from web.config."); } bool debugScripts = config.Scripts.Debug; if (string.IsNullOrEmpty(config.Routes.AssemblyScripts)) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyScripts configuration attribute must be specified."); } if (!config.Routes.AssemblyScripts.Contains("{" + SaltarelleController.AssemblyNameParam + "}")) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyScripts configuration attribute must contain the route value placeholder {" + SaltarelleController.AssemblyNameParam + "}."); } if (string.IsNullOrEmpty(config.Routes.AssemblyCss)) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyCss configuration attribute must be specified."); } if (!config.Routes.AssemblyCss.Contains("{" + SaltarelleController.AssemblyNameParam + "}")) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyCss configuration attribute must contain the route value placeholder {" + SaltarelleController.AssemblyNameParam + "}."); } if (string.IsNullOrEmpty(config.Routes.AssemblyResources)) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyResources configuration attribute must be specified."); } if (!config.Routes.AssemblyResources.Contains("{" + SaltarelleController.AssemblyNameParam + "}") || !config.Routes.AssemblyResources.Contains("{version}") || !config.Routes.AssemblyResources.Contains("{*" + SaltarelleController.ResourceNameParam + "}")) { throw new ConfigurationErrorsException("The saltarelle/routes/@assemblyResources configuration attribute must contain the route value placeholders {" + SaltarelleController.AssemblyNameParam + "}, {version} and {*" + SaltarelleController.ResourceNameParam + "}."); } if (string.IsNullOrEmpty(config.Routes.Delegate)) { throw new ConfigurationErrorsException("The saltarelle/routes/@delegate configuration attribute must be specified."); } if (!config.Routes.Delegate.Contains("{" + SaltarelleController.DelegateTypeNameParam + "}") || !config.Routes.Delegate.Contains("{" + SaltarelleController.DelegateMethodParam + "}")) { throw new ConfigurationErrorsException("The saltarelle/routes/@delegate configuration attribute must contain the route value placeholders {" + SaltarelleController.DelegateTypeNameParam + "} and {" + SaltarelleController.DelegateMethodParam + "}."); } RegisterSingle(routes, AssemblyScriptsRouteName, config.Routes.AssemblyScripts, (SaltarelleController c) => c.GetAssemblyScript(null, null), debugScripts ? new Dictionary <string, Func <RouteValueDictionary, string> >() { { "version", assemblyVersionDependency }, { SaltarelleController.ScriptDebugParam, _ => "1" } } : new Dictionary <string, Func <RouteValueDictionary, string> >() { { "version", assemblyVersionDependency } }); RegisterSingle(routes, AssemblyCssRouteName, config.Routes.AssemblyCss, (SaltarelleController c) => c.GetAssemblyCss(null), new Dictionary <string, Func <RouteValueDictionary, string> >() { { "version", assemblyVersionDependency } }); RegisterSingle(routes, AssemblyResourcesRouteName, config.Routes.AssemblyResources, (SaltarelleController c) => c.GetAssemblyResource(null, null), new Dictionary <string, Func <RouteValueDictionary, string> >() { { "version", assemblyVersionDependency } }); RegisterSingle(routes, DelegateRouteName, config.Routes.Delegate, (SaltarelleController c) => c.Delegate(null, null), null); }