Exemple #1
0
        private void Execute(IRespondWithNoResultSuccessOrError <ErrorOutput> presenter)
        {
            var processStartInfo = _processPipeLineTask.CommandToExecute();

            try
            {
                _process = _processFactory.CreateBackgroundProcess(processStartInfo);

                _process.Start();

                var errorTask = _process.ReadStdErrToEndAsync();

                if (!errorTask.Wait(500))
                {
                    // was there error data to fetch?
                    presenter.Respond();
                    return;
                }

                var error = errorTask.Result;
                if (HasError(error))
                {
                    var errorOutput     = new ErrorOutput();
                    var trimedArugments = processStartInfo.Arguments.Substring(3);
                    errorOutput.AddError($"Failed to execute {trimedArugments}");
                    errorOutput.AddError(error);
                    presenter.Respond(errorOutput);
                    return;
                }

                presenter.Respond();
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to execute [{processStartInfo.FileName}] with [{processStartInfo.Arguments}]", e);
            }
        }