コード例 #1
0
        public SparkViewEngine Engine()
        {
            if (engine != null)
            {
                return(engine);
            }

            var settings = new SparkSettings()
                           .SetPageBaseType(typeof(WebFormsSparkView))
                           .SetNullBehaviour(NullBehaviour.Strict);

            foreach (var ns in namespaces)
            {
                settings = settings.AddNamespace(ns);
            }
            foreach (var a in assemblies)
            {
                settings = settings.AddAssembly(a);
            }

            engine = new SparkViewEngine(settings);

            engine.ViewFolder = GetViewFolder();

            engine.BatchCompilation(GetViewDescriptors());
            return(engine);
        }
コード例 #2
0
        public override void Install(IDictionary stateSaver)
        {
            // figure out all paths based on this assembly in the bin dir
            string assemblyPath  = GetType().Assembly.Location;
            string targetPath    = Path.ChangeExtension(assemblyPath, ".Views.dll");
            string webSitePath   = Path.GetDirectoryName(Path.GetDirectoryName(assemblyPath));
            string webBinPath    = Path.Combine(webSitePath, "bin");
            string webFileHack   = Path.Combine(webSitePath, "web");
            string viewsLocation = Path.Combine(webSitePath, "Views");

            // this hack enables you to open the web.config as if it was an .exe.config
            File.Create(webFileHack).Close();
            Configuration config = ConfigurationManager.OpenExeConfiguration(webFileHack);

            File.Delete(webFileHack);

            // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding
            AppDomain.CurrentDomain.AssemblyResolve +=
                ((sender, e) => Assembly.LoadFile(Path.Combine(webBinPath, e.Name + ".dll")));
            var settings = (ISparkSettings)config.GetSection("spark");

            // Finally create an engine with the <spark> settings from the web.config
            var engine = new SparkViewEngine(settings)
            {
                ViewFolder = new FileSystemViewFolder(viewsLocation)
            };

            // And generate all of the known view/master templates into the target assembly
            engine.BatchCompilation(targetPath, Global.AllKnownDescriptors());
        }