Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
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. 4
0
        public static MethodAnalysis Analyze(this CimMethodDeclaration d, IDictionary <string, CimTypeDeclaration> typeRepo)
        {
            TypeSyntax returnType;
            var        dotnetReturnType = CimConverter.GetDotNetType(d.ReturnType);

            if (d.ReturnType == CimType.DateTime)
            {
                dotnetReturnType = typeof(DateTime);
            }
            if (d.ReturnType == CimType.DateTimeArray)
            {
                dotnetReturnType = typeof(DateTime[]);
            }
            if (dotnetReturnType == null)
            {
                returnType = SyntaxFactory.ParseTypeName("void");
            }
            else
            {
                returnType = SyntaxFactory.ParseTypeName(dotnetReturnType.FullName);
            }
            var inputParameters  = new List <NameAndType>();
            var outputParameters = new List <NameAndType>();

            foreach (var p in d.Parameters)
            {
                var type  = ResolveType(p.CimType, p.ReferenceClassName ?? p.Qualifiers["EmbeddedInstance"]?.Value as string, p.Qualifiers.IsNotNull(), typeRepo, out var isCimObject, out var isNullableValueType, out var isEnumerable, out var enumeratedType);
                var entry = new NameAndType
                {
                    IsCimObject         = isCimObject,
                    Name                = p.Name,
                    Type                = type,
                    IsNullableValueType = isNullableValueType,
                    IsEnumerable        = isEnumerable,
                    CimType             = p.CimType,
                    EnumeratedType      = enumeratedType,
                };
                if (IsIn(p))
                {
                    inputParameters.Add(entry);
                }
                if (IsOut(p))
                {
                    outputParameters.Add(entry);
                }
            }
            return(new MethodAnalysis
            {
                ReturnType = returnType,
                InputParameters = inputParameters.ToArray(),
                OutputParameters = outputParameters.ToArray()
            });
        }
Esempio n. 5
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. 6
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;
     }
 }
        internal static string CimTypeToTypeNameDisplayString(CimType cimType)
        {
            switch (cimType)
            {
            case CimType.DateTime:
            case CimType.Instance:
            case CimType.Reference:
            case CimType.DateTimeArray:
            case CimType.InstanceArray:
            case CimType.ReferenceArray:
                return("CimInstance#" + cimType.ToString());

            default:
                return(ToStringCodeMethods.Type(
                           CimConverter.GetDotNetType(cimType)));
            }
        }
Esempio n. 8
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));
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="adaptedProperty"></param>
        /// <param name="value"></param>
        public override void SetPropertyValue(PSAdaptedProperty adaptedProperty, object value)
        {
            if (adaptedProperty == null)
            {
                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;
        }
Esempio n. 10
0
        private static TypeSyntax ResolveType(CimType cimType, string referenceClassName, bool isNotNull, IDictionary <string, CimTypeDeclaration> typeRepo, out bool isCimObject, out bool isNullableValueType, out bool isEnumerable, out TypeSyntax enumeratedType)
        {
            isEnumerable        = false;
            isCimObject         = false;
            isNullableValueType = false;
            enumeratedType      = null;
            switch (cimType)
            {
            case Microsoft.Management.Infrastructure.CimType.Instance:
            case Microsoft.Management.Infrastructure.CimType.Reference:
                if (referenceClassName != null)
                {
                    return(SyntaxFactory.ParseTypeName(typeRepo.CSharpNameOrCimInstance(referenceClassName, out isCimObject)));
                }
                return(SyntaxFactory.ParseTypeName("CimInstance"));

            case Microsoft.Management.Infrastructure.CimType.InstanceArray:
            case Microsoft.Management.Infrastructure.CimType.ReferenceArray:
                isEnumerable = true;
                if (referenceClassName != null)
                {
                    enumeratedType = SyntaxFactory.ParseTypeName(typeRepo.CSharpNameOrCimInstance(referenceClassName, out isCimObject));
                    return(SyntaxHelper.EnumerableOf(enumeratedType));
                }
                enumeratedType = SyntaxFactory.ParseTypeName("CimInstance");
                return(SyntaxHelper.EnumerableOf(enumeratedType));

            default:
                var type = CimConverter.GetDotNetType(cimType);
                if (cimType == CimType.DateTime)
                {
                    type = typeof(DateTime);
                }
                if (cimType == CimType.DateTimeArray)
                {
                    type = typeof(DateTime[]);
                }
                if (type.IsValueType && !isNotNull)
                {
                    isNullableValueType = true;
                    return(SyntaxFactory.ParseTypeName(type.FullName + "?"));
                }
                return(SyntaxFactory.ParseTypeName(type.FullName));
            }
        }
Esempio n. 11
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. 12
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. 13
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. 14
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);
        }