Example #1
0
        internal Collection <PSObject> ExecuteCurrentPowerShell(out Exception exceptionThrown, IEnumerable input = null)
        {
            exceptionThrown = null;

            // This flag indicates a previous call to this method had its pipeline cancelled
            if (this.CancelTabCompletion)
            {
                return(new Collection <PSObject>());
            }

            Collection <PSObject> results = null;

            try
            {
                results = CurrentPowerShell.Invoke(input);

                // If this pipeline has been stopped lets set a flag to cancel all future tab completion calls
                // untill the next completion
                if (this.IsStopped)
                {
                    results = new Collection <PSObject>();
                    this.CancelTabCompletion = true;
                }
            }
            catch (Exception e)
            {
                exceptionThrown = e;
            }
            finally
            {
                CurrentPowerShell.Commands.Clear();
            }

            return(results);
        }
        internal Collection <PSObject> ExecuteCommand(string command, bool isScript, out Exception exceptionThrown, Hashtable args)
        {
            Diagnostics.Assert(command != null, "caller to verify command is not null");

            exceptionThrown = null;

            // This flag indicates a previous call to this method had its pipeline cancelled
            if (this.CancelTabCompletion)
            {
                return(new Collection <PSObject>());
            }

            CurrentPowerShell.AddCommand(command);

            Command cmd = new Command(command, isScript);

            if (args != null)
            {
                foreach (DictionaryEntry arg in args)
                {
                    cmd.Parameters.Add((string)(arg.Key), arg.Value);
                }
            }

            Collection <PSObject> results = null;

            try
            {
                // blocks until all results are retrieved.
                //results = this.ExecuteCommand(cmd);

                // If this pipeline has been stopped lets set a flag to cancel all future tab completion calls
                // untill the next completion
                if (this.IsStopped)
                {
                    results = new Collection <PSObject>();
                    this.CancelTabCompletion = true;
                }
            }
            catch (Exception e)
            {
                CommandProcessorBase.CheckForSevereException(e);
                exceptionThrown = e;
            }

            return(results);
        }