Ejemplo n.º 1
0
 internal CimPropertyStandalone(string name, object value, CimType cimType, CimFlags flags)
 {
     this._name    = name;
     this._cimType = cimType;
     this._flags   = flags;
     this.Value    = value;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimInstance"/> with given properties.
        /// </para>
        /// </summary>
        /// <param name="className"></param>
        /// <param name="key"></param>
        /// <param name="properties"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create.</exception>
        /// <exception cref="ArgumentException">CimProperty.Create.</exception>
        private CimInstance CreateCimInstance(
            string className,
            string cimNamespace,
            IEnumerable <string> key,
            IDictionary properties,
            NewCimInstanceCommand cmdlet)
        {
            CimInstance cimInstance = new(className, cimNamespace);

            if (properties == null)
            {
                return(cimInstance);
            }

            List <string> keys = new();

            if (key != null)
            {
                foreach (string keyName in key)
                {
                    keys.Add(keyName);
                }
            }

            IDictionaryEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CimFlags flag         = CimFlags.None;
                string   propertyName = enumerator.Key.ToString().Trim();
                if (keys.Contains(propertyName, StringComparer.OrdinalIgnoreCase))
                {
                    flag = CimFlags.Key;
                }

                object propertyValue = GetBaseObject(enumerator.Value);

                DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, propertyName, propertyValue, flag);

                PSReference cimReference = propertyValue as PSReference;
                if (cimReference != null)
                {
                    CimProperty newProperty = CimProperty.Create(propertyName, GetBaseObject(cimReference.Value), CimType.Reference, flag);
                    cimInstance.CimInstanceProperties.Add(newProperty);
                }
                else
                {
                    CimProperty newProperty = CimProperty.Create(
                        propertyName,
                        propertyValue,
                        flag);
                    cimInstance.CimInstanceProperties.Add(newProperty);
                }
            }

            return(cimInstance);
        }
Ejemplo n.º 3
0
        internal CimPropertyStandalone(string name, object value, CimType cimType, CimFlags flags)
        {
            Debug.Assert(name != null, "Caller should verify name != null");

            this._name    = name;
            this._cimType = cimType;
            this._flags   = flags;

            this.Value           = value;
            this.IsValueModified = false;
        }
Ejemplo n.º 4
0
        private CimInstance CreateCimInstance(string className, string cimNamespace, IEnumerable <string> key, IDictionary properties, NewCimInstanceCommand cmdlet)
        {
            CimInstance cimInstance = new CimInstance(className, cimNamespace);

            if (properties != null)
            {
                List <string> strs = new List <string>();
                if (key != null)
                {
                    foreach (string str in key)
                    {
                        strs.Add(str);
                    }
                }
                IDictionaryEnumerator enumerator = properties.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CimFlags cimFlag = CimFlags.None;
                    string   str1    = enumerator.Key.ToString().Trim();
                    if (strs.Contains <string>(str1, StringComparer.OrdinalIgnoreCase))
                    {
                        cimFlag = CimFlags.Key;
                    }
                    object   baseObject = base.GetBaseObject(enumerator.Value);
                    object[] objArray   = new object[3];
                    objArray[0] = str1;
                    objArray[1] = baseObject;
                    objArray[2] = cimFlag;
                    DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, objArray);
                    PSReference pSReference = baseObject as PSReference;
                    if (pSReference == null)
                    {
                        CimProperty cimProperty = CimProperty.Create(str1, baseObject, cimFlag);
                        cimInstance.CimInstanceProperties.Add(cimProperty);
                    }
                    else
                    {
                        CimProperty cimProperty1 = CimProperty.Create(str1, base.GetBaseObject(pSReference.Value), CimType.Reference, cimFlag);
                        cimInstance.CimInstanceProperties.Add(cimProperty1);
                    }
                }
                return(cimInstance);
            }
            else
            {
                return(cimInstance);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// <para>
        /// Create <see cref="CimMethodParametersCollection"/> with given key properties.
        /// And/or <see cref="CimClass"/> object.
        /// </para>
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="cimClass"></param>
        /// <param name="cimInstance"></param>
        /// <param name="methodName"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">See CimProperty.Create.</exception>
        /// <exception cref="ArgumentException">CimProperty.Create.</exception>
        private CimMethodParametersCollection CreateParametersCollection(
            IDictionary parameters,
            CimClass cimClass,
            CimInstance cimInstance,
            string methodName)
        {
            DebugHelper.WriteLogEx();

            CimMethodParametersCollection collection = null;

            if (parameters == null)
            {
                return(collection);
            }
            else if (parameters.Count == 0)
            {
                return(collection);
            }

            collection = new CimMethodParametersCollection();
            IDictionaryEnumerator enumerator = parameters.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string parameterName = enumerator.Key.ToString();

                const CimFlags parameterFlags = CimFlags.In;
                object         parameterValue = GetBaseObject(enumerator.Value);

                DebugHelper.WriteLog(@"Create parameter name= {0}, value= {1}, flags= {2}.", 4,
                                     parameterName,
                                     parameterValue,
                                     parameterFlags);

                CimMethodParameter   parameter   = null;
                CimMethodDeclaration declaration = null;
                string className = null;
                if (cimClass != null)
                {
                    className   = cimClass.CimSystemProperties.ClassName;
                    declaration = cimClass.CimClassMethods[methodName];
                    if (declaration == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CultureInfo.CurrentUICulture, CimCmdletStrings.InvalidMethod, methodName, className));
                    }
                }
                else if (cimInstance != null)
                {
                    className   = cimInstance.CimClass.CimSystemProperties.ClassName;
                    declaration = cimInstance.CimClass.CimClassMethods[methodName];
                }

                if (declaration != null)
                {
                    CimMethodParameterDeclaration paramDeclaration = declaration.Parameters[parameterName];
                    if (paramDeclaration == null)
                    {
                        throw new ArgumentException(string.Format(
                                                        CultureInfo.CurrentUICulture, CimCmdletStrings.InvalidMethodParameter, parameterName, methodName, className));
                    }

                    parameter = CimMethodParameter.Create(
                        parameterName,
                        parameterValue,
                        paramDeclaration.CimType,
                        parameterFlags);
                    // FIXME: check in/out qualifier
                    // parameterFlags = paramDeclaration.Qualifiers;
                }
                else
                {
                    if (parameterValue == null)
                    {
                        // try the best to get the type while value is null
                        parameter = CimMethodParameter.Create(
                            parameterName,
                            parameterValue,
                            CimType.String,
                            parameterFlags);
                    }
                    else
                    {
                        CimType referenceType   = CimType.Unknown;
                        object  referenceObject = GetReferenceOrReferenceArrayObject(parameterValue, ref referenceType);
                        if (referenceObject != null)
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                referenceObject,
                                referenceType,
                                parameterFlags);
                        }
                        else
                        {
                            parameter = CimMethodParameter.Create(
                                parameterName,
                                parameterValue,
                                parameterFlags);
                        }
                    }
                }

                if (parameter != null)
                {
                    collection.Add(parameter);
                }
            }

            return(collection);
        }
