private static PSAdaptedProperty GetPSComputerNameAdapter(CimInstance cimInstance) { PSAdaptedProperty psComputerNameProperty = new PSAdaptedProperty(RemotingConstants.ComputerNameNoteProperty, cimInstance); psComputerNameProperty.baseObject = cimInstance; //psComputerNameProperty.adapter = this; return psComputerNameProperty; }
private static PSAdaptedProperty GetCimPropertyAdapter(CimProperty property, object baseObject, string propertyName) { PSAdaptedProperty propertyToAdd = new PSAdaptedProperty(propertyName, property); propertyToAdd.baseObject = baseObject; //propertyToAdd.adapter = this; return propertyToAdd; }
private object ConvertValue(PSAdaptedProperty property, object valueObject, Type attrType, Type valType) { Exception exception = null; object obj = null; if (!this.TryConvertValue(property, valueObject, attrType, valType, out obj, out exception)) { if (exception == null) { object[] name = new object[3]; name[0] = property.Name; name[1] = valType; name[2] = attrType; throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.NoConversionExists, name)); } else { object[] message = new object[3]; message[0] = valType; message[1] = attrType; message[2] = exception.Message; throw new FormatException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeConversionError, message), exception); } } else { return obj; } }
/// <summary> /// Returns null if propertyName is not a property in the adapter or /// the corresponding PSProperty with its adapterData set to information /// to be used when retrieving the property. /// </summary> protected override PSProperty DoGetProperty(object obj, string propertyName) { PSAdaptedProperty property = null; try { property = _externalAdapter.GetProperty(obj, propertyName); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException( "PSPropertyAdapter.GetProperty", exception, ExtendedTypeSystem.GetProperty, propertyName, obj.ToString()); } if (property != null) { InitializeProperty(property, obj); } return(property); }
/// <summary> /// Ensures that the adapter and base object are set in the given PSAdaptedProperty /// </summary> private void InitializeProperty(PSAdaptedProperty property, object baseObject) { if (property.adapter == null) { property.adapter = this; property.baseObject = baseObject; } }
public override PSMemberInfo Copy() { PSAdaptedProperty destiny = new PSAdaptedProperty(base.name, base.adapter, base.baseObject, base.adapterData); base.CloneBaseProperties(destiny); destiny.typeOfValue = base.typeOfValue; destiny.serializedValue = base.serializedValue; destiny.isDeserialized = base.isDeserialized; return destiny; }
private void InitializeProperty(PSAdaptedProperty property, object baseObject) { if (property.adapter != null) { return; } property.adapter = (Adapter)this; property.baseObject = baseObject; }
public override PSMemberInfo Copy() { PSAdaptedProperty destiny = new PSAdaptedProperty(base.name, base.adapter, base.baseObject, base.adapterData); base.CloneBaseProperties(destiny); destiny.typeOfValue = base.typeOfValue; destiny.serializedValue = base.serializedValue; destiny.isDeserialized = base.isDeserialized; return(destiny); }
protected override string PropertyType(PSProperty property, bool forDisplay) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; string propertyTypeName = null; try { propertyTypeName = this.externalAdapter.GetPropertyTypeName(adaptedProperty); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertyTypeError", exception, ExtendedTypeSystem.PropertyTypeError, new object[] { property.Name }); } return(propertyTypeName ?? "System.Object"); }
protected override object PropertyGet(PSProperty property) { object propertyValue; PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; try { propertyValue = this.externalAdapter.GetPropertyValue(adaptedProperty); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertyGetError", exception, ExtendedTypeSystem.PropertyGetError, new object[] { property.Name }); } return(propertyValue); }
protected override bool PropertyIsSettable(PSProperty property) { bool flag; PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; try { flag = this.externalAdapter.IsSettable(adaptedProperty); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertyIsSettableError", exception, ExtendedTypeSystem.PropertyIsSettableError, new object[] { property.Name }); } return(flag); }
protected override object PropertyGet(PSProperty property) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; try { return(this.externalAdapter.GetPropertyValue(adaptedProperty)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertyGetError", ex, "ExtendedTypeSystem", "PropertyGetError", new object[1] { (object)property.Name }); } }
protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; try { this.externalAdapter.SetPropertyValue(adaptedProperty, setValue); } catch (SetValueException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertySetError", exception, ExtendedTypeSystem.PropertySetError, new object[] { property.Name }); } }
/// <summary> /// Returns the value from a property coming from a previous call to DoGetProperty /// </summary> protected override object PropertyGet(PSProperty property) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; Diagnostics.Assert(adaptedProperty != null, "ThirdPartyAdapter should only receive PSAdaptedProperties"); try { return(_externalAdapter.GetPropertyValue(adaptedProperty)); } catch (Exception exception) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.PropertyGetError", exception, ExtendedTypeSystem.PropertyGetError, property.Name); } }
protected override string PropertyType(PSProperty property) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; string propertyTypeName; try { propertyTypeName = this.externalAdapter.GetPropertyTypeName(adaptedProperty); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw new ExtendedTypeSystemException("PSPropertyAdapter.PropertyTypeError", ex, "ExtendedTypeSystem", "PropertyTypeError", new object[1] { (object)property.Name }); } return(propertyTypeName ?? "System.Object"); }
/// <summary> /// Sets the value of a property coming from a previous call to DoGetProperty /// </summary> protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; Diagnostics.Assert(adaptedProperty != null, "ThirdPartyAdapter should only receive PSAdaptedProperties"); try { _externalAdapter.SetPropertyValue(adaptedProperty, setValue); } catch (SetValueException) { throw; } catch (Exception exception) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.PropertySetError", exception, ExtendedTypeSystem.PropertySetError, property.Name); } }
/// <summary> /// Returns true if the property is gettable /// </summary> protected override bool PropertyIsGettable(PSProperty property) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; Diagnostics.Assert(adaptedProperty != null, "ThirdPartyAdapter should only receive PSAdaptedProperties"); try { return(_externalAdapter.IsGettable(adaptedProperty)); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw new ExtendedTypeSystemException( "PSPropertyAdapter.PropertyIsGettableError", exception, ExtendedTypeSystem.PropertyIsGettableError, property.Name); } }
/// <summary> /// Returns the name of the type corresponding to the property /// </summary> protected override string PropertyType(PSProperty property, bool forDisplay) { PSAdaptedProperty adaptedProperty = property as PSAdaptedProperty; Diagnostics.Assert(adaptedProperty != null, "ThirdPartyAdapter should only receive PSAdaptedProperties"); string propertyTypeName = null; try { propertyTypeName = _externalAdapter.GetPropertyTypeName(adaptedProperty); } catch (Exception exception) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.PropertyTypeError", exception, ExtendedTypeSystem.PropertyTypeError, property.Name); } return(propertyTypeName ?? "System.Object"); }
protected override PSProperty DoGetFirstPropertyOrDefault(object obj, MemberNamePredicate predicate) { PSAdaptedProperty property = null; try { property = _externalAdapter.GetFirstPropertyOrDefault(obj, predicate); } catch (Exception exception) { throw new ExtendedTypeSystemException( "PSPropertyAdapter.GetProperty", exception, ExtendedTypeSystem.GetProperty, nameof(predicate), obj.ToString()); } if (property != null) { InitializeProperty(property, obj); } return(property); }
/// <summary> /// /// </summary> /// <param name="adaptedProperty"></param> /// <returns></returns> public override bool IsSettable(PSAdaptedProperty adaptedProperty) { /* I was explicitly asked to only use MI_FLAG_READONLY for now // based on DSP0004, version 2.6.0, section "5.5.3.55 Write" (pages 89-90, lines 3056-3061) bool writeQualifierValue = this.GetPropertyQualifierValue(adaptedProperty, "Write", defaultValue: false); return writeQualifierValue; */ if (null == adaptedProperty) { return false; } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; if (cimProperty == null) { return false; } bool isReadOnly = (CimFlags.ReadOnly == (cimProperty.Flags & CimFlags.ReadOnly)); bool isSettable = !isReadOnly; return isSettable; }
/// <summary> /// /// </summary> /// <param name="adaptedProperty"></param> /// <param name="value"></param> public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value) { if (null == adaptedProperty) { throw new ArgumentNullException("adaptedProperty"); } if (!IsSettable(adaptedProperty)) { throw new SetValueException("ReadOnlyCIMProperty", null, CimInstanceTypeAdapterResources.ReadOnlyCIMProperty, adaptedProperty.Name); } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; object valueToSet = value; if (valueToSet != null) { // Convert only if value is not null Type paramType; switch (cimProperty.CimType) { case CimType.DateTime: paramType = typeof(object); break; case CimType.DateTimeArray: paramType = typeof(object[]); break; default: paramType = CimConverter.GetDotNetType(cimProperty.CimType); Dbg.Assert(paramType != null, "'default' case should only be used for well-defined CimType->DotNetType conversions"); break; } valueToSet = Adapter.PropertySetAndMethodArgumentConvertTo( value, paramType, CultureInfo.InvariantCulture); } cimProperty.Value = valueToSet; return; }
public override object GetPropertyValue(PSAdaptedProperty property) { if (property != null) { if (property.BaseObject != null) { if (property.Name != null) { ADEntity baseObject = property.BaseObject as ADEntity; if (baseObject != null) { return ADEntityAdapter.GetPropertyValue(baseObject, property.Name); } else { object[] typeAdapterTypeName = new object[2]; typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName; typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName)); } } else { throw new ArgumentNullException("property.Name"); } } else { throw new ArgumentNullException("property.BaseObject"); } } else { throw new ArgumentNullException("property"); } }
public override bool IsSettable(PSAdaptedProperty property) { if (property != null) { ADEntity baseObject = property.BaseObject as ADEntity; if (baseObject != null) { PropertyInfo dotNetProperty = baseObject.GetDotNetProperty(property.Name); if (dotNetProperty == null) { return baseObject.PropertyIsWritable(property.Name); } else { return dotNetProperty.CanWrite; } } else { object[] typeAdapterTypeName = new object[2]; typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName; typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName)); } } else { throw new ArgumentNullException("property"); } }
public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value) { if (adaptedProperty == null) { throw new ArgumentNullException("adaptedProperty"); } if (!this.IsSettable(adaptedProperty)) { throw new SetValueException("ReadOnlyCIMProperty", null, CimInstanceTypeAdapterResources.ReadOnlyCIMProperty, new object[] { adaptedProperty.Name }); } CimProperty tag = adaptedProperty.Tag as CimProperty; object obj2 = value; if (obj2 != null) { Type dotNetType; CimType cimType = tag.CimType; if (cimType == CimType.DateTime) { dotNetType = typeof(object); } else if (cimType == CimType.DateTimeArray) { dotNetType = typeof(object[]); } else { dotNetType = CimConverter.GetDotNetType(tag.CimType); } obj2 = Adapter.PropertySetAndMethodArgumentConvertTo(value, dotNetType, CultureInfo.InvariantCulture); } tag.Value = obj2; }
public override bool IsSettable(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { return false; } CimProperty tag = adaptedProperty.Tag as CimProperty; if (tag == null) { return false; } bool flag = CimFlags.ReadOnly == (tag.Flags & CimFlags.ReadOnly); return !flag; }
/// <summary> /// Gets the native <see cref="Type"/> name for the property value. /// </summary> /// <param name="adaptedProperty">The property to check.</param> /// <returns>The native <see cref="Type"/> name for the property value.</returns> /// <exception cref="InvalidOperationException">The property did not contain enough information to complete this operation.</exception> public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { var column = adaptedProperty.Tag as Column; if (null != column) { return column.ColumnType.FullName; } throw new InvalidOperationException(); }
public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { throw new ArgumentNullException("adaptedProperty"); } CimProperty tag = adaptedProperty.Tag as CimProperty; if (tag == null) { if (!adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentNullException("adaptedProperty"); } return ToStringCodeMethods.Type(typeof(string), false); } switch (tag.CimType) { case CimType.DateTime: case CimType.Reference: case CimType.Instance: case CimType.DateTimeArray: case CimType.ReferenceArray: case CimType.InstanceArray: return ("CimInstance#" + tag.CimType.ToString()); } return ToStringCodeMethods.Type(CimConverter.GetDotNetType(tag.CimType), false); }
public override void SetPropertyValue(PSAdaptedProperty property, object valueObject) { Type realType; Type type; object obj = null; Exception exception = null; if (property != null) { ADEntity baseObject = property.BaseObject as ADEntity; if (baseObject != null) { PSObject pSObject = valueObject as PSObject; if (pSObject != null) { valueObject = pSObject.BaseObject; } PropertyInfo dotNetProperty = baseObject.GetDotNetProperty(property.Name); if (dotNetProperty == null) { if (this.IsSettable(property)) { if (valueObject != null) { realType = this.GetRealType(baseObject.GetPropertyType(property.Name)); type = this.GetRealType(valueObject.GetType()); if (realType == typeof(object) || realType == type) { baseObject[property.Name].Value = valueObject; return; } else { if (baseObject.PropertyIsSingleValue(property.Name) || valueObject as ICollection == null) { baseObject[property.Name].Value = this.ConvertValue(property, valueObject, realType, type); return; } else { if (!this.TryConvertValue(property, valueObject, realType, type, out obj, out exception)) { ICollection collections = valueObject as ICollection; ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(); foreach (object obj1 in collections) { if (obj1 == null) { continue; } Type type1 = obj1.GetType(); if (type1 != realType) { aDPropertyValueCollection.Add(this.ConvertValue(property, obj1, realType, type1)); } else { aDPropertyValueCollection.Add(obj1); } } baseObject[property.Name].Value = aDPropertyValueCollection; return; } else { baseObject[property.Name].Value = obj; return; } } } } else { baseObject[property.Name].Value = null; return; } } else { object[] name = new object[1]; name[0] = property.Name; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, name)); } } else { if (dotNetProperty.CanWrite) { if (valueObject != null) { realType = this.GetRealType(dotNetProperty.PropertyType); type = this.GetRealType(valueObject.GetType()); if (realType == typeof(object) || realType == type) { dotNetProperty.SetValue(baseObject, valueObject, null); return; } else { dotNetProperty.SetValue(baseObject, this.ConvertValue(property, valueObject, realType, type), null); return; } } else { dotNetProperty.SetValue(baseObject, null, null); return; } } else { object[] objArray = new object[1]; objArray[0] = property.Name; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.PropertyIsReadonly, objArray)); } } } else { object[] typeAdapterTypeName = new object[2]; typeAdapterTypeName[0] = ADEntityAdapter.TypeAdapterTypeName; typeAdapterTypeName[1] = ADEntityAdapter.ADEntityTypeName; throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.TypeAdapterForADEntityOnly, typeAdapterTypeName)); } } else { throw new ArgumentNullException("property"); } }
private bool TryConvertValue(PSAdaptedProperty property, object valueObject, Type attrType, Type valType, out object newValue, out Exception conversionException) { bool flag; newValue = null; conversionException = null; if (!attrType.IsEnum) { if (!(attrType == typeof(string)) || !valType.IsPrimitive && !(valueObject is Guid) && valueObject as ADObject == null) { Type[] typeArray = new Type[1]; typeArray[0] = valType; Type[] typeArray1 = typeArray; object[] objArray = new object[1]; objArray[0] = valueObject; object[] objArray1 = objArray; ConstructorInfo constructor = attrType.GetConstructor(typeArray1); if (constructor != null) { try { newValue = constructor.Invoke(objArray1); flag = true; return flag; } catch (TargetInvocationException targetInvocationException1) { TargetInvocationException targetInvocationException = targetInvocationException1; conversionException = targetInvocationException.InnerException; } catch (TargetException targetException1) { TargetException targetException = targetException1; conversionException = targetException; } } if (attrType.IsPrimitive && valType.IsPrimitive) { object[] str = new object[1]; str[0] = valueObject.ToString(); objArray1 = str; Type[] typeArray2 = new Type[1]; typeArray2[0] = typeof(string); typeArray1 = typeArray2; } MethodInfo method = attrType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, typeArray1, null); if (method != null) { try { newValue = method.Invoke(null, objArray1); flag = true; return flag; } catch (TargetInvocationException targetInvocationException3) { TargetInvocationException targetInvocationException2 = targetInvocationException3; conversionException = targetInvocationException2.InnerException; } catch (TargetException targetException3) { TargetException targetException2 = targetException3; conversionException = targetException2; } } return false; } else { newValue = valueObject.ToString(); return true; } } else { if (!Utils.TryParseEnum(attrType, valueObject, out newValue)) { object[] objArray2 = new object[2]; objArray2[0] = valueObject; objArray2[1] = attrType; conversionException = new FormatException(string.Format(CultureInfo.CurrentCulture, StringResources.EnumConversionError, objArray2)); return false; } else { return true; } } }
/// <summary> /// Returns true if the given property is gettable /// </summary> public abstract bool IsGettable(PSAdaptedProperty adaptedProperty);
/// <summary> /// Sets the property value. /// </summary> /// <param name="adaptedProperty">The property to set.</param> /// <param name="value">The property value to set.</param> /// <exception cref="NotSupportedException">The operation is not supported.</exception> public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value) { throw new NotSupportedException(); }
/// <summary> /// Gets whether the property is gettable. /// </summary> /// <param name="adaptedProperty">The property to check.</param> /// <returns>Always returns true.</returns> public override bool IsGettable(PSAdaptedProperty adaptedProperty) { return true; }
/// <summary> /// /// </summary> /// <param name="adaptedProperty"></param> /// <returns></returns> public override bool IsGettable(PSAdaptedProperty adaptedProperty) { /* I was explicitly asked to only use MI_FLAG_READONLY for now // based on DSP0004, version 2.6.0, section "5.5.3.41 Read" (page 85, lines 2881-2884) bool readQualifierValue = this.GetPropertyQualifierValue(adaptedProperty, "Read", defaultValue: true); return readQualifierValue; */ return true; }
public override object GetPropertyValue(PSAdaptedProperty adaptedProperty) { if (adaptedProperty == null) { throw new ArgumentNullException("adaptedProperty"); } CimProperty tag = adaptedProperty.Tag as CimProperty; if (tag != null) { return tag.Value; } if (!adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentNullException("adaptedProperty"); } CimInstance instance = (CimInstance) adaptedProperty.Tag; return instance.GetCimSessionComputerName(); }
/// <summary> /// Sets the value of a given property /// </summary> public abstract void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value);
/// <summary> /// Returns the value of a given property /// </summary> public abstract object GetPropertyValue(PSAdaptedProperty adaptedProperty);
public abstract string GetPropertyTypeName(PSAdaptedProperty adaptedProperty);
/// <summary> /// Returns the type for a given property /// </summary> public abstract string GetPropertyTypeName(PSAdaptedProperty adaptedProperty);
public abstract object GetPropertyValue(PSAdaptedProperty adaptedProperty);
/// <summary> /// Gets the property value. /// </summary> /// <param name="adaptedProperty">The property to get.</param> /// <returns>The property value.</returns> /// <exception cref="InvalidOperationException">The property did not contain enough information to complete this operation.</exception> public override object GetPropertyValue(PSAdaptedProperty adaptedProperty) { if (null != adaptedProperty) { return GetPropertyValue(adaptedProperty, adaptedProperty.BaseObject as Record); } throw new InvalidOperationException(); }
public abstract bool IsSettable(PSAdaptedProperty adaptedProperty);
/// <summary> /// Gets whether the property is settable. /// </summary> /// <param name="adaptedProperty">The property to check.</param> /// <returns>Always returns false.</returns> public override bool IsSettable(PSAdaptedProperty adaptedProperty) { return false; }
public abstract void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value);
internal static object GetPropertyValue(PSAdaptedProperty adaptedProperty, Record record) { var column = adaptedProperty.Tag as Column; if (null != column && null != record) { return record.Data[column.Index]; } throw new InvalidOperationException(); }
/// <summary> /// /// </summary> /// <param name="adaptedProperty"></param> /// <returns></returns> public override string GetPropertyTypeName(PSAdaptedProperty adaptedProperty) { if (null == adaptedProperty) { throw new ArgumentNullException("adaptedProperty"); } CimProperty cimProperty = adaptedProperty.Tag as CimProperty; if (cimProperty != null) { return CimTypeToTypeNameDisplayString(cimProperty.CimType); } if (adaptedProperty.Name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase)) { return ToStringCodeMethods.Type(typeof(string)); } throw new ArgumentNullException("adaptedProperty"); }