Пример #1
0
 private static bool TryGetErrorDataProperty <T>(CimInstance errorData, string propertyName, out T propertyValue)
 {
     propertyValue = default(T);
     if (errorData == null)
     {
         return(false);
     }
     try
     {
         CimProperty property = errorData.CimInstanceProperties[propertyName];
         if (property == null)
         {
             return(false);
         }
         if (!(property.Value is T))
         {
             return(false);
         }
         propertyValue = (T)property.Value;
         return(true);
     }
     catch (CimException)
     {
         return(false);
     }
 }
Пример #2
0
 private static PSAdaptedProperty GetCimPropertyAdapter(CimProperty property, object baseObject, string propertyName)
 {
     PSAdaptedProperty propertyToAdd = new PSAdaptedProperty(propertyName, property);
     propertyToAdd.baseObject = baseObject;
     //propertyToAdd.adapter = this;
     return propertyToAdd;
 }
Пример #3
0
        private static bool TryGetErrorDataProperty <T>(CimInstance errorData, string propertyName, out T propertyValue)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(propertyName), "Caller should verify !string.IsNullOrWhiteSpace(propertyName)");
            propertyValue = default(T);

            if (errorData == null)
            {
                return(false);
            }

            try
            {
                CimProperty property = errorData.CimInstanceProperties[propertyName];
                if (property == null)
                {
                    return(false);
                }

                if (!(property.Value is T))
                {
                    return(false);
                }

                propertyValue = (T)property.Value;
                return(true);
            }
            catch (CimException)
            {
                return(false);
            }
        }
Пример #4
0
        public override void Add(CimMethodParameter newParameter)
        {
            this.AssertNotDisposed();
            if (newParameter == null)
            {
                throw new ArgumentNullException("newParameter");
            }
            CimProperty newItem = CimProperty.Create(newParameter.Name, newParameter.Value, newParameter.CimType, newParameter.Flags);

            this._backingInstance.CimInstanceProperties.Add(newItem);
        }
Пример #5
0
 private static PSAdaptedProperty GetCimPropertyAdapter(CimProperty property, object baseObject)
 {
     try
     {
         string name = property.Name;
         return GetCimPropertyAdapter(property, baseObject, name);
     }
     catch (CimException)
     {
         return null;
     }
 }
Пример #6
0
 private static PSAdaptedProperty GetCimPropertyAdapter(CimProperty property, object baseObject)
 {
     try
     {
         string propertyName = property.Name;
         return GetCimPropertyAdapter(property, baseObject, propertyName);
     }
     catch (CimException)
     {
         // ignore "Name" property access failures and move on.
         return null;
     }
 }
Пример #7
0
        public override string ToString()
        {
            string      className;
            CimProperty item  = this.CimInstanceProperties["Caption"];
            string      value = null;

            if (item != null)
            {
                value = item.Value as string;
            }
            string str = ", ";
            CimKeyedCollection <CimProperty> cimInstanceProperties = this.CimInstanceProperties;
            string str1 = string.Join <CimProperty>(str, cimInstanceProperties.Where <CimProperty>((CimProperty p) => CimFlags.Key == (p.Flags & CimFlags.Key)));

            if (!string.IsNullOrEmpty(str1) || !string.IsNullOrEmpty(value))
            {
                if (!string.IsNullOrEmpty(value))
                {
                    if (!string.IsNullOrEmpty(str1))
                    {
                        object[] objArray = new object[3];
                        objArray[0] = this.CimSystemProperties.ClassName;
                        objArray[1] = str1;
                        objArray[2] = value;
                        className   = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringFullData, objArray);
                    }
                    else
                    {
                        object[] className1 = new object[2];
                        className1[0] = this.CimSystemProperties.ClassName;
                        className1[1] = value;
                        className     = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringNoKeys, className1);
                    }
                }
                else
                {
                    object[] objArray1 = new object[2];
                    objArray1[0] = this.CimSystemProperties.ClassName;
                    objArray1[1] = str1;
                    className    = string.Format(CultureInfo.InvariantCulture, System.Management.Automation.Strings.CimInstanceToStringNoCaption, objArray1);
                }
            }
            else
            {
                className = this.CimSystemProperties.ClassName;
            }
            return(className);
        }
        public override CimMethodParameter this[string parameterName]
        {
            get
            {
                this.AssertNotDisposed();
                if (string.IsNullOrWhiteSpace(parameterName))
                {
                    throw new ArgumentNullException("parameterName");
                }

                CimProperty backingProperty = this._backingInstance.CimInstanceProperties[parameterName];
                return((backingProperty == null)
                    ? null
                    : new CimMethodParameterBackedByCimProperty(backingProperty, this._backingInstance.GetCimSessionComputerName(), this._backingInstance.GetCimSessionInstanceId()));
            }
        }
