Ejemplo n.º 1
0
        } // ShouldProcess

        /// <Content contentref="System.Management.Automation.Cmdlet.ShouldProcess" />
        public bool ShouldProcess(
            string verboseDescription,
            string verboseWarning,
            string caption,
            out ShouldProcessReason shouldProcessReason)
        {
            using (PSTransactionManager.GetEngineProtectionScope())
            {
                Diagnostics.Assert(
                    Context != null,
                    "The context should always be set");

                return Context.ShouldProcess(
                    verboseDescription,
                    verboseWarning,
                    caption,
                    out shouldProcessReason);
            }
        } // ShouldProcess
Ejemplo n.º 2
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     return provider.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper function for ShouldProcess APIs
        /// </summary>
        /// <param name="verboseDescription">
        /// Description of operation, to be printed for Continue or WhatIf
        /// </param>
        /// <param name="verboseWarning">
        /// Warning prompt, to be printed for Inquire
        /// </param>
        /// <param name="caption">
        /// This is the caption of the window which may be displayed
        /// if the user is prompted whether or not to perform the action.
        /// It may be displayed by some hosts, but not all.
        /// </param>
        /// <param name="shouldProcessReason">
        /// Indicates the reason(s) why ShouldProcess returned what it returned.
        /// Only the reasons enumerated in
        /// <see cref="System.Management.Automation.ShouldProcessReason"/>
        /// are returned.
        /// </param>
        /// <remarks>true iff the action should be performed</remarks>
        /// <exception cref="System.Management.Automation.PipelineStoppedException">
        /// The pipeline has already been terminated, or was terminated
        /// during the execution of this method.
        /// The Cmdlet should generally just allow PipelineStoppedException
        /// to percolate up to the caller of ProcessRecord etc.
        /// </exception>
        /// <remarks>
        /// If the pipeline is terminated due to ActionPreference.Stop
        /// or ActionPreference.Inquire, this method will throw
        /// <see cref="System.Management.Automation.PipelineStoppedException"/>,
        /// but the command failure will ultimately be
        /// <see cref="System.Management.Automation.ActionPreferenceStopException"/>,
        /// </remarks>
        private bool DoShouldProcess(
            string verboseDescription,
            string verboseWarning,
            string caption,
            out ShouldProcessReason shouldProcessReason)
        {
            ThrowIfStopping();

            shouldProcessReason = ShouldProcessReason.None;

            switch (lastShouldProcessContinueStatus)
            {
                case ContinueStatus.NoToAll:
                    return false;
                case ContinueStatus.YesToAll:
                    return true;
            }

            if (WhatIf)
            {
                // 2005/05/24 908827
                // WriteDebug/WriteVerbose/WriteProgress/WriteWarning should only be callable from the main thread
                //
                // WriteError/WriteObject have a check that prevents them to be called from outside 
                // Begin/Process/End. This is done because the Pipeline needs to be ready before these 
                // functions can be called.
                //
                // WriteDebug/Warning/Verbose/Process used to do the same check, even though it is not 
                // strictly needed. If we ever implement pipelines for these objects we may need to 
                // enforce the check again.
                //
                // See bug 583774 in the Windows 7 database for more details.
                //
                ThrowIfWriteNotPermitted(false);

                shouldProcessReason = ShouldProcessReason.WhatIf;
                string whatIfMessage =
                    StringUtil.Format(CommandBaseStrings.ShouldProcessWhatIfMessage,
                        verboseDescription);

                CBhost.InternalUI.TranscribeResult(whatIfMessage);
                CBhost.UI.WriteLine(whatIfMessage);
                return false;
            }

            if (this.CanShouldProcessAutoConfirm())
            {
                if (this.Verbose)
                {
                    // 2005/05/24 908827
                    // WriteDebug/WriteVerbose/WriteProgress/WriteWarning should only be callable from the main thread
                    //
                    // WriteError/WriteObject have a check that prevents them to be called from outside 
                    // Begin/Process/End. This is done because the Pipeline needs to be ready before these 
                    // functions can be called.
                    //
                    // WriteDebug/Warning/Verbose/Process used to do the same check, even though it is not 
                    // strictly needed. If we ever implement pipelines for these objects we may need to 
                    // enforce the check again.
                    //
                    // See bug 583774 in the Windows 7 database for more details.
                    //
                    ThrowIfWriteNotPermitted(false);

                    WriteVerbose(verboseDescription);
                }

                return true;
            }

            if (String.IsNullOrEmpty(verboseWarning))
                verboseWarning = StringUtil.Format(CommandBaseStrings.ShouldProcessWarningFallback,
                    verboseDescription);

            // 2005/05/24 908827
            // WriteDebug/WriteVerbose/WriteProgress/WriteWarning should only be callable from the main thread
            //
            // WriteError/WriteObject have a check that prevents them to be called from outside 
            // Begin/Process/End. This is done because the Pipeline needs to be ready before these 
            // functions can be called.
            //
            // WriteDebug/Warning/Verbose/Process used to do the same check, even though it is not 
            // strictly needed. If we ever implement pipelines for these objects we may need to 
            // enforce the check again.
            //
            // See bug 583774 in the Windows 7 database for more details.
            //
            ThrowIfWriteNotPermitted(false);

            lastShouldProcessContinueStatus = InquireHelper(
                verboseWarning,
                caption,
                true,   // allowYesToAll
                true,   // allowNoToAll
                false,  // replaceNoWithHalt
                false   // hasSecurityImpact
                );

            switch (lastShouldProcessContinueStatus)
            {
                case ContinueStatus.No:
                case ContinueStatus.NoToAll:
                    return false;
            }

            return true;
        }
