Example #1
0
 protected void CloseAllInputStreams()
 {
     foreach (IThrottleOperation operation in this.Operations)
     {
         ExecutionCmdletHelper helper = (ExecutionCmdletHelper)operation;
         helper.Pipeline.Input.Close();
     }
 }
Example #2
0
 protected void AggregateResultsFromHelper(ExecutionCmdletHelper helper)
 {
     Pipeline pipeline = helper.Pipeline;
     pipeline.Output.DataReady += new EventHandler(this.HandleOutputReady);
     pipeline.Error.DataReady += new EventHandler(this.HandleErrorReady);
     pipeline.StateChanged += new EventHandler<PipelineStateEventArgs>(this.HandlePipelineStateChanged);
     RemotePipeline pipeline2 = pipeline as RemotePipeline;
     pipeline2.MethodExecutorStream.DataReady += new EventHandler(this.HandleHostCalls);
     pipeline2.PowerShell.Streams.Progress.DataAdded += new EventHandler<DataAddedEventArgs>(this.HandleProgressAdded);
     pipeline2.PowerShell.Streams.Warning.DataAdded += new EventHandler<DataAddedEventArgs>(this.HandleWarningAdded);
     pipeline2.PowerShell.Streams.Verbose.DataAdded += new EventHandler<DataAddedEventArgs>(this.HandleVerboseAdded);
     pipeline2.PowerShell.Streams.Debug.DataAdded += new EventHandler<DataAddedEventArgs>(this.HandleDebugAdded);
     pipeline2.IsMethodExecutorStreamEnabled = true;
     IThrottleOperation operation = helper;
     operation.OperationComplete += new EventHandler<OperationStateEventArgs>(this.HandleOperationComplete);
 }
Example #3
0
 internal PSRemotingChildJob(string remoteCommand, ExecutionCmdletHelper helper, ThrottleManager throttleManager) : base(remoteCommand)
 {
     this.hideComputerName = true;
     this.SyncObject = new object();
     base.UsesResultsCollection = true;
     this.helper = helper;
     this.remoteRunspace = helper.Pipeline.Runspace;
     this.remotePipeline = helper.Pipeline as RemotePipeline;
     this.throttleManager = throttleManager;
     RemoteRunspace remoteRunspace = this.remoteRunspace as RemoteRunspace;
     if ((remoteRunspace != null) && (remoteRunspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen))
     {
         remoteRunspace.URIRedirectionReported += new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported);
     }
     this.AggregateResultsFromHelper(helper);
     this.RegisterThrottleComplete(throttleManager);
 }
Example #4
0
 internal PSRemotingChildJob(ExecutionCmdletHelper helper, ThrottleManager throttleManager, bool aggregateResults = false)
 {
     this.hideComputerName = true;
     this.SyncObject = new object();
     base.UsesResultsCollection = true;
     this.helper = helper;
     this.remotePipeline = helper.Pipeline as RemotePipeline;
     this.remoteRunspace = helper.Pipeline.Runspace;
     this.throttleManager = throttleManager;
     if (aggregateResults)
     {
         this.AggregateResultsFromHelper(helper);
     }
     else
     {
         this.remotePipeline.StateChanged += new EventHandler<PipelineStateEventArgs>(this.HandlePipelineStateChanged);
         this.remotePipeline.Output.DataReady += new EventHandler(this.HandleOutputReady);
         this.remotePipeline.Error.DataReady += new EventHandler(this.HandleErrorReady);
     }
     IThrottleOperation operation = helper;
     operation.OperationComplete += new EventHandler<OperationStateEventArgs>(this.HandleOperationComplete);
     base.SetJobState(JobState.Disconnected, null);
 }
