public static IViewEngineManager GetViewManager() { var config = new MonoRailConfiguration(); config.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(BooViewEngine), false)); config.ViewEngineConfig.ViewPathRoot = Path.Combine(@"..\..\..\AdminInterface", "Views"); var provider = new FakeServiceProvider(); var loader = new FileAssemblyViewSourceLoader(config.ViewEngineConfig.ViewPathRoot); loader.AddAssemblySource(new AssemblySourceInfo("Common.Web.Ui", "Common.Web.Ui.Views")); provider.Services.Add(typeof(IMonoRailConfiguration), config); provider.Services.Add(typeof(IViewSourceLoader), loader); var manager = new DefaultViewEngineManager(); manager.Service(provider); var options = Exposed.From(manager).viewEnginesFastLookup[0].Options; var namespaces = options.NamespacesToImport; namespaces.Add("Boo.Lang.Builtins"); namespaces.Add("AdminInterface.Helpers"); namespaces.Add("Common.Web.Ui.Helpers"); options.AssembliesToReference.Add(Assembly.Load("AdminInterface")); return(manager); }
IMonoRailConfiguration ObtainConfiguration(HttpApplication appInstance) { IMonoRailConfiguration config = MonoRailConfiguration.GetConfig(); MethodInfo method = appInstance.GetType().GetMethod("MonoRail_Configure"); if (method != null) { config = config ?? new MonoRailConfiguration(); if (method.IsStatic) { method.Invoke(null, new object[] { config }); } else { method.Invoke(appInstance, new object[] { config }); } } if (config == null) { throw new ApplicationException("You have to provide a small configuration to use MonoRail. This can be done using the web.config or your global asax (your class that extends HttpApplication) through the method MonoRail_Configure(IMonoRailConfiguration config). Check the samples or the documentation."); } return(config); }
/// <summary> </summary> private static String virtural_veiw_path() { MonoRailConfiguration section = (MonoRailConfiguration)ConfigurationManager.GetSection("monorail"); string path = section.ViewEngineConfig.VirtualPathRoot; return(path); }
/// <summary> /// Reads the attribute <c>customsession</c> /// from <see cref="MonoRailConfiguration"/> and /// instantiate it based on the type name provided. /// </summary> /// <exception cref="ConfigurationException"> /// If the typename was not provided or the type /// could not be instantiated/found /// </exception> /// <param name="configuration"></param> public override void Init(MonoRailConfiguration configuration) { XmlAttribute customSessionAtt = configuration.ConfigSection.Attributes["customsession"]; if (customSessionAtt == null || customSessionAtt.Value.Length == 0) { throw new ConfigurationException("The CustomSessionExtension requires that " + "the type that implements ICustomSessionFactory be specified through the " + "'customsession' attribute on 'monoRail' configuration node"); } Type customSessType = MonoRailConfiguration.GetType(customSessionAtt.Value); if (customSessType == null) { throw new ConfigurationException("The Type for the custom session could not be loaded. " + customSessionAtt.Value); } try { customSession = (ICustomSessionFactory)Activator.CreateInstance(customSessType); } catch (InvalidCastException) { throw new ConfigurationException("The Type for the custom session must " + "implement ICustomSessionFactory. " + customSessionAtt.Value); } }
/*----------------------------------------------------------------------------------------*/ #region Public Methods /// <summary> /// Initializes the controller factory by searching the configured assemblies for defined controllers. /// </summary> public void Initialize() { IMonoRailConfiguration config = MonoRailConfiguration.GetConfig(); if (config != null) { foreach (string assembly in config.ControllersConfig.Assemblies) { Inspect(assembly); } } }
private void InstallExceptionHandler(XmlNode node, String typeName) { IExceptionHandler handler = null; Type handlerType = MonoRailConfiguration.GetType(typeName); if (handlerType == null) { throw new ConfigurationException("The Type for the custom session could not be loaded. " + typeName); } try { handler = (IExceptionHandler)Activator.CreateInstance(handlerType); } catch (InvalidCastException) { throw new ConfigurationException("The Type for the custom session must " + "implement ICustomSessionFactory. " + typeName); } IConfigurableHandler configurableHandler = handler as IConfigurableHandler; if (configurableHandler != null) { configurableHandler.Configure(node); } handler.Initialize(); if (firstHandler == null) { firstHandler = handler; } else { IExceptionHandler navHandler = firstHandler; while (navHandler != null) { if (navHandler.Next == null) { navHandler.Next = handler; break; } navHandler = navHandler.Next; } } }
/// <summary> /// /// </summary> /// <param name="configuration"></param> public override void Init(MonoRailConfiguration configuration) { XmlNodeList handlers = configuration.ConfigSection.SelectNodes("exception/exceptionHandler"); HttpContext.Current.ApplicationInstance.Error += new EventHandler(ApplicationInstance_Error); foreach (XmlNode node in handlers) { XmlAttribute typeAtt = node.Attributes["type"]; if (typeAtt == null) { // TODO: Throw configuration exception } InstallExceptionHandler(node, typeAtt.Value); } }
public static IViewEngineManager Init(Assembly assembly = null) { if (assembly == null) { assembly = Assembly.GetEntryAssembly(); } ActiveRecordStarter.Initialize( new[] { Assembly.Load("AdminInterface"), Assembly.Load("Common.Web.Ui") }, ActiveRecordSectionHandler.Instance); var config = new MonoRailConfiguration(); config.ViewEngineConfig.ViewEngines.Add(new ViewEngineInfo(typeof(BooViewEngine), false)); var loader = new FileAssemblyViewSourceLoader(""); loader.AddAssemblySource(new AssemblySourceInfo(assembly, assembly.GetName().Name + ".Views")); var provider = new FakeServiceProvider(); provider.Services.Add(typeof(IMonoRailConfiguration), config); provider.Services.Add(typeof(IViewSourceLoader), loader); var manager = new DefaultViewEngineManager(); manager.Service(provider); var options = ((BooViewEngine)manager.ResolveEngine(".brail")).Options; options.AssembliesToReference.Add(Assembly.Load("Common.Web.Ui")); var namespaces = options.NamespacesToImport; namespaces.Add("Boo.Lang.Builtins"); namespaces.Add("AdminInterface.Helpers"); namespaces.Add("Common.Web.Ui.Helpers"); BaseMailer.ViewEngineManager = manager; return(manager); }
private IMonoRailConfiguration ObtainConfiguration(HttpApplication appInstance) { IMonoRailConfiguration config = MonoRailConfiguration.GetConfig(); var events = appInstance as IMonoRailConfigurationEvents; if (events != null) { config = config ?? new MonoRailConfiguration(); events.Configure(config); } if (config == null) { throw new ApplicationException("You have to provide a small configuration to use " + "MonoRail. This can be done using the web.config or " + "your global asax (your class that extends HttpApplication) " + "through the method MonoRail_Configure(IMonoRailConfiguration config). " + "Check the samples or the documentation."); } return(config); }
/// <summary> /// Implementors have a chance to read custom /// elements from <see cref="MonoRailConfiguration"/> /// </summary> /// <param name="configuration"></param> public virtual void Init(MonoRailConfiguration configuration) { this.configuration = configuration; }
/// <summary> /// Initializes a module and prepares it to handle requests. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpApplication"></see> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application</param> public void Init(HttpApplication context) { context.BeginRequest += OnBeginRequest; routingRules = MonoRailConfiguration.GetConfig().RoutingRules; }
public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(OnBeginRequest); routingRules = MonoRailConfiguration.GetConfig().RoutingRules; }
/// <summary> /// Implementors have a chance to read custom /// elements from <see cref="MonoRailConfiguration"/> /// </summary> /// <param name="configuration"></param> public void Init(MonoRailConfiguration configuration) { throw new NotImplementedException(); }