Beispiel #1
0
        public ISparkViewEntry CreateEntryInternal(SparkViewDescriptor descriptor, bool compile)
        {
            var entry = new CompiledViewEntry
            {
                Descriptor      = descriptor,
                Loader          = CreateViewLoader(),
                Compiler        = LanguageFactory.CreateViewCompiler(this, descriptor),
                LanguageFactory = LanguageFactory
            };


            var chunksLoaded    = new List <IList <Chunk> >();
            var templatesLoaded = new List <string>();

            LoadTemplates(entry.Loader, entry.Descriptor.Templates, chunksLoaded, templatesLoaded);

            if (compile)
            {
                entry.Compiler.CompileView(chunksLoaded, entry.Loader.GetEverythingLoaded());

                entry.Activator = ViewActivatorFactory.Register(entry.Compiler.CompiledType);
            }
            else
            {
                entry.Compiler.GenerateSourceCode(chunksLoaded, entry.Loader.GetEverythingLoaded());
            }

            return(entry);
        }
Beispiel #2
0
        public Assembly BatchCompilation(string outputAssembly, IList <SparkViewDescriptor> descriptors)
        {
            var batch      = new List <CompiledViewEntry>();
            var sourceCode = new List <string>();

            foreach (var descriptor in descriptors)
            {
                var entry = new CompiledViewEntry
                {
                    Descriptor = descriptor,
                    Loader     = CreateViewLoader(),
                    Compiler   = LanguageFactory.CreateViewCompiler(this, descriptor)
                };

                var chunksLoaded    = new List <IList <Chunk> >();
                var templatesLoaded = new List <string>();
                LoadTemplates(entry.Loader, descriptor.Templates, chunksLoaded, templatesLoaded);

                entry.Compiler.GenerateSourceCode(chunksLoaded, entry.Loader.GetEverythingLoaded());
                sourceCode.Add(entry.Compiler.SourceCode);

                batch.Add(entry);
            }

            var batchCompiler = new BatchCompiler {
                OutputAssembly = outputAssembly
            };

            var assembly = batchCompiler.Compile(Settings.Debug, "csharp", sourceCode.ToArray());

            foreach (var entry in batch)
            {
                entry.Compiler.CompiledType = assembly.GetType(entry.Compiler.ViewClassFullName);
                entry.Activator             = ViewActivatorFactory.Register(entry.Compiler.CompiledType);
                CompiledViewHolder.Store(entry);
            }
            return(assembly);
        }