Ejemplo n.º 1
0
        protected appendType executeOnce(docScriptInstruction ins, appendTypeKind kind)
        {
            // log("--- execution method: " + kind.ToString());
            appendType output = ins.type;

            if (!settings.supportedAppends.Contains(ins.type))
            {
                log("Ignoring instruction: {0} ({2}) -- not supported by builder: {1}".f(ins.type.ToString(), render.GetType().Name, kind.ToString()));
                return(ins.type);
            }

            if (output != appendType.none)
            {
                output = runSpecialInstruction(ins);
            }
            if (output != appendType.none)
            {
                output = runOtherInstruction(ins);
            }

            return(output);
        }
        /// <summary>
        /// Executes the and save.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="runstamp">The runstamp.</param>
        /// <param name="__data">The data.</param>
        protected void execute(metaDocumentRootSet report, string runstamp, PropertyCollection __data = null)
        {
            dataDictionary = new PropertyCollectionDictionary();

            if (!unit.scriptFlags.HasFlag(docScriptFlags.disableGlobalCollection))
            {
                logStartPhase("Collect data", "#2 phase of data collecting");
                dataDictionary = report.collect(dataDictionary);
                logEndPhase();
            }
            else
            {
                log("Global data collection disabled by unit.scriptFlags");
            }

            logStartPhase("Script composing", "#3 phase of data composing");

            script       = new docScript("Script - unit[" + unit.name + "] - runstamp: " + runstamp);
            script.flags = unit.scriptFlags;

            script = report.compose(script);
            if (doBuildDeliveryMeta)
            {
                string scMeta = script.ToString(docScriptInstructionTextFormatEnum.meta);
                scMeta.saveStringToFile(directoryRoot.FullName.add("deliveryMeta.md", "\\"), getWritableFileMode.autoRenameExistingOnOtherDate, Encoding.UTF8);

                string csMeta = script.ToString(docScriptInstructionTextFormatEnum.cs_compose);
                csMeta.saveStringToFile(directoryRoot.FullName.add("deliveryMeta.cs", "\\"), getWritableFileMode.autoRenameExistingOnOtherDate, Encoding.UTF8);
            }

            logEndPhase();

            setup(unit.theme, data, renders.getTextRenders());

            logStartPhase("Script compilation", "#4 applying data to content");

            compiled = compile(script, dataDictionary);

            repo = new reportOutputRepository(directoryRoot, script.name);

            logStartPhase("Execute docScriptInstructions ", "5# executing scripttotal instructions (" + script.Count() + ")");

            index = 0;
            int tIndex = 1000;

            int mediumTimerLimit = 10;
            int mediumTimerIndex = 0;

            foreach (docScriptInstructionCompiled instruction in compiled)
            {
                try
                {
                    appendTypeKind kind = instruction.type.getAppendTypeKind();

                    if (doVerboseLog)
                    {
                        log(index.ToString("D4") + " " + instruction.ToString(docScriptInstructionTextFormatEnum.meta));
                    }

                    //afinal = appendType.none;

                    appendType final = executeOnce(instruction, kind);

                    if (final != appendType.none)
                    {
                        final = runStyleInstruction(instruction);
                    }

                    if (final == appendType.none)
                    {
                    }
                    else
                    {
                        var scopeLevel = scope.elementLevel;

                        foreach (var it in unit.outputByLevel[scopeLevel])
                        {
                            deliveryUnitItemSimpleRenderOutput output = it as deliveryUnitItemSimpleRenderOutput;

                            if (output != null)
                            {
                                output.executeScriptInstruction(this, instruction);
                                final = appendType.none;
                                //  builder = output.builder;
                            }
                        }
                    }

                    if (executionStopFlagCheck())
                    {
                        log("Execution is stopped by executionStopFlag!");
                        break;
                    }

                    index++;
                }
                catch (Exception ex)
                {
                    string msg = Environment.NewLine + "Report script execution [" + index + "/" + compiled.Count() + "] error. Instruction: [" + instruction.ToString(docScriptInstructionTextFormatEnum.cs_compose) + "]";
                    msg = msg.addLine("-- scoped meta object: path:[" + scope.path + "] -- [" + scope.name + "] -- [" + scope.GetType().Name + "]");
                    msg = msg.addLine("-- directory: [" + directoryScope.FullName + "]");
                    msg = msg.addLine("-- exception: [" + ex.GetType().Name + "] => [" + ex.Message + "]");

                    var axe = new aceReportException(msg + "Report instruction [" + instruction.type.ToString() + "] exception");
                    //if (axe.callInfo != null)
                    //{
                    //    msg = msg.addLine("-- source of ex: [" + axe.callInfo.sourceCodeLine + "]");
                    //    msg = msg.addLine("-- source file:  [" + axe.callInfo.Filepath + "]");
                    //    msg = msg.addLine("-- source line:  [" + axe.callInfo.line + "]");
                    //    msg = msg.addLine("-- source class:  [" + axe.callInfo.className + "]");
                    //}

                    log(msg + Environment.NewLine);
                    string path = "errorReport_" + index.ToString() + ".txt";
                    path = directoryScope.FullName.add(path, "\\");
                    msg.saveStringToFile(path, getWritableFileMode.autoRenameExistingOnOtherDate, Encoding.UTF8);

                    if (errorPolicy.doThrow())
                    {
                        throw axe;
                    }
                    executionError("Internal exception during an instruction execution", instruction, ex);
                }

                #region ----------------------------------

                if (compiled.Count() > 1000)
                {
                    if (tIndex > 0)
                    {
                        tIndex--;
                    }
                    else
                    {
                        mediumTimerIndex++;
                        double ratio = ((double)index) / ((double)compiled.Count());
                        aceLog.log("Report generation at [" + ratio.ToString("P") + "] done");
                        tIndex = 1000;
                    }
                }
                if (mediumTimerIndex > mediumTimerLimit)
                {
                    var memBefore = GC.GetTotalMemory(false);
                    GC.Collect();
                    var memBefore2 = memBefore - GC.GetTotalMemory(false);
                    aceLog.log("-- garbage collector invoked - memory released: " + memBefore2.getMByteCountFormated());
                    // aceLog.saveAllLogs(true);
                    mediumTimerIndex = 0;
                }

                #endregion ----------------------------------
            }

            GC.Collect();
            GC.WaitForFullGCComplete();

            logEndPhase();

            AppendPairs(data, false, " -> ");

            log("Completed");

            foreach (IDeliveryUnitItem item in unit.items)
            {
                item.reportFinishedOperation(this);
            }

            // aceLog.consoleControl.removeFromOutput(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the specified ins.
        /// </summary>
        /// <param name="ins">The ins.</param>
        /// <param name="kind">The kind.</param>
        /// <returns></returns>
        protected virtual appendType execute(docScriptInstruction ins, appendTypeKind kind, appendType output)
        {
            //appendType output = ins.type;

            if (output != appendType.none)
            {
                output = runComplexInstruction(ins);
            }
            if (output != appendType.none)
            {
                output = runStyleInstruction(ins);
            }

            if (output != appendType.none)
            {
                string str = ins.getProperString(d.dsa_contentLine, d.dsa_title, d.dsa_description);

                appendRole role = ins.getProperEnum <appendRole>(appendRole.paragraph, d.dsa_role);

                styleTextShot tshot = null;

                styleContainerShot sshot = null;

                if (role != appendRole.none)
                {
                    tshot = new styleTextShot(role, theme);
                    sshot = new styleContainerShot(role, ins.type, theme);
                }
                else
                {
                    tshot = new styleTextShot(ins.type, theme);
                }

                List <string> lines = ins.getProperObject <List <string> >(d.dsa_content);

                if (lines == null)
                {
                    lines = ins.getFirstOfType <List <string> >(true);
                }

                if (!str.isNullOrEmpty())
                {
                    lines.Add(str);
                }

                if (lines.Any())
                {
                    foreach (string logLine in lines)
                    {
                        if (hasDocRender)
                        {
                            if (tshot != null)
                            {
                                docRender.ApplyStyle(tshot, render.c.getPencil(pencilType.point, 1));
                            }
                            if (sshot != null)
                            {
                                docRender.ApplyStyle(sshot, render.c.getPencil(pencilType.point, 1));
                            }
                        }
                        render.Append(logLine, ins.type, !ins.isHorizontal);
                    }
                }
                else
                {
                    if (script.flags.HasFlag(docScriptFlags.ignoreArgumentValueNull))
                    {
                        if (doVerboseLog)
                        {
                            log("Simple append called but no content nor contentLine provided");
                        }
                    }
                    else
                    {
                        executionError("Simple append called but no content nor contentLine provided", ins);
                    }
                }
            }

            return(output);
        }