/// <summary>
        /// Adds the specified ins.
        /// </summary>
        /// <param name="ins">The ins.</param>
        /// <returns></returns>
        public docScriptInstructionCompiled compile(docScriptInstruction ins, IRenderExecutionContext log, PropertyCollectionDictionary __indata, PropertyCollection __extraData, docScriptFlags flags)
        {
            docScriptInstructionCompiled instructionCompiled = new docScriptInstructionCompiled(ins, flags);

            try
            {
                PropertyCollectionDictionary indata    = __indata;
                PropertyCollection           extraData = __extraData;

                if (ins.type == appendType.x_scopeIn)
                {
                    currentDataPath = ins.getProperString(d.dsa_path);
                }
                else if (ins.type == appendType.x_scopeOut)
                {
                    currentDataPath = currentDataPath.getPathVersion(1, "\\", true);
                }

                PropertyCollection dataItem = null;
                if (indata != null)
                {
                    var tmp = indata[currentDataPath];
#pragma warning disable CS0184 // The given expression is never of the provided ('DictionaryEntry') type
                    if (tmp is DictionaryEntry)
#pragma warning restore CS0184 // The given expression is never of the provided ('DictionaryEntry') type
                    {
                        //DictionaryEntry entry = (DictionaryEntry)tmp;
                        //dataItem = entry.Value as PropertyCollection;
                    }
                    else
                    {
                        dataItem = tmp as PropertyCollection;
                    }
                }

                /// Compiling data into template
                instructionCompiled.compileTemplate(dataItem, extraData);

                if (instructionCompiled.isCompileFailed)
                {
                    string msg = scriptInstructions.Count().ToString("D4") + " " + ins.type.ToString() + " failed on: " + instructionCompiled.missingData.toCsvInLine();
                    if (flags.HasFlag(docScriptFlags.ignoreCompilationFails))
                    {
                        log.log(msg);
                    }
                    else
                    {
                        log.compileError(msg, instructionCompiled);
                    }

                    if (flags.HasFlag(docScriptFlags.allowFailedInstructions))
                    {
                        scriptInstructions.Add(instructionCompiled);
                    }
                    scriptInstructionsFailed.Add(instructionCompiled);
                }
                else
                {
                    scriptInstructions.Add(instructionCompiled);

                    if (instructionCompiled.isCompilable)
                    {
                        // log.log("--- compiled Strings(" + instructionCompiled.keyListForStrings.Count + ") and StringCollections(" + instructionCompiled.keyListForStringCollections.Count + ")");
                    }
                }

                missingData.AddRange(instructionCompiled.missingData);
            }
            catch (Exception ex)
            {
            }
            return(instructionCompiled);
        }
