예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <summary>
        /// Creates another instance of script, using this as template
        /// </summary>
        /// <param name="pars">The pars.</param>
        public aceConsoleScript DeployTemplate(string[] pars, String newScriptName = "")
        {
            String newPath = "";

            if (newScriptName.isNullOrEmpty())
            {
                String   filename    = info.Name.removeEndsWith(".ace");
                FileInfo newFileInfo = filename.getWritableFile(getWritableFileMode.autoRenameThis);
                newPath = newFileInfo.FullName;
            }
            else
            {
                newPath = info.Directory.FullName.add(newScriptName.ensureEndsWith(".ace"));
            }

            aceConsoleScript output     = new aceConsoleScript(newPath, false);
            String           scriptCode = "";

            foreach (String line in this)
            {
                scriptCode = scriptCode + line + Environment.NewLine;
            }

            try
            {
                scriptCode = String.Format(scriptCode, pars);
            } catch (Exception ex)
            {
                aceLog.log(ex.Message, null, true);
                output.isReady = false;
            }

            //List<String> scriptLines = new List<string>();
            //scriptLines.AddRange();

            foreach (String line in scriptCode.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                output.Append(line, false);
            }



            return(output);
        }