示例#1
0
 /// <summary>
 /// Constructs an instance with the specified command instance
 /// </summary>
 /// 
 /// <param name="commandRuntime">
 /// The instance of the command that the parameters should set the
 /// user feedback properties on when the parameters get bound.
 /// </param>
 /// 
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="cmdlet"/> is null.
 /// </exception>
 /// 
 internal CommonParameters(MshCommandRuntime commandRuntime)
 {
     if (commandRuntime == null)
     {
         throw PSTraceSource.NewArgumentNullException("commandRuntime");
     }
     _commandRuntime = commandRuntime;
 } // ctor
示例#2
0
        private Pipe GetRedirectionPipe(
            PipelineResultTypes toType,
            MshCommandRuntime mcr)
        {
            if (toType == PipelineResultTypes.Output)
            {
                return(mcr.OutputPipe);
            }

            Pipe pipe = new Pipe();

            pipe.NullPipe = true;
            return(pipe);
        }
        internal static void CollectShouldProcessParameters(PSCmdlet cmdlet, out bool whatIf, out bool confirm)
        {
            whatIf  = false;
            confirm = true;
            MshCommandRuntime commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;

            if (commandRuntime != null)
            {
                whatIf = (bool)commandRuntime.WhatIf;
                if (commandRuntime.IsConfirmFlagSet)
                {
                    confirm = (bool)commandRuntime.Confirm;
                }
            }
        }
