Пример #1
0
 public static FuncDefs CoreFuncDefs()
 {
     lock (typeof(DataLoader))
         if (funcDefs == null)
         {
             funcDefs = new FuncDefs().AddFrom(typeof(FuncDefs_Core));
         }
     return(funcDefs);
 }
Пример #2
0
        static Contexts GetCtxForCode(Contexts parent, string codeText)
        {
            var obj = FuncDefs_Core._Cached($"$Contexts_{codeText.GetHashCode()}", (Func <object>)(() =>
            {
                var res = new Contexts();

                //***** формируем по тексту синтаксическое дерево
                var e = Parser.ParseToExpr(codeText);

                if (parent == null)
                {
                    var funcDefs = new W.Expressions.FuncDefs()
                                   .AddFrom(typeof(W.Expressions.FuncDefs_Core))
                                   .AddFrom(typeof(W.Expressions.FuncDefs_Excel))
                                   .AddFrom(typeof(W.Expressions.FuncDefs_Report))
                    ;
                    var valsDefs = new Dictionary <string, object>();
                    //***** создаём контекст кодогенератора, содержащий предопределённые значения и перечень функций
                    res.gCtx = new Generator.Ctx(valsDefs, funcDefs.GetFuncs);
                    //***** формируем код
                    var g = Generator.Generate(e, res.gCtx);
                    //***** проверяем, заданы ли выражения для всех именованных значений
                    try { res.gCtx.CheckUndefinedValues(); }
                    catch (W.Expressions.Generator.Exception ex) { throw new UndefinedValuesException(ex.Message); }
                    res.eCtx = new AsyncExprRootCtx(res.gCtx.name2ndx, res.gCtx.values, OPs.GlobalMaxParallelismSemaphore);
                }
                else
                {
                    //***** создаём контекст кодогенератора, содержащий предопределённые значения и перечень функций
                    res.gCtx = new Generator.Ctx(parent.gCtx);
                    //***** формируем код
                    var g = Generator.Generate(e, res.gCtx);
                    //***** проверяем, заданы ли выражения для всех именованных значений
                    try { res.gCtx.CheckUndefinedValues(); }
                    catch (W.Expressions.Generator.Exception ex) { throw new UndefinedValuesException(ex.Message); }
                    res.eCtx = new AsyncExprCtx(res.gCtx, res.gCtx.values, parent.eCtx);
                }
                return(res);
            }), DateTime.UtcNow.AddMinutes(5), ObjectCache.NoSlidingExpiration);

            return((Contexts)obj);
        }