Exemplo n.º 1
0
        private PostActionExecutionStatus ProcessAction(
            ICreationEffects creationEffects,
            ICreationResult creationResult,
            string outputBaseDirectory,
            IPostAction action,
            IPostActionProcessor actionProcessor)
        {
            if (actionProcessor is PostActionProcessor2Base actionProcessor2Base)
            {
                actionProcessor2Base.Callbacks = _callbacks;
            }

            //catch all exceptions on post action execution
            //post actions can be added using components and it's not sure if they handle exceptions properly
            try
            {
                if (actionProcessor.Process(_environment, action, creationEffects, creationResult, outputBaseDirectory))
                {
                    return(PostActionExecutionStatus.Success);
                }

                Reporter.Error.WriteLine(LocalizableStrings.PostActionFailedInstructionHeader);
                DisplayInstructionsForAction(action, useErrorOutput: true);
                return(PostActionExecutionStatus.Failure);
            }
            catch (Exception e)
            {
                Reporter.Error.WriteLine(LocalizableStrings.PostActionFailedInstructionHeader);
                Reporter.Verbose.WriteLine(string.Format(LocalizableStrings.Generic_Details, e.ToString()));
                DisplayInstructionsForAction(action, useErrorOutput: true);
                return(PostActionExecutionStatus.Failure);
            }
        }
        public void Process()
        {
            if (_creationResult.ResultInfo.PostActions.Count > 0)
            {
                Reporter.Output.WriteLine();
                Reporter.Output.WriteLine("Processing Post Actions");
            }

            foreach (IPostAction action in _creationResult.ResultInfo.PostActions)
            {
                IPostActionProcessor actionProcessor = null;

                if (action.ActionId == null || !_settings.SettingsLoader.Components.TryGetComponent(action.ActionId, out actionProcessor) || actionProcessor == null)
                {
                    actionProcessor = new InstructionDisplayPostActionProcessor();
                }

                bool result = actionProcessor.Process(_settings, action, _creationResult.ResultInfo, _creationResult.OutputBaseDirectory);

                if (!result && !action.ContinueOnError)
                {
                    break;
                }
            }
        }
        public void Process(Func <string> inputGetter)
        {
            if (_creationResult.ResultInfo.PostActions.Count > 0)
            {
                Reporter.Output.WriteLine();
                Reporter.Output.WriteLine(LocalizableStrings.ProcessingPostActions);
            }

            foreach (IPostAction action in _creationResult.ResultInfo.PostActions)
            {
                IPostActionProcessor actionProcessor = null;

                if (action.ActionId != null)
                {
                    _environment.SettingsLoader.Components.TryGetComponent(action.ActionId, out actionProcessor);
                }

                bool result = false;

                if (actionProcessor == null)
                {   // The host doesn't know how to handle this action, just display instructions.
                    result = DisplayInstructionsForAction(action);
                }
                else if (actionProcessor is ProcessStartPostActionProcessor)
                {
                    if (_canRunScripts == AllowPostActionsSetting.No)
                    {
                        DisplayInstructionsForAction(action);
                        result = false; // post action didn't run, it's an error in the sense that continue on error sees it.
                    }
                    else if (_canRunScripts == AllowPostActionsSetting.Yes)
                    {
                        result = ProcessAction(action, actionProcessor);
                    }
                    else if (_canRunScripts == AllowPostActionsSetting.Prompt)
                    {
                        result = HandlePromptRequired(action, actionProcessor, inputGetter);
                    }
                    // no trailing else - no other cases.
                }
                else
                {
                    result = ProcessAction(action, actionProcessor);
                    if (!result && !string.IsNullOrEmpty(action.ManualInstructions))
                    {
                        Reporter.Output.WriteLine(LocalizableStrings.PostActionFailedInstructionHeader);
                        DisplayInstructionsForAction(action);
                    }
                }

                if (!result && !action.ContinueOnError)
                {
                    break;
                }

                Reporter.Output.WriteLine();
            }
        }
        private bool ProcessAction(IPostAction action, IPostActionProcessor actionProcessor)
        {
            if (actionProcessor is IPostActionProcessor2 actionProcessor2 && _creationResult.CreationEffects is ICreationEffects2 creationEffects)
            {
                return(actionProcessor2.Process(_environment, action, creationEffects, _creationResult.ResultInfo, _creationResult.OutputBaseDirectory));
            }

            return(actionProcessor.Process(_environment, action, _creationResult.ResultInfo, _creationResult.OutputBaseDirectory));
        }
