public override void Execute(CmdletOperationBase cmdlet) { Exception cimException; try { try { if (this.error != null) { cimException = new CimException(this.error); } else { cimException = this.Exception; } Exception exception = cimException; cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, exception, this.cimResultContext)); this.responseType = CimResponseType.Yes; } catch { this.responseType = CimResponseType.NoToAll; throw; } } finally { this.OnComplete(); } }
/// <summary> /// Create <see cref="ErrorRecord"/> from <see cref="CimException"/> object. /// </summary> /// <param name="context"></param> /// <param name="cimException"></param> /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param> /// <returns></returns> internal static ErrorRecord CreateFromCimException( InvocationContext context, CimException cimException, CimResultContext cimResultContext) { Debug.Assert(cimException != null, "Caller should verify cimException != null"); return InitializeErrorRecord(context, cimException, cimResultContext); }
internal static ErrorCategory ConvertCimExceptionToErrorCategory(CimException cimException) { ErrorCategory errorCategory = ErrorCategory.NotSpecified; if (cimException.ErrorData != null) { errorCategory = ErrorToErrorRecord.ConvertCimErrorToErrorCategory(cimException.ErrorData); } if (errorCategory == ErrorCategory.NotSpecified) { errorCategory = ErrorToErrorRecord.ConvertCimNativeErrorCodeToErrorCategory(cimException.NativeErrorCode); } return errorCategory; }
/// <summary> /// Sets a custom option /// </summary> /// <param name="optionName"></param> /// <param name="optionValue"></param> /// <param name="flags"></param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="optionName"/> is <c>null</c></exception> public void SetInterval(string optionName, TimeSpan optionValue, UInt32 flags) { if (string.IsNullOrWhiteSpace(optionName)) { throw new ArgumentNullException("optionName"); } this.AssertNotDisposed(); // TODO: convert optionValue to MI_Interval MI_Interval interval; interval.days = interval.hours = interval.minutes = interval.seconds = interval.microseconds = interval.__padding1 = interval.__padding2 = interval.__padding3 = 0; MI_Result result = this._subscriptionDeliveryOptionsHandle.SetInterval(optionName, interval, flags); CimException.ThrowIfMiResultFailure(result); }
private static ErrorCategory ConvertCimExceptionToErrorCategory(CimException cimException) { ErrorCategory result = ErrorCategory.NotSpecified; if (cimException.ErrorData != null) { result = ConvertCimErrorToErrorCategory(cimException.ErrorData); } if (result == ErrorCategory.NotSpecified) { result = ConvertCimNativeErrorCodeToErrorCategory(cimException.NativeErrorCode); } return(result); }
public override CimQualifier this[string qualifierName] { get { if (string.IsNullOrWhiteSpace(qualifierName)) { throw new ArgumentNullException("qualifierName"); } UInt32 index; MI_Value value; bool valueExists; MI_Type type; string referenceClass; MI_QualifierSet qualifierSet; MI_Flags flags; MI_Result result = this.classHandle.GetElement(name, out value, out valueExists, out type, out referenceClass, out qualifierSet, out flags, out index); CimException.ThrowIfMiResultFailure(result); MI_Type qualifierType; MI_Flags qualifierFlags; MI_Value qualifierValue; result = qualifierSet.GetQualifier(qualifierName, out qualifierType, out qualifierFlags, out qualifierValue, out index); switch (result) { case MI_Result.MI_RESULT_NO_SUCH_PROPERTY: case MI_Result.MI_RESULT_NOT_FOUND: return(null); default: CimException.ThrowIfMiResultFailure(result); return(new CimQualifierOfProperty(this.classHandle, name, (int)index)); } } }
internal void ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, bool moreResults, MiResult operationResult, string errorMessage, InstanceHandle errorDetailsHandle) { Action <CimOperation> action = null; if (!moreResults) { base.DisposeOperationWhenPossible(); } if (currentItem != null || operationResult != MiResult.OK) { if (currentItem != null) { this.OnNextInternal(callbackProcessingContext, currentItem); } } else { if (this._reportOperationStarted) { this.OnNextInternal(callbackProcessingContext, currentItem); } } CimException exceptionIfMiResultFailure = CimException.GetExceptionIfMiResultFailure(operationResult, errorMessage, errorDetailsHandle); if (exceptionIfMiResultFailure != null) { try { throw exceptionIfMiResultFailure; } catch (CimException cimException1) { CimException cimException = cimException1; exceptionIfMiResultFailure = cimException; } } if (!moreResults) { CimAsyncObserverProxyBase <T> cimAsyncObserverProxyBase = this; if (action == null) { action = (CimOperation cimOperation) => this.ProcessEndOfResultsWorker(callbackProcessingContext, cimOperation, exceptionIfMiResultFailure); } cimAsyncObserverProxyBase.InvokeWhenOperationIsSet(action); } }
private static ApplicationHandle GetApplicationHandle() { ApplicationHandle applicationHandle = null; InstanceHandle instanceHandle = null; MiResult miResult = ApplicationMethods.Initialize(0, AppDomain.CurrentDomain.FriendlyName, out instanceHandle, out applicationHandle); CimException.ThrowIfMiResultFailure(miResult, instanceHandle); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.DomainUnload += (object sender, EventArgs eventArgs) => CimApplication.Shutdown(); AppDomain appDomain = AppDomain.CurrentDomain; appDomain.ProcessExit += (object param0, EventArgs param1) => { ApplicationMethods.SupressFurtherCallbacks(); CimApplication.Shutdown(); }; return(applicationHandle); }
/// <summary> /// Create <see cref="ErrorRecord"/> from <see cref="CimException"/> object. /// </summary> /// <param name="context"></param> /// <param name="cimException"></param> /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param> /// <returns></returns> internal static ErrorRecord InitializeErrorRecord( InvocationContext context, CimException cimException, CimResultContext cimResultContext) { ErrorRecord errorRecord = InitializeErrorRecordCore( context, exception: cimException, errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode, errorCategory: ConvertCimExceptionToErrorCategory(cimException), cimResultContext: cimResultContext); if (cimException.ErrorData != null) { errorRecord.CategoryInfo.TargetName = cimException.ErrorSource; } return(errorRecord); }
private CimPropertyStandalone GetProperty() { string name; MI_Value value; MI_Type type; MI_Flags flags; MI_Result result = this._instance.InstanceHandle.GetElementAt((uint)this._index, out name, out value, out type, out flags); CimException.ThrowIfMiResultFailure(result); var convertedValue = ValueHelpers.ConvertFromNativeLayer(value, type, flags); return(new CimPropertyStandalone(name, convertedValue, type.ToCimType(), flags.ToCimFlags())); }
internal void Cancel(CancellationMode cancellationMode) { Debug.Assert(cancellationMode != CancellationMode.NoCancellationOccured, "Caller should verify the right cancellation mode is used"); Debug.Assert(cancellationMode != CancellationMode.IgnoreCancellationRequests, "Caller should verify the right cancellation mode is used"); lock (this._cancellationModeLock) { if (this._cancellationMode == CancellationMode.IgnoreCancellationRequests) { return; } this._cancellationMode = cancellationMode; } MI_Result result = this._handle.Cancel(MI_CancellationReason.MI_REASON_NONE); CimException.ThrowIfMiResultFailure(result); this.Cancelled.SafeInvoke(this, EventArgs.Empty); }
internal static ErrorRecord InitializeErrorRecord(InvocationContext context, CimException cimException, CimResultContext cimResultContext) { InvocationContext invocationContext = context; CimException cimException1 = cimException; string messageId = cimException.MessageId; string str = messageId; if (messageId == null) { str = string.Concat("MiClientApiError_", cimException.NativeErrorCode); } ErrorRecord errorSource = ErrorToErrorRecord.InitializeErrorRecordCore(invocationContext, cimException1, str, ErrorToErrorRecord.ConvertCimExceptionToErrorCategory(cimException), cimResultContext); if (cimException.ErrorData != null) { errorSource.CategoryInfo.TargetName = cimException.ErrorSource; } return(errorSource); }
/// <summary> /// Creates a new <see cref="CimOperationOptions"/> instance. /// </summary> /// <param name="mustUnderstand">Indicates whether the server has to understand all the options.</param> public CimOperationOptions(bool mustUnderstand) { var operationCallbacks = new MI_OperationCallbacks(); this._operationCallback = operationCallbacks; _writeMessageCallback = null; _writeProgressCallback = null; _writeErrorCallback = null; _promptUserCallback = null; this._operationOptionsHandle = new Lazy <MI_OperationOptions>( delegate { MI_OperationOptions operationOptionsHandle; MI_Result result = CimApplication.Handle.NewOperationOptions( mustUnderstand, out operationOptionsHandle); CimException.ThrowIfMiResultFailure(result); return(operationOptionsHandle); }); }
/// <summary> /// Sets a custom server or CIM provider option /// </summary> /// <exception cref="ArgumentNullException">Thrown if <paramref name="optionName"/> is <c>null</c></exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="optionName"/> or <paramref name="optionValue"/> is <c>null</c></exception> public void SetCustomOption(string optionName, object optionValue, CimType cimType, bool mustComply) { if (string.IsNullOrWhiteSpace(optionName)) { throw new ArgumentNullException("optionName"); } if (optionValue == null) { throw new ArgumentNullException("optionValue"); } this.AssertNotDisposed(); MI_Value nativeLayerValue; try { nativeLayerValue = ValueHelpers.ConvertToNativeLayer(optionValue, cimType); ValueHelpers.ThrowIfMismatchedType(cimType.FromCimType(), nativeLayerValue); } catch (InvalidCastException e) { throw new ArgumentException(e.Message, "optionValue", e); } catch (FormatException e) { throw new ArgumentException(e.Message, "optionValue", e); } catch (ArgumentException e) { throw new ArgumentException(e.Message, "optionValue", e); } MI_OperationOptionsFlags flags = MI_OperationOptionsFlags.Unused; MI_Result result = this.OperationOptionsHandleOnDemand.SetCustomOption( optionName, cimType.FromCimType(), nativeLayerValue, mustComply, flags); CimException.ThrowIfMiResultFailure(result); }
internal Exception GetExceptionIfBrokenSession(CimSession potentiallyBrokenSession, bool skipTestConnection, out bool sessionWasAlreadyTerminated) { CimInstance cimInstance = null; CimException cimException = null; if (!this.IsSessionTerminated(potentiallyBrokenSession)) { Exception exception = null; if (!skipTestConnection && !this.DidSessionAlreadyPassedConnectivityTest(potentiallyBrokenSession)) { try { potentiallyBrokenSession.TestConnection(out cimInstance, out cimException); exception = cimException; if (exception == null) { this.MarkSessionAsConnected(potentiallyBrokenSession); } } catch (InvalidOperationException invalidOperationException1) { InvalidOperationException invalidOperationException = invalidOperationException1; exception = invalidOperationException; } } if (exception == null) { sessionWasAlreadyTerminated = false; return(exception); } else { this.MarkSessionAsTerminated(potentiallyBrokenSession, out sessionWasAlreadyTerminated); return(exception); } } else { sessionWasAlreadyTerminated = true; return(null); } }
internal static ErrorRecord ErrorRecordFromAnyException(InvocationContext context, Exception inner, CimResultContext cimResultContext) { CimException cimException = inner as CimException; if (cimException == null) { IContainsErrorRecord containsErrorRecord = inner as IContainsErrorRecord; if (containsErrorRecord == null) { return(ErrorToErrorRecord.InitializeErrorRecord(context, inner, string.Concat("CimCmdlet_", inner.GetType().Name), ErrorCategory.NotSpecified, cimResultContext)); } else { return(ErrorToErrorRecord.InitializeErrorRecord(context, inner, string.Concat("CimCmdlet_", containsErrorRecord.ErrorRecord.FullyQualifiedErrorId), containsErrorRecord.ErrorRecord.CategoryInfo.Category, cimResultContext)); } } else { return(ErrorToErrorRecord.CreateFromCimException(context, cimException, cimResultContext)); } }
public void AddCredentials(string optionName, CimCredential optionValue, uint flags) { if (string.IsNullOrWhiteSpace(optionName) || optionValue == null) { throw new ArgumentNullException("optionName"); } else { if (optionValue != null) { this.AssertNotDisposed(); MiResult miResult = MiResult.OK; //TODO: SubscriptionDeliveryOptionsMethods.AddCredentials(this._subscriptionDeliveryOptionsHandle, optionName, optionValue.GetCredential(), flags); CimException.ThrowIfMiResultFailure(miResult); return; } else { throw new ArgumentNullException("optionValue"); } } }
private CimSessionOptions(string protocol, bool validateProtocol) { if (validateProtocol) { if (string.IsNullOrWhiteSpace(protocol)) { throw new ArgumentNullException("protocol"); } } this.Protocol = protocol; this._destinationOptionsHandle = new Lazy <MI_DestinationOptions>( delegate { MI_DestinationOptions tmp; MI_Result result = CimApplication.Handle.NewDestinationOptions(out tmp); CimException.ThrowIfMiResultFailure(result); return(tmp); }); }
/// <summary> /// Instantiates a deep copy of <paramref name="optionsToClone"/> /// </summary> /// <param name="optionsToClone">options to clone</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="optionsToClone"/> is <c>null</c></exception> public CimOperationOptions(CimOperationOptions optionsToClone) { if (optionsToClone == null) { throw new ArgumentNullException("optionsToClone"); } this._operationCallback = optionsToClone.GetOperationCallbacks(); _writeMessageCallback = optionsToClone._writeMessageCallback; _writeProgressCallback = optionsToClone._writeProgressCallback; _writeErrorCallback = optionsToClone._writeErrorCallback; _promptUserCallback = optionsToClone._promptUserCallback; this._operationOptionsHandle = new Lazy <MI_OperationOptions>( delegate { MI_OperationOptions tmp; MI_Result result = optionsToClone.OperationOptionsHandle.Clone(out tmp); CimException.ThrowIfMiResultFailure(result); return(tmp); }); }
private CimResponseType WriteErrorCallback(CimInstance cimError) { lock (_jobStateLock) { _jobHadErrors = true; } var cimException = new CimException(cimError); var jobException = CimJobException.CreateFromCimException(this.GetDescription(), this.JobContext, cimException); var errorRecord = jobException.ErrorRecord; switch (this.JobContext.ErrorActionPreference) { case ActionPreference.Stop: case ActionPreference.Inquire: return(this.BlockingWriteError(errorRecord)); default: this.WriteError(errorRecord); return(CimResponseType.Yes); } }
public override CimQualifier this[string methodName] { get { if (string.IsNullOrWhiteSpace(methodName)) { throw new ArgumentNullException("methodName"); } string name; MI_QualifierSet qualifierSet; MI_ParameterSet parameterSet; MI_Result result = this.classHandle.GetMethodAt((uint)methodIndex, out name, out qualifierSet, out parameterSet); CimException.ThrowIfMiResultFailure(result); MI_Type qualifierType; MI_Flags qualifierFlags; MI_Value qualifierValue; UInt32 index; result = qualifierSet.GetQualifier(name, out qualifierType, out qualifierFlags, out qualifierValue, out index); switch (result) { case MI_Result.MI_RESULT_NOT_FOUND: return(null); default: CimException.ThrowIfMiResultFailure(result); return(new CimMethodQualifierDeclarationOfMethod(this.classHandle, methodIndex, (int)index)); } } }
public override CimMethodParameterDeclaration this[string parameterName] { get { if (string.IsNullOrWhiteSpace(parameterName)) { throw new ArgumentNullException("parameterName"); } UInt32 index; string name; MI_QualifierSet qualifierSet; MI_ParameterSet parameterSet; MI_Result result = this.classHandle.GetMethodAt((uint)methodIndex, out name, out qualifierSet, out parameterSet); CimException.ThrowIfMiResultFailure(result); MI_Type parameterType; string referenceClass; result = parameterSet.GetParameter(parameterName, out parameterType, out referenceClass, out qualifierSet, out index); switch (result) { case MI_Result.MI_RESULT_NOT_FOUND: return(null); default: CimException.ThrowIfMiResultFailure(result); return(new CimMethodParameterDeclarationOfMethod(this.classHandle, methodIndex, (int)index)); } } }
internal void Cancel(CancellationMode cancellationMode) { lock (this._cancellationModeLock) { if (this._cancellationMode != CancellationMode.IgnoreCancellationRequests) { this._cancellationMode = cancellationMode; } else { return; } } lock (this._cancelVsCloseLock) { if (this._handle != null) { MiResult miResult = OperationMethods.Cancel(this._handle, MiCancellationReason.None); CimException.ThrowIfMiResultFailure(miResult); } } this.Cancelled.SafeInvoke <EventArgs>(this, EventArgs.Empty); }
public override CimPropertyDeclaration this[string propertyName] { get { if (string.IsNullOrWhiteSpace(propertyName)) { throw new ArgumentNullException("propertyName"); } MI_Value value; bool valueExists; MI_Type type; string referenceClass; MI_QualifierSet qualifierSet; MI_Flags flags; UInt32 index; MI_Result result = this.classHandle.GetElement(propertyName, out value, out valueExists, out type, out referenceClass, out qualifierSet, out flags, out index); switch (result) { case MI_Result.MI_RESULT_NO_SUCH_PROPERTY: return(null); default: CimException.ThrowIfMiResultFailure(result); return(new CimClassPropertyOfClass(this.classHandle, (int)index)); } } }
internal static CimJobException CreateFromAnyException( string jobDescription, CimJobContext jobContext, Exception inner) { Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null"); Dbg.Assert(jobContext != null, "Caller should verify jobContext != null"); Dbg.Assert(inner != null, "Caller should verify inner != null"); CimException cimException = inner as CimException; if (cimException != null) { return(CreateFromCimException(jobDescription, jobContext, cimException)); } string message = BuildErrorMessage(jobDescription, jobContext, inner.Message); CimJobException cimJobException = new CimJobException(message, inner); var containsErrorRecord = inner as IContainsErrorRecord; if (containsErrorRecord != null) { cimJobException.InitializeErrorRecord( jobContext, errorId: "CimJob_" + containsErrorRecord.ErrorRecord.FullyQualifiedErrorId, errorCategory: containsErrorRecord.ErrorRecord.CategoryInfo.Category); } else { cimJobException.InitializeErrorRecord( jobContext, errorId: "CimJob_" + inner.GetType().Name, errorCategory: ErrorCategory.NotSpecified); } return(cimJobException); }
public override CimQualifier this[string qualifierName] { get { if (string.IsNullOrWhiteSpace(qualifierName)) { throw new ArgumentNullException("qualifierName"); } MI_QualifierSet qualifierSet; MI_Result result = this.classHandle.GetClassQualifierSet(out qualifierSet); CimException.ThrowIfMiResultFailure(result); // TODO: there aren't many comments for the above pattern throughout the MMI sources, but if the above fails we shouldn't throw exception, just return MI_RESULT_NOT_FOUND like below. Make sure all of these cases are accounted for in MMI MI_Type qualifierType; MI_Flags qualifierFlags; MI_Value qualifierValue; UInt32 index; result = qualifierSet.GetQualifier(qualifierName, out qualifierType, out qualifierFlags, out qualifierValue, out index); switch (result) { case MI_Result.MI_RESULT_NOT_FOUND: return(null); default: CimException.ThrowIfMiResultFailure(result); return(new CimQualifierOfClass(this.classHandle, (int)index)); } } }
internal static CimJobException CreateFromAnyException(string jobDescription, CimJobContext jobContext, Exception inner) { CimException cimException = inner as CimException; if (cimException == null) { string str = CimJobException.BuildErrorMessage(jobDescription, jobContext, inner.Message); CimJobException cimJobException = new CimJobException(str, inner); IContainsErrorRecord containsErrorRecord = inner as IContainsErrorRecord; if (containsErrorRecord == null) { cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", inner.GetType().Name), ErrorCategory.NotSpecified); } else { cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", containsErrorRecord.ErrorRecord.FullyQualifiedErrorId), containsErrorRecord.ErrorRecord.CategoryInfo.Category); } return(cimJobException); } else { return(CimJobException.CreateFromCimException(jobDescription, jobContext, cimException)); } }
private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception) { CimProperty cimProperty; bool flag; DebugHelper.WriteLogEx(); if (properties.Count != 0) { IDictionaryEnumerator enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { object baseObject = base.GetBaseObject(enumerator.Value); string str = enumerator.Key.ToString(); object[] objArray = new object[2]; objArray[0] = str; objArray[1] = baseObject; DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, objArray); try { CimProperty item = cimInstance.CimInstanceProperties[str]; if (item == null) { if (baseObject != null) { CimType cimType = CimType.Unknown; object referenceOrReferenceArrayObject = base.GetReferenceOrReferenceArrayObject(baseObject, ref cimType); if (referenceOrReferenceArrayObject == null) { cimProperty = CimProperty.Create(str, baseObject, (CimFlags)((long)4)); } else { cimProperty = CimProperty.Create(str, referenceOrReferenceArrayObject, cimType, (CimFlags)((long)4)); } } else { cimProperty = CimProperty.Create(str, baseObject, CimType.String, (CimFlags)((long)4)); } try { cimInstance.CimInstanceProperties.Add(cimProperty); } catch (CimException cimException1) { CimException cimException = cimException1; if (cimException.NativeErrorCode != NativeErrorCode.Failed) { exception = cimException; } else { object[] name = new object[2]; name[0] = cimProperty.Name; name[1] = cimInstance; string str1 = string.Format(CultureInfo.CurrentUICulture, Strings.UnableToAddPropertyToInstance, name); exception = new CimException(str1, cimException); } flag = false; return(flag); } object[] objArray1 = new object[2]; objArray1[0] = str; objArray1[1] = baseObject; DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, objArray1); } else { if ((item.Flags & CimFlags.ReadOnly) != CimFlags.ReadOnly) { object[] value = new object[2]; value[0] = str; value[1] = item.Value; DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, value); item.Value = baseObject; } else { object[] objArray2 = new object[2]; objArray2[0] = str; objArray2[1] = cimInstance; exception = new CimException(string.Format(CultureInfo.CurrentUICulture, Strings.CouldNotModifyReadonlyProperty, objArray2)); flag = false; return(flag); } } continue; } catch (Exception exception2) { Exception exception1 = exception2; object[] objArray3 = new object[1]; objArray3[0] = exception1; DebugHelper.WriteLog("Exception {0}", 4, objArray3); exception = exception1; flag = false; } return(flag); } return(true); } else { return(true); } }
/// <summary> /// Convert <see cref="CimException"/> to <see cref="ErrorCategory"/>. /// </summary> /// <param name="cimException"></param> /// <returns></returns> internal static ErrorCategory ConvertCimExceptionToErrorCategory(CimException cimException) { ErrorCategory result = ErrorCategory.NotSpecified; if (cimException.ErrorData != null) { result = ConvertCimErrorToErrorCategory(cimException.ErrorData); } if (result == ErrorCategory.NotSpecified) { result = ConvertCimNativeErrorCodeToErrorCategory(cimException.NativeErrorCode); } return result; }
/// <summary> /// Create <see cref="ErrorRecord"/> from <see cref="CimException"/> object. /// </summary> /// <param name="context"></param> /// <param name="cimException"></param> /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param> /// <returns></returns> internal static ErrorRecord InitializeErrorRecord( InvocationContext context, CimException cimException, CimResultContext cimResultContext) { ErrorRecord errorRecord = InitializeErrorRecordCore( context, exception: cimException, errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode, errorCategory: ConvertCimExceptionToErrorCategory(cimException), cimResultContext: cimResultContext); if (cimException.ErrorData != null) { errorRecord.CategoryInfo.TargetName = cimException.ErrorSource; } return errorRecord; }
internal static CimJobException CreateFromCimException(string jobDescription, CimJobContext jobContext, CimException cimException) { string str = CimJobException.BuildErrorMessage(jobDescription, jobContext, cimException.Message); CimJobException cimJobException = new CimJobException(str, cimException); cimJobException.InitializeErrorRecord(jobContext, cimException); return(cimJobException); }
/// <summary> /// <para> /// Set the properties value to be modified to the given /// <see cref="CimInstance"/> /// </para> /// </summary> /// <param name="properties"></param> /// <param name="cimInstance"></param> /// <param name="terminationMessage"></param> /// <returns></returns> private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception) { DebugHelper.WriteLogEx(); if (properties.Count == 0) { // simply ignore if empty properties was provided return true; } IDictionaryEnumerator enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { object value = GetBaseObject(enumerator.Value); string key = enumerator.Key.ToString(); DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, key, value); try { CimProperty property = cimInstance.CimInstanceProperties[key]; // modify existing property value if found if (property != null) { if ((property.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly) { // can not modify ReadOnly property exception = new CimException(String.Format(CultureInfo.CurrentUICulture, Strings.CouldNotModifyReadonlyProperty, key, cimInstance)); return false; } // allow modify the key property value as long as it is not readonly, // then the modified ciminstance is stand for a different CimInstance DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, key, property.Value); property.Value = value; } else // For dynamic instance, it is valid to add a new property { CimProperty newProperty; if( value == null ) { newProperty = CimProperty.Create( key, value, CimType.String, CimFlags.Property); } else { CimType referenceType = CimType.Unknown; object referenceObject = GetReferenceOrReferenceArrayObject(value, ref referenceType); if (referenceObject != null) { newProperty = CimProperty.Create( key, referenceObject, referenceType, CimFlags.Property); } else { newProperty = CimProperty.Create( key, value, CimFlags.Property); } } try { cimInstance.CimInstanceProperties.Add(newProperty); } catch (CimException e) { if (e.NativeErrorCode == NativeErrorCode.Failed) { string errorMessage = String.Format(CultureInfo.CurrentUICulture, Strings.UnableToAddPropertyToInstance, newProperty.Name, cimInstance); exception = new CimException(errorMessage, e); } else { exception = e; } return false; } DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, key, value); } } catch (Exception e) { DebugHelper.WriteLog("Exception {0}", 4, e); exception = e; return false; } } return true; }
private bool MoveNext(bool discardResultsAndErrors) { T t = null; MiResult miResult = MiResult.OK; string str = null; InstanceHandle instanceHandle = null; bool flag; if (!discardResultsAndErrors) { lock (this._internalErrorWhileProcessingAsyncCallbackLock) { if (this._internalErrorWhileProcessingAsyncCallback != null) { throw this._internalErrorWhileProcessingAsyncCallback; } } } if (this._moreResultsAreExpected) { this.AssertNotDisposed(); MiResult miResult1 = this.NativeMoveNext(base.Operation.Handle, out t, out this._moreResultsAreExpected, out miResult, out str, out instanceHandle); CimException.ThrowIfMiResultFailure(miResult1); if (!this._moreResultsAreExpected) { base.Operation.IgnoreSubsequentCancellationRequests(); } if (!discardResultsAndErrors) { lock (this._internalErrorWhileProcessingAsyncCallbackLock) { if (this._internalErrorWhileProcessingAsyncCallback != null) { throw this._internalErrorWhileProcessingAsyncCallback; } } CimException exceptionIfMiResultFailure = CimException.GetExceptionIfMiResultFailure(miResult, str, instanceHandle); if (exceptionIfMiResultFailure == null) { this.DisposeCurrentItemIfNeeded(); this.Current = t; } else { CancellationMode cancellationMode = base.Operation.CancellationMode; if (cancellationMode != CancellationMode.ThrowOperationCancelledException) { throw exceptionIfMiResultFailure; } else { throw new OperationCanceledException(exceptionIfMiResultFailure.Message, exceptionIfMiResultFailure); } } } else { IDisposable disposable = (object)t as IDisposable; if (disposable != null) { disposable.Dispose(); t = default(T); } if (instanceHandle != null) { instanceHandle.Dispose(); } } if (t == null) { flag = this._moreResultsAreExpected; } else { flag = true; } return(flag); } else { return(false); } }
private static bool IsWsManQuotaReached(Exception exception) { CimException cimException = exception as CimException; if (cimException != null) { if (cimException.NativeErrorCode == NativeErrorCode.ServerLimitsExceeded) { CimInstance errorData = cimException.ErrorData; if (errorData != null) { CimProperty item = errorData.CimInstanceProperties["error_Code"]; if (item != null) { if (item.CimType == CimType.UInt32) { uint wsManErrorCode = (uint)item.Value; switch (wsManErrorCode) { case 2144108123: case 2144108122: case (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_USER): case 2144108120: case (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_SYSTEM | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLUSERS): { return(true); } case 2144108119: case 2144108118: { return(false); } default: { if (wsManErrorCode == 2144108060 || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_USERS_PPQ) || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_PLUGINSHELLS_PPQ) || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_USER | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_USERS_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_PLUGINSHELLS_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_PLUGINOPERATIONS_PPQ) || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_SYSTEM | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS_USER_PPQ) || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_SYSTEM | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS_USER_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_COMMANDS_PER_SHELL_PPQ) || wsManErrorCode == (CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_SYSTEM | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_OPERATIONS_USER_PPQ | CimChildJobBase <T> .WsManErrorCode.ERROR_WSMAN_QUOTA_MIN_REQUIREMENT_NOT_AVAILABLE_PPQ)) { return(true); } return(false); } } } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } }
public static void PrintCimException(CimException exception) { Console.WriteLine("Error Code = " + exception.NativeErrorCode); Console.WriteLine("MessageId = " + exception.MessageId); Console.WriteLine("ErrorSource = " + exception.ErrorSource); Console.WriteLine("ErrorType = " + exception.ErrorType); Console.WriteLine("Status Code = " + exception.StatusCode); }
internal static CimJobException CreateFromCimException(string jobDescription, CimJobContext jobContext, CimException cimException) { string str = CimJobException.BuildErrorMessage(jobDescription, jobContext, cimException.Message); CimJobException cimJobException = new CimJobException(str, cimException); cimJobException.InitializeErrorRecord(jobContext, cimException); return cimJobException; }
/// <summary> /// <para> /// Set the properties value to be modified to the given /// <see cref="CimInstance"/> /// </para> /// </summary> /// <param name="properties"></param> /// <param name="cimInstance"></param> /// <param name="terminationMessage"></param> /// <returns></returns> private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception) { DebugHelper.WriteLogEx(); if (properties.Count == 0) { // simply ignore if empty properties was provided return(true); } IDictionaryEnumerator enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { object value = GetBaseObject(enumerator.Value); string key = enumerator.Key.ToString(); DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, key, value); try { CimProperty property = cimInstance.CimInstanceProperties[key]; // modify existing property value if found if (property != null) { if ((property.Flags & CimFlags.ReadOnly) == CimFlags.ReadOnly) { // can not modify ReadOnly property exception = new CimException(String.Format(CultureInfo.CurrentUICulture, Strings.CouldNotModifyReadonlyProperty, key, cimInstance)); return(false); } // allow modify the key property value as long as it is not readonly, // then the modified ciminstance is stand for a different CimInstance DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, key, property.Value); property.Value = value; } else // For dynamic instance, it is valid to add a new property { CimProperty newProperty; if (value == null) { newProperty = CimProperty.Create( key, value, CimType.String, CimFlags.Property); } else { CimType referenceType = CimType.Unknown; object referenceObject = GetReferenceOrReferenceArrayObject(value, ref referenceType); if (referenceObject != null) { newProperty = CimProperty.Create( key, referenceObject, referenceType, CimFlags.Property); } else { newProperty = CimProperty.Create( key, value, CimFlags.Property); } } try { cimInstance.CimInstanceProperties.Add(newProperty); } catch (CimException e) { if (e.NativeErrorCode == NativeErrorCode.Failed) { string errorMessage = String.Format(CultureInfo.CurrentUICulture, Strings.UnableToAddPropertyToInstance, newProperty.Name, cimInstance); exception = new CimException(errorMessage, e); } else { exception = e; } return(false); } DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, key, value); } } catch (Exception e) { DebugHelper.WriteLog("Exception {0}", 4, e); exception = e; return(false); } } return(true); }
private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException) { InitializeErrorRecordCore( jobContext: jobContext, exception: cimException, errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode, errorCategory: ConvertCimExceptionToErrorCategory(cimException)); if (cimException.ErrorData != null) { _errorRecord.CategoryInfo.TargetName = cimException.ErrorSource; _errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null; } }
internal static CimJobException CreateFromCimException( string jobDescription, CimJobContext jobContext, CimException cimException) { Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null"); Dbg.Assert(jobContext != null, "Caller should verify jobContext != null"); Dbg.Assert(cimException != null, "Caller should verify cimException != null"); string message = BuildErrorMessage(jobDescription, jobContext, cimException.Message); CimJobException cimJobException = new CimJobException(message, cimException); cimJobException.InitializeErrorRecord(jobContext, cimException); return cimJobException; }
internal static ErrorRecord CreateFromCimException(InvocationContext context, CimException cimException, CimResultContext cimResultContext) { return ErrorToErrorRecord.InitializeErrorRecord(context, cimException, cimResultContext); }
internal static ErrorRecord InitializeErrorRecord(InvocationContext context, CimException cimException, CimResultContext cimResultContext) { InvocationContext invocationContext = context; CimException cimException1 = cimException; string messageId = cimException.MessageId; string str = messageId; if (messageId == null) { str = string.Concat("MiClientApiError_", cimException.NativeErrorCode); } ErrorRecord errorSource = ErrorToErrorRecord.InitializeErrorRecordCore(invocationContext, cimException1, str, ErrorToErrorRecord.ConvertCimExceptionToErrorCategory(cimException), cimResultContext); if (cimException.ErrorData != null) { errorSource.CategoryInfo.TargetName = cimException.ErrorSource; } return errorSource; }
internal static ErrorRecord CreateFromCimException(InvocationContext context, CimException cimException, CimResultContext cimResultContext) { return(ErrorToErrorRecord.InitializeErrorRecord(context, cimException, cimResultContext)); }
public bool TestConnection(out CimInstance instance, out CimException exception) { this.AssertNotDisposed(); bool flag = true; instance = null; exception = null; IEnumerable<CimInstance> cimSyncInstanceEnumerable = new CimSyncInstanceEnumerable(null, this.InstanceId, this.ComputerName, (CimAsyncCallbacksReceiverBase asyncCallbacksReceiver) => this.TestConnectionCore(null, asyncCallbacksReceiver)); try { instance = cimSyncInstanceEnumerable.SingleOrDefault<CimInstance>(); } catch (CimException cimException1) { CimException cimException = cimException1; exception = cimException; flag = false; } return flag; }
private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException) { string cmdletizationClassName; CimJobException cimJobException = this; CimJobContext cimJobContext = jobContext; CimException cimException1 = cimException; string messageId = cimException.MessageId; string str = messageId; if (messageId == null) { str = string.Concat("MiClientApiError_", cimException.NativeErrorCode); } cimJobException.InitializeErrorRecordCore(cimJobContext, cimException1, str, CimJobException.ConvertCimExceptionToErrorCategory(cimException)); if (cimException.ErrorData != null) { this.errorRecord.CategoryInfo.TargetName = cimException.ErrorSource; ErrorCategoryInfo categoryInfo = this.errorRecord.CategoryInfo; if (jobContext != null) { cmdletizationClassName = jobContext.CmdletizationClassName; } else { cmdletizationClassName = null; } categoryInfo.TargetType = cmdletizationClassName; } }
private bool SetProperty(IDictionary properties, ref CimInstance cimInstance, ref Exception exception) { CimProperty cimProperty; bool flag; DebugHelper.WriteLogEx(); if (properties.Count != 0) { IDictionaryEnumerator enumerator = properties.GetEnumerator(); while (enumerator.MoveNext()) { object baseObject = base.GetBaseObject(enumerator.Value); string str = enumerator.Key.ToString(); object[] objArray = new object[2]; objArray[0] = str; objArray[1] = baseObject; DebugHelper.WriteLog("Input property name '{0}' with value '{1}'", 1, objArray); try { CimProperty item = cimInstance.CimInstanceProperties[str]; if (item == null) { if (baseObject != null) { CimType cimType = CimType.Unknown; object referenceOrReferenceArrayObject = base.GetReferenceOrReferenceArrayObject(baseObject, ref cimType); if (referenceOrReferenceArrayObject == null) { cimProperty = CimProperty.Create(str, baseObject, (CimFlags)((long)4)); } else { cimProperty = CimProperty.Create(str, referenceOrReferenceArrayObject, cimType, (CimFlags)((long)4)); } } else { cimProperty = CimProperty.Create(str, baseObject, CimType.String, (CimFlags)((long)4)); } try { cimInstance.CimInstanceProperties.Add(cimProperty); } catch (CimException cimException1) { CimException cimException = cimException1; if (cimException.NativeErrorCode != NativeErrorCode.Failed) { exception = cimException; } else { object[] name = new object[2]; name[0] = cimProperty.Name; name[1] = cimInstance; string str1 = string.Format(CultureInfo.CurrentUICulture, Strings.UnableToAddPropertyToInstance, name); exception = new CimException(str1, cimException); } flag = false; return flag; } object[] objArray1 = new object[2]; objArray1[0] = str; objArray1[1] = baseObject; DebugHelper.WriteLog("Add non-key property name '{0}' with value '{1}'.", 3, objArray1); } else { if ((item.Flags & CimFlags.ReadOnly) != CimFlags.ReadOnly) { object[] value = new object[2]; value[0] = str; value[1] = item.Value; DebugHelper.WriteLog("Set property name '{0}' has old value '{1}'", 4, value); item.Value = baseObject; } else { object[] objArray2 = new object[2]; objArray2[0] = str; objArray2[1] = cimInstance; exception = new CimException(string.Format(CultureInfo.CurrentUICulture, Strings.CouldNotModifyReadonlyProperty, objArray2)); flag = false; return flag; } } continue; } catch (Exception exception2) { Exception exception1 = exception2; object[] objArray3 = new object[1]; objArray3[0] = exception1; DebugHelper.WriteLog("Exception {0}", 4, objArray3); exception = exception1; flag = false; } return flag; } return true; } else { return true; } }