Ejemplo n.º 1
0
        private ActionPreference InquireForActionPreference(
            string message,
            ExecutionContext context)
        {
            InternalHostUserInterface      ui      = (InternalHostUserInterface)context.EngineHostInterface.UI;
            Collection <ChoiceDescription> choices = new Collection <ChoiceDescription>();
            string resourceString1 = ResourceManagerCache.GetResourceString("Parser", "ContinueLabel");
            string resourceString2 = ResourceManagerCache.GetResourceString("Parser", "ContinueHelpMessage");
            string resourceString3 = ResourceManagerCache.GetResourceString("Parser", "SilentlyContinueLabel");
            string resourceString4 = ResourceManagerCache.GetResourceString("Parser", "SilentlyContinueHelpMessage");
            string resourceString5 = ResourceManagerCache.GetResourceString("Parser", "BreakLabel");
            string resourceString6 = ResourceManagerCache.GetResourceString("Parser", "BreakHelpMessage");
            string resourceString7 = ResourceManagerCache.GetResourceString("Parser", "SuspendLabel");
            string helpMessage     = ResourceManagerCache.FormatResourceString("Parser", "SuspendHelpMessage");

            choices.Add(new ChoiceDescription(resourceString1, resourceString2));
            choices.Add(new ChoiceDescription(resourceString3, resourceString4));
            choices.Add(new ChoiceDescription(resourceString5, resourceString6));
            choices.Add(new ChoiceDescription(resourceString7, helpMessage));
            string resourceString8 = ResourceManagerCache.GetResourceString("Parser", "ExceptionActionPromptCaption");
            int    num;

            while ((num = ui.PromptForChoice(resourceString8, message, choices, 0)) == 3)
            {
                context.EngineHostInterface.EnterNestedPrompt();
            }
            if (num == 0)
            {
                return(ActionPreference.Continue);
            }
            return(num == 1 ? ActionPreference.SilentlyContinue : ActionPreference.Stop);
        }
Ejemplo n.º 2
0
        internal static ActionPreference InquireForActionPreference(string message, ExecutionContext context)
        {
            int num;
            InternalHostUserInterface      uI      = (InternalHostUserInterface)context.EngineHostInterface.UI;
            Collection <ChoiceDescription> choices = new Collection <ChoiceDescription>();
            string continueLabel               = ParserStrings.ContinueLabel;
            string continueHelpMessage         = ParserStrings.ContinueHelpMessage;
            string silentlyContinueLabel       = ParserStrings.SilentlyContinueLabel;
            string silentlyContinueHelpMessage = ParserStrings.SilentlyContinueHelpMessage;
            string breakLabel       = ParserStrings.BreakLabel;
            string breakHelpMessage = ParserStrings.BreakHelpMessage;
            string suspendLabel     = ParserStrings.SuspendLabel;
            string helpMessage      = StringUtil.Format(ParserStrings.SuspendHelpMessage, new object[0]);

            choices.Add(new ChoiceDescription(continueLabel, continueHelpMessage));
            choices.Add(new ChoiceDescription(silentlyContinueLabel, silentlyContinueHelpMessage));
            choices.Add(new ChoiceDescription(breakLabel, breakHelpMessage));
            choices.Add(new ChoiceDescription(suspendLabel, helpMessage));
            string exceptionActionPromptCaption = ParserStrings.ExceptionActionPromptCaption;

            while ((num = uI.PromptForChoice(exceptionActionPromptCaption, message, choices, 0)) == 3)
            {
                context.EngineHostInterface.EnterNestedPrompt();
            }
            switch (num)
            {
            case 0:
                return(ActionPreference.Continue);

            case 1:
                return(ActionPreference.SilentlyContinue);
            }
            return(ActionPreference.Stop);
        }
