Пример #1
0
        /// <summary>
        /// This method only parses the template so we can get to the header info.
        /// </summary>
        /// <param name="templateName">The template file path.</param>
        public void Parse(string templateName)
        {
            this._templateHeader = null;

            CachedTemplate cachedTemplate = TemplateCache.GetCachedTemplate(templateName, CompileAction.ParseOnly);

            _codeBuilder = cachedTemplate.CodeBuilder;
            _assembly    = cachedTemplate.CompiledAssembly;
            _results     = cachedTemplate.CompilerResults;
        }
Пример #2
0
        /// <summary>
        /// Compiles a template, and set the current template information accordingly. Note that this does not execute the template.
        /// </summary>
        /// <param name="templateName">The template file path.</param>
        public void Compile(string templateName)
        {
            this._templateHeader = null;

            CachedTemplate cachedTemplate = TemplateCache.GetCachedTemplate(templateName, CompileAction.Compile);

            _codeBuilder = cachedTemplate.CodeBuilder;
            _assembly    = cachedTemplate.CompiledAssembly;
            _results     = cachedTemplate.CompilerResults;

            if (_results != null && _results.Errors.HasErrors)
            {
                throw new CompilerException(_results, this);
            }
        }
Пример #3
0
        /// <summary>
        /// Compiles and executes a template, and also sets the current template information accordingly.
        /// </summary>
        /// <param name="esMeta">The esMeta object which holds the context needed for an EntitySpaces template to generate meaningful code.</param>
        /// <param name="templateLocation">The template file path.</param>
        public void Execute(Root esMeta, string templateLocation)
        {
            try
            {
                _buffer = new StringBuilder();

                this._templateHeader = null;

                Compile(templateLocation);

                if (_assembly != null)
                {
                    Type            type = _assembly.GetTypes()[0];
                    ConstructorInfo info = type.GetConstructor(new Type[] { typeof(Root), typeof(StringBuilder) });
                    object          o    = info.Invoke(new object[] { esMeta, _buffer });
                    MethodInfo      m    = type.GetMethod("Render");
                    m.Invoke(o, new object[] { this });
                }
            }
            catch (TargetInvocationException tie)
            {
                throw tie.InnerException;
            }
        }
        /// <summary>
        /// Compiles and executes a template, and also sets the current template information accordingly.
        /// </summary>
        /// <param name="esMeta">The esMeta object which holds the context needed for an EntitySpaces template to generate meaningful code.</param>
        /// <param name="templateLocation">The template file path.</param>
        public void Execute(Root esMeta, string templateLocation)
        {
            try
            {
                _buffer = new StringBuilder();

                this._templateHeader = null;

                Compile(templateLocation);

                if (_assembly != null)
                {
                    Type type = _assembly.GetTypes()[0];
                    ConstructorInfo info = type.GetConstructor(new Type[] { typeof(Root), typeof(StringBuilder) });
                    object o = info.Invoke(new object[] { esMeta, _buffer });
                    MethodInfo m = type.GetMethod("Render");
                    m.Invoke(o, new object[] { this });
                }
            }
            catch (TargetInvocationException tie)
            {
                throw tie.InnerException;
            }
        }
        /// <summary>
        /// Compiles a template, and set the current template information accordingly. Note that this does not execute the template.
        /// </summary>
        /// <param name="templateName">The template file path.</param>
        public void Compile(string templateName)
        {
            this._templateHeader = null;

            CachedTemplate cachedTemplate = TemplateCache.GetCachedTemplate(templateName, CompileAction.Compile);

            _codeBuilder = cachedTemplate.CodeBuilder;
            _assembly = cachedTemplate.CompiledAssembly;
            _results = cachedTemplate.CompilerResults;

            if (_results != null && _results.Errors.HasErrors)
            {
                throw new CompilerException(_results, this);
            }
        }
        /// <summary>
        /// This method only parses the template so we can get to the header info.
        /// </summary>
        /// <param name="templateName">The template file path.</param>
        public void Parse(string templateName)
        {
            this._templateHeader = null;

            CachedTemplate cachedTemplate = TemplateCache.GetCachedTemplate(templateName, CompileAction.ParseOnly);

            _codeBuilder = cachedTemplate.CodeBuilder;
            _assembly = cachedTemplate.CompiledAssembly;
            _results = cachedTemplate.CompilerResults;
        }