Exemplo 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;
 }
Exemplo 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);
        }
Exemplo 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;
     }
 }
Exemplo 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));
            }
        }
Exemplo 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);
     }
 }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo 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);
        }