/// <summary>
        /// Installs any dependent software via a DOS command file before executing the configured file list.
        /// </summary>
        /// <param name="executionData"></param>
        public void Setup(PluginExecutionData executionData)
        {
            _activityData = executionData?.GetMetadata <ExecutorActivityData>();

            if (!string.IsNullOrEmpty(_activityData?.SetupFileName))
            {
                SystemSetup.Run(_activityData.SetupFileName, string.Empty, executionData?.Credential, _activityData.CopyDirectory);
            }
        }
 public void Initialize(PluginConfigurationData configuration, PluginEnvironment environment)
 {
     // Initialize the activity data by deserializing it from an existing copy of configuration information.
     _activityData = configuration?.GetMetadata <ExecutorActivityData>();
     if (_activityData != null)
     {
         dataGridView_executables.DataSource = _activityData.Executables;
         setupPath_textBox.Text   = _activityData.SetupFileName;
         copydir_checkBox.Checked = _activityData.CopyDirectory;
     }
 }
        /// <summary>
        /// Execute the plugin operation.
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            if (!_setupDone)
            {
                Setup(executionData);
                _setupDone = true;
            }

            _activityData = executionData?.GetMetadata <ExecutorActivityData>();
            _exectuables  = _activityData?.Executables;
            TimeSpan timeout = TimeSpan.FromMinutes(5);

            if (_exectuables == null)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "No files were configured to execute."));
            }

            foreach (Executable exe in _exectuables)
            {
                string   finalArgument  = exe.Arguments + (exe.PassSessionId ? $" {executionData?.SessionId}" : string.Empty);
                DateTime executionStart = DateTime.Now;

                ProcessExecutionResult result = ProcessUtil.Execute(exe.FilePath, finalArgument, timeout);

                if (result.SuccessfulExit)
                {
                    //Framework.ExecutionServices.SystemTrace.LogDebug($"Success. Output: {result.StandardOutput}");
                    RefreshGrid(new ExecutionResult {
                        FileName = exe.FileName, Result = "Succeeded", ExecutionDateTime = executionStart
                    });
                }
                else
                {
                    RefreshGrid(new ExecutionResult {
                        FileName = exe.FileName, Result = "Failed", ExecutionDateTime = executionStart
                    });

                    StringBuilder errorDescription = new StringBuilder("Error: ");
                    errorDescription.Append(GetProcessError(result, executionStart, timeout));
                    errorDescription.Append(Environment.NewLine);
                    errorDescription.Append("Output: ");
                    errorDescription.Append(result.StandardOutput);
                    errorDescription.Append(Environment.NewLine);
                    errorDescription.Append("File: ");
                    errorDescription.Append(exe.FileName);
                    Framework.ExecutionServices.SystemTrace.LogDebug(errorDescription.ToString());

                    return(new PluginExecutionResult(PluginResult.Failed, errorDescription.ToString()));
                }
            }

            return(new PluginExecutionResult(PluginResult.Passed));
        }
 public void Initialize(PluginEnvironment environment)
 {
     // Initialize the activity data with a default value
     _activityData = new ExecutorActivityData();
 }