Exemplo n.º 1
0
        private TemplateEngine(string path, ITemplateContext ctx, ICache<string, TemplateAST> cache, ExpressionLanguageEngineConfig cfg)
        {
            _ctx = ctx ?? new TemplateContext();
            _cache = cache ?? NoCache.GetInstance<string, TemplateAST>();
            _cfg = cfg ?? ExpressionLanguageEngineConfig.Default;

            if (string.IsNullOrEmpty(path))
                _path = Runtime.StartupDirectory;
            else
                _path = System.IO.Path.GetFullPath(path);
        }
 protected override void DoCheck(IValidateResult result, object instance, object propertyValue)
 {
     //Extend:use cache to improve performance.
     ExpressionLanguageEngineConfig cfg = new ExpressionLanguageEngineConfig(EvalExceptionHandlingPolicy.IgnorePolicy);
     ExpressionLanguageEngine engine = ExpressionLanguageEngine.CreateEngine(cfg);
     engine.Assign(INSTANCE, instance);
     engine.Assign(VALUE, propertyValue);
     object b = engine.Eval(_expr);
     if (!engine.EvalToBool(b))
     {
         string msg = string.Format(MSG, _pInfo.Name, instance.GetType().Name, propertyValue, _expr);
         this.LogValidateResult(result, msg);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Build up a template engine.
 /// </summary>
 /// <param name="path">All template files is supposed in a specified directory(include sub directory).
 ///                    If it is null, will use current app directory.
 /// </param>
 /// <param name="ctx">Template context, also work as EL context when eval expresion in the template.</param>
 /// <param name="cache">Template AST cache.</param>
 /// <param name="cfg">the EL engine (which used in eval expression in the template) create config.</param>
 /// <returns>Instance of template engine.</returns>
 public static TemplateEngine CreateInstance(string path = null, ITemplateContext ctx = null, ICache<string, TemplateAST> cache = null, ExpressionLanguageEngineConfig cfg = null)
 {
     return new TemplateEngine(path, ctx, cache, cfg);
 }
Exemplo n.º 4
0
        public static ExpressionLanguageEngine CreateEngine(ExpressionLanguageEngineConfig cfg, IEvalContext ctx = null)
        {
            cfg.ThrowIfNullArgument(nameof(cfg));

            return(new ExpressionLanguageEngine(ctx, cfg.Policy, cfg.FallbackValue, cfg.Cache));
        }