Beispiel #1
0
        /// <summary>
        /// Runs the style instruction.
        /// </summary>
        /// <param name="ins">The ins.</param>
        /// <returns></returns>
        /// <remarks>This is for mutliple execution</remarks>
        /// <exception cref="System.NotImplementedException">No implementation for: " + ins.type.ToString()</exception>
        protected appendType runStyleInstruction(docScriptInstruction ins)
        {
            //if (!hasDocRender)
            //{
            //    return ins.type;
            //}

            switch (ins.type)
            {
            case appendType.s_settings:

                if (ins.containsKey(d.dsa_background))
                {
                    string bgColor = ins.getProperString(Color.White.ColorToHex(), d.dsa_background);
                    string fgColor = ins.getProperString(Color.Black.ColorToHex(), d.dsa_forecolor);

                    docRender.ApplyColor(bgColor, null, false);
                    docRender.ApplyColor(fgColor, null, true);
                }
                else if (ins.containsKey(d.dsa_innerAppend))
                {
                    appendType           ap_type = ins.getProperEnum <appendType>(appendType.regular, d.dsa_innerAppend);
                    appendRole           ap_role = ins.getProperEnum <appendRole>(appendRole.paragraph, d.dsa_styleTarget);
                    styleApplicationFlag ap_flag = ins.getProperEnum <styleApplicationFlag>(styleApplicationFlag.allShots, d.dsa_stylerSettings);

                    styleAutoShotSet         _shot = new styleAutoShotSet(ap_flag, ap_type, ap_role);
                    List <IStyleInstruction> shots = _shot.resolve(theme);
                    foreach (IStyleInstruction sh in shots)
                    {
                        docRender.ApplyStyle(sh, render.c.getPencil(pencilType.point, 1));
                    }
                }
                else if (ins.containsKey(d.dsa_variationRole))
                {
                    aceColorPalette palette = ins.getProperObject <aceColorPalette>(d.dsa_stylerSettings, null);
                    int             var     = ins.getProperInt32(0, d.dsa_variationRole);

                    acePaletteShotResEnum res = ins.getProperEnum <acePaletteShotResEnum>(acePaletteShotResEnum.background, d.dsa_styleTarget);
                    Color col = palette.bgColors[var];
                    switch (res)
                    {
                    case acePaletteShotResEnum.foreground:
                        col = palette.fgColors[var];
                        break;

                    case acePaletteShotResEnum.background:
                        col = palette.bgColors[var];
                        break;

                    case acePaletteShotResEnum.border:
                        col = palette.tpColors[var];
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    docRender.ApplyColor(col.ColorToHex());
                    render.c.enter();
                }

                break;

            case appendType.s_width:

                int  key          = ins.getProperInt32(0, d.dsa_key);
                int  val          = ins.getProperInt32(0, d.dsa_value);
                bool isHorizontal = ins.isHorizontal;
                var  corner       = ins.getProperEnum <textCursorZoneCorner>(textCursorZoneCorner.none, d.dsa_cursorCorner);
                bool isAutofit    = (bool)ins.get(d.dsa_autostyling, false);
                if (isHorizontal)
                {
                    docRender.ApplyColumn(key, val, corner, isAutofit);
                }
                else
                {
                    docRender.ApplyRow(key, val, corner, isAutofit);
                }

                break;

            case appendType.s_variation:

                throw new NotImplementedException("No implementation for: " + ins.type.ToString());
                break;

            case appendType.s_style:

                selectRangeArea area = resolveAreaForStyleShot(ins[d.dsa_styleTarget]);     //.get(d.dsa_styleTarget));

                if (ins.containsAllOfKeys(d.dsa_autostyling, d.dsa_styleTarget))
                {
                    styleApplicationFlag flag = ins.getProperEnum <styleApplicationFlag>(styleApplicationFlag.none, d.dsa_autostyling);

                    styleAutoShotSet shot = new styleAutoShotSet(flag);

                    styleStack.Add(shot, area);
                }
                else if (ins.containsAllOfKeys(d.dsa_stylerSettings, d.dsa_styleTarget))
                {
                    IStyleInstruction shot = ins[d.dsa_stylerSettings] as IStyleInstruction;

                    if (shot == null)
                    {
                        throw new ArgumentNullException("dsa_stylerSettings", "docScript.s_style(null) - no IStyleInstruction for this instruction");
                    }
                    else
                    {
                        styleStack.Add(shot, area);
                    }
                }
                else
                {
                }
                break;

            case appendType.s_zone:
                if (ins.containsAnyOfTypes(typeof(textCursorZone)))
                {
                    render.c.switchToZone(ins.getProperEnum <textCursorZone>(textCursorZone.unknownZone), ins.getProperEnum <textCursorZoneCorner>(textCursorZoneCorner.default_corner));
                }
                else if (ins.containsAnyOfTypes(typeof(cursorSubzoneFrame)))
                {
                    // prosledjena mu je zona
                    render.c.setTempFrame(ins.getProperEnum <cursorSubzoneFrame>(cursorSubzoneFrame.fullFrame), ins.getProperEnum <textCursorZoneCorner>(textCursorZoneCorner.default_corner));
                }
                else if (ins.containsAnyOfTypes(typeof(cursorZoneRole)))
                {
                    cursorZoneRole zr  = ins.getProperEnum <cursorZoneRole>(cursorZoneRole.master);
                    int            szi = ins.getProperInt32(0, docScriptArguments.dsa_value, docScriptArguments.dsa_level, docScriptArguments.dsa_priority);
                    render.c.setToSubFrame(zr, szi);
                }
                else
                {
                    throw new ArgumentNullException(ins.type.ToString(), "Minimum applicable docScriptArguments are missing - can't execute instruction like this");
                }
                break;

            case appendType.s_alternate:

                theme.styler.isDisabled = false;
                break;

            case appendType.s_normal:
                theme.styler.isDisabled = true;
                break;

            case appendType.s_palette:
                acePaletteRole newRole = (acePaletteRole)ins.getProperField(d.dsa_paletteRole);
                if (ins.containsAnyOfKeys(d.dsa_dataTable, d.dsa_dataPairs, d.dsa_zoneFrame, d.dsa_variationRole))
                {
                    theme.styler.layoutPaletteRole = newRole;
                }
                else
                {
                    theme.styler.mainPaletteRole = newRole;
                }
                break;

            default:
                //executionError(String.Format("Instruction ({0}) not supported by runStyleInstruction() method", ins.type.ToString()), ins);
                //executionError(String.Format("Instruction ({0}) not supported by runSpecialInstruction() method", ins.type.ToString()), ins);
                return(ins.type);

                break;
            }

            return(appendType.none);
        }
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);
        }