示例#4
0
 private bool NeedToLog()
 {
     if (this._commands != null)
     {
         foreach (CommandProcessorBase base2 in this._commands)
         {
             MshCommandRuntime commandRuntime = base2.Command.commandRuntime as MshCommandRuntime;
             if ((commandRuntime != null) && commandRuntime.LogPipelineExecutionDetail)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
示例#5
0
        internal override void DoBeginProcessing()
        {
            MshCommandRuntime commandRuntime = this.CommandRuntime as MshCommandRuntime;

            if (((commandRuntime != null) && (commandRuntime.UseTransaction != false)) && !base.Context.TransactionManager.HasTransaction)
            {
                string noTransactionStarted = TransactionStrings.NoTransactionStarted;
                if (base.Context.TransactionManager.IsLastTransactionCommitted)
                {
                    noTransactionStarted = TransactionStrings.NoTransactionStartedFromCommit;
                }
                else if (base.Context.TransactionManager.IsLastTransactionRolledBack)
                {
                    noTransactionStarted = TransactionStrings.NoTransactionStartedFromRollback;
                }
                throw new InvalidOperationException(noTransactionStarted);
            }
            this.BeginProcessing();
        }
示例#6
0
        protected override void ProcessRecord()
        {
            MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;

            if (commandRuntime != null)
            {
                DebugRecord    record        = new DebugRecord(this.Message);
                InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
                if (variableValue != null)
                {
                    record.SetInvocationInfo(variableValue);
                }
                commandRuntime.WriteDebug(record, false);
            }
            else
            {
                base.WriteDebug(this.Message);
            }
        }
示例#7
0
 public object GetDynamicParameters()
 {
     this._commandRuntime = (MshCommandRuntime)base.commandRuntime;
     if (this._scriptBlock.HasDynamicParameters)
     {
         ArrayList resultList = new ArrayList();
         this._functionContext._outputPipe = new Pipe(resultList);
         this.RunClause(this._runOptimized ? this._scriptBlock.DynamicParamBlock : this._scriptBlock.UnoptimizedDynamicParamBlock, AutomationNull.Value, AutomationNull.Value);
         if (resultList.Count > 1)
         {
             throw PSTraceSource.NewInvalidOperationException("AutomationExceptions", "DynamicParametersWrongType", new object[] { PSObject.ToStringParser(base.Context, resultList) });
         }
         if (resultList.Count != 0)
         {
             return(PSObject.Base(resultList[0]));
         }
     }
     return(null);
 }
 public override void BeginProcessing()
 {
     if (this.AsJob.IsPresent)
     {
         MshCommandRuntime commandRuntime = (MshCommandRuntime)base.Cmdlet.CommandRuntime;
         string            str            = null;
         if (commandRuntime.WhatIf.IsPresent)
         {
             str = "WhatIf";
         }
         else if (commandRuntime.Confirm.IsPresent)
         {
             str = "Confirm";
         }
         if (str != null)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, CmdletizationResources.SessionBasedWrapper_ShouldProcessVsJobConflict, new object[] { str }));
         }
     }
     this.parentJob = new ThrottlingJob(Job.GetCommandTextFromInvocationInfo(base.Cmdlet.MyInvocation), this.GenerateParentJobName(), "CimJob", this.ThrottleLimit, !this.AsJob.IsPresent);
 }
 /// <summary>
 /// Constructs an instance with the specified command instance.
 /// </summary>
 /// <param name="commandRuntime">
 /// The instance of the command that the parameters should set the
 /// user feedback properties on when the parameters get bound.
 /// </param>
 internal TransactionParameters(MshCommandRuntime commandRuntime)
 {
     _commandRuntime = commandRuntime;
 }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        protected override void BeginProcessing()
        {
            //ValidateNotNullOrEmpty attribute is not working for System.Uri datatype, so handling it here
            if ((_cssuriSpecified) && (string.IsNullOrEmpty(_cssuri.OriginalString.Trim())))
            {
                ArgumentException ex = new ArgumentException(StringUtil.Format(UtilityCommonStrings.EmptyCSSUri, "CSSUri"));
                ErrorRecord       er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.InvalidArgument, "CSSUri");
                ThrowTerminatingError(er);
            }

            _propertyMshParameterList = ProcessParameter(_property);

            if (!String.IsNullOrEmpty(_title))
            {
                WebUtility.HtmlEncode(_title);
            }


            // This first line ensures w3c validation will succeed. However we are not specifying
            // an encoding in the HTML because we don't know where the text will be written and
            // if a particular encoding will be used.

            if (!_fragment)
            {
                if (!_transitional)
                {
                    WriteObject("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
                }
                else
                {
                    WriteObject("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                }
                WriteObject("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                WriteObject("<head>");
                if (_charsetSpecified)
                {
                    WriteObject("<meta charset=\"" + _charset + "\">");
                }
                if (_metaSpecified)
                {
                    List <string> useditems = new List <string>();
                    foreach (string s in _meta.Keys)
                    {
                        if (!useditems.Contains(s))
                        {
                            switch (s.ToLower())
                            {
                            case "content-type":
                            case "default-style":
                            case "x-ua-compatible":
                                WriteObject("<meta http-equiv=\"" + s + "\" content=\"" + _meta[s] + "\">");
                                break;

                            case "application-name":
                            case "author":
                            case "description":
                            case "generator":
                            case "keywords":
                            case "viewport":
                                WriteObject("<meta name=\"" + s + "\" content=\"" + _meta[s] + "\">");
                                break;

                            default:
                                MshCommandRuntime mshCommandRuntime = this.CommandRuntime as MshCommandRuntime;
                                string            Message           = StringUtil.Format(ConvertHTMLStrings.MetaPropertyNotFound, s, _meta[s]);
                                WarningRecord     record            = new WarningRecord(Message);
                                InvocationInfo    invocationInfo    = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;

                                if (invocationInfo != null)
                                {
                                    record.SetInvocationInfo(invocationInfo);
                                }
                                mshCommandRuntime.WriteWarning(record);
                                WriteObject("<meta name=\"" + s + "\" content=\"" + _meta[s] + "\">");
                                break;
                            }
                            useditems.Add(s);
                        }
                    }
                }
                WriteObject(_head ?? new string[] { "<title>" + _title + "</title>" }, true);
                if (_cssuriSpecified)
                {
                    WriteObject("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + _cssuri + "\" />");
                }
                WriteObject("</head><body>");
                if (_body != null)
                {
                    WriteObject(_body, true);
                }
            }
            if (_preContent != null)
            {
                WriteObject(_preContent, true);
            }
            WriteObject("<table>");
            _isTHWritten       = false;
            _propertyCollector = new StringCollection();
        }
示例#11
0
        internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false)
        {
            switch (this.ObjectType)
            {
            case PSStreamObjectType.Output:
                if (instanceId != Guid.Empty)
                {
                    PSObject psObj = this.Value as PSObject;
                    if (psObj != null)
                    {
                        AddSourceJobNoteProperty(psObj, instanceId);
                    }
                }
                cmdlet.WriteObject(this.Value);
                return;

            case PSStreamObjectType.Error:
            {
                ErrorRecord errorRecord = (ErrorRecord)this.Value;
                if ((!(errorRecord is RemotingErrorRecord) && (errorRecord.ErrorDetails != null)) && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction))
                {
                    string str;
                    Guid   guid;
                    GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction, out guid, out str);
                    errorRecord = new RemotingErrorRecord(errorRecord, new OriginInfo(str, Guid.Empty, guid));
                }
                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (commandRuntime == null)
                {
                    break;
                }
                commandRuntime.WriteError(errorRecord, overrideInquire);
                return;
            }

            case PSStreamObjectType.MethodExecutor:
            case PSStreamObjectType.BlockingError:
            case PSStreamObjectType.ShouldMethod:
            case PSStreamObjectType.WarningRecord:
                this.WriteStreamObject(cmdlet, overrideInquire);
                break;

            case PSStreamObjectType.Warning:
            {
                string            message  = (string)this.Value;
                WarningRecord     record   = new WarningRecord(message);
                MshCommandRuntime runtime2 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime2 == null)
                {
                    break;
                }
                runtime2.WriteWarning(record, overrideInquire);
                return;
            }

            case PSStreamObjectType.Debug:
            {
                string            str5     = (string)this.Value;
                DebugRecord       record7  = new DebugRecord(str5);
                MshCommandRuntime runtime5 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime5 == null)
                {
                    break;
                }
                runtime5.WriteDebug(record7, overrideInquire);
                return;
            }

            case PSStreamObjectType.Progress:
            {
                ProgressRecord progressRecord = (ProgressRecord)this.Value;
                if (!(progressRecord is RemotingProgressRecord))
                {
                    Guid   guid2;
                    string str4;
                    GetIdentifierInfo(progressRecord.CurrentOperation, out guid2, out str4);
                    OriginInfo originInfo = new OriginInfo(str4, Guid.Empty, guid2);
                    progressRecord = new RemotingProgressRecord(progressRecord, originInfo);
                }
                MshCommandRuntime runtime4 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime4 == null)
                {
                    break;
                }
                runtime4.WriteProgress(progressRecord, overrideInquire);
                return;
            }

            case PSStreamObjectType.Verbose:
            {
                string            str3     = (string)this.Value;
                VerboseRecord     record4  = new VerboseRecord(str3);
                MshCommandRuntime runtime3 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime3 == null)
                {
                    break;
                }
                runtime3.WriteVerbose(record4, overrideInquire);
                return;
            }

            default:
                return;
            }
        }