Ejemplo n.º 6
0
 public static MI_Flags FromCimFlags(this CimFlags cimFlags)
 {
     return((MI_Flags)cimFlags);
 }
Ejemplo n.º 7
0
 public static CimMethodParameter Create(string name, object value, Microsoft.Management.Infrastructure.CimType type, CimFlags flags)
 {
     return(new CimMethodParameterBackedByCimProperty(new CimPropertyStandalone(name, value, type, flags)));
 }
Ejemplo n.º 8
0
 public static CimMethodParameter Create(string name, object value, CimFlags flags)
 {
     Microsoft.Management.Infrastructure.CimType cimTypeFromDotNetValueOrThrowAnException = CimConverter.GetCimTypeFromDotNetValueOrThrowAnException(value);
     return(Create(name, value, cimTypeFromDotNetValueOrThrowAnException, flags));
 }
Ejemplo n.º 9
0
 public static MiFlags ToMiFlags(this CimFlags cimFlags)
 {
     return((MiFlags)((uint)cimFlags));
 }
Ejemplo n.º 10
0
		internal CimPropertyStandalone(string name, object value, CimType cimType, CimFlags flags)
		{
			this._name = name;
			this._cimType = cimType;
			this._flags = flags;
			this.Value = value;
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new property.
        /// This method overload tries to infer <see cref="CimType"/> from the property <paramref name="value"/>
        /// </summary>
        /// <param name="name">Name of the property</param>
        /// <param name="value">Value of the property.  <c>null</c> is the property doesn't have an associated value.</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null</exception>
        /// <exception cref="ArgumentException">Thrown when the <see cref="CimType"/> cannot be inferred from the property <paramref name="value"/> </exception>
        static public CimProperty Create(string name, object value, CimFlags flags)
        {
            CimType cimType = CimConverter.GetCimTypeFromDotNetValueOrThrowAnException(value);

            return(Create(name, value, cimType, flags));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new property.
 /// </summary>
 /// <param name="name">Name of the property</param>
 /// <param name="value">Value of the property.  <c>null</c> is the property doesn't have an associated value.</param>
 /// <param name="type"></param>
 /// <param name="flags"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null</exception>
 /// <exception cref="ArgumentException">Thrown when the <paramref name="value"/> doesn't match <paramref name="type"/></exception>
 static public CimProperty Create(string name, object value, CimType type, CimFlags flags)
 {
     return(new CimPropertyStandalone(name, value, type, flags));
 }
Ejemplo n.º 13
0
        private CimMethodParametersCollection CreateParametersCollection(IDictionary parameters, CimClass cimClass, CimInstance cimInstance, string methodName)
        {
            DebugHelper.WriteLogEx();
            CimMethodParametersCollection cimMethodParametersCollection = null;

            if (parameters != null)
            {
                if (parameters.Count != 0)
                {
                    cimMethodParametersCollection = new CimMethodParametersCollection();
                    IDictionaryEnumerator enumerator = parameters.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string   str        = enumerator.Key.ToString();
                        CimFlags cimFlag    = CimFlags.In;
                        object   baseObject = base.GetBaseObject(enumerator.Value);
                        object[] objArray   = new object[3];
                        objArray[0] = str;
                        objArray[1] = baseObject;
                        objArray[2] = cimFlag;
                        DebugHelper.WriteLog("Create parameter name= {0}, value= {1}, flags= {2}.", 4, objArray);
                        CimMethodParameter   cimMethodParameter = null;
                        CimMethodDeclaration item = null;
                        string className          = null;
                        if (cimClass == null)
                        {
                            if (cimInstance != null)
                            {
                                className = cimInstance.CimClass.CimSystemProperties.ClassName;
                                item      = cimInstance.CimClass.CimClassMethods[methodName];
                            }
                        }
                        else
                        {
                            className = cimClass.CimSystemProperties.ClassName;
                            item      = cimClass.CimClassMethods[methodName];
                            if (item == null)
                            {
                                object[] objArray1 = new object[2];
                                objArray1[0] = methodName;
                                objArray1[1] = className;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Strings.InvalidMethod, objArray1));
                            }
                        }
                        if (item == null)
                        {
                            if (baseObject != null)
                            {
                                CimType cimType = CimType.Unknown;
                                object  referenceOrReferenceArrayObject = base.GetReferenceOrReferenceArrayObject(baseObject, ref cimType);
                                if (referenceOrReferenceArrayObject == null)
                                {
                                    cimMethodParameter = CimMethodParameter.Create(str, baseObject, cimFlag);
                                }
                                else
                                {
                                    cimMethodParameter = CimMethodParameter.Create(str, referenceOrReferenceArrayObject, cimType, cimFlag);
                                }
                            }
                            else
                            {
                                cimMethodParameter = CimMethodParameter.Create(str, baseObject, CimType.String, cimFlag);
                            }
                        }
                        else
                        {
                            CimMethodParameterDeclaration cimMethodParameterDeclaration = item.Parameters[str];
                            if (cimMethodParameterDeclaration != null)
                            {
                                cimMethodParameter = CimMethodParameter.Create(str, baseObject, cimMethodParameterDeclaration.CimType, cimFlag);
                            }
                            else
                            {
                                object[] objArray2 = new object[3];
                                objArray2[0] = str;
                                objArray2[1] = methodName;
                                objArray2[2] = className;
                                throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Strings.InvalidMethodParameter, objArray2));
                            }
                        }
                        if (cimMethodParameter == null)
                        {
                            continue;
                        }
                        cimMethodParametersCollection.Add(cimMethodParameter);
                    }
                    return(cimMethodParametersCollection);
                }
                else
                {
                    return(cimMethodParametersCollection);
                }
            }
            else
            {
                return(cimMethodParametersCollection);
            }
        }
Ejemplo n.º 14
0
 public static CimProperty Create(string name, object value, Microsoft.Management.Infrastructure.CimType type, CimFlags flags)
 {
     return new CimPropertyStandalone(name, value, type, flags);
 }
Ejemplo n.º 15
0
 public static CimProperty Create(string name, object value, CimFlags flags)
 {
     Microsoft.Management.Infrastructure.CimType cimTypeFromDotNetValueOrThrowAnException = CimConverter.GetCimTypeFromDotNetValueOrThrowAnException(value);
     return Create(name, value, cimTypeFromDotNetValueOrThrowAnException, flags);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a new parameter.
        /// </summary>
        /// <param name="name">Name of the parameter</param>
        /// <param name="value">Value of the parameter.  <c>null</c> is the parameter doesn't have an associated value.</param>
        /// <param name="type"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null</exception>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="value"/> doesn't match <paramref name="type"/></exception>
        static public CimMethodParameter Create(string name, object value, CimType type, CimFlags flags)
        {
            CimProperty backingProperty = new CimPropertyStandalone(name, value, type, flags);

            return(new CimMethodParameterBackedByCimProperty(backingProperty));
        }