Beispiel #2
0
        /// <summary>
        /// Runs the special instruction.
        /// </summary>
        /// <param name="ins">The ins.</param>
        /// <remarks>THIS IS NOT FOR LOOP EXECUTION</remarks>
        /// <returns></returns>
        protected appendType runSpecialInstruction(docScriptInstruction ins)
        {
            string externalPath = "";

            externalPath = ins.getProperString("temp", d.dsa_path);
            FileInfo   efi;
            string     dsaName     = ins.getProperString(d.dsa_name);
            appendType innerAppend = ins.getProperEnum <appendType>(appendType.regular, d.dsa_innerAppend);

            // reportOutputFormatName form = builder.format; //ins.getProperEnum<reportOutputFormatName>(render.formats.getDefaultFormat(), d.dsa_format);

            switch (ins.type)
            {
            //case appendType.i_chart:
            //    throw new NotImplementedException("No implementation for: " + ins.type.ToString());
            //    break;
            case appendType.i_meta:
                data.add(ins.getProperField(d.dsa_key, d.dsa_name, d.dsa_path) as Enum, ins.getProperField(d.dsa_value, d.dsa_contentLine, d.dsa_content, d.dsa_dataList));
                break;

            case appendType.x_data:
                addOrUpdateStateData(data);
                break;

            case appendType.i_dataSource:
                //if (render is IDocumentRender)
                //{
                //    //render.AppendData(ins.getFirstOfType<PropertyCollection>(), ins.getProperEnum<existingDataMode>(existingDataMode.overwriteExisting), false);
                //}
                //else
                //{
                //}

                data.AppendData(ins.getFirstOfType <PropertyCollection>(), ins.getProperEnum <existingDataMode>(existingDataMode.overwriteExisting));
                break;

            case appendType.x_scopeIn:
                string             scopePath = ins.getProperString(d.dsa_path);
                IMetaContentNested newScope  = ins.getProperField(d.dsa_value) as IMetaContentNested;
                if (newScope == null)
                {
                }
                x_scopeIn(newScope);

                break;

            case appendType.x_scopeOut:
                x_scopeOut();

                break;

            case appendType.i_load:

                string importPath = ins.getProperString(d.dsa_path);

                List <string> importLines = new List <string>();

                appendType imType = ins.getProperEnum <appendType>(appendType.i_document, d.dsa_innerAppend);
                if (imType == appendType.i_document)     // load document
                {
                    // render.loadDocument(importPath, dsaName, form);
                }
                else if (imType == appendType.i_page)     // load page
                {
                    // render.loadPage(importPath, dsaName, form);
                }
                else     /// -------------------------------------- import lines/content
                {
                    importLines = importPath.openFileToList(false);
                    foreach (string line in importLines)
                    {
                        render.Append(line, imType, true);
                    }
                }

                break;

            case appendType.i_external:

                efi = externalPath.getWritableFile(getWritableFileMode.newOrExisting);
                List <string> externalLines = efi.openFileToList(false);

                bool       reCompile = ins.containsAnyOfKeys(d.dsa_recompile);
                appendType apType    = ins.getProperEnum <appendType>(appendType.regular, d.dsa_innerAppend);
                ins.add(d.dsa_content, externalLines, false);

                //docScriptInstruction cins = ins;

                if (reCompile)
                {
                    // recompilation     d.dsa_recompile
                    docScriptInstructionCompiled cins = new docScriptInstructionCompiled(ins, script.flags);
                    //scope.path;
                    cins.compileTemplate(data);
                    //{
                    //compileInstruction(ins);/                    }
                    if (apType != appendType.none)     // internal append       dsa_innerAppend
                    {
                        execute(cins, apType.getAppendTypeKind(), apType);
                    }
                }
                break;

            case appendType.i_log:
                string        logStr   = ins.getProperString(d.dsa_contentLine, d.dsa_title, d.dsa_description);
                List <string> logLines = ins.getProperObject <List <string> >(d.dsa_content);

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

                if (!logStr.isNullOrEmpty())
                {
                    logLines.Add(logStr);
                }

                if (logLines.Any())
                {
                    foreach (string logLine in logLines)
                    {
                        log("ins> " + logLine);
                    }
                }
                else
                {
                    error("Log was called but no line/s passed with instruction", ins.type);
                }
                break;
            //case appendType.i_page:
            //    var newPage = render.addPage(dsaName, ins.containsAnyOfKeys(d.dsa_scopeToNew), getWritableFileMode.autoRenameThis, form);

            //    break;
            //case appendType.i_document:
            //    render.addDocument(dsaName, ins.containsAnyOfKeys(d.dsa_scopeToNew), getWritableFileMode.autoRenameExistingOnOtherDate, form);

            //    break;

            case appendType.i_function:    // recompile,
                render.AppendFunction(ins.getProperField(d.dsa_contentLine, d.dsa_value).toStringSafe());
                break;

            case appendType.x_directory:
                directoryOperation op = ins.getProperEnum <directoryOperation>(directoryOperation.selectIfExists, d.dsa_dirOperation);
                op.doDirectoryOperation(externalPath, directoryScope, ins.containsAnyOfKeys(d.dsa_scopeToNew));
                break;

            case appendType.x_save:
                //if (innerAppend == appendType.i_document)
                //{
                //    efi = externalPath.getWritableFile(getWritableFileMode.newOrExisting);
                //    render.saveDocument(dsaName, getWritableFileMode.autoRenameExistingOnOtherDate, form);
                //} else if (innerAppend == appendType.i_page)
                //{
                //    //efi = externalPath.getWritableFile(getWritableFileMode.newOrExisting);

                //    render.savePage(externalPath, form);

                //} else

                if (innerAppend == appendType.i_log)
                {
                    externalPath = GetType().Name.add("log", "_").add(externalPath, "_").ensureEndsWith(".txt");
                    efi          = externalPath.getWritableFile(getWritableFileMode.newOrExisting);
                    // this.ToString().saveStringToFile(efi.FullName, getWritableFileMode.autoRenameExistingOnOtherDate);
                }
                else if (innerAppend == appendType.i_meta)
                {
                    if (ins.containsAnyOfKeys(d.dsa_metaContent, d.dsa_value, d.dsa_dataSource))
                    {
                        object itm = ins.getProperField(d.dsa_metaContent, d.dsa_value, d.dsa_dataSource);
                        if (itm != null)
                        {
                            objectSerialization.saveObjectToXML(itm, externalPath);
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("No meta content invoked :: ".add(innerAppend.ToString(), " inner:"));
                    }
                }
                else
                {
                    error("Save was called but no clue in innerAppend what to save", ins.type);
                }

                break;

            case appendType.x_openTool:
                /*
                 * externalTool exTool = ins.getProperEnum<externalTool>(externalTool.notepadpp, d.dsa_externalTool);
                 * if (externalPath == "temp" || externalPath.isNullOrEmpty()) externalPath = Path.GetTempFileName();
                 * if (ins.containsAnyOfKeys(d.dsa_path))
                 * {
                 *  exTool.run(externalPath);
                 * } else if (ins.containsAnyOfKeys(d.dsa_content, d.dsa_contentLine))
                 * {
                 *  List<string> lns = ins.getFirstOfType<List<string>>(true);
                 *  lns.Add(ins.getProperString("", d.dsa_contentLine));
                 *  saveBase.saveToFile(externalPath, lns);
                 *  exTool.run(externalPath);
                 * } else if (ins.containsAnyOfKeys(d.dsa_metaContent, d.dsa_value, d.dsa_dataSource))
                 * {
                 *  object itm = ins.getProperField(d.dsa_metaContent, d.dsa_value, d.dsa_dataSource);
                 *  if (itm != null)
                 *  {
                 *      objectSerialization.saveObjectToXML(itm, externalPath);
                 *  }
                 *  exTool.run(externalPath);
                 * } else
                 * {
                 *  exTool.run();
                 * }
                 */
                break;
            //case appendType.x_export:
            //    builder.sessionManager.setContext(this);
            //    appendType act = ins.getProperEnum<appendType>(appendType.none, d.dsa_innerAppend);
            //    String sessionname = ins.getProperString(d.dsa_path);
            //    reportOutputFormatName __format = ins.getProperEnum<reportOutputFormatName>(reportOutputFormatName.textMdFile, d.dsa_format);

            //    switch (act)
            //    {
            //        case appendType.x_subcontent:

            //            break;
            //        case appendType.c_open:
            //            reportAPI api = ins.getProperEnum<reportAPI>(reportAPI.imbMarkdown, d.dsa_styleTarget);
            //            elementLevelFormPreset preset = ins.getProperEnum<elementLevelFormPreset>(elementLevelFormPreset.none, d.dsa_stylerSettings);
            //            builder.sessionManager.startNewSession(sessionname, __format, api, preset);

            //            break;
            //        case appendType.c_close:
            //            builder.sessionManager.endSession(sessionname, __format);
            //            break;
            //    }
            //    break;
            case appendType.x_move:

                bool movezone   = Convert.ToBoolean(ins.getProperField(d.dsa_zoneFrame));
                bool isRelative = Convert.ToBoolean(ins.getProperField(d.dsa_relative));

                if (ins.containsKey(d.dsa_vector))
                {
                    selectRange vector = ins.getProperField(d.dsa_vector) as selectRange;

                    if (movezone)
                    {
                        render.zone.margin.moveTopLeftByVector(vector);
                    }
                    else
                    {
                        render.c.moveByVector(vector, isRelative);
                    }
                }
                else if (ins.containsKey(d.dsa_cursorCorner))
                {
                    textCursorZoneCorner direction = ins.getProperEnum <textCursorZoneCorner>(textCursorZoneCorner.none, d.dsa_cursorCorner);
                    if (direction != textCursorZoneCorner.none)     // move in direction, for 1 or more steps
                    {
                        int steps = ins.getProperInt32(1, d.dsa_value, d.dsa_x, d.dsa_y, d.dsa_w, d.dsa_h);

                        if (isRelative)
                        {
                            selectRange vector = direction.toVector(steps);

                            if (movezone)
                            {
                                render.zone.margin.moveTopLeftByVector(vector, true);
                            }
                            else
                            {
                                render.c.moveInDirection(direction, steps);
                            }
                        }
                        else
                        {
                            render.c.moveToCorner(direction);
                        }
                    }
                }
                else if (ins.containsAnyOfKeys(d.dsa_w, d.dsa_h, d.dsa_x, d.dsa_y))
                {
                    int x = ins.getProperInt32(0, d.dsa_x, d.dsa_w);
                    int y = ins.getProperInt32(0, d.dsa_y, d.dsa_h);

                    selectRange vector = new selectRange(x, y);

                    if (movezone)
                    {
                        render.zone.margin.moveTopLeftByVector(vector, isRelative);
                    }
                    else
                    {
                        if (isRelative)
                        {
                            render.c.moveFor(x, y);
                        }
                        else
                        {
                            render.c.moveTo(x, y);
                        }
                    }
                }

                //if (movezone)
                //{
                //    render.c.setMarginHere(textCursorZoneCorner.UpLeft);
                //    render.c.moveToCorner(textCursorZoneCorner.UpLeft);
                //}

                break;

            case appendType.i_dataInDocument:
                templateFieldBasic[] flds = new templateFieldBasic[0];
                if (hasDocRender)
                {
                    // docRender.AppendInfo(ins.getFirstOfType<PropertyCollection>(), false, ins.getProperEnum<templateFieldBasic[]>(flds));
                }
                if (ins.containsAnyOfKeys(d.dsa_value))
                {
                    data.AppendData(ins.getFirstOfType <PropertyCollection>(), ins.getProperEnum <existingDataMode>(existingDataMode.overwriteExisting));
                }

                break;

            default:

                return(ins.type);

                break;
            }
            return(appendType.none);
        }