示例#12
0
        internal void WriteStreamObject(Cmdlet cmdlet, bool overrideInquire = false)
        {
            switch (this.ObjectType)
            {
            case PSStreamObjectType.Output:
                cmdlet.WriteObject(this.Value);
                return;

            case PSStreamObjectType.Error:
            {
                ErrorRecord errorRecord = (ErrorRecord)this.Value;
                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (commandRuntime == null)
                {
                    break;
                }
                commandRuntime.WriteError(errorRecord, overrideInquire);
                return;
            }

            case PSStreamObjectType.MethodExecutor:
                ((ClientMethodExecutor)this.Value).Execute(cmdlet);
                return;

            case PSStreamObjectType.Warning:
            {
                string            message  = (string)this.Value;
                WarningRecord     record   = new WarningRecord(message);
                MshCommandRuntime runtime3 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime3 == null)
                {
                    break;
                }
                runtime3.WriteWarning(record, overrideInquire);
                return;
            }

            case PSStreamObjectType.BlockingError:
            {
                CmdletMethodInvoker <object> cmdletMethodInvoker = (CmdletMethodInvoker <object>) this.Value;
                InvokeCmdletMethodAndWaitForResults <object>(cmdletMethodInvoker, cmdlet);
                return;
            }

            case PSStreamObjectType.ShouldMethod:
            {
                CmdletMethodInvoker <bool> invoker2 = (CmdletMethodInvoker <bool>) this.Value;
                InvokeCmdletMethodAndWaitForResults <bool>(invoker2, cmdlet);
                return;
            }

            case PSStreamObjectType.WarningRecord:
            {
                WarningRecord     record5  = (WarningRecord)this.Value;
                MshCommandRuntime runtime6 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime6 == null)
                {
                    break;
                }
                runtime6.AppendWarningVarList(record5);
                return;
            }

            case PSStreamObjectType.Debug:
            {
                string            str      = (string)this.Value;
                DebugRecord       record2  = new DebugRecord(str);
                MshCommandRuntime runtime2 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime2 == null)
                {
                    break;
                }
                runtime2.WriteDebug(record2, overrideInquire);
                return;
            }

            case PSStreamObjectType.Progress:
            {
                MshCommandRuntime runtime5 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime5 == null)
                {
                    break;
                }
                runtime5.WriteProgress((ProgressRecord)this.Value, overrideInquire);
                return;
            }

            case PSStreamObjectType.Verbose:
            {
                string            str3     = (string)this.Value;
                VerboseRecord     record4  = new VerboseRecord(str3);
                MshCommandRuntime runtime4 = cmdlet.CommandRuntime as MshCommandRuntime;
                if (runtime4 == null)
                {
                    break;
                }
                runtime4.WriteVerbose(record4, overrideInquire);
                return;
            }

            case PSStreamObjectType.Exception:
            {
                Exception exception = (Exception)this.Value;
                throw exception;
            }

            default:
                return;
            }
        }