Example #5
0
        /// <summary>
        /// The expression will be executed in the remote computer if a
        /// remote runspace parameter or computer name is specified. If
        /// none other than command parameter is specified, then it
        /// just executes the command locally without creating a new
        /// remote runspace object.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (ParameterSetName == DefinitionNameParameterSet)
            {
                // Get the Job2 object from the Job Manager for this definition name and start the job.
                string resolvedPath = null;
                if (!string.IsNullOrEmpty(_definitionPath))
                {
                    ProviderInfo provider = null;
                    System.Collections.ObjectModel.Collection <string> paths =
                        this.Context.SessionState.Path.GetResolvedProviderPathFromPSPath(_definitionPath, out provider);

                    // Only file system paths are allowed.
                    if (!provider.NameEquals(this.Context.ProviderNames.FileSystem))
                    {
                        string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotFSProvider,
                                                           _definitionName,
                                                           _definitionPath,
                                                           provider.FullName);
                        WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotFileSystemProvider",
                                                   ErrorCategory.InvalidArgument, null));

                        return;
                    }

                    // Only a single file path is allowed.
                    if (paths.Count != 1)
                    {
                        string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotSingle,
                                                           _definitionName,
                                                           _definitionPath);
                        WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotSingle",
                                                   ErrorCategory.InvalidArgument, null));

                        return;
                    }

                    resolvedPath = paths[0];
                }
                List <Job2> jobs = JobManager.GetJobToStart(_definitionName, resolvedPath, _definitionType, this, false);

                if (jobs.Count == 0)
                {
                    string message = (_definitionType != null) ?
                                     StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound2, _definitionType, _definitionName) :
                                     StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound1, _definitionName);

                    WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNameNotFound",
                                               ErrorCategory.ObjectNotFound, null));

                    return;
                }

                if (jobs.Count > 1)
                {
                    string message = StringUtil.Format(RemotingErrorIdStrings.StartJobManyDefNameMatches, _definitionName);
                    WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNameMoreThanOneMatch",
                                               ErrorCategory.InvalidResult, null));

                    return;
                }

                // Start job.
                Job2 job = jobs[0];
                job.StartJob();

                // Write job object to host.
                WriteObject(job);

                return;
            }

            if (_firstProcessRecord)
            {
                _firstProcessRecord = false;

                PSRemotingJob job = new PSRemotingJob(ResolvedComputerNames, Operations,
                                                      ScriptBlock.ToString(), ThrottleLimit, _name);

                job.PSJobTypeName = s_startJobType;

                this.JobRepository.Add(job);
                WriteObject(job);
            }

            // inject input
            if (InputObject != AutomationNull.Value)
            {
                foreach (IThrottleOperation operation in Operations)
                {
                    ExecutionCmdletHelper helper = (ExecutionCmdletHelper)operation;
                    helper.Pipeline.Input.Write(InputObject);
                }
            }
        } // ProcessRecord
Example #6
0
 protected override void ProcessRecord()
 {
     if (base.ParameterSetName == "DefinitionName")
     {
         string definitionPath = null;
         if (!string.IsNullOrEmpty(this._definitionPath))
         {
             ProviderInfo        provider = null;
             Collection <string> resolvedProviderPathFromPSPath = base.Context.SessionState.Path.GetResolvedProviderPathFromPSPath(this._definitionPath, out provider);
             if (!provider.NameEquals(base.Context.ProviderNames.FileSystem))
             {
                 string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotFSProvider, new object[] { this._definitionName, this._definitionPath, provider.FullName });
                 base.WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotFileSystemProvider", ErrorCategory.InvalidArgument, null));
                 return;
             }
             if (resolvedProviderPathFromPSPath.Count != 1)
             {
                 string str3 = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotSingle, this._definitionName, this._definitionPath);
                 base.WriteError(new ErrorRecord(new RuntimeException(str3), "StartJobFromDefinitionNamePathInvalidNotSingle", ErrorCategory.InvalidArgument, null));
                 return;
             }
             definitionPath = resolvedProviderPathFromPSPath[0];
         }
         List <Job2> list = base.JobManager.GetJobToStart(this._definitionName, definitionPath, this._definitionType, this, false);
         if (list.Count == 0)
         {
             string str4 = (this._definitionType != null) ? StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound2, this._definitionType, this._definitionName) : StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound1, this._definitionName);
             base.WriteError(new ErrorRecord(new RuntimeException(str4), "StartJobFromDefinitionNameNotFound", ErrorCategory.ObjectNotFound, null));
         }
         else if (list.Count > 1)
         {
             string str5 = StringUtil.Format(RemotingErrorIdStrings.StartJobManyDefNameMatches, this._definitionName);
             base.WriteError(new ErrorRecord(new RuntimeException(str5), "StartJobFromDefinitionNameMoreThanOneMatch", ErrorCategory.InvalidResult, null));
         }
         else
         {
             Job2 sendToPipeline = list[0];
             sendToPipeline.StartJob();
             base.WriteObject(sendToPipeline);
         }
     }
     else
     {
         if (this.firstProcessRecord)
         {
             this.firstProcessRecord = false;
             PSRemotingJob item = new PSRemotingJob(base.ResolvedComputerNames, base.Operations, this.ScriptBlock.ToString(), this.ThrottleLimit, this.name)
             {
                 PSJobTypeName = StartJobType
             };
             base.JobRepository.Add(item);
             base.WriteObject(item);
         }
         if (this.InputObject != AutomationNull.Value)
         {
             foreach (IThrottleOperation operation in base.Operations)
             {
                 ExecutionCmdletHelper helper = (ExecutionCmdletHelper)operation;
                 helper.Pipeline.Input.Write(this.InputObject);
             }
         }
     }
 }
Example #7
0
 protected void StopAggregateResultsFromHelper(ExecutionCmdletHelper helper)
 {
     this.RemoveAggreateCallbacksFromHelper(helper);
     helper.Pipeline.Dispose();
 }