Ejemplo n.º 3
0
 internal PSHostTraceListener(PSCmdlet cmdlet) : base("")
 {
     this.cachedWrite = new StringBuilder();
     if (cmdlet == null)
     {
         throw new PSArgumentNullException("cmdlet");
     }
     this.ui = cmdlet.Host.UI as InternalHostUserInterface;
 }
Ejemplo n.º 4
0
        internal Collection <RemoteHostCall> PerformSecurityChecksOnHostMessage(string computerName)
        {
            this._computerName = computerName;
            Collection <RemoteHostCall> collection = new Collection <RemoteHostCall>();

            if ((this._methodId == RemoteHostMethodId.PromptForCredential1) || (this._methodId == RemoteHostMethodId.PromptForCredential2))
            {
                string str  = this.ModifyCaption((string)this._parameters[0]);
                string str2 = this.ModifyMessage((string)this._parameters[1], computerName);
                this._parameters[0] = str;
                this._parameters[1] = str2;
                return(collection);
            }
            if (this._methodId == RemoteHostMethodId.Prompt)
            {
                if (this._parameters.Length == 3)
                {
                    Collection <FieldDescription> collection2 = (Collection <FieldDescription>) this._parameters[2];
                    bool flag = false;
                    foreach (FieldDescription description in collection2)
                    {
                        description.IsFromRemoteHost = true;
                        Type fieldType = InternalHostUserInterface.GetFieldType(description);
                        if (fieldType != null)
                        {
                            if (fieldType == typeof(PSCredential))
                            {
                                flag = true;
                                description.ModifiedByRemotingProtocol = true;
                            }
                            else if (fieldType == typeof(SecureString))
                            {
                                collection.Add(this.ConstructWarningMessageForSecureString(computerName, RemotingErrorIdStrings.RemoteHostPromptSecureStringPrompt));
                            }
                        }
                    }
                    if (flag)
                    {
                        string str3 = this.ModifyCaption((string)this._parameters[0]);
                        string str4 = this.ModifyMessage((string)this._parameters[1], computerName);
                        this._parameters[0] = str3;
                        this._parameters[1] = str4;
                    }
                }
                return(collection);
            }
            if (this._methodId == RemoteHostMethodId.ReadLineAsSecureString)
            {
                collection.Add(this.ConstructWarningMessageForSecureString(computerName, RemotingErrorIdStrings.RemoteHostReadLineAsSecureStringPrompt));
                return(collection);
            }
            if (this._methodId == RemoteHostMethodId.GetBufferContents)
            {
                collection.Add(this.ConstructWarningMessageForGetBufferContents(computerName));
            }
            return(collection);
        }
Ejemplo n.º 5
0
        internal void TraceLine(IScriptExtent extent)
        {
            string message = PositionUtilities.BriefMessage(extent.StartScriptPosition);
            InternalHostUserInterface uI         = (InternalHostUserInterface)this._context.EngineHostInterface.UI;
            ActionPreference          preference = this._context.PSDebugTraceStep ? ActionPreference.Inquire : ActionPreference.Continue;

            uI.WriteDebugLine(message, ref preference);
            if (preference == ActionPreference.Continue)
            {
                this._context.PSDebugTraceStep = false;
            }
        }
