コード例 #1
0
ファイル: ViewEngine.cs プロジェクト: lht6/Furion
        /// <summary>
        /// 通过缓存解析模板
        /// </summary>
        /// <param name="content"></param>
        /// <param name="model"></param>
        /// <param name="cacheFileName"></param>
        /// <param name="builderAction"></param>
        /// <returns></returns>
        public async Task <string> RunCompileFromCachedAsync <T>(string content, T model, string cacheFileName = default, Action <IViewEngineOptionsBuilder> builderAction = null)
            where T : class, new()
        {
            var fileName = cacheFileName ?? MD5Encryption.Encrypt(content);

            IViewEngineTemplate <ViewEngineModel <T> > template;

            if (File.Exists(Penetrates.GetTemplateFileName(fileName)))
            {
                template = await ViewEngineTemplate <ViewEngineModel <T> > .LoadFromFileAsync(fileName);
            }
            else
            {
                template = await CompileAsync <ViewEngineModel <T> >(content, builderAction);

                await template.SaveToFileAsync(fileName);
            }

            var result = await template.RunAsync(u =>
            {
                u.Model = model;
            });

            return(result);
        }
コード例 #2
0
ファイル: ViewEngine.cs プロジェクト: lht6/Furion
        /// <summary>
        /// 通过缓存解析模板
        /// </summary>
        /// <param name="content"></param>
        /// <param name="model"></param>
        /// <param name="cacheFileName"></param>
        /// <param name="builderAction"></param>
        /// <returns></returns>
        public string RunCompileFromCached(string content, object model = null, string cacheFileName = default, Action <IViewEngineOptionsBuilder> builderAction = null)
        {
            var fileName = cacheFileName ?? MD5Encryption.Encrypt(content);

            IViewEngineTemplate template;

            if (File.Exists(Penetrates.GetTemplateFileName(fileName)))
            {
                template = ViewEngineTemplate.LoadFromFile(fileName);
            }
            else
            {
                template = Compile(content, builderAction);
                template.SaveToFile(fileName);
            }

            var result = template.Run(model);

            return(result);
        }
コード例 #3
0
ファイル: ViewEngine.cs プロジェクト: cfqdream/Furion
        /// <summary>
        /// 通过缓存解析模板
        /// </summary>
        /// <param name="content"></param>
        /// <param name="model"></param>
        /// <param name="cacheFile"></param>
        /// <param name="builderAction"></param>
        /// <returns></returns>
        public async Task <string> RunCompileFromCachedAsync(string content, object model = null, string cacheFile = default, Action <IViewEngineOptionsBuilder> builderAction = null)
        {
            var fileName = cacheFile ?? MD5Encryption.Encrypt(content);

            IViewEngineTemplate template;

            if (File.Exists(Penetrates.GetTemplateFileName(fileName)))
            {
                template = await ViewEngineTemplate.LoadFromFileAsync(fileName);
            }
            else
            {
                template = await CompileAsync(content, builderAction);

                await template.SaveToFileAsync(fileName);
            }

            var result = await template.RunAsync(model);

            return(result);
        }