示例#13
0
        internal virtual bool BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
        {
            bool flag  = false;
            bool flag2 = (flags & ParameterBindingFlags.ShouldCoerceType) != ParameterBindingFlags.None;

            if (parameter == null)
            {
                throw PSTraceSource.NewArgumentNullException("parameter");
            }
            if (parameterMetadata == null)
            {
                throw PSTraceSource.NewArgumentNullException("parameterMetadata");
            }
            using (bindingTracer.TraceScope("BIND arg [{0}] to parameter [{1}]", new object[] { parameter.ArgumentValue, parameterMetadata.Name }))
            {
                parameter.ParameterName = parameterMetadata.Name;
                object argumentValue         = parameter.ArgumentValue;
                ScriptParameterBinder binder = this as ScriptParameterBinder;
                bool bindingScriptCmdlet     = false;
                if (binder != null)
                {
                    bindingScriptCmdlet = binder.Script.UsesCmdletBinding;
                }
                foreach (ArgumentTransformationAttribute attribute in parameterMetadata.ArgumentTransformationAttributes)
                {
                    using (bindingTracer.TraceScope("Executing DATA GENERATION metadata: [{0}]", new object[] { attribute.GetType() }))
                    {
                        try
                        {
                            ArgumentTypeConverterAttribute attribute2 = attribute as ArgumentTypeConverterAttribute;
                            if (attribute2 != null)
                            {
                                if (flag2)
                                {
                                    argumentValue = attribute2.Transform(this.engine, argumentValue, true, bindingScriptCmdlet);
                                }
                            }
                            else
                            {
                                argumentValue = attribute.Transform(this.engine, argumentValue);
                            }
                            bindingTracer.WriteLine("result returned from DATA GENERATION: {0}", new object[] { argumentValue });
                        }
                        catch (Exception exception)
                        {
                            CommandProcessorBase.CheckForSevereException(exception);
                            bindingTracer.WriteLine("ERROR: DATA GENERATION: {0}", new object[] { exception.Message });
                            ParameterBindingException exception2 = new ParameterBindingArgumentTransformationException(exception, ErrorCategory.InvalidData, this.InvocationInfo, this.GetErrorExtent(parameter), parameterMetadata.Name, parameterMetadata.Type, (argumentValue == null) ? null : argumentValue.GetType(), "ParameterBinderStrings", "ParameterArgumentTransformationError", new object[] { exception.Message });
                            throw exception2;
                        }
                    }
                }
                if (flag2)
                {
                    argumentValue = this.CoerceTypeAsNeeded(parameter, parameterMetadata.Name, parameterMetadata.Type, parameterMetadata.CollectionTypeInformation, argumentValue);
                }
                else if (!this.ShouldContinueUncoercedBind(parameter, parameterMetadata, flags, ref argumentValue))
                {
                    goto Label_040E;
                }
                if ((parameterMetadata.PSTypeName != null) && (argumentValue != null))
                {
                    IEnumerable enumerable = LanguagePrimitives.GetEnumerable(argumentValue);
                    if (enumerable != null)
                    {
                        foreach (object obj3 in enumerable)
                        {
                            this.ValidatePSTypeName(parameter, parameterMetadata, !flag2, obj3);
                        }
                    }
                    else
                    {
                        this.ValidatePSTypeName(parameter, parameterMetadata, !flag2, argumentValue);
                    }
                }
                if ((flags & ParameterBindingFlags.IsDefaultValue) == ParameterBindingFlags.None)
                {
                    foreach (ValidateArgumentsAttribute attribute3 in parameterMetadata.ValidationAttributes)
                    {
                        using (bindingTracer.TraceScope("Executing VALIDATION metadata: [{0}]", new object[] { attribute3.GetType() }))
                        {
                            try
                            {
                                attribute3.InternalValidate(argumentValue, this.engine);
                            }
                            catch (Exception exception3)
                            {
                                CommandProcessorBase.CheckForSevereException(exception3);
                                bindingTracer.WriteLine("ERROR: VALIDATION FAILED: {0}", new object[] { exception3.Message });
                                ParameterBindingValidationException exception4 = new ParameterBindingValidationException(exception3, ErrorCategory.InvalidData, this.InvocationInfo, this.GetErrorExtent(parameter), parameterMetadata.Name, parameterMetadata.Type, (argumentValue == null) ? null : argumentValue.GetType(), "ParameterBinderStrings", "ParameterArgumentValidationError", new object[] { exception3.Message });
                                throw exception4;
                            }
                            tracer.WriteLine("Validation attribute on {0} returned {1}.", new object[] { parameterMetadata.Name, flag });
                        }
                    }
                    if (IsParameterMandatory(parameterMetadata))
                    {
                        this.ValidateNullOrEmptyArgument(parameter, parameterMetadata, parameterMetadata.Type, argumentValue, true);
                    }
                }
                Exception innerException = null;
                try
                {
                    this.BindParameter(parameter.ParameterName, argumentValue);
                    flag = true;
                }
                catch (SetValueException exception6)
                {
                    innerException = exception6;
                }
                if (innerException != null)
                {
                    Type typeSpecified = (argumentValue == null) ? null : argumentValue.GetType();
                    ParameterBindingException exception7 = new ParameterBindingException(innerException, ErrorCategory.WriteError, this.InvocationInfo, this.GetErrorExtent(parameter), parameterMetadata.Name, parameterMetadata.Type, typeSpecified, "ParameterBinderStrings", "ParameterBindingFailed", new object[] { innerException.Message });
                    throw exception7;
                }
                Label_040E :;
                bindingTracer.WriteLine("BIND arg [{0}] to param [{1}] {2}", new object[] { argumentValue, parameter.ParameterName, flag ? "SUCCESSFUL" : "SKIPPED" });
                if (flag)
                {
                    if (this.RecordBoundParameters)
                    {
                        this.CommandLineParameters.Add(parameter.ParameterName, argumentValue);
                    }
                    MshCommandRuntime commandRuntime = this.Command.commandRuntime as MshCommandRuntime;
                    if ((commandRuntime != null) && commandRuntime.LogPipelineExecutionDetail)
                    {
                        IEnumerable source = LanguagePrimitives.GetEnumerable(argumentValue);
                        if (source != null)
                        {
                            string parameterValue = string.Join(", ", source.Cast <object>().ToArray <object>());
                            commandRuntime.PipelineProcessor.LogExecutionParameterBinding(this.InvocationInfo, parameter.ParameterName, parameterValue);
                        }
                        else
                        {
                            commandRuntime.PipelineProcessor.LogExecutionParameterBinding(this.InvocationInfo, parameter.ParameterName, (argumentValue == null) ? "" : argumentValue.ToString());
                        }
                    }
                }
                return(flag);
            }
        }
