예제 #1
0
 /// <summary>
 /// Unloads the Razor host if running in a separate appdomain by
 /// unloading the AppDomain.
 /// </summary>
 public static void UnloadRazorHostInAppDomain()
 {
     if (Current != null)
     {
         Current.UnloadHost();
     }
     Current = null;
 }
예제 #2
0
        /// <summary>
        /// Creates an instance of the RazorHost in a new AppDomain. This
        /// version creates a static singleton that that is cached and you
        /// can call UnloadRazorHostInAppDomain to unload it.
        /// </summary>
        /// <returns></returns>
        public static RazorEngine <TBaseTemplateType> CreateRazorHostInAppDomain()
        {
            if (Current == null)
            {
                Current = new RazorEngineFactory <TBaseTemplateType>();
            }

            return(Current.GetRazorHostInAppDomain());
        }
예제 #3
0
        /// <summary>
        /// Create an instance of the RazorHost in the current
        /// AppDomain. No special handling...
        /// </summary>
        /// <returns></returns>
        public static RazorEngine <TBaseTemplateType> CreateRazorHost(CSharpCodeProvider codeProvider = null)
        {
            if (Current == null)
            {
                Current = new RazorEngineFactory <TBaseTemplateType>();
            }

            return(Current.GetRazorHost(codeProvider));
        }
        /// <summary>
        /// Stops the Host and releases the host AppDomain and cached
        /// assemblies.
        /// </summary>
        /// <returns>true or false</returns>
        public bool Stop()
        {
            this.LoadedAssemblies.Clear();

            RazorEngineFactory <RazorTemplateBase> .UnloadRazorHostInAppDomain();

            this.Engine = null;
            return(true);
        }
예제 #5
0
        /// <summary>
        /// Stops the Host and releases the host AppDomain and cached
        /// assemblies.
        /// </summary>
        /// <returns>true or false</returns>
        public bool Stop()
        {
            if (Engine != null)
            {
                // Release cached assemblies
                LoadedAssemblies.Clear();

                RazorEngineFactory <RazorTemplateBase> .UnloadRazorHostInAppDomain();

                Engine = null;
            }

            return(true);
        }
예제 #6
0
        /// <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(CodeProvider);
                }

                if (Engine == null)
                {
                    SetError(RazorEngineFactory <TBaseTemplateType> .Current.ErrorMessage);
                    return(false);
                }

                Engine.HostContainer = this;

                foreach (string Namespace in ReferencedNamespaces)
                {
                    Engine.AddNamespace(Namespace);
                }

                foreach (string assembly in ReferencedAssemblies)
                {
                    Engine.AddAssembly(assembly);
                }

                Engine.Configuration = Configuration;
            }

            return(true);
        }