private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker terminatingErrorTracker) { bool flag = false; string str; bool flag1 = this.CmdletInvocationInfo.BoundParameters.ContainsKey("Confirm"); bool flag2 = this.CmdletInvocationInfo.BoundParameters.ContainsKey("WhatIf"); if ((flag1 || flag2) && cimSession.ComputerName != null && !cimSession.ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase)) { PSPropertyInfo item = PSObject.AsPSObject(cimSession).Properties["Protocol"]; if (item != null && item.Value != null && item.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase)) { terminatingErrorTracker.MarkSessionAsTerminated(cimSession, out flag); if (!flag) { if (!flag1) { str = "-WhatIf"; } else { str = "-Confirm"; } object[] computerName = new object[2]; computerName[0] = cimSession.ComputerName; computerName[1] = str; string str1 = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimCmdletAdapter_RemoteDcomDoesntSupportExtendedSemantics, computerName); Exception notSupportedException = new NotSupportedException(str1); ErrorRecord errorRecord = new ErrorRecord(notSupportedException, "NoExtendedSemanticsSupportInRemoteDcomProtocol", ErrorCategory.NotImplemented, cimSession); base.Cmdlet.WriteError(errorRecord); } } } return(true); }
private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker terminatingErrorTracker) { bool confirmSwitchSpecified = this.CmdletInvocationInfo.BoundParameters.ContainsKey("Confirm"); bool whatIfSwitchSpecified = this.CmdletInvocationInfo.BoundParameters.ContainsKey("WhatIf"); if (confirmSwitchSpecified || whatIfSwitchSpecified) { if (cimSession.ComputerName != null && (!cimSession.ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))) { PSPropertyInfo protocolProperty = PSObject.AsPSObject(cimSession).Properties["Protocol"]; if ((protocolProperty != null) && (protocolProperty.Value != null) && (protocolProperty.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase))) { bool sessionWasAlreadyTerminated; terminatingErrorTracker.MarkSessionAsTerminated(cimSession, out sessionWasAlreadyTerminated); if (!sessionWasAlreadyTerminated) { string nameOfUnsupportedSwitch; if (confirmSwitchSpecified) { nameOfUnsupportedSwitch = "-Confirm"; } else { Dbg.Assert(whatIfSwitchSpecified, "Confirm and WhatIf are the only detected settings"); nameOfUnsupportedSwitch = "-WhatIf"; } string errorMessage = string.Format( CultureInfo.InvariantCulture, CmdletizationResources.CimCmdletAdapter_RemoteDcomDoesntSupportExtendedSemantics, cimSession.ComputerName, nameOfUnsupportedSwitch); Exception exception = new NotSupportedException(errorMessage); ErrorRecord errorRecord = new( exception, "NoExtendedSemanticsSupportInRemoteDcomProtocol", ErrorCategory.NotImplemented, cimSession); this.Cmdlet.WriteError(errorRecord); } } } } return(true); }
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); }