Пример #1
0
        private void WriteReasonError(System.Management.Automation.Job job)
        {
            PSRemotingChildJob job2 = job as PSRemotingChildJob;

            if ((job2 != null) && (job2.FailureErrorRecord != null))
            {
                this._results.Add(new PSStreamObject(PSStreamObjectType.Error, job2.FailureErrorRecord, job2.InstanceId));
            }
            else if (job.JobStateInfo.Reason != null)
            {
                Exception          reason     = job.JobStateInfo.Reason;
                Exception          exception  = reason;
                JobFailedException exception3 = reason as JobFailedException;
                if (exception3 != null)
                {
                    exception = exception3.Reason;
                }
                ErrorRecord record = new ErrorRecord(exception, "JobStateFailed", ErrorCategory.InvalidResult, null);
                if ((exception3 != null) && (exception3.DisplayScriptPosition != null))
                {
                    if (record.InvocationInfo == null)
                    {
                        record.SetInvocationInfo(new InvocationInfo(null, null));
                    }
                    record.InvocationInfo.DisplayScriptPosition = exception3.DisplayScriptPosition;
                }
                this._results.Add(new PSStreamObject(PSStreamObjectType.Error, record, job.InstanceId));
            }
        }
Пример #2
0
        internal void ReportJobFailure(IContainsErrorRecord exception)
        {
            TerminatingErrorTracker terminatingErrorTracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo);

            bool      sessionWasAlreadyTerminated = false;
            bool      isThisTerminatingError      = false;
            Exception brokenSessionException      = null;

            lock (_jobStateLock)
            {
                if (!_jobWasStopped)
                {
                    brokenSessionException = terminatingErrorTracker.GetExceptionIfBrokenSession(
                        this.JobContext.Session,
                        this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SkipTestConnection,
                        out sessionWasAlreadyTerminated);
                }
            }

            if (brokenSessionException != null)
            {
                string brokenSessionMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationResources.CimJob_BrokenSession,
                    brokenSessionException.Message);
                exception = CimJobException.CreateWithFullControl(
                    this.JobContext,
                    brokenSessionMessage,
                    "CimJob_BrokenCimSession",
                    ErrorCategory.ResourceUnavailable,
                    brokenSessionException);
                isThisTerminatingError = true;
            }
            else
            {
                CimJobException cje = exception as CimJobException;
                if ((cje != null) && (cje.IsTerminatingError))
                {
                    terminatingErrorTracker.MarkSessionAsTerminated(this.JobContext.Session, out sessionWasAlreadyTerminated);
                    isThisTerminatingError = true;
                }
            }

            bool writeError = !sessionWasAlreadyTerminated;

            if (writeError)
            {
                lock (_jobStateLock)
                {
                    if (_jobWasStopped)
                    {
                        writeError = false;
                    }
                }
            }

            ErrorRecord errorRecord = exception.ErrorRecord;

            errorRecord.SetInvocationInfo(this.JobContext.CmdletInvocationInfo);
            errorRecord.PreserveInvocationInfoOnce = true;

            if (writeError)
            {
                lock (_jobStateLock)
                {
                    if (!_alreadyReachedCompletedState)
                    {
                        if (isThisTerminatingError)
                        {
                            this.Error.Add(errorRecord);
                            CmdletMethodInvoker <bool> methodInvoker = terminatingErrorTracker.GetErrorReportingDelegate(errorRecord);
                            this.Results.Add(new PSStreamObject(PSStreamObjectType.ShouldMethod, methodInvoker));
                        }
                        else
                        {
                            this.WriteError(errorRecord);
                        }
                    }
                }
            }

            this.SetCompletedJobState(JobState.Failed, errorRecord.Exception);
        }
Пример #3
0
        internal void ReportJobFailure(IContainsErrorRecord exception)
        {
            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo);
            bool      flag  = false;
            bool      flag1 = false;
            Exception exceptionIfBrokenSession = null;

            lock (this._jobStateLock)
            {
                if (!this._jobWasStopped)
                {
                    exceptionIfBrokenSession = tracker.GetExceptionIfBrokenSession(this.JobContext.Session, this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SkipTestConnection, out flag);
                }
            }
            if (exceptionIfBrokenSession == null)
            {
                CimJobException cimJobException = exception as CimJobException;
                if (cimJobException != null && cimJobException.IsTerminatingError)
                {
                    tracker.MarkSessionAsTerminated(this.JobContext.Session, out flag);
                    flag1 = true;
                }
            }
            else
            {
                object[] message = new object[1];
                message[0] = exceptionIfBrokenSession.Message;
                string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_BrokenSession, message);
                exception = CimJobException.CreateWithFullControl(this.JobContext, str, "CimJob_BrokenCimSession", ErrorCategory.ResourceUnavailable, exceptionIfBrokenSession);
                flag1     = true;
            }
            bool flag2 = !flag;

            if (flag2)
            {
                lock (this._jobStateLock)
                {
                    if (this._jobWasStopped)
                    {
                        flag2 = false;
                    }
                }
            }
            ErrorRecord errorRecord = exception.ErrorRecord;

            errorRecord.SetInvocationInfo(this.JobContext.CmdletInvocationInfo);
            errorRecord.PreserveInvocationInfoOnce = true;
            if (flag2)
            {
                lock (this._jobStateLock)
                {
                    if (!this._alreadyReachedCompletedState)
                    {
                        if (!flag1)
                        {
                            this.WriteError(errorRecord);
                        }
                        else
                        {
                            base.Error.Add(errorRecord);
                            CmdletMethodInvoker <bool> errorReportingDelegate = tracker.GetErrorReportingDelegate(errorRecord);
                            base.Results.Add(new PSStreamObject(PSStreamObjectType.ShouldMethod, errorReportingDelegate));
                        }
                    }
                }
            }
            this.SetCompletedJobState(JobState.Failed, errorRecord.Exception);
        }