Ejemplo n.º 1
0
        public TemplatesCompilationResult Compile(params TemplateSource[] sources)
        {
            var parameters = new TemplatesCompilationParameters();

            foreach (var source in sources)
            {
                parameters.Templates.Add(source);
            }
            return(Compile(parameters));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compiles a Template Filer.
        /// </summary>
        /// <param name="filePath">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="TemplateCompilationResult"/>
        /// </returns>
        /// <exception cref="TemplateCompilerNotFoundException">No template compiler was found for the given file extension</exception>
        public TemplatesCompilationResult Compile(TemplatesCompilationParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            TemplatesCompilationResult            generalResult     = new TemplatesCompilationResult();
            Dictionary <string, TemplateCompiler> compilerInstances = new Dictionary <string, TemplateCompiler> ();

            foreach (TemplateSource source in parameters.Templates)
            {
                var fileExtension = normalizeFileExtension(source.TemplateFileExtension);
                if (!this.fileCompilers.ContainsKey(fileExtension))
                {
                    throw new TemplateCompilerNotFoundException(string.Format("No template compiler was found for extension '{0}'", fileExtension));
                }
                TemplateCompiler compiler = null;
                if (compilerInstances.ContainsKey(fileExtension))
                {
                    compiler = compilerInstances[fileExtension];
                }
                else
                {
                    compiler = TemplateCompiler.CreateInstance(this.fileCompilers[fileExtension]);
                    compilerInstances[fileExtension] = compiler;
                }
                compiler.Sources.Add(source);
            }
            foreach (TemplateCompiler compiler in compilerInstances.Values)
            {
                var compilationResult = compiler.Compile();
                foreach (var error in compilationResult.CompilationErrors)
                {
                    generalResult.CompilationErrors.Add(error);
                }
                foreach (var assembly in compilationResult.Assemblies)
                {
                    generalResult.Assemblies.Add(assembly);
                    extractInstanceDiscoveryProvider(assembly);
                }
            }
            return(generalResult);
        }