Example #8
0
 protected void RemoveAggreateCallbacksFromHelper(ExecutionCmdletHelper helper)
 {
     Pipeline pipeline = helper.Pipeline;
     pipeline.Output.DataReady -= new EventHandler(this.HandleOutputReady);
     pipeline.Error.DataReady -= new EventHandler(this.HandleErrorReady);
     pipeline.StateChanged -= new EventHandler<PipelineStateEventArgs>(this.HandlePipelineStateChanged);
     RemotePipeline pipeline2 = pipeline as RemotePipeline;
     pipeline2.MethodExecutorStream.DataReady -= new EventHandler(this.HandleHostCalls);
     if (pipeline2.PowerShell != null)
     {
         pipeline2.PowerShell.Streams.Progress.DataAdded -= new EventHandler<DataAddedEventArgs>(this.HandleProgressAdded);
         pipeline2.PowerShell.Streams.Warning.DataAdded -= new EventHandler<DataAddedEventArgs>(this.HandleWarningAdded);
         pipeline2.PowerShell.Streams.Verbose.DataAdded -= new EventHandler<DataAddedEventArgs>(this.HandleVerboseAdded);
         pipeline2.PowerShell.Streams.Debug.DataAdded -= new EventHandler<DataAddedEventArgs>(this.HandleDebugAdded);
         pipeline2.IsMethodExecutorStreamEnabled = false;
     }
 }
Example #9
0
 protected void ProcessJobFailure(ExecutionCmdletHelper helper, out Exception failureException, out ErrorRecord failureErrorRecord)
 {
     RemotePipeline pipeline = helper.Pipeline as RemotePipeline;
     RemoteRunspace runspace = pipeline.GetRunspace() as RemoteRunspace;
     failureException = null;
     failureErrorRecord = null;
     if (helper.InternalException != null)
     {
         string errorId = "RemotePipelineExecutionFailed";
         failureException = helper.InternalException;
         if ((failureException is InvalidRunspaceStateException) || (failureException is InvalidRunspacePoolStateException))
         {
             errorId = "InvalidSessionState";
             if (!string.IsNullOrEmpty(failureException.Source))
             {
                 errorId = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { errorId, failureException.Source });
             }
         }
         failureErrorRecord = new ErrorRecord(helper.InternalException, errorId, ErrorCategory.OperationStopped, helper);
     }
     else if (runspace.RunspaceStateInfo.State == RunspaceState.Broken)
     {
         failureException = runspace.RunspaceStateInfo.Reason;
         object computerName = runspace.ConnectionInfo.ComputerName;
         string str2 = null;
         PSRemotingTransportException exception = failureException as PSRemotingTransportException;
         string fQEIDFromTransportError = WSManTransportManagerUtils.GetFQEIDFromTransportError((exception != null) ? exception.ErrorCode : 0, "PSSessionStateBroken");
         if (exception != null)
         {
             str2 = "[" + runspace.ConnectionInfo.ComputerName + "] ";
             if (exception.ErrorCode == -2144108135)
             {
                 string str4 = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.URIRedirectionReported, new object[] { exception.Message, "MaximumConnectionRedirectionCount", "PSSessionOption", "AllowRedirection" });
                 str2 = str2 + str4;
             }
             else if (!string.IsNullOrEmpty(exception.Message))
             {
                 str2 = str2 + exception.Message;
             }
             else if (!string.IsNullOrEmpty(exception.TransportMessage))
             {
                 str2 = str2 + exception.TransportMessage;
             }
         }
         if (failureException == null)
         {
             failureException = new RuntimeException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteRunspaceOpenUnknownState, new object[] { runspace.RunspaceStateInfo.State }));
         }
         failureErrorRecord = new ErrorRecord(failureException, computerName, fQEIDFromTransportError, ErrorCategory.OpenError, null, null, null, null, null, str2, null);
     }
     else if (pipeline.PipelineStateInfo.State == PipelineState.Failed)
     {
         object targetObject = runspace.ConnectionInfo.ComputerName;
         failureException = pipeline.PipelineStateInfo.Reason;
         if (failureException != null)
         {
             RemoteException exception2 = failureException as RemoteException;
             ErrorRecord errorRecord = null;
             if (exception2 != null)
             {
                 errorRecord = exception2.ErrorRecord;
             }
             else
             {
                 errorRecord = new ErrorRecord(pipeline.PipelineStateInfo.Reason, "JobFailure", ErrorCategory.OperationStopped, targetObject);
             }
             string str5 = ((RemoteRunspace) pipeline.GetRunspace()).ConnectionInfo.ComputerName;
             Guid instanceId = pipeline.GetRunspace().InstanceId;
             OriginInfo originInfo = new OriginInfo(str5, instanceId);
             failureErrorRecord = new RemotingErrorRecord(errorRecord, originInfo);
         }
     }
 }
Example #10
0
        protected void DeterminedAndSetJobState(ExecutionCmdletHelper helper)
        {
            Exception exception;
            this.ProcessJobFailure(helper, out exception, out this.failureErrorRecord);
            if (exception != null)
            {
                base.SetJobState(JobState.Failed, exception);
            }
            else
            {
                switch (helper.Pipeline.PipelineStateInfo.State)
                {
                    case PipelineState.NotStarted:
                        base.SetJobState(JobState.Stopped);
                        return;

                    case PipelineState.Completed:
                        base.SetJobState(JobState.Completed);
                        return;
                }
                base.SetJobState(JobState.Stopped);
            }
        }