Exemplo n.º 1
0
        /// <summary>
        /// Constructs the parameter binder with the specified type metadata. The binder is only valid
        /// for a single instance of a bindable runtime-defined parameter collection and only for the duration of a command.
        /// </summary>
        /// 
        /// <param name="target">
        /// The target runtime-defined parameter collection that the parameter values will be bound to.
        /// </param>
        /// 
        /// <param name="command">
        /// An instance of the command so that attributes can access the context.
        /// </param>
        /// 
        /// <param name="commandLineParameters">
        /// The Command line parameter collection to update...
        /// </param>
        /// 
        internal RuntimeDefinedParameterBinder(
            RuntimeDefinedParameterDictionary target,
            InternalCommand command,
            CommandLineParameters commandLineParameters)
            : base(target, command.MyInvocation, command.Context, command)
        {
            // NTRAID#Windows Out Of Band Releases-927103-2006/01/25-JonN
            foreach (var pair in target)
            {
                string key = pair.Key;
                RuntimeDefinedParameter pp = pair.Value;
                string ppName = (null == pp) ? null : pp.Name;
                if (null == pp || key != ppName)
                {
                    ParameterBindingException bindingException =
                        new ParameterBindingException(
                            ErrorCategory.InvalidArgument,
                            command.MyInvocation,
                            null,
                            ppName,
                            null,
                            null,
                            ParameterBinderStrings.RuntimeDefinedParameterNameMismatch,
                            "RuntimeDefinedParameterNameMismatch",
                            key);

                    throw bindingException;
                }
            }
            this.CommandLineParameters = commandLineParameters;
        }
Exemplo n.º 2
0
        internal bool RecordFailure(Exception e, InternalCommand command)
        {
            bool stopping = false;

            lock (this.StopReasonLock)
            {
                if (this.firstTerminatingError == null)
                {
                    RuntimeException.LockStackTrace(e);
                    this.firstTerminatingError = e;
                }
                else if ((!(this.firstTerminatingError is PipelineStoppedException) && (command != null)) && (command.Context != null))
                {
                    Exception innerException = e;
                    while (((innerException is TargetInvocationException) || (innerException is CmdletInvocationException)) && (innerException.InnerException != null))
                    {
                        innerException = innerException.InnerException;
                    }
                    if (!(innerException is PipelineStoppedException))
                    {
                        InvalidOperationException exception = new InvalidOperationException(StringUtil.Format(PipelineStrings.SecondFailure, new object[] { this.firstTerminatingError.GetType().Name, this.firstTerminatingError.StackTrace, innerException.GetType().Name, innerException.StackTrace }), innerException);
                        MshLog.LogCommandHealthEvent(command.Context, exception, Severity.Warning);
                    }
                }
                stopping      = this.stopping;
                this.stopping = true;
            }
            return(!stopping);
        }
Exemplo n.º 3
0
 public void Begin(InternalCommand command)
 {
     if ((command == null) || (command.MyInvocation == null))
     {
         throw new ArgumentNullException("command");
     }
     this.Begin(command.MyInvocation.ExpectingInput, command.commandRuntime);
 }
Exemplo n.º 4
0
 internal MshCommandRuntime(System.Management.Automation.ExecutionContext context, CommandInfo commandInfo, InternalCommand thisCommand)
 {
     this.context = context;
     this.host = context.EngineHostInterface;
     this.CBhost = context.EngineHostInterface;
     this.commandInfo = commandInfo;
     this.thisCommand = thisCommand;
     this.shouldLogPipelineExecutionDetail = this.InitShouldLogPipelineExecutionDetail();
 }