Пример #9
0
        public override string ToString()
        {
            CimProperty captionProperty = this.CimInstanceProperties["Caption"];
            string      captionValue    = null;

            if (captionProperty != null)
            {
                captionValue = captionProperty.Value as string;
            }

            string keyValues = string.Join(", ", this.CimInstanceProperties.Where(p => CimFlags.Key == (p.Flags & CimFlags.Key)));

            string toStringValue;

            if (string.IsNullOrEmpty(keyValues) && (string.IsNullOrEmpty(captionValue)))
            {
                toStringValue = this.CimSystemProperties.ClassName;
            }
            else if (string.IsNullOrEmpty(captionValue))
            {
                toStringValue = string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.CimInstanceToStringNoCaption,
                    this.CimSystemProperties.ClassName,
                    keyValues);
            }
            else if (string.IsNullOrEmpty(keyValues))
            {
                toStringValue = string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.CimInstanceToStringNoKeys,
                    this.CimSystemProperties.ClassName,
                    captionValue);
            }
            else
            {
                toStringValue = string.Format(
                    CultureInfo.InvariantCulture,
                    Strings.CimInstanceToStringFullData,
                    this.CimSystemProperties.ClassName,
                    keyValues,
                    captionValue);
            }
            return(toStringValue);
        }
Пример #10
0
        internal static object ConvertToNativeLayer(object value, CimType cimType)
        {
            CimInstance cimInstance = value as CimInstance;

            if (cimInstance == null)
            {
                CimInstance[] cimInstanceArray = value as CimInstance[];
                if (cimInstanceArray == null)
                {
                    if (cimType != CimType.Unknown)
                    {
                        return(CimProperty.ConvertToNativeLayer(value, cimType));
                    }
                    else
                    {
                        return(value);
                    }
                }
                else
                {
                    InstanceHandle[] instanceHandle = new InstanceHandle[(int)cimInstanceArray.Length];
                    for (int i = 0; i < (int)cimInstanceArray.Length; i++)
                    {
                        CimInstance cimInstance1 = cimInstanceArray[i];
                        if (cimInstance1 != null)
                        {
                            instanceHandle[i] = cimInstance1.InstanceHandle;
                        }
                        else
                        {
                            instanceHandle[i] = null;
                        }
                    }
                    return(instanceHandle);
                }
            }
            else
            {
                return(cimInstance.InstanceHandle);
            }
        }
Пример #11
0
 private static PSAdaptedProperty GetCimPropertyAdapter(CimProperty property, object baseObject, string propertyName)
 {
     return new PSAdaptedProperty(propertyName, property) { baseObject = baseObject };
 }
		internal CimMethodParameterBackedByCimProperty(CimProperty backingProperty, string cimSessionComputerName, Guid cimSessionInstanceId)
		{
			this._backingProperty = backingProperty;
			this.Initialize(cimSessionComputerName, cimSessionInstanceId);
		}
		internal CimMethodParameterBackedByCimProperty(CimProperty backingProperty)
		{
			this._backingProperty = backingProperty;
			this.Initialize(null, Guid.Empty);
		}