Esempio n. 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">Type for which this entry is created</param>
 /// <param name="serializer">TypeSerializerDelegate for serializing the type</param>
 /// <param name="cimClassName">The CimClass name whose instance needs to be created for this type</param>
 internal MITypeSerializationInfo(Type type, MITypeSerializerDelegate serializer,
                                  string cimClassName)
 {
     Type         = type;
     Serializer   = serializer;
     CimType      = CimConverter.GetCimType(type);
     CimClassName = cimClassName;
 }
Esempio n. 2
0
        public static MiResult AddElement(InstanceHandle handle, string name, object obj, object par, MiFlags miFlags)
        {
            NativeCimInstance   instance   = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance>(handle.DangerousGetHandle());
            NativeCimProperties properties = NativeCimPropertiesHelper.Deserialize(instance.Properties);

            CimType type = CimConverter.GetCimType(obj.GetType());

            properties.Add(new NativeCimProperty {
                Name = name, Type = type, Origin = "client", IsArray = false, IsLocal = false, Value = obj
            });
            instance.Properties = NativeCimPropertiesHelper.Serialize(properties);
            handle.DangerousSetHandle((IntPtr)CimNativeApi.MarshalledObject.Create <NativeCimInstance>(instance));
            return(MiResult.OK);
        }
Esempio n. 3
0
 internal static void SetCustomOption(CimOperationOptions operationOptions, string optionName, object optionValue)
 {
     if (optionValue != null)
     {
         object  cim     = CimValueConverter.ConvertFromDotNetToCim(optionValue);
         CimType cimType = CimConverter.GetCimType(CimValueConverter.GetCimType(optionValue.GetType()));
         operationOptions.SetCustomOption(optionName, cim, cimType, false);
         return;
     }
     else
     {
         return;
     }
 }
Esempio n. 4
0
        internal static CimType GetCimTypeEnum(Type dotNetType)
        {
            Dbg.Assert(dotNetType != null, "Caller should make sure that dotNetType != null");

            if (typeof(PSReference).IsAssignableFrom(dotNetType))
            {
                return(CimType.Reference);
            }
            if (typeof(PSReference[]).IsAssignableFrom(dotNetType))
            {
                return(CimType.ReferenceArray);
            }
            else
            {
                return(CimConverter.GetCimType(dotNetType));
            }
        }
Esempio n. 5
0
 internal static CimType GetCimTypeEnum(Type dotNetType)
 {
     if (!typeof(PSReference).IsAssignableFrom(dotNetType))
     {
         if (!typeof(PSReference[]).IsAssignableFrom(dotNetType))
         {
             return(CimConverter.GetCimType(dotNetType));
         }
         else
         {
             return(CimType.ReferenceArray);
         }
     }
     else
     {
         return(CimType.Reference);
     }
 }
Esempio n. 6
0
        internal static void SetCustomOption(
            CimOperationOptions operationOptions,
            string optionName,
            object optionValue,
            CimSensitiveValueConverter cimSensitiveValueConverter)
        {
            Dbg.Assert(!string.IsNullOrWhiteSpace(optionName), "Caller should verify optionName != null");

            if (optionValue is null)
            {
                return;
            }

            object  cimValue = cimSensitiveValueConverter.ConvertFromDotNetToCim(optionValue);
            CimType cimType  = CimConverter.GetCimType(CimSensitiveValueConverter.GetCimType(optionValue.GetType()));

            operationOptions.SetCustomOption(optionName, cimValue, cimType, mustComply: false);
        }
Esempio n. 7
0
        public static MiResult GetElementAt_GetType(InstanceHandle handle, int _index, out MiType miType)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));
            int i = 0;

            miType = MiType.Boolean;
            foreach (var element in properties)
            {
                if (i == _index)
                {
                    Type type = element.Value.GetType();
                    miType = CimConverter.GetCimType(type).ToMiType();
                    break;
                }
                i++;
            }
            return(MiResult.OK);
        }
Esempio n. 8
0
        internal CimInstance ToCimInstance()
        {
            CimInstance c            = InternalMISerializer.CreateCimInstance("PS_Parameter");
            CimProperty nameProperty = InternalMISerializer.CreateCimProperty("Name", this.Name,
                                                                              Microsoft.Management.Infrastructure.CimType.String);

            c.CimInstanceProperties.Add(nameProperty);
            Microsoft.Management.Infrastructure.CimType cimType = CimConverter.GetCimType(this.Value.GetType());
            CimProperty valueProperty;

            if (cimType == Microsoft.Management.Infrastructure.CimType.Unknown)
            {
                valueProperty = InternalMISerializer.CreateCimProperty("Value", (object)PSMISerializer.Serialize(this.Value),
                                                                       Microsoft.Management.Infrastructure.CimType.Instance);
            }
            else
            {
                valueProperty = InternalMISerializer.CreateCimProperty("Value", this.Value, cimType);
            }

            c.CimInstanceProperties.Add(valueProperty);
            return(c);
        }