public override void OnCompleted() { this.ExceptionSafeWrapper( delegate { foreach (ClientSideQuery.NotFoundError notFoundError in _cimQuery.GenerateNotFoundErrors()) { string errorId = "CmdletizationQuery_NotFound"; if (!string.IsNullOrEmpty(notFoundError.PropertyName)) { errorId = errorId + "_" + notFoundError.PropertyName; } CimJobException cimJobException = CimJobException.CreateWithFullControl( this.JobContext, notFoundError.ErrorMessageGenerator(this.Description, this.JobContext.ClassName), errorId, ErrorCategory.ObjectNotFound); if (!string.IsNullOrEmpty(notFoundError.PropertyName)) { cimJobException.ErrorRecord.SetTargetObject(notFoundError.PropertyValue); } this.WriteError(cimJobException.ErrorRecord); } }); base.OnCompleted(); }
private void OnNext(CimMethodStreamedResult streamedResult) { MethodParameter methodParameter = base.GetMethodOutputParameters().SingleOrDefault <MethodParameter>((MethodParameter p) => p.Name.Equals(streamedResult.ParameterName, StringComparison.OrdinalIgnoreCase)); if (methodParameter != null) { IEnumerable enumerable = LanguagePrimitives.GetEnumerable(streamedResult.ItemValue); if (enumerable == null) { this.WriteObject(streamedResult.ItemValue, methodParameter); } else { foreach (object obj in enumerable) { this.WriteObject(obj, methodParameter); } } return; } else { object[] methodSubject = new object[3]; methodSubject[0] = base.MethodSubject; methodSubject[1] = base.MethodName; methodSubject[2] = streamedResult.ParameterName; string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_InvalidOutputParameterName, methodSubject); throw CimJobException.CreateWithFullControl(base.JobContext, str, "CimJob_InvalidOutputParameterName", ErrorCategory.MetadataError, null); } }
private void OnNext(CimMethodStreamedResult streamedResult) { MethodParameter methodParameter = this.GetMethodOutputParameters() .SingleOrDefault(p => p.Name.Equals(streamedResult.ParameterName, StringComparison.OrdinalIgnoreCase)); if (methodParameter == null) { string errorMessage = string.Format( CultureInfo.InvariantCulture, CmdletizationResources.CimJob_InvalidOutputParameterName, this.MethodSubject, this.MethodName, streamedResult.ParameterName); throw CimJobException.CreateWithFullControl( this.JobContext, errorMessage, "CimJob_InvalidOutputParameterName", ErrorCategory.MetadataError); } var array = LanguagePrimitives.GetEnumerable(streamedResult.ItemValue); if (array != null) { foreach (var element in array) { this.WriteObject(element, methodParameter); } } else { this.WriteObject(streamedResult.ItemValue, methodParameter); } }
public override void OnCompleted() { base.ExceptionSafeWrapper(() => { foreach (ClientSideQuery.NotFoundError notFoundError in this._cimQuery.GenerateNotFoundErrors()) { string str = "CmdletizationQuery_NotFound"; if (!string.IsNullOrEmpty(notFoundError.PropertyName)) { str = string.Concat(str, "_", notFoundError.PropertyName); } CimJobException cimJobException = CimJobException.CreateWithFullControl(base.JobContext, notFoundError.ErrorMessageGenerator(this.Description, base.JobContext.ClassName), str, ErrorCategory.ObjectNotFound, null); if (!string.IsNullOrEmpty(notFoundError.PropertyName)) { cimJobException.ErrorRecord.SetTargetObject(notFoundError.PropertyValue); } this.WriteError(cimJobException.ErrorRecord); } } ); base.OnCompleted(); }
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); }
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); }