Exemplo n.º 5
0
 internal ParameterBinderBase(System.Management.Automation.InvocationInfo invocationInfo, System.Management.Automation.ExecutionContext context, InternalCommand command)
 {
     this.RecordBoundParameters = true;
     bindingTracer.ShowHeaders = false;
     this.command = command;
     this.invocationInfo = invocationInfo;
     this.context = context;
     this.engine = context.EngineIntrinsics;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a ScriptParameterBinder with the specified context
        /// </summary>
        /// 
        /// <param name="script">
        /// The script block representing the code being run
        /// </param>
        /// 
        /// <param name="invocationInfo">
        /// The invocation information about the code that is being run.
        /// </param>
        /// 
        /// <param name="context">
        /// The context under which the shell function is executing.
        /// </param>
        /// 
        /// <param name="command">
        /// The command instance that represents the script in a pipeline. May be null.
        /// </param>
        /// 
        /// <param name="localScope">
        /// If binding in a new local scope, the scope to set variables in.  If dotting, the value is null.
        /// </param>
        internal ScriptParameterBinder(
            ScriptBlock script,
            InvocationInfo invocationInfo,
            ExecutionContext context,
            InternalCommand command,
            SessionStateScope localScope) : base(invocationInfo, context, command)
        {
            Diagnostics.Assert(script != null, "caller to verify script is not null.");

            this.Script = script;
            this.LocalScope = localScope;
        }
 internal ScriptParameterBinderController(ScriptBlock script, InvocationInfo invocationInfo, ExecutionContext context, InternalCommand command, SessionStateScope localScope) : base(invocationInfo, context, new ScriptParameterBinder(script, invocationInfo, context, command, localScope))
 {
     this.DollarArgs = new List<object>();
     if (script.HasDynamicParameters)
     {
         base.UnboundParameters = base.BindableParameters.ReplaceMetadata(script.ParameterMetadata);
     }
     else
     {
         base._bindableParameters = script.ParameterMetadata;
         base.UnboundParameters = new List<MergedCompiledCommandParameter>(base._bindableParameters.BindableParameters.Values);
     }
 }
Exemplo n.º 8
0
 internal ProviderIntrinsics(Cmdlet cmdlet)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     this.cmdlet = cmdlet;
     this.item = new ItemCmdletProviderIntrinsics(cmdlet);
     this.childItem = new ChildItemCmdletProviderIntrinsics(cmdlet);
     this.content = new ContentCmdletProviderIntrinsics(cmdlet);
     this.property = new PropertyCmdletProviderIntrinsics(cmdlet);
     this.securityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(cmdlet);
 }
 internal RuntimeDefinedParameterBinder(RuntimeDefinedParameterDictionary target, InternalCommand command, CommandLineParameters commandLineParameters) : base(target, command.MyInvocation, command.Context, command)
 {
     foreach (string str in target.Keys)
     {
         RuntimeDefinedParameter parameter = target[str];
         string parameterName = (parameter == null) ? null : parameter.Name;
         if ((parameter == null) || (str != parameterName))
         {
             ParameterBindingException exception = new ParameterBindingException(ErrorCategory.InvalidArgument, command.MyInvocation, null, parameterName, null, null, "ParameterBinderStrings", "RuntimeDefinedParameterNameMismatch", new object[] { str });
             throw exception;
         }
     }
     base.CommandLineParameters = commandLineParameters;
 }
        /// <summary>
        /// Initializes the cmdlet parameter binder controller for
        /// the specified cmdlet and engine context
        /// </summary>
        /// 
        /// <param name="script">
        /// The script that contains the parameter metadata.
        /// </param>
        /// <param name="invocationInfo">
        /// The invocation information about the code being run.
        /// </param>
        /// <param name="context">
        /// The engine context the cmdlet is run in.
        /// </param>
        /// <param name="command">
        /// The command that the parameters will be bound to.
        /// </param>
        /// <param name="localScope">
        /// The scope that the parameter binder will use to set parameters.
        /// </param>
        internal ScriptParameterBinderController(
            ScriptBlock script,
            InvocationInfo invocationInfo,
            ExecutionContext context,
            InternalCommand command,
            SessionStateScope localScope)
            : base(invocationInfo, context, new ScriptParameterBinder(script, invocationInfo, context, command, localScope))
        {
            this.DollarArgs = new List<object>();

            // Add the script parameter metadata to the bindable parameters
            // And add them to the unbound parameters list

            if (script.HasDynamicParameters)
            {
                UnboundParameters = this.BindableParameters.ReplaceMetadata(script.ParameterMetadata);
            }
            else
            {
                _bindableParameters = script.ParameterMetadata;
                UnboundParameters = new List<MergedCompiledCommandParameter>(_bindableParameters.BindableParameters.Values);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor for InvocationInfo object when the associated command object is present. 
 /// </summary>
 /// <param name="command"></param>
 internal InvocationInfo(InternalCommand command)
     : this(command.CommandInfo,
            command.InvocationExtent ?? PositionUtilities.EmptyExtent)
 {
     CommandOrigin = command.CommandOrigin;
 }
Exemplo n.º 12
0
 internal ScriptParameterBinder(ScriptBlock script, InvocationInfo invocationInfo, ExecutionContext context, InternalCommand command, SessionStateScope localScope) : base(invocationInfo, context, command)
 {
     this._copyMutableValueSite = CallSite<Func<CallSite, object, object>>.Create(PSVariableAssignmentBinder.Get());
     this.Script = script;
     this.LocalScope = localScope;
 }
Exemplo n.º 13
0
 internal void EnterNestedPrompt(InternalCommand callingCommand)
 {
     LocalRunspace runspace = null;
     try
     {
         runspace = this.Runspace as LocalRunspace;
     }
     catch (PSNotImplementedException)
     {
     }
     if (runspace != null)
     {
         Pipeline currentlyRunningPipeline = this.Runspace.GetCurrentlyRunningPipeline();
         if ((currentlyRunningPipeline != null) && (currentlyRunningPipeline == runspace.PulsePipeline))
         {
             throw new InvalidOperationException();
         }
     }
     if (this.nestedPromptCount < 0)
     {
         throw PSTraceSource.NewInvalidOperationException("InternalHostStrings", "EnterExitNestedPromptOutOfSync", new object[0]);
     }
     this.nestedPromptCount++;
     this.executionContext.SetVariable(SpecialVariables.NestedPromptCounterVarPath, this.nestedPromptCount);
     PromptContextData item = new PromptContextData {
         SavedContextData = this.executionContext.SaveContextData(),
         SavedCurrentlyExecutingCommandVarValue = this.executionContext.GetVariableValue(SpecialVariables.CurrentlyExecutingCommandVarPath),
         SavedPSBoundParametersVarValue = this.executionContext.GetVariableValue(SpecialVariables.PSBoundParametersVarPath),
         RunspaceAvailability = this.Context.CurrentRunspace.RunspaceAvailability,
         LanguageMode = this.executionContext.LanguageMode
     };
     PSPropertyInfo info = null;
     PSPropertyInfo info2 = null;
     object obj2 = null;
     object obj3 = null;
     if (callingCommand != null)
     {
         PSObject newValue = PSObject.AsPSObject(callingCommand);
         info = newValue.Properties["CommandInfo"];
         if (info == null)
         {
             newValue.Properties.Add(new PSNoteProperty("CommandInfo", callingCommand.CommandInfo));
         }
         else
         {
             obj2 = info.Value;
             info.Value = callingCommand.CommandInfo;
         }
         info2 = newValue.Properties["StackTrace"];
         if (info2 == null)
         {
             newValue.Properties.Add(new PSNoteProperty("StackTrace", new StackTrace()));
         }
         else
         {
             obj3 = info2.Value;
             info2.Value = new StackTrace();
         }
         this.executionContext.SetVariable(SpecialVariables.CurrentlyExecutingCommandVarPath, newValue);
     }
     this.contextStack.Push(item);
     this.executionContext.PSDebugTraceStep = false;
     this.executionContext.PSDebugTraceLevel = 0;
     this.executionContext.ResetShellFunctionErrorOutputPipe();
     if (this.executionContext.HasRunspaceEverUsedConstrainedLanguageMode)
     {
         this.executionContext.LanguageMode = PSLanguageMode.ConstrainedLanguage;
     }
     this.Context.CurrentRunspace.UpdateRunspaceAvailability(RunspaceAvailability.AvailableForNestedCommand, true);
     try
     {
         this.externalHostRef.Value.EnterNestedPrompt();
     }
     catch
     {
         this.ExitNestedPromptHelper();
         throw;
     }
     finally
     {
         if (info != null)
         {
             info.Value = obj2;
         }
         if (info2 != null)
         {
             info2.Value = obj3;
         }
     }
 }
 internal ItemCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     _cmdlet = cmdlet;
 }
Exemplo n.º 15
0
 public StopUpstreamCommandsException(InternalCommand requestingCommand)
 {
     this.RequestingCommandProcessor = requestingCommand.Context.CurrentCommandProcessor;
 }
Exemplo n.º 16
0
 internal AllowWrite(InternalCommand permittedToWrite, bool permittedToWriteToPipeline)
 {
     if (permittedToWrite == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite");
     }
     MshCommandRuntime commandRuntime = permittedToWrite.commandRuntime as MshCommandRuntime;
     if (commandRuntime == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime");
     }
     this._pp = commandRuntime.PipelineProcessor;
     if (this._pp == null)
     {
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime.PipelineProcessor");
     }
     this._wasPermittedToWrite = this._pp._permittedToWrite;
     this._wasPermittedToWriteToPipeline = this._pp._permittedToWriteToPipeline;
     this._wasPermittedToWriteThread = this._pp._permittedToWriteThread;
     this._pp._permittedToWrite = permittedToWrite;
     this._pp._permittedToWriteToPipeline = permittedToWriteToPipeline;
     this._pp._permittedToWriteThread = Thread.CurrentThread;
 }
Exemplo n.º 17
0
 internal ParameterBinderController NewParameterBinderController(InternalCommand command)
 {
     ParameterBinderBase base2;
     Cmdlet cmdlet = command as Cmdlet;
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentException("command");
     }
     IScriptCommandInfo commandInfo = base.CommandInfo as IScriptCommandInfo;
     if (commandInfo != null)
     {
         base2 = new ScriptParameterBinder(commandInfo.ScriptBlock, cmdlet.MyInvocation, base._context, cmdlet, base.CommandScope);
     }
     else
     {
         base2 = new ReflectionParameterBinder(cmdlet, cmdlet);
     }
     this._cmdletParameterBinderController = new System.Management.Automation.CmdletParameterBinderController(cmdlet, base.CommandInfo.CommandMetadata, base2);
     return this._cmdletParameterBinderController;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Begin the scope where WriteObject/WriteError is permitted.
 /// </summary>
 internal AllowWrite(InternalCommand permittedToWrite, bool permittedToWriteToPipeline)
 {
     if (null == permittedToWrite)
         throw PSTraceSource.NewArgumentNullException("permittedToWrite");
     MshCommandRuntime mcr = permittedToWrite.commandRuntime as MshCommandRuntime;
     if (mcr == null)
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime");
     _pp = mcr.PipelineProcessor;
     if (_pp == null)
         throw PSTraceSource.NewArgumentNullException("permittedToWrite.CommandRuntime.PipelineProcessor");
     _wasPermittedToWrite = _pp._permittedToWrite;
     _wasPermittedToWriteToPipeline = _pp._permittedToWriteToPipeline;
     _wasPermittedToWriteThread = _pp._permittedToWriteThread;
     _pp._permittedToWrite = permittedToWrite;
     _pp._permittedToWriteToPipeline = permittedToWriteToPipeline;
     _pp._permittedToWriteThread = Thread.CurrentThread;
 }
Exemplo n.º 19
0
 internal MshCommandRuntime(ExecutionContext context, CommandInfo commandInfo, InternalCommand thisCommand)
 {
     Context = context;
     Host = context.EngineHostInterface;
     this.CBhost = (InternalHost)context.EngineHostInterface;
     _commandInfo = commandInfo;
     _thisCommand = thisCommand;
     LogPipelineExecutionDetail = InitShouldLogPipelineExecutionDetail();
 }
Exemplo n.º 20
0
        /// <summary>
        /// Gets a new instance of a ParameterBinderController using a NativeCommandParameterBinder
        /// </summary>
        /// 
        /// <param name="command">
        /// The native command to be run.
        /// </param>
        /// 
        /// <returns>
        /// A new parameter binder controller for the specified command.
        /// </returns>
        /// 
        internal ParameterBinderController NewParameterBinderController(InternalCommand command)
        {
            Dbg.Assert(_isPreparedCalled, "parameter binder should not be created before prepared is called");

            if (_isMiniShell)
            {
                _nativeParameterBinderController =
                    new MinishellParameterBinderController(
                        this.nativeCommand);
            }
            else
            {
                _nativeParameterBinderController =
                    new NativeCommandParameterBinderController(
                        this.nativeCommand);
            }

            return _nativeParameterBinderController;
        }
Exemplo n.º 21
0
 internal ParameterBinderController NewParameterBinderController(InternalCommand command)
 {
     if (this.isMiniShell)
     {
         this.nativeParameterBinderController = new MinishellParameterBinderController(this.nativeCommand);
     }
     else
     {
         this.nativeParameterBinderController = new NativeCommandParameterBinderController(this.nativeCommand);
     }
     return this.nativeParameterBinderController;
 }
Exemplo n.º 22
0
 internal ProcessInputWriter(InternalCommand command)
 {
     this.command = command;
 }
Exemplo n.º 23
0
 internal PropertyCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     _cmdlet = cmdlet;
 }
 internal SecurityDescriptorCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     _cmdlet = cmdlet;
 }
