예제 #1
0
        /// <summary>
        /// Executes the command console script. <see cref="aceConsoleScript"/>
        /// </summary>
        /// <param name="script">The console script to execute</param>
        /// <param name="delay">The delay between two instructions in the script, in miliseconds</param>
        public aceConsoleScript executeScript(IAceConsoleScript script, Int32 delay = 10)
        {
            aceConsoleScript parent = scriptRunning as aceConsoleScript;

            scriptRunning = script as aceConsoleScript;

            scriptRunning.Execute(this, parent, delay);
            return(scriptRunning);
        }
예제 #2
0
        /// <summary>
        /// Executes the specified console.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <param name="__parent">The parent.</param>
        /// <param name="delay">The delay.</param>
        /// <param name="skipLines">Number of lines to skip</param>
        public void Execute(aceCommandConsole console, aceConsoleScript __parent, Int32 delay = 1, Int32 skipLines = -1)
        {
            parent = __parent;

            executionStart = DateTime.Now;
            currentLine    = 0;
            foreach (String line in this)
            {
                if (currentLine > skipLines)
                {
                    if (line.isNullOrEmptyString() || line == Environment.NewLine)
                    {
                        // skipping empty line
                    }
                    else
                    {
                        if (scriptExecutionAborted)
                        {
                            scriptExecutionAborted = false;
                            break;
                        }

                        switch (imbACECoreConfig.settings.doShowScriptLines)
                        {
                        case scriptLineShowMode.none:
                            break;

                        case scriptLineShowMode.undefined:
                            break;

                        case scriptLineShowMode.onlyCodeLine:
                            console.output.AppendLine(line);
                            break;

                        case scriptLineShowMode.fullPrefixAndCodeLine:
                            console.output.log("Script [" + currentLine.ToString("D3") + "]: " + line);
                            break;

                        case scriptLineShowMode.codeNumberAndCodeLine:
                            console.output.AppendLine("[" + currentLine.ToString("D3") + "] _" + line + "_");
                            break;
                        }



                        console.executeCommand(line);
                        Thread.Sleep(delay);
                    }
                }

                currentLine++;
            }
            executionFinish = DateTime.Now;
        }
예제 #3
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);
        }
예제 #4
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);
        }
        /// <summary>Uses template script file to dynamically create customized execution script</summary>
        /// <remarks><para>It loads specified template script file and applies provided parameters to the {n} template placeholders</para></remarks>
        /// <param name="templateName">Name of template file</param>
        /// <param name="parameters">Comma separated values for parameters</param>
        /// <param name="saveScript">true</param>
        /// <seealso cref="aceOperationSetExecutorBase"/>
        public void aceOperation_scriptTemplate(
            [Description("Name of template file")] String templateName = "word",
            [Description("Comma separated values for parameters")] String parameters = "2,SM-LSD,1,preloadLexicon",
            [Description("true")] Boolean saveScript = true)
        {
            String[]         pars           = parameters.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            aceConsoleScript script         = workspace.loadScript(templateName);
            aceConsoleScript scriptInstance = script.DeployTemplate(pars);

            if (saveScript)
            {
                scriptInstance.Save();
            }

            if (scriptInstance.isReady)
            {
                executeScript(scriptInstance);
            }
            else
            {
                output.log("Script instance [" + scriptInstance.info.Name + "] creation from template script [" + script.info.Name + "] failed to construct. Check number of parameters!");
            }
        }