Esempio n. 1
0
        /// <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);
        }
        public void SimplestRazorEngineTestWithAppDomain()
        {
            string template = @"Hello World @Model.Name. Time is: @DateTime.Now";

            // Load engine into new AppDomain
            var host = RazorEngineFactory <RazorTemplateBase> .CreateRazorHostInAppDomain();

            // Note: You can't use anonymouse types for cross-AppDomain calls
            //       Models passed must inherit MarshalByRefObject or be [Serializable]
            string result = host.RenderTemplate(template, new Person {
                Name = "Joe Doe"
            });

            Assert.IsNotNull(result, host.ErrorMessage);
            Assert.IsTrue(result.Contains("Joe Doe"));

            // shut down AppDomain
            RazorEngineFactory <RazorTemplateBase> .UnloadRazorHostInAppDomain();

            Console.WriteLine(result);
        }