/// <summary> /// Gets the script in another <see cref="commandLineFormat"/> /// </summary> /// <param name="console">The console.</param> /// <param name="format">The format.</param> /// <param name="newPath">The new path.</param> /// <returns></returns> public aceConsoleScript GetScriptInForm(IAceCommandConsole console, commandLineFormat format, String newPath = null) { String p = newPath; if (p.isNullOrEmpty()) { p = path; } //if (File.Exists(p)) aceConsoleScript output = new aceConsoleScript(p, false); foreach (String st in this) { aceCommandEntry entry = new aceCommandEntry(console, st); try { if (!entry.isSyntaxError) { output.Append(entry.GetScriptLine(format)); } else { output.Append(commandLineEntry.commentPrefix + " line: " + entry.inputLine + " - error: " + entry.errorMessage); } } catch (Exception ex) { output.Append("// error in line transformation: " + entry.inputLine); output.Append("// " + ex.toStringSafe()); output.Append("// " + ex.Message); } } if (!newPath.isNullOrEmpty()) { output.SaveAs(newPath, getWritableFileMode.overwrite, console.output); } return(output); }
/// <summary>Processing script into selected form</summary> /// <remarks><para>It will load the specified script and process it into selected format</para></remarks> /// <param name="script">Filename of script file to process</param> /// <param name="format">Format to process script into</param> /// <param name="askForFormat">Prompt user to choose the format</param> /// <seealso cref="aceOperationSetExecutorBase"/> public void aceOperation_scriptProcess( [Description("Filename of script file to process")] String script = "script.ace", [Description("Format to process script into")] commandLineFormat format = commandLineFormat.explicitFormat, [Description("Prompt user to choose the format")] Boolean askForFormat = true) { if (script == "*") { var list = workspace.getScriptList(); script = aceTerminalInput.askForOption("Select script file to load", list.First(), list, null).toStringSafe(); } if (askForFormat) { format = (commandLineFormat)aceTerminalInput.askForOption("Choose command format to be applied on the specified ACE script.", format); } var ace_script = workspace.loadScript(script); String scriptName = aceTerminalInput.askForString("Please enter filename for reformatted script:", ace_script.info.Name); var newScript = ace_script.GetScriptInForm(this, format, workspace.folder[aceCCFolders.scripts].pathFor(scriptName)); }
IAceConsoleScript IAceConsoleScript.GetScriptInForm(IAceCommandConsole console, commandLineFormat format, string newPath) => GetScriptInForm(console, format, newPath);
/// <summary> /// Returns the string form of the command with current parameters /// </summary> /// <param name="format">The format.</param> /// <returns></returns> public String GetScriptLine(commandLineFormat __format = commandLineFormat.explicitFormat) { String output = ""; if (hasCommand) { switch (__format) { case commandLineFormat.emptyLine: output = ""; break; case commandLineFormat.explicitFormat: if (carg.paramSet != null) { output = command.add(carg.paramSet.ToString(false, true, true), " "); } else { output = command; } break; case commandLineFormat.implicitFormat: if (carg.paramSet != null) { output = command.add(carg.paramSet.ToString(false, true, false), " "); } else { output = command; } break; case commandLineFormat.onlyCommand: output = command; break; case commandLineFormat.onlyComment: output = commentPrefix + " " + commentLine; break; case commandLineFormat.unknown: output = inputLine; break; } if (hasComment) { output = output.add(commentLine, " " + commentPrefix); } } else { switch (__format) { case commandLineFormat.emptyLine: output = ""; break; case commandLineFormat.onlyComment: output = inputLine; break; default: case commandLineFormat.unknown: output = inputLine; break; } } if (hasPrefix) { output = prefix.toCsvInLine(COMMANDPREFIX_SEPARATOR).add(output, "."); } return(output); }