Ejemplo n.º 4
0
        private bool DoShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
        {
            this.ThrowIfStopping();
            shouldProcessReason = ShouldProcessReason.None;
            switch (this.lastShouldProcessContinueStatus)
            {
                case ContinueStatus.YesToAll:
                    return true;

                case ContinueStatus.NoToAll:
                    return false;

                default:
                    if (this.WhatIf != 0)
                    {
                        this.ThrowIfWriteNotPermitted(false);
                        shouldProcessReason = ShouldProcessReason.WhatIf;
                        string str = StringUtil.Format(CommandBaseStrings.ShouldProcessWhatIfMessage, verboseDescription);
                        this.CBhost.UI.WriteLine(str);
                        return false;
                    }
                    if (this.CanShouldProcessAutoConfirm())
                    {
                        if (this.Verbose)
                        {
                            this.ThrowIfWriteNotPermitted(false);
                            this.WriteVerbose(verboseDescription);
                        }
                        return true;
                    }
                    if (string.IsNullOrEmpty(verboseWarning))
                    {
                        verboseWarning = StringUtil.Format(CommandBaseStrings.ShouldProcessWarningFallback, verboseDescription);
                    }
                    this.ThrowIfWriteNotPermitted(false);
                    this.lastShouldProcessContinueStatus = this.InquireHelper(verboseWarning, caption, true, true, false);
                    switch (this.lastShouldProcessContinueStatus)
                    {
                        case ContinueStatus.No:
                        case ContinueStatus.NoToAll:
                            return false;
                    }
                    break;
            }
            return true;
        }
Ejemplo n.º 5
0
 internal bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     bool flag = true;
     if (this.command != null)
     {
         flag = this.command.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
     }
     else
     {
         shouldProcessReason = ShouldProcessReason.None;
     }
     tracer.WriteLine("result = {0}", new object[] { flag });
     return flag;
 }
Ejemplo n.º 6
0
 public virtual bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     return cmdlet.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
 }
