Пример #1
0
 /// <summary>
 /// Execute the given action
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public IAction ExecuteAction(IAction action, object context      = null,
                              bool performPostExecutionOperations = true, bool promptForInputs = true,
                              bool chain = false)
 {
     if (action != null)
     {
         CurrentAction = action;
         string commandName = action.GetCommandName();
         try
         {
             if (action is IContextualAction)
             {
                 ((IContextualAction)action).PopulateInputsFromContext(context);
             }
             if (PreviousActions.ContainsKey(commandName))
             {
                 action.CopyPersistentValuesFrom(PreviousActions[commandName]);
             }
             if (!promptForInputs || action.PromptUserForInputs(chain))
             {
                 if (action.PreExecutionOperations())
                 {
                     //Core.Instance.Undo.BeginStage();
                     action.Execute();
                     if (performPostExecutionOperations)
                     {
                         action.PostExecutionOperations();
                     }
                     //Core.Instance.Undo.EndStage();
                     Core.Instance.Host.Refresh();
                 }
             }
         }
         catch (Exception ex)
         {
             Core.PrintLine("Error: Newt action '" + commandName + "' failed to complete.");
             Core.PrintLine(ex.Message);
             Core.PrintLine(ex.StackTrace);
         }
         PreviousActions[commandName] = action;
         LastCommand   = action;
         CurrentAction = null;
     }
     return(action);
 }