示例#14
0
 /// <summary>
 /// Constructs an instance with the specified command instance
 /// </summary>
 /// 
 /// <param name="commandRuntime">
 /// The instance of the command that the parameters should set the
 /// user feedback properties on when the parameters get bound.
 /// </param>
 /// 
 internal TransactionParameters(MshCommandRuntime commandRuntime)
 {
     _commandRuntime = commandRuntime;
 } // ctor
示例#15
0
        /// <summary>
        /// Handle the object obtained from an ObjectStream's reader
        /// based on its type.
        /// </summary>
        /// <param name="cmdlet">Cmdlet to use for outputting the object.</param>
        /// <param name="overrideInquire">Used by Receive-Job to suppress inquire preference.</param>
        public void WriteStreamObject(Cmdlet cmdlet, bool overrideInquire = false)
        {
            if (cmdlet != null)
            {
                switch (this.ObjectType)
                {
                case PSStreamObjectType.Output:
                {
                    cmdlet.WriteObject(this.Value);
                }

                break;

                case PSStreamObjectType.Error:
                {
                    ErrorRecord errorRecord = (ErrorRecord)this.Value;
                    errorRecord.PreserveInvocationInfoOnce = true;
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteError(errorRecord, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Debug:
                {
                    string            debug             = (string)Value;
                    DebugRecord       debugRecord       = new DebugRecord(debug);
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteDebug(debugRecord, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Warning:
                {
                    string            warning           = (string)Value;
                    WarningRecord     warningRecord     = new WarningRecord(warning);
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteWarning(warningRecord, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Verbose:
                {
                    string            verbose           = (string)Value;
                    VerboseRecord     verboseRecord     = new VerboseRecord(verbose);
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Progress:
                {
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteProgress((ProgressRecord)Value, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.Information:
                {
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.WriteInformation((InformationRecord)Value, overrideInquire);
                    }
                }

                break;

                case PSStreamObjectType.WarningRecord:
                {
                    WarningRecord     warningRecord     = (WarningRecord)Value;
                    MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                    if (mshCommandRuntime != null)
                    {
                        mshCommandRuntime.AppendWarningVarList(warningRecord);
                    }
                }

                break;

                case PSStreamObjectType.MethodExecutor:
                {
                    Dbg.Assert(this.Value is ClientMethodExecutor,
                               "Expected psstreamObject.value is ClientMethodExecutor");
                    ClientMethodExecutor methodExecutor = (ClientMethodExecutor)Value;
                    methodExecutor.Execute(cmdlet);
                }

                break;

                case PSStreamObjectType.BlockingError:
                {
                    CmdletMethodInvoker <object> methodInvoker = (CmdletMethodInvoker <object>)Value;
                    InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet);
                }

                break;

                case PSStreamObjectType.ShouldMethod:
                {
                    CmdletMethodInvoker <bool> methodInvoker = (CmdletMethodInvoker <bool>)Value;
                    InvokeCmdletMethodAndWaitForResults(methodInvoker, cmdlet);
                }

                break;

                case PSStreamObjectType.Exception:
                {
                    Exception e = (Exception)Value;
                    throw e;
                }
                }
            }
            else if (ObjectType == PSStreamObjectType.Exception)
            {
                Exception e = (Exception)Value;
                throw e;
            }
        }
示例#16
0
 internal ShouldProcessParameters(MshCommandRuntime commandRuntime)
 {
     using (ShouldProcessParameters.tracer.TraceConstructor((object)this))
         this.commandRuntime = commandRuntime != null ? commandRuntime : throw ShouldProcessParameters.tracer.NewArgumentNullException(nameof(commandRuntime));
 }
示例#17
0
 internal CommandInvocationIntrinsics(ExecutionContext context, PSCmdlet cmdlet)
 {
     this._context       = context;
     this._cmdlet        = cmdlet;
     this.commandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
 }
示例#18
0
 private void WriteJobResults(System.Management.Automation.Job job)
 {
     if (job != null)
     {
         if (job.JobStateInfo.State == JobState.Disconnected)
         {
             PSRemotingChildJob job2 = job as PSRemotingChildJob;
             if ((job2 != null) && job2.DisconnectedAndBlocked)
             {
                 return;
             }
         }
         if (job.JobStateInfo.State == JobState.Blocked)
         {
             DoUnblockJob(job);
         }
         if (!(job is Job2) && job.UsesResultsCollection)
         {
             Collection <PSStreamObject> collection = this.ReadAll <PSStreamObject>(job.Results);
             if (this._wait)
             {
                 foreach (PSStreamObject obj2 in collection)
                 {
                     obj2.WriteStreamObject(this, job.Results.SourceId, false);
                 }
             }
             else
             {
                 foreach (PSStreamObject obj3 in collection)
                 {
                     obj3.WriteStreamObject(this, false);
                 }
             }
         }
         else
         {
             foreach (PSObject obj4 in this.ReadAll <PSObject>(job.Output))
             {
                 if (obj4 != null)
                 {
                     base.WriteObject(obj4);
                 }
             }
             foreach (ErrorRecord record in this.ReadAll <ErrorRecord>(job.Error))
             {
                 if (record != null)
                 {
                     MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;
                     if (commandRuntime != null)
                     {
                         commandRuntime.WriteError(record, true);
                     }
                 }
             }
             foreach (VerboseRecord record2 in this.ReadAll <VerboseRecord>(job.Verbose))
             {
                 if (record2 != null)
                 {
                     MshCommandRuntime runtime2 = base.CommandRuntime as MshCommandRuntime;
                     if (runtime2 != null)
                     {
                         runtime2.WriteVerbose(record2, true);
                     }
                 }
             }
             foreach (DebugRecord record3 in this.ReadAll <DebugRecord>(job.Debug))
             {
                 if (record3 != null)
                 {
                     MshCommandRuntime runtime3 = base.CommandRuntime as MshCommandRuntime;
                     if (runtime3 != null)
                     {
                         runtime3.WriteDebug(record3, true);
                     }
                 }
             }
             foreach (WarningRecord record4 in this.ReadAll <WarningRecord>(job.Warning))
             {
                 if (record4 != null)
                 {
                     MshCommandRuntime runtime4 = base.CommandRuntime as MshCommandRuntime;
                     if (runtime4 != null)
                     {
                         runtime4.WriteWarning(record4, true);
                     }
                 }
             }
             foreach (ProgressRecord record5 in this.ReadAll <ProgressRecord>(job.Progress))
             {
                 if (record5 != null)
                 {
                     MshCommandRuntime runtime5 = base.CommandRuntime as MshCommandRuntime;
                     if (runtime5 != null)
                     {
                         runtime5.WriteProgress(record5, true);
                     }
                 }
             }
         }
         if (job.JobStateInfo.State == JobState.Failed)
         {
             this.WriteReasonError(job);
         }
     }
 }
示例#19
0
        /// <summary>
        /// Handle the object obtained from an ObjectStream's reader
        /// based on its type.
        /// </summary>
        /// <param name="cmdlet">Cmdlet to use for outputting the object.</param>
        /// <param name="instanceId"></param>
        /// <param name="overrideInquire">Suppresses prompt on messages with Inquire preference.
        /// Needed for Receive-Job</param>
        internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false)
        {
            switch (ObjectType)
            {
            case PSStreamObjectType.Output:
            {
                if (instanceId != Guid.Empty)
                {
                    PSObject o = Value as PSObject;
                    if (o != null)
                    {
                        AddSourceJobNoteProperty(o, instanceId);
                    }
                }

                cmdlet.WriteObject(Value);
            }

            break;

            case PSStreamObjectType.Error:
            {
                ErrorRecord         errorRecord       = (ErrorRecord)this.Value;
                RemotingErrorRecord remoteErrorRecord = errorRecord as RemotingErrorRecord;

                if (remoteErrorRecord == null)
                {
                    // if we get a base ErrorRecord object, check if the computerName is
                    // populated in the RecommendedAction field
                    if (errorRecord.ErrorDetails != null && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction,
                                          out jobInstanceId, out computerName);

                        errorRecord = new RemotingErrorRecord(errorRecord,
                                                              new OriginInfo(computerName, Guid.Empty,
                                                                             jobInstanceId));
                    }
                }
                else
                {
                    errorRecord = remoteErrorRecord;
                }

                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteError(errorRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Warning:
            {
                string            warning           = (string)Value;
                WarningRecord     warningRecord     = new WarningRecord(warning);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteWarning(warningRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Verbose:
            {
                string            verbose           = (string)Value;
                VerboseRecord     verboseRecord     = new VerboseRecord(verbose);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Progress:
            {
                ProgressRecord progressRecord = (ProgressRecord)Value;

                RemotingProgressRecord remotingProgressRecord = progressRecord as RemotingProgressRecord;
                if (remotingProgressRecord == null)
                {
                    Guid   jobInstanceId;
                    string computerName;
                    GetIdentifierInfo(progressRecord.CurrentOperation, out jobInstanceId,
                                      out computerName);
                    OriginInfo info = new OriginInfo(computerName, Guid.Empty, jobInstanceId);
                    progressRecord = new RemotingProgressRecord(progressRecord, info);
                }
                else
                {
                    progressRecord = remotingProgressRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteProgress(progressRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Debug:
            {
                string            debug             = (string)Value;
                DebugRecord       debugRecord       = new DebugRecord(debug);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteDebug(debugRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Information:
            {
                InformationRecord         informationRecord       = (InformationRecord)this.Value;
                RemotingInformationRecord remoteInformationRecord = informationRecord as RemotingInformationRecord;

                if (remoteInformationRecord == null)
                {
                    // if we get a base InformationRecord object, check if the computerName is
                    // populated in the Source field
                    if (!string.IsNullOrEmpty(informationRecord.Source))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(informationRecord.Source, out jobInstanceId, out computerName);
                        informationRecord = new RemotingInformationRecord(informationRecord,
                                                                          new OriginInfo(computerName, Guid.Empty,
                                                                                         jobInstanceId));
                    }
                }
                else
                {
                    informationRecord = remoteInformationRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteInformation(informationRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.WarningRecord:
            case PSStreamObjectType.MethodExecutor:
            case PSStreamObjectType.BlockingError:
            case PSStreamObjectType.ShouldMethod:
            {
                WriteStreamObject(cmdlet, overrideInquire);
            }

            break;
            }
        }
 internal TransactionParameters(MshCommandRuntime commandRuntime) => this.commandRuntime = commandRuntime;