Exemplo n.º 5
0
        // If the action is just instructions, display them and be done with the action.
        // Otherwise ask the user if they want to run the action.
        // If they do, run it, and return the result.
        // Otherwise return false, indicating the action was not run.
        private bool HandlePromptRequired(IPostAction action, IPostActionProcessor actionProcessor, Func <string> inputGetter)
        {
            if (actionProcessor is InstructionDisplayPostActionProcessor)
            {   // it's just instructions, no need to prompt
                bool result = ProcessAction(action, actionProcessor);
                return(result);
            }

            // TODO: determine if this is the proper way to get input.
            bool userWantsToRunAction = AskUserIfActionShouldRun(action, inputGetter);

            if (!userWantsToRunAction)
            {
                return(false);
            }

            return(ProcessAction(action, actionProcessor));
        }
Exemplo n.º 6
0
 private bool ProcessAction(IPostAction action, IPostActionProcessor actionProcessor)
 {
     return(actionProcessor.Process(_environment, action, _creationResult.ResultInfo, _creationResult.OutputBaseDirectory));
 }
Exemplo n.º 7
0
        internal void Process(Func <string> inputGetter)
        {
            IReadOnlyList <IPostAction> postActions = _creationResult.ResultInfo?.PostActions ?? _creationResult.CreationEffects.CreationResult.PostActions;

            if (postActions.Count > 0)
            {
                Reporter.Output.WriteLine();
                Reporter.Output.WriteLine(LocalizableStrings.ProcessingPostActions);
            }

            foreach (IPostAction action in postActions)
            {
                IPostActionProcessor actionProcessor = null;

                if (action.ActionId != null)
                {
                    _environment.SettingsLoader.Components.TryGetComponent(action.ActionId, out actionProcessor);
                }

                bool result = false;

                if (actionProcessor == null)
                {
                    // The host doesn't know how to handle this action, just display instructions.
                    result = DisplayInstructionsForAction(action);
                }
                else if (actionProcessor is ProcessStartPostActionProcessor)
                {
                    if (_canRunScripts == AllowPostActionsSetting.No || _isDryRun)
                    {
                        DisplayInstructionsForAction(action);
                        result = false; // post action didn't run, it's an error in the sense that continue on error sees it.
                    }
                    else if (_canRunScripts == AllowPostActionsSetting.Yes)
                    {
                        result = ProcessAction(action, actionProcessor);
                    }
                    else if (_canRunScripts == AllowPostActionsSetting.Prompt)
                    {
                        result = HandlePromptRequired(action, actionProcessor, inputGetter);
                    }
                    // no trailing else - no other cases.
                }
                else
                {
                    if (!_isDryRun)
                    {
                        result = ProcessAction(action, actionProcessor);
                    }
                    else
                    {
                        Reporter.Output.WriteLine(LocalizableStrings.ActionWouldHaveBeenTakenAutomatically);

                        if (!string.IsNullOrWhiteSpace(action.Description))
                        {
                            Reporter.Output.WriteLine("  " + action.Description);
                            result = true;
                        }
                    }

                    if (!result && !string.IsNullOrEmpty(action.ManualInstructions))
                    {
                        Reporter.Output.WriteLine(LocalizableStrings.PostActionFailedInstructionHeader);
                        DisplayInstructionsForAction(action);
                    }
                }

                if (!result && !action.ContinueOnError)
                {
                    break;
                }

                Reporter.Output.WriteLine();
            }
        }