Ejemplo n.º 7
0
        public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
        {
            // if we are on the original thread, just call straight thru.
            if (this.originalThread == System.Threading.Thread.CurrentThread)
            {
                return(originalCommandRuntime.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason));
            }

            CheckForInteractive();

            // otherwise, queue up the request and wait for the main thread to do the right thing.
            try
            {
                // wait for our turn to talk to the main thread
                WaitOurTurn();

                bool result = false;
                ShouldProcessReason reason = ShouldProcessReason.None;

                // set the function to run
                runOnMainThread = () => result = originalCommandRuntime.ShouldProcess(verboseDescription, verboseWarning, caption, out reason);

                // tell the main thread to go ahead
                readyToRun.Set();

                // wait for the result (or cancellation!)
                WaitForCompletion();

                // set the output variables
                shouldProcessReason = reason;
                return(result);
            }
            catch (System.OperationCanceledException exception)
            {
                // maybe don't even worry?
                throw exception;
            }
        }
Ejemplo n.º 8
0
 public virtual bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     return(cmdlet.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason));
 }
Ejemplo n.º 9
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     return(_provider.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason));
 }
Ejemplo n.º 10
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     CheckForInteractive();
     shouldProcessReason = ShouldProcessReason.None;
     return(false);
 }
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Default implementation - always returns true.
 /// </summary>
 /// <param name="verboseDescription">Ignored.</param>
 /// <param name="verboseWarning">Ignored.</param>
 /// <param name="caption">Ignored.</param>
 /// <param name="shouldProcessReason">Ignored.</param>
 /// <returns>True.</returns>
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     shouldProcessReason = ShouldProcessReason.None; return(true);
 }
Ejemplo n.º 13
0
        public new Task <bool> ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
        {
            if (IsCancelled() || !IsInvocation)
            {
                shouldProcessReason = ShouldProcessReason.None;
                return(false.AsResultTask());
            }

            // todo: Uh, this is gonna be tricky!?
            shouldProcessReason = ShouldProcessReason.None;
            return(QueueMessage(() => base.ShouldProcess(verboseDescription, verboseWarning, caption)));
        }
Ejemplo n.º 14
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     shouldProcessReason = ShouldProcessReason.None;
     return true;
 }
Ejemplo n.º 15
0
        } // ShouldProcess

        /// <summary>
        /// Confirm the operation with the user
        /// </summary>
        /// <param name="verboseDescription">
        /// This should contain a textual description of the action to be
        /// performed.  This is what will be displayed to the user for
        /// ActionPreference.Continue.
        /// </param>
        /// <param name="verboseWarning">
        /// This should contain a textual query of whether the action
        /// should be performed, usually in the form of a question.
        /// This is what will be displayed to the user for
        /// ActionPreference.Inquire.
        /// </param>
        /// <param name="caption">
        /// This is the caption of the window which may be displayed
        /// if the user is prompted whether or not to perform the action.
        /// It may be displayed by some hosts, but not all.
        /// </param>
        /// <param name="shouldProcessReason">
        /// Indicates the reason(s) why ShouldProcess returned what it returned.
        /// Only the reasons enumerated in
        /// <see cref="System.Management.Automation.ShouldProcessReason"/>
        /// are returned.
        /// </param>
        /// <remarks>true iff the action should be performed</remarks>
        /// <exception cref="PipelineStoppedException">
        /// The ActionPreference.Stop or ActionPreference.Inquire policy
        /// triggered a terminating error.  The pipeline failure will be
        /// ActionPreferenceStopException.
        /// Also, this occurs if the pipeline was already stopped.
        /// </exception>
        internal bool ShouldProcess(
            string verboseDescription,
            string verboseWarning,
            string caption,
            out ShouldProcessReason shouldProcessReason)
        {
            bool result = true;
            if (_command != null)
            {
                result = _command.ShouldProcess(
                    verboseDescription,
                    verboseWarning,
                    caption,
                    out shouldProcessReason);
            }
            else
            {
                shouldProcessReason = ShouldProcessReason.None;
            }

            return result;
        } // ShouldProcess
Ejemplo n.º 16
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 public bool ShouldProcess(string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason)
 {
     using (PSTransactionManager.GetEngineProtectionScope())
     {
         return this.Context.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason);
     }
 }