public static object WRptGenerateReportExpr(CallExpr ce, Generator.Ctx callerCtx)//(object tmplFileName, Expr outputFilesExpr) { var ctx = new Generator.Ctx(callerCtx); ctx.CreateValue(FuncDefs_Core.stateTryGetConst, string.Empty); var templateFileName = Convert.ToString(Generator.Generate(ce.args[0], ctx)); var outputFilesExpr = ce.args[1]; var sheetExprs = new List <Expr>(); int iSheet = 0; int blockNum = 0; var xr = new Xlsx.Reader(templateFileName); var lstStrTbl = new OPs.ListOfConst(xr.stringTable); ctx.CreateValue(XlsxR.Sheet.sStrTbl, lstStrTbl); foreach (var s in xr.EnumSheetInfos()) { var cells = new XlsxR.Sheet(s.sheetCells.ToArray(), xr.styles); var sheetExpr = cells.GetSheetExpr(s.sheetFile, ctx, outputFilesExpr, ref blockNum); sheetExprs.Add(new CallExpr(FuncDefs_Core._block, sheetExpr, XlsxR.PROGRESS("sheet", new ConstExpr(xr.sheetNames[iSheet])) )); iSheet++; } ; var loopRef = new ReferenceExpr("sheet"); var res = CallExpr.Eval( CallExpr.let(new ConstExpr(XlsxR.Sheet.sTmplFiles), new ConstExpr(xr.xmlFiles)), CallExpr.let(new ConstExpr(XlsxR.Sheet.sStrTbl), new ConstExpr(lstStrTbl)), XlsxR.PROGRESS("sheets", new ConstExpr(new OPs.ListOfConst(xr.sheetNames))), new CallExpr(FuncDefs_Core._ForEach, loopRef, new ArrayExpr(sheetExprs), loopRef), new CallExpr((Fxy)WRptCopyFiles, new ConstExpr(xr.xmlFiles), outputFilesExpr), new CallExpr((Fx)WRptWriterDone, outputFilesExpr) ); return(res); }
/// <summary> /// Iterative topological sorting of expressions (ability of calculated values names is taked into account) /// </summary> /// <param name="srcItems"></param> /// <param name="parentCtx"></param> /// <returns></returns> public static IEnumerable <Expr> DoSort2(IEnumerable <Expr> srcItems, Generator.Ctx parentCtx) { var items = new List <Expr>(srcItems); var mh = new ModifyHelper(); var allLets = new Dictionary <string, Expr>(); while (true) { mh.ctx = new Generator.Ctx(parentCtx); mh.ctx.CreateValue(FuncDefs_Core.stateTryGetConst, string.Empty); for (int i = 0; i < items.Count; i++) { var item = items[i]; item = mh.modify(item); items[i] = item; foreach (var letName in mh.lets) { allLets[letName] = item; //mh.ctx.CreateValue(letName); } mh.lets.Clear(); } { var values = mh.ctx.values; var lets = new List <Expr>(); foreach (var p in mh.ctx.name2ndx) { if (p.Value == 0) { continue; } var v = values[p.Value]; if (v == null || allLets.ContainsKey(p.Key) || OPs.KindOf(v) != ValueKind.Const) { continue; } var le = CallExpr.let(new ReferenceExpr(p.Key), new ConstExpr(v)); allLets.Add(p.Key, le); lets.Add(le); } if (lets.Count > 0) { items.InsertRange(0, lets); } } if (!mh.thereIsNameResolve && !mh.thereIsNonresolved) { break; } mh.thereIsNonresolved = mh.thereIsNameResolve = false; items = TopoSort.DoSort(items, e => EnumRefs(e) .Where(s => s != null && allLets.ContainsKey(s)) .Select(s => allLets[s]) ); allLets.Clear(); } return(items); }