Ejemplo n.º 6
0
        internal Collection <RemoteHostCall> PerformSecurityChecksOnHostMessage(
            string computerName)
        {
            this._computerName = computerName;
            Collection <RemoteHostCall> collection = new Collection <RemoteHostCall>();

            if (this._methodId == RemoteHostMethodId.PromptForCredential1 || this._methodId == RemoteHostMethodId.PromptForCredential2)
            {
                string str1 = this.ModifyCaption((string)this._parameters[0]);
                string str2 = this.ModifyMessage((string)this._parameters[1], computerName);
                this._parameters[0] = (object)str1;
                this._parameters[1] = (object)str2;
            }
            else if (this._methodId == RemoteHostMethodId.Prompt)
            {
                if (this._parameters.Length == 3)
                {
                    foreach (FieldDescription field in (Collection <FieldDescription>) this._parameters[2])
                    {
                        field.IsFromRemoteHost = true;
                        Type fieldType = InternalHostUserInterface.GetFieldType(field);
                        if (fieldType != null)
                        {
                            if (fieldType == typeof(PSCredential))
                            {
                                string str1 = this.ModifyCaption((string)this._parameters[0]);
                                string str2 = this.ModifyMessage((string)this._parameters[1], computerName);
                                this._parameters[0] = (object)str1;
                                this._parameters[1] = (object)str2;
                                field.ModifiedByRemotingProtocol = true;
                            }
                            else if (fieldType == typeof(SecureString))
                            {
                                collection.Add(this.ConstructWarningMessageForSecureString(computerName, PSRemotingErrorId.RemoteHostPromptSecureStringPrompt));
                            }
                        }
                    }
                }
            }
            else if (this._methodId == RemoteHostMethodId.ReadLineAsSecureString)
            {
                collection.Add(this.ConstructWarningMessageForSecureString(computerName, PSRemotingErrorId.RemoteHostReadLineAsSecureStringPrompt));
            }
            else if (this._methodId == RemoteHostMethodId.GetBufferContents)
            {
                collection.Add(this.ConstructWarningMessageForGetBufferContents(computerName));
            }
            return(collection);
        }
Ejemplo n.º 7
0
        internal static void TraceLine(ExecutionContext context, ParseTreeNode statement)
        {
            if (statement == null || !context.ShouldTraceStatement || statement.NodeToken == null)
            {
                return;
            }
            string message = statement.NodeToken.Position(false);
            InternalHostUserInterface ui         = (InternalHostUserInterface)context.EngineHostInterface.UI;
            ActionPreference          preference = context.StepScript ? ActionPreference.Inquire : ActionPreference.Continue;

            ui.WriteDebugLine(message, ref preference);
            if (preference != ActionPreference.Continue)
            {
                return;
            }
            context.StepScript = false;
        }
        public override Dictionary <string, PSObject> Prompt(string caption, string message, Collection <FieldDescription> descriptions)
        {
            Dictionary <string, PSObject> dictionary = this._serverMethodExecutor.ExecuteMethod <Dictionary <string, PSObject> >(RemoteHostMethodId.Prompt, new object[] { caption, message, descriptions });

            foreach (FieldDescription description in descriptions)
            {
                PSObject obj2;
                object   obj3;
                Type     fieldType = InternalHostUserInterface.GetFieldType(description);
                if (((fieldType != null) && dictionary.TryGetValue(description.Name, out obj2)) && LanguagePrimitives.TryConvertTo(obj2, fieldType, CultureInfo.InvariantCulture, out obj3))
                {
                    if (obj3 != null)
                    {
                        dictionary[description.Name] = PSObject.AsPSObject(obj3);
                    }
                    else
                    {
                        dictionary[description.Name] = null;
                    }
                }
            }
            return(dictionary);
        }
Ejemplo n.º 9
0
        public override Dictionary <string, PSObject> Prompt(
            string caption,
            string message,
            Collection <FieldDescription> descriptions)
        {
            Dictionary <string, PSObject> dictionary = this._serverMethodExecutor.ExecuteMethod <Dictionary <string, PSObject> >(RemoteHostMethodId.Prompt, new object[3]
            {
                (object)caption,
                (object)message,
                (object)descriptions
            });

            foreach (FieldDescription description in descriptions)
            {
                Type     fieldType = InternalHostUserInterface.GetFieldType(description);
                PSObject psObject;
                object   result;
                if (fieldType != null && dictionary.TryGetValue(description.Name, out psObject) && LanguagePrimitives.TryConvertTo((object)psObject, fieldType, (IFormatProvider)CultureInfo.InvariantCulture, out result))
                {
                    dictionary[description.Name] = result == null ? (PSObject)null : PSObject.AsPSObject(result);
                }
            }
            return(dictionary);
        }