Esempio n. 1
0
        public IList <SparkViewDescriptor> LoadBatchCompilation(Assembly assembly)
        {
            var descriptors = new List <SparkViewDescriptor>();

            foreach (var type in assembly.GetExportedTypes())
            {
                if (!typeof(ISparkView).IsAssignableFrom(type))
                {
                    continue;
                }

                var attributes = type.GetCustomAttributes(typeof(SparkViewAttribute), false);
                if (attributes == null || attributes.Length == 0)
                {
                    continue;
                }

                var descriptor = ((SparkViewAttribute)attributes[0]).BuildDescriptor();

                var entry = new CompiledViewEntry
                {
                    Descriptor = descriptor,
                    Loader     = new ViewLoader(),
                    Compiler   = new CSharpViewCompiler {
                        CompiledType = type
                    },
                    Activator = ViewActivatorFactory.Register(type)
                };
                CompiledViewHolder.Store(entry);

                descriptors.Add(descriptor);
            }

            return(descriptors);
        }
        // end-workaround
        public ThemedViewFactory()
        {
            var container = SparkEngineStarter.CreateContainer();
            _defaultViewFolder = container.GetService<IViewFolder>();
            _defaultEngine = container.GetService<IViewEngine>();

            // workaround
            _defaultViews = CompiledViewHolder.Current;
            // end-workaround
        }
Esempio n. 3
0
        public ISparkViewEntry CreateEntry(SparkViewDescriptor descriptor)
        {
            var entry = CompiledViewHolder.Lookup(descriptor);

            if (entry == null)
            {
                entry = CreateEntryInternal(descriptor, true);
                CompiledViewHolder.Store(entry);
            }
            return(entry);
        }
Esempio n. 4
0
        public void ReleaseInstance(ISparkView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            var entry = CompiledViewHolder.Lookup(view.GeneratedViewId);

            if (entry != null)
            {
                entry.ReleaseInstance(view);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public CompiledViewHolder.Entry CreateEntry(CompiledViewHolder.Key key, bool compile)
        {
            var entry = new CompiledViewHolder.Entry
            {
                Key = key,
                Loader = CreateViewLoader(),
                Compiler = LanguageFactory.CreateViewCompiler(this, key.Descriptor),
                LanguageFactory = LanguageFactory
            };

            var chunksLoaded = new List<IList<Chunk>>();
            var templatesLoaded = new List<string>();
            LoadTemplates(entry.Loader, key.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;
        }
Esempio n. 7
0
 public CompiledViewHolder.Entry CreateEntry(CompiledViewHolder.Key key)
 {
     return CreateEntry(key, true);
 }
Esempio n. 8
0
 public ISparkViewEntry GetEntry(SparkViewDescriptor descriptor)
 {
     return(CompiledViewHolder.Lookup(descriptor));
 }