Exemplo n.º 25
0
 /// <summary>
 /// Creates an instance of ProcessInputWriter 
 /// </summary>
 internal ProcessInputWriter(InternalCommand command)
 {
     Dbg.Assert(command != null, "Caller should validate the parameter");
     _command = command;
 }
Exemplo n.º 26
0
        // CommandProcessor

#endregion ctor

#region internal members
        /// <summary>
        /// Returns a CmdletParameterBinderController for the specified command
        /// </summary>
        /// 
        /// <param name="command">
        /// The cmdlet to bind parameters to.
        /// </param>
        /// 
        /// <returns>
        /// A new instance of a CmdletParameterBinderController.
        /// </returns>
        /// 
        /// <exception cref="ArgumentException">
        /// if <paramref name="command"/> is not a Cmdlet.
        /// </exception>
        /// 
        internal ParameterBinderController NewParameterBinderController(InternalCommand command)
        {
            Cmdlet cmdlet = command as Cmdlet;
            if (cmdlet == null)
            {
                throw PSTraceSource.NewArgumentException("command");
            }

            ParameterBinderBase parameterBinder;
            IScriptCommandInfo scriptCommandInfo = CommandInfo as IScriptCommandInfo;
            if (scriptCommandInfo != null)
            {
                parameterBinder = new ScriptParameterBinder(scriptCommandInfo.ScriptBlock, cmdlet.MyInvocation, this._context, cmdlet, CommandScope);
            }
            else
            {
                parameterBinder = new ReflectionParameterBinder(cmdlet, cmdlet);
            }

            _cmdletParameterBinderController = new CmdletParameterBinderController(cmdlet, CommandInfo.CommandMetadata, parameterBinder);

            return _cmdletParameterBinderController;
        }
Exemplo n.º 27
0
 internal bool RecordFailure(Exception e, InternalCommand command)
 {
     bool stopping = false;
     lock (this.StopReasonLock)
     {
         if (this.firstTerminatingError == null)
         {
             RuntimeException.LockStackTrace(e);
             this.firstTerminatingError = e;
         }
         else if ((!(this.firstTerminatingError is PipelineStoppedException) && (command != null)) && (command.Context != null))
         {
             Exception innerException = e;
             while (((innerException is TargetInvocationException) || (innerException is CmdletInvocationException)) && (innerException.InnerException != null))
             {
                 innerException = innerException.InnerException;
             }
             if (!(innerException is PipelineStoppedException))
             {
                 InvalidOperationException exception = new InvalidOperationException(StringUtil.Format(PipelineStrings.SecondFailure, new object[] { this.firstTerminatingError.GetType().Name, this.firstTerminatingError.StackTrace, innerException.GetType().Name, innerException.StackTrace }), innerException);
                 MshLog.LogCommandHealthEvent(command.Context, exception, Severity.Warning);
             }
         }
         stopping = this.stopping;
         this.stopping = true;
     }
     return !stopping;
 }
Exemplo n.º 28
0
 /// <summary>
 /// Makes an internal note of the exception, but only if this is
 /// the first error.
 /// </summary>
 /// <param name="e">error which terminated the pipeline</param>
 /// <param name="command">command against which to log SecondFailure</param>
 /// <returns>true iff the pipeline was not already stopped</returns>
 internal bool RecordFailure(Exception e, InternalCommand command)
 {
     bool wasStopping = false;
     lock (_stopReasonLock)
     {
         if (null == _firstTerminatingError)
         {
             _firstTerminatingError = ExceptionDispatchInfo.Capture(e);
         }
         // 905900-2005/05/12
         // Drop5: Error Architecture: Log/trace second and subsequent RecordFailure
         // Note that the pipeline could have been stopped asynchronously
         // before hitting the error, therefore we check whether
         // firstTerminatingError is PipelineStoppedException.
         else if ((!(_firstTerminatingError.SourceException is PipelineStoppedException))
             && null != command && null != command.Context)
         {
             Exception ex = e;
             while ((ex is TargetInvocationException || ex is CmdletInvocationException)
                     && (null != ex.InnerException))
             {
                 ex = ex.InnerException;
             }
             if (!(ex is PipelineStoppedException))
             {
                 string message = StringUtil.Format(PipelineStrings.SecondFailure,
                     _firstTerminatingError.GetType().Name,
                     _firstTerminatingError.SourceException.StackTrace,
                     ex.GetType().Name,
                     ex.StackTrace
                 );
                 InvalidOperationException ioe
                     = new InvalidOperationException(message, ex);
                 MshLog.LogCommandHealthEvent(
                     command.Context,
                     ioe,
                     Severity.Warning);
             }
         }
         wasStopping = _stopping;
         _stopping = true;
     }
     return !wasStopping;
 }