示例#1
0
        // ------------------------------------------
        // EXECUTING
        // ------------------------------------------

        #region Executing

        /// <summary>
        /// Executes this instance with result.
        /// </summary>
        /// <param name="resultString">The result to get.</param>
        /// <param name="appScope">The application scope to consider.</param>
        /// <param name="scriptVariableSet">The script variable set to use.</param>
        /// <param name="runtimeMode">The runtime mode to consider.</param>
        /// <returns>The log of execution log.</returns>
        public override ILog ExecuteWithResult(
            out string resultString,
            IAppScope appScope = null,
            IScriptVariableSet scriptVariableSet = null,
            RuntimeMode runtimeMode = RuntimeMode.Normal)
        {
            resultString = "";

            ILog log = appScope.Check(true);

            if (string.IsNullOrEmpty(this.FileName))
            {
                log.AddWarning(
                    title: "File name missing",
                    description: "No file name defined in command '" + this.Key() + "'.");
            }
            else if (!log.HasErrorsOrExceptions())
            {
                try
                {
                    Process process = new Process();
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.FileName         = this.FileName;
                    process.StartInfo.Arguments        = this.ArgumentString;
                    process.StartInfo.WorkingDirectory = this.WorkingDirectory;
                    process.Start();
                    resultString = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                }
                catch (Exception ex)
                {
                    log.AddException(ex);
                }
            }

            return(log);
        }