/// <summary> /// Call to start the Host running. Follow by a calls to RenderTemplate to /// render individual templates. Call Stop when done. /// </summary> /// <returns>true or false - check ErrorMessage on false </returns> public virtual bool Start() { if (Engine == null) { if (UseAppDomain) { Engine = RazorEngineFactory <TBaseTemplateType> .CreateRazorHostInAppDomain(); } else { Engine = RazorEngineFactory <TBaseTemplateType> .CreateRazorHost(); } if (Engine == null) { return(false); } Engine.HostContainer = this; Engine.ReferencedNamespaces.AddRange(ReferencedNamespaces); Engine.Configuration = Configuration; if (Engine == null) { this.ErrorMessage = EngineFactory.ErrorMessage; return(false); } } return(true); }
/// <summary> /// Routine that returns an instance of the RazorHost hosted /// in a separate AppDomain. Checks for existance of the host /// and creates only if needed. You need to cache the host /// to avoid excessive resource use. /// </summary> /// <returns></returns> private RazorEngine <RazorTemplateBase> CreateHost() { if (this.Host != null) { return(this.Host); } // Use Static Methods - no error message if host doesn't load this.Host = RazorEngineFactory <RazorTemplateBase> .CreateRazorHost(); //this.Host = RazorEngineFactory<RazorTemplateBase>.CreateRazorHostInAppDomain(); if (this.Host == null) { System.Windows.Forms.MessageBox.Show("Unable to load Razor Template Host", "Razor Hosting", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(this.Host); }