public InstrumentationClassAttribute(InstrumentationType instrumentationType) { this.instrumentationType = instrumentationType; }
public InstrumentationClassAttribute(InstrumentationType instrumentationType, string managedBaseClassName) { this.instrumentationType = instrumentationType; this.managedBaseClassName = managedBaseClassName; }
public InstrumentationToken(MockInstrumenter instrumenter, InstrumentationType type, InstrumentationPayload payload) { _instrumenter = instrumenter; _type = type; _payload = payload; }
public SchemaMapping(Type type, SchemaNaming naming, Hashtable mapTypeToConverterClassName) { codeClassName = (string)mapTypeToConverterClassName[type]; classType = type; bool hasGenericEmbeddedObject = false; string baseClassName = ManagedNameAttribute.GetBaseClassName(type); className = ManagedNameAttribute.GetMemberName(type); instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType; classPath = naming.NamespaceName + ":" + className; if(null == baseClassName) { newClass = new ManagementClass(naming.NamespaceName, "", null); newClass.SystemProperties ["__CLASS"].Value = className; } else { ManagementClass baseClass = new ManagementClass(naming.NamespaceName + ":" + baseClassName); if(instrumentationType == InstrumentationType.Instance) { bool baseAbstract = false; try { QualifierData o = baseClass.Qualifiers["abstract"]; if(o.Value is bool) baseAbstract = (bool)o.Value; } catch(ManagementException e) { if(e.ErrorCode != ManagementStatus.NotFound) throw; } if(!baseAbstract) throw new Exception(RC.GetString("CLASSINST_EXCEPT")); } newClass = baseClass.Derive(className); } // Create the converter class CodeWriter codeClass = code.AddChild("public class "+codeClassName+" : IWmiConverter"); // Create code block for one line Members CodeWriter codeOneLineMembers = codeClass.AddChild(new CodeWriter()); codeOneLineMembers.Line("static ManagementClass managementClass = new ManagementClass(@\"" + classPath + "\");"); codeOneLineMembers.Line("static IntPtr classWbemObjectIP;"); codeOneLineMembers.Line("static Guid iidIWbemObjectAccess = new Guid(\"49353C9A-516B-11D1-AEA6-00C04FB68820\");"); codeOneLineMembers.Line("internal ManagementObject instance = managementClass.CreateInstance();"); codeOneLineMembers.Line("object reflectionInfoTempObj = null ; "); codeOneLineMembers.Line("FieldInfo reflectionIWbemClassObjectField = null ; "); codeOneLineMembers.Line("IntPtr emptyWbemObject = IntPtr.Zero ; "); codeOneLineMembers.Line("IntPtr originalObject = IntPtr.Zero ; "); codeOneLineMembers.Line("bool toWmiCalled = false ; "); // // Reuters VSQFE#: 750 [marioh] see comments above // Used as a temporary pointer to the newly created instance that we create to avoid re-using the same // object causing unbound memory usage in IWbemClassObject implementation. codeOneLineMembers.Line("IntPtr theClone = IntPtr.Zero;"); codeOneLineMembers.Line("public static ManagementObject emptyInstance = managementClass.CreateInstance();"); // codeOneLineMembers.Line("public IntPtr instWbemObjectAccessIP;"); // Create static constructor to initialize handles CodeWriter codeCCTOR = codeClass.AddChild("static "+codeClassName+"()"); codeCCTOR.Line("classWbemObjectIP = (IntPtr)managementClass;"); codeCCTOR.Line("IntPtr wbemObjectAccessIP;"); codeCCTOR.Line("Marshal.QueryInterface(classWbemObjectIP, ref iidIWbemObjectAccess, out wbemObjectAccessIP);"); codeCCTOR.Line("int cimType;"); // Create constructor CodeWriter codeCTOR = codeClass.AddChild("public "+codeClassName+"()"); codeCTOR.Line("IntPtr wbemObjectIP = (IntPtr)instance;"); codeCTOR.Line("originalObject = (IntPtr)instance;"); codeCTOR.Line("Marshal.QueryInterface(wbemObjectIP, ref iidIWbemObjectAccess, out instWbemObjectAccessIP);"); // // Reuters VSQFE#: 750 [marioh] // In the CCTOR we set things up only once: // 1. We get the IWbemClassObjectFreeThreaded object '_wbemObject' from the ManagementObject instance // 2. We then get the actual IntPtr to the underlying WMI object // 3. Finally, the simple cast to IntPtr from the ManagementObject instance // These fields will be used later during the ToWMI call. codeCTOR.Line ("FieldInfo tempField = instance.GetType().GetField ( \"_wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic );" ); codeCTOR.Line("if ( tempField == null )"); codeCTOR.Line("{"); codeCTOR.Line(" tempField = instance.GetType().GetField ( \"wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic ) ;"); codeCTOR.Line("}"); codeCTOR.Line ("reflectionInfoTempObj = tempField.GetValue (instance) ;"); codeCTOR.Line("reflectionIWbemClassObjectField = reflectionInfoTempObj.GetType().GetField (\"pWbemClassObject\", BindingFlags.Instance | BindingFlags.NonPublic );"); codeCTOR.Line("emptyWbemObject = (IntPtr) emptyInstance;"); // Create destructor that will be called at process cleanup CodeWriter codeDTOR = codeClass.AddChild("~"+codeClassName+"()"); codeDTOR.AddChild("if(instWbemObjectAccessIP != IntPtr.Zero)").Line("Marshal.Release(instWbemObjectAccessIP);"); // [marioh] Make sure we release the initial instance so that we dont leak codeDTOR.Line("if ( toWmiCalled == true )"); codeDTOR.Line("{"); codeDTOR.Line(" Marshal.Release (originalObject);"); codeDTOR.Line("}"); // Create method to convert from managed code to WMI CodeWriter codeToWMI = codeClass.AddChild("public void ToWMI(object obj)"); // // Reuters VSQFE#: 750 [marioh] see comments above // Ensure the release of the WbemObjectAccess interface pointer. codeToWMI.Line( "toWmiCalled = true ;" ) ; codeToWMI.Line( "if(instWbemObjectAccessIP != IntPtr.Zero)" ) ; codeToWMI.Line( "{" ) ; codeToWMI.Line(" Marshal.Release(instWbemObjectAccessIP);" ) ; codeToWMI.Line(" instWbemObjectAccessIP = IntPtr.Zero;" ) ; codeToWMI.Line( "}" ) ; codeToWMI.Line( "if(theClone != IntPtr.Zero)" ) ; codeToWMI.Line( "{" ) ; codeToWMI.Line(" Marshal.Release(theClone);" ) ; codeToWMI.Line(" theClone = IntPtr.Zero;" ) ; codeToWMI.Line( "}" ) ; codeToWMI.Line( "IWOA.Clone_f(12, emptyWbemObject, out theClone) ;" ) ; codeToWMI.Line( "Marshal.QueryInterface(theClone, ref iidIWbemObjectAccess, out instWbemObjectAccessIP) ;" ) ; codeToWMI.Line( "reflectionIWbemClassObjectField.SetValue ( reflectionInfoTempObj, theClone ) ;" ) ; codeToWMI.Line(String.Format("{0} instNET = ({0})obj;", type.FullName.Replace('+', '.'))); // bug#92918 - watch for nested classes // Explicit cast to IntPtr CodeWriter codeIntPtrCast = codeClass.AddChild("public static explicit operator IntPtr("+codeClassName+" obj)"); codeIntPtrCast.Line("return obj.instWbemObjectAccessIP;"); // Add GetInstance codeOneLineMembers.Line("public ManagementObject GetInstance() {return instance;}"); PropertyDataCollection props = newClass.Properties; // type specific info switch(instrumentationType) { case InstrumentationType.Event: break; case InstrumentationType.Instance: props.Add("ProcessId", CimType.String, false); props.Add("InstanceId", CimType.String, false); props["ProcessId"].Qualifiers.Add("key", true); props["InstanceId"].Qualifiers.Add("key", true); newClass.Qualifiers.Add("dynamic", true, false, false, false, true); newClass.Qualifiers.Add("provider", naming.DecoupledProviderInstanceName, false, false, false, true); break; case InstrumentationType.Abstract: newClass.Qualifiers.Add("abstract", true, false, false, false, true); break; default: break; } int propCount = 0; bool needsNullObj = false; foreach(MemberInfo field in type.GetMembers()) { if(!(field is FieldInfo || field is PropertyInfo)) continue; if(field.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length > 0) continue; if(field is FieldInfo) { FieldInfo fi = field as FieldInfo; // We ignore statics if(fi.IsStatic) ThrowUnsupportedMember(field); } else if (field is PropertyInfo) { PropertyInfo pi = field as PropertyInfo; // We must have a 'get' property accessor if(!pi.CanRead) ThrowUnsupportedMember(field); // We ignore static properties MethodInfo mi = pi.GetGetMethod(); if(null == mi || mi.IsStatic) ThrowUnsupportedMember(field); // We don't support parameters on properties if(mi.GetParameters().Length > 0) ThrowUnsupportedMember(field); } String propName = ManagedNameAttribute.GetMemberName(field); #if SUPPORTS_ALTERNATE_WMI_PROPERTY_TYPE Type t2 = ManagedTypeAttribute.GetManagedType(field); #else Type t2; if(field is FieldInfo) t2 = (field as FieldInfo).FieldType; else t2 = (field as PropertyInfo).PropertyType; #endif bool isArray = false; if(t2.IsArray) { // We only support one dimensional arrays in this version if(t2.GetArrayRank() != 1) ThrowUnsupportedMember(field); isArray = true; t2 = t2.GetElementType(); } string embeddedTypeName = null; string embeddedConverterName = null; if(mapTypeToConverterClassName.Contains(t2)) { embeddedConverterName = (string)mapTypeToConverterClassName[t2]; embeddedTypeName = ManagedNameAttribute.GetMemberName(t2); } bool isGenericEmbeddedObject = false; if(t2 == typeof(object)) { isGenericEmbeddedObject = true; if(hasGenericEmbeddedObject == false) { hasGenericEmbeddedObject = true; // Add map codeOneLineMembers.Line("static Hashtable mapTypeToConverter = new Hashtable();"); foreach(DictionaryEntry entry in mapTypeToConverterClassName) { codeCCTOR.Line(String.Format("mapTypeToConverter[typeof({0})] = typeof({1});", ((Type)entry.Key).FullName.Replace('+', '.'), (string)entry.Value)); // bug#92918 - watch for nested classes } } } string propFieldName = "prop_" + (propCount); string handleFieldName = "handle_" + (propCount++); // Add handle for field, which is static accross all instances codeOneLineMembers.Line("static int " + handleFieldName + ";"); codeCCTOR.Line(String.Format("IWOA.GetPropertyHandle_f27(27, wbemObjectAccessIP, \"{0}\", out cimType, out {1});", propName, handleFieldName)); // Add PropertyData for field, which is specific to each instance codeOneLineMembers.Line("PropertyData " + propFieldName + ";"); codeCTOR.Line(String.Format("{0} = instance.Properties[\"{1}\"];", propFieldName, propName)); if(isGenericEmbeddedObject) { CodeWriter codeNotNull = codeToWMI.AddChild(String.Format("if(instNET.{0} != null)", field.Name)); CodeWriter codeElse = codeToWMI.AddChild("else"); codeElse.Line(String.Format("{0}.Value = null;", propFieldName)); if(isArray) { codeNotNull.Line(String.Format("int len = instNET.{0}.Length;", field.Name)); codeNotNull.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeNotNull.Line("IWmiConverter[] embeddedConverters = new IWmiConverter[len];"); CodeWriter codeForLoop = codeNotNull.AddChild("for(int i=0;i<len;i++)"); CodeWriter codeFoundType = codeForLoop.AddChild(String.Format("if((instNET.{0}[i] != null) && mapTypeToConverter.Contains(instNET.{0}[i].GetType()))", field.Name)); codeFoundType.Line(String.Format("Type type = (Type)mapTypeToConverter[instNET.{0}[i].GetType()];", field.Name)); codeFoundType.Line("embeddedConverters[i] = (IWmiConverter)Activator.CreateInstance(type);"); codeFoundType.Line(String.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", field.Name)); codeFoundType.Line("embeddedObjects[i] = embeddedConverters[i].GetInstance();"); codeForLoop.AddChild("else").Line(String.Format("embeddedObjects[i] = SafeAssign.GetManagementObject(instNET.{0}[i]);", field.Name)); codeNotNull.Line(String.Format("{0}.Value = embeddedObjects;", propFieldName)); } else { CodeWriter codeFoundType = codeNotNull.AddChild(String.Format("if(mapTypeToConverter.Contains(instNET.{0}.GetType()))", field.Name)); codeFoundType.Line(String.Format("Type type = (Type)mapTypeToConverter[instNET.{0}.GetType()];", field.Name)); codeFoundType.Line("IWmiConverter converter = (IWmiConverter)Activator.CreateInstance(type);"); codeFoundType.Line(String.Format("converter.ToWMI(instNET.{0});", field.Name)); codeFoundType.Line(String.Format("{0}.Value = converter.GetInstance();", propFieldName)); codeNotNull.AddChild("else").Line(String.Format("{0}.Value = SafeAssign.GetInstance(instNET.{1});", propFieldName, field.Name)); } } else if(embeddedTypeName != null) { // If this is an embedded struct, it cannot be null CodeWriter codeNotNull; if(t2.IsValueType) codeNotNull = codeToWMI; else { codeNotNull = codeToWMI.AddChild(String.Format("if(instNET.{0} != null)", field.Name)); CodeWriter codeElse = codeToWMI.AddChild("else"); codeElse.Line(String.Format("{0}.Value = null;", propFieldName)); } if(isArray) { codeNotNull.Line(String.Format("int len = instNET.{0}.Length;", field.Name)); codeNotNull.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeNotNull.Line(String.Format("{0}[] embeddedConverters = new {0}[len];", embeddedConverterName)); CodeWriter codeForLoop = codeNotNull.AddChild("for(int i=0;i<len;i++)"); codeForLoop.Line(String.Format("embeddedConverters[i] = new {0}();", embeddedConverterName)); // If this is a struct array, the elements are never null if(t2.IsValueType) { codeForLoop.Line(String.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", field.Name)); } else { CodeWriter codeArrayElementNotNull = codeForLoop.AddChild(String.Format("if(instNET.{0}[i] != null)", field.Name)); codeArrayElementNotNull.Line(String.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", field.Name)); } codeForLoop.Line("embeddedObjects[i] = embeddedConverters[i].instance;"); codeNotNull.Line(String.Format("{0}.Value = embeddedObjects;", propFieldName)); } else { // We cannot create an instance of 'embeddedConverterName' because it may be the // same type as we are defining (in other words, a cyclic loop, such as class XXX // having an instance of an XXX as a member). To prevent an infinite loop of constructing // converter classes, we create a 'lazy' variable that is initialized to NULL, and the first // time it is used, we set it to a 'new embeddedConverterName'. codeOneLineMembers.Line(String.Format("{0} lazy_embeddedConverter_{1} = null;", embeddedConverterName, propFieldName)); CodeWriter codeConverterProp = codeClass.AddChild(String.Format("{0} embeddedConverter_{1}", embeddedConverterName, propFieldName)); CodeWriter codeGet = codeConverterProp.AddChild("get"); CodeWriter codeIf = codeGet.AddChild(String.Format("if(null == lazy_embeddedConverter_{0})", propFieldName)); codeIf.Line(String.Format("lazy_embeddedConverter_{0} = new {1}();", propFieldName, embeddedConverterName)); codeGet.Line(String.Format("return lazy_embeddedConverter_{0};", propFieldName)); codeNotNull.Line(String.Format("embeddedConverter_{0}.ToWMI(instNET.{1});", propFieldName, field.Name)); codeNotNull.Line(String.Format("{0}.Value = embeddedConverter_{0}.instance;", propFieldName)); } } else if(!isArray) { if(t2 == typeof(Byte) || t2 == typeof(SByte)) { // // [PS#128409, marioh] CS0206 Compile error occured when instrumentated types contains public properties of type SByte, Int16, and UInt16 // Properties can not be passed as ref and therefore we store the property value in a tmp local variable before calling WritePropertyValue. // codeToWMI.Line(String.Format("{0} instNET_{1} = instNET.{1} ;", t2, field.Name)); codeToWMI.Line(String.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 1, ref instNET_{1});", handleFieldName, field.Name)); } else if(t2 == typeof(Int16) || t2 == typeof(UInt16) || t2 == typeof(Char)) { // // [PS#128409, marioh] CS0206 Compile error occured when instrumentated types contains public properties of type SByte, Int16, and UInt16 // Properties can not be passed as ref and therefore we store the property value in a tmp local variable before calling WritePropertyValue. // codeToWMI.Line(String.Format("{0} instNET_{1} = instNET.{1} ;", t2, field.Name)); codeToWMI.Line(String.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref instNET_{1});", handleFieldName, field.Name)); } else if(t2 == typeof(UInt32) || t2 == typeof(Int32) || t2 == typeof(Single)) codeToWMI.Line(String.Format("IWOA.WriteDWORD_f31(31, instWbemObjectAccessIP, {0}, instNET.{1});", handleFieldName, field.Name)); else if(t2 == typeof(UInt64) || t2 == typeof(Int64) || t2 == typeof(Double)) codeToWMI.Line(String.Format("IWOA.WriteQWORD_f33(33, instWbemObjectAccessIP, {0}, instNET.{1});", handleFieldName, field.Name)); else if(t2 == typeof(Boolean)) { // codeToWMI.Line(String.Format("if(instNET.{0})", field.Name)); codeToWMI.Line(String.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolTrue);", handleFieldName)); codeToWMI.Line("else"); codeToWMI.Line(String.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolFalse);", handleFieldName)); } else if(t2 == typeof(String)) { CodeWriter codeQuickString = codeToWMI.AddChild(String.Format("if(null != instNET.{0})", field.Name)); codeQuickString.Line(String.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, (instNET.{1}.Length+1)*2, instNET.{1});", handleFieldName, field.Name)); // codeToWMI.AddChild("else").Line(String.Format("{0}.Value = instNET.{1};", propFieldName, field.Name)); codeToWMI.AddChild("else").Line(String.Format("IWOA.Put_f5(5, instWbemObjectAccessIP, \"{0}\", 0, ref nullObj, 8);", propName)); if(needsNullObj == false) { needsNullObj = true; // Bug#111623 - This line used to say 'nullObj = null;' When nullObj was passed // to IWOA.Put, this did NOT set the value of a string variable to NULL. The correct // thing to do was to pass a reference to DBNull.Value to IWOA.Put instead. codeOneLineMembers.Line("object nullObj = DBNull.Value;"); } } else if(t2 == typeof(DateTime) || t2 == typeof(TimeSpan)) { codeToWMI.Line(String.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 52, SafeAssign.WMITimeToString(instNET.{1}));", handleFieldName, field.Name)); // codeToWMI.Line(String.Format("{0}.Value = SafeAssign.DateTimeToString(instNET.{1});", propFieldName, field.Name)); } else codeToWMI.Line(String.Format("{0}.Value = instNET.{1};", propFieldName, field.Name)); } else { // We have an array type if(t2 == typeof(DateTime) || t2 == typeof(TimeSpan)) { codeToWMI.AddChild(String.Format("if(null == instNET.{0})", field.Name)).Line(String.Format("{0}.Value = null;", propFieldName)); codeToWMI.AddChild("else").Line(String.Format("{0}.Value = SafeAssign.WMITimeArrayToStringArray(instNET.{1});", propFieldName, field.Name)); } else { // This handles arrays of all primative types codeToWMI.Line(String.Format("{0}.Value = instNET.{1};", propFieldName, field.Name)); } } CimType cimtype = CimType.String; if(field.DeclaringType != type) continue; #if REQUIRES_EXPLICIT_DECLARATION_OF_INHERITED_PROPERTIES if(InheritedPropertyAttribute.GetAttribute(field) != null) continue; #else // See if this field already exists on the WMI class // In other words, is it inherited from a base class // bool propertyExists = true; try { PropertyData prop = newClass.Properties[propName]; // HACK for bug#96863 - The above line used to throw a // not found exception. This was changed with a recent // checkin. If this functionality is not reverted, the // following statement should force the necessary 'not // found' exception that we are looking for. CimType cimType = prop.Type; // Make sure that if the property exists, it is inherited // If it is local, they probably named two properties with // the same name if(prop.IsLocal) { throw new ArgumentException(String.Format(RC.GetString("MEMBERCONFLILCT_EXCEPT"), field.Name), field.Name); } } catch(ManagementException e) { if(e.ErrorCode != ManagementStatus.NotFound) throw; else propertyExists = false; } if(propertyExists) continue; #endif if(embeddedTypeName != null) cimtype = CimType.Object; else if(isGenericEmbeddedObject) cimtype = CimType.Object; else if(t2 == typeof(ManagementObject)) cimtype = CimType.Object; else if(t2 == typeof(SByte)) cimtype = CimType.SInt8; else if(t2 == typeof(Byte)) cimtype = CimType.UInt8; else if(t2 == typeof(Int16)) cimtype = CimType.SInt16; else if(t2 == typeof(UInt16)) cimtype = CimType.UInt16; else if(t2 == typeof(Int32)) cimtype = CimType.SInt32; else if(t2 == typeof(UInt32)) cimtype = CimType.UInt32; else if(t2 == typeof(Int64)) cimtype = CimType.SInt64; else if(t2 == typeof(UInt64)) cimtype = CimType.UInt64; else if(t2 == typeof(Single)) cimtype = CimType.Real32; else if(t2 == typeof(Double)) cimtype = CimType.Real64; else if(t2 == typeof(Boolean)) cimtype = CimType.Boolean; else if(t2 == typeof(String)) cimtype = CimType.String; else if(t2 == typeof(Char)) cimtype = CimType.Char16; else if(t2 == typeof(DateTime)) cimtype = CimType.DateTime; else if(t2 == typeof(TimeSpan)) cimtype = CimType.DateTime; else ThrowUnsupportedMember(field); // HACK: The following line cause a strange System.InvalidProgramException when run through InstallUtil // throw new Exception("Unsupported type for event member - " + t2.Name); // #if SUPPORTS_WMI_DEFAULT_VAULES Object defaultValue = ManagedDefaultValueAttribute.GetManagedDefaultValue(field); // if(null == defaultValue) props.Add(propName, cimtype, false); else props.Add(propName, defaultValue, cimtype); #else try { props.Add(propName, cimtype, isArray); } catch(ManagementException e) { ThrowUnsupportedMember(field, e); } #endif // Must at 'interval' SubType on TimeSpans if(t2 == typeof(TimeSpan)) { PropertyData prop = props[propName]; prop.Qualifiers.Add("SubType", "interval", false, true, true, true); } if(embeddedTypeName != null) { PropertyData prop = props[propName]; prop.Qualifiers["CIMTYPE"].Value = "object:"+embeddedTypeName; } } codeCCTOR.Line("Marshal.Release(wbemObjectAccessIP);"); // codeToWMI.Line("Console.WriteLine(instance.GetText(TextFormat.Mof));"); }
public SchemaMapping(Type type, SchemaNaming naming) { classType = type; string baseClassName = ManagedNameAttribute.GetBaseClassName(type); className = ManagedNameAttribute.GetMemberName(type); instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType; classPath = naming.NamespaceName + ":" + className; if (null == baseClassName) { newClass = new ManagementClass(naming.NamespaceName, "", null); newClass.SystemProperties ["__CLASS"].Value = className; } else { ManagementClass baseClass = new ManagementClass(naming.NamespaceName + ":" + baseClassName); newClass = baseClass.Derive(className); } PropertyDataCollection props = newClass.Properties; // type specific info switch (instrumentationType) { case InstrumentationType.Event: break; case InstrumentationType.Instance: props.Add("ProcessId", CimType.String, false); props.Add("InstanceId", CimType.String, false); props["ProcessId"].Qualifiers.Add("key", true); props["InstanceId"].Qualifiers.Add("key", true); newClass.Qualifiers.Add("dynamic", true, false, false, false, true); newClass.Qualifiers.Add("provider", naming.DecoupledProviderInstanceName, false, false, false, true); break; case InstrumentationType.Abstract: newClass.Qualifiers.Add("abstract", true, false, false, false, true); break; default: break; } foreach (MemberInfo field in type.GetFields()) { if (!(field is FieldInfo || field is PropertyInfo)) { continue; } if (field.DeclaringType != type) { continue; } if (field.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length > 0) { continue; } String propName = ManagedNameAttribute.GetMemberName(field); #if REQUIRES_EXPLICIT_DECLARATION_OF_INHERITED_PROPERTIES if (InheritedPropertyAttribute.GetAttribute(field) != null) { continue; } #else // See if this field already exists on the WMI class // In other words, is it inherited from a base class // TODO: Make this more efficient // - If we have a null base class name, all property names // should be new // - We could get all base class property names into a // hashtable, and look them up from there bool propertyExists = true; try { PropertyData prop = newClass.Properties[propName]; } catch (ManagementException e) { if (e.ErrorCode != ManagementStatus.NotFound) { throw e; } else { propertyExists = false; } } if (propertyExists) { continue; } #endif #if SUPPORTS_ALTERNATE_WMI_PROPERTY_TYPE Type t2 = ManagedTypeAttribute.GetManagedType(field); #else Type t2; if (field is FieldInfo) { t2 = (field as FieldInfo).FieldType; } else { t2 = (field as PropertyInfo).PropertyType; } #endif CimType cimtype = CimType.String; if (t2 == typeof(SByte)) { cimtype = CimType.SInt8; } else if (t2 == typeof(Byte)) { cimtype = CimType.UInt8; } else if (t2 == typeof(Int16)) { cimtype = CimType.SInt16; } else if (t2 == typeof(UInt16)) { cimtype = CimType.UInt16; } else if (t2 == typeof(Int32)) { cimtype = CimType.SInt32; } else if (t2 == typeof(UInt32)) { cimtype = CimType.UInt32; } else if (t2 == typeof(Int64)) { cimtype = CimType.SInt64; } else if (t2 == typeof(UInt64)) { cimtype = CimType.UInt64; } else if (t2 == typeof(Single)) { cimtype = CimType.Real32; } else if (t2 == typeof(Double)) { cimtype = CimType.Real64; } else if (t2 == typeof(Boolean)) { cimtype = CimType.Boolean; } else if (t2 == typeof(String)) { cimtype = CimType.String; } else if (t2 == typeof(Char)) { cimtype = CimType.Char16; } else if (t2 == typeof(DateTime)) { cimtype = CimType.DateTime; } else if (t2 == typeof(TimeSpan)) { cimtype = CimType.DateTime; } else { throw new Exception(String.Format("Unsupported type for event member - {0}", t2.Name)); } // HACK: The following line cause a strange System.InvalidProgramException when run through InstallUtil // throw new Exception("Unsupported type for event member - " + t2.Name); // TODO: if(t2 == typeof(Decimal)) #if SUPPORTS_WMI_DEFAULT_VAULES Object defaultValue = ManagedDefaultValueAttribute.GetManagedDefaultValue(field); // TODO: Is it safe to make this one line? if (null == defaultValue) { props.Add(propName, cimtype, false); } else { props.Add(propName, defaultValue, cimtype); } #else props.Add(propName, cimtype, false); #endif // Must at 'interval' SubType on TimeSpans if (t2 == typeof(TimeSpan)) { PropertyData prop = props[propName]; prop.Qualifiers.Add("SubType", "interval", false, true, true, true); } } }
public InstrumentationClassAttribute(InstrumentationType instrumentationType, string managedBaseClassName) {}
// Constructors public InstrumentationClassAttribute(InstrumentationType instrumentationType) {}
public SchemaMapping(Type type, SchemaNaming naming, Hashtable mapTypeToConverterClassName) { int num; bool flag; MemberInfo memberInfo; FieldInfo fieldInfo; PropertyInfo propertyInfo; MethodInfo getMethod; string memberName; Type propertyType; bool flag1; string str; string item; bool flag2; DictionaryEntry dictionaryEntry; string str1; string str2; CodeWriter codeWriter; CodeWriter codeWriter1; CodeWriter codeWriter2; CodeWriter codeWriter3; CodeWriter codeWriter4; CodeWriter codeWriter5; CodeWriter codeWriter6; CodeWriter codeWriter7; CodeWriter codeWriter8; CodeWriter codeWriter9; CodeWriter codeWriter10; CodeWriter codeWriter11; CodeWriter codeWriter12; CimType cimType; bool flag3; PropertyData propertyDatum; PropertyData item1; PropertyData propertyDatum1; MemberInfo[] members; int i; int num1; this.code = new CodeWriter(); this.codeClassName = (string)mapTypeToConverterClassName[type]; this.classType = type; bool flag4 = false; string baseClassName = ManagedNameAttribute.GetBaseClassName(type); this.className = ManagedNameAttribute.GetMemberName(type); this.instrumentationType = InstrumentationClassAttribute.GetAttribute(type).InstrumentationType; this.classPath = string.Concat(naming.NamespaceName, ":", this.className); if (baseClassName != null) { ManagementClass managementClass = new ManagementClass(string.Concat(naming.NamespaceName, ":", baseClassName)); if (this.instrumentationType == InstrumentationType.Instance) { bool value = false; try { QualifierData qualifierDatum = managementClass.Qualifiers["abstract"]; if (qualifierDatum.Value is bool) { value = (bool)qualifierDatum.Value; } } catch (ManagementException managementException1) { ManagementException managementException = managementException1; if (managementException.ErrorCode != ManagementStatus.NotFound) { throw; } } if (!value) { throw new Exception(RC.GetString("CLASSINST_EXCEPT")); } } this.newClass = managementClass.Derive(this.className); } else { this.newClass = new ManagementClass(naming.NamespaceName, "", null); this.newClass.SystemProperties["__CLASS"].Value = this.className; } CodeWriter codeWriter13 = this.code.AddChild(string.Concat("public class ", this.codeClassName, " : IWmiConverter")); CodeWriter codeWriter14 = codeWriter13.AddChild(new CodeWriter()); codeWriter14.Line(string.Concat("static ManagementClass managementClass = new ManagementClass(@\"", this.classPath, "\");")); codeWriter14.Line("static IntPtr classWbemObjectIP;"); codeWriter14.Line("static Guid iidIWbemObjectAccess = new Guid(\"49353C9A-516B-11D1-AEA6-00C04FB68820\");"); codeWriter14.Line("internal ManagementObject instance = managementClass.CreateInstance();"); codeWriter14.Line("object reflectionInfoTempObj = null ; "); codeWriter14.Line("FieldInfo reflectionIWbemClassObjectField = null ; "); codeWriter14.Line("IntPtr emptyWbemObject = IntPtr.Zero ; "); codeWriter14.Line("IntPtr originalObject = IntPtr.Zero ; "); codeWriter14.Line("bool toWmiCalled = false ; "); codeWriter14.Line("IntPtr theClone = IntPtr.Zero;"); codeWriter14.Line("public static ManagementObject emptyInstance = managementClass.CreateInstance();"); codeWriter14.Line("public IntPtr instWbemObjectAccessIP;"); CodeWriter codeWriter15 = codeWriter13.AddChild(string.Concat("static ", this.codeClassName, "()")); codeWriter15.Line("classWbemObjectIP = (IntPtr)managementClass;"); codeWriter15.Line("IntPtr wbemObjectAccessIP;"); codeWriter15.Line("Marshal.QueryInterface(classWbemObjectIP, ref iidIWbemObjectAccess, out wbemObjectAccessIP);"); codeWriter15.Line("int cimType;"); CodeWriter codeWriter16 = codeWriter13.AddChild(string.Concat("public ", this.codeClassName, "()")); codeWriter16.Line("IntPtr wbemObjectIP = (IntPtr)instance;"); codeWriter16.Line("originalObject = (IntPtr)instance;"); codeWriter16.Line("Marshal.QueryInterface(wbemObjectIP, ref iidIWbemObjectAccess, out instWbemObjectAccessIP);"); codeWriter16.Line("FieldInfo tempField = instance.GetType().GetField ( \"_wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic );"); codeWriter16.Line("if ( tempField == null )"); codeWriter16.Line("{"); codeWriter16.Line(" tempField = instance.GetType().GetField ( \"wbemObject\", BindingFlags.Instance | BindingFlags.NonPublic ) ;"); codeWriter16.Line("}"); codeWriter16.Line("reflectionInfoTempObj = tempField.GetValue (instance) ;"); codeWriter16.Line("reflectionIWbemClassObjectField = reflectionInfoTempObj.GetType().GetField (\"pWbemClassObject\", BindingFlags.Instance | BindingFlags.NonPublic );"); codeWriter16.Line("emptyWbemObject = (IntPtr) emptyInstance;"); CodeWriter codeWriter17 = codeWriter13.AddChild(string.Concat("~", this.codeClassName, "()")); codeWriter17.AddChild("if(instWbemObjectAccessIP != IntPtr.Zero)").Line("Marshal.Release(instWbemObjectAccessIP);"); codeWriter17.Line("if ( toWmiCalled == true )"); codeWriter17.Line("{"); codeWriter17.Line("\tMarshal.Release (originalObject);"); codeWriter17.Line("}"); CodeWriter codeWriter18 = codeWriter13.AddChild("public void ToWMI(object obj)"); codeWriter18.Line("toWmiCalled = true ;"); codeWriter18.Line("if(instWbemObjectAccessIP != IntPtr.Zero)"); codeWriter18.Line("{"); codeWriter18.Line(" Marshal.Release(instWbemObjectAccessIP);"); codeWriter18.Line(" instWbemObjectAccessIP = IntPtr.Zero;"); codeWriter18.Line("}"); codeWriter18.Line("if(theClone != IntPtr.Zero)"); codeWriter18.Line("{"); codeWriter18.Line(" Marshal.Release(theClone);"); codeWriter18.Line(" theClone = IntPtr.Zero;"); codeWriter18.Line("}"); codeWriter18.Line("IWOA.Clone_f(12, emptyWbemObject, out theClone) ;"); codeWriter18.Line("Marshal.QueryInterface(theClone, ref iidIWbemObjectAccess, out instWbemObjectAccessIP) ;"); codeWriter18.Line("reflectionIWbemClassObjectField.SetValue ( reflectionInfoTempObj, theClone ) ;"); codeWriter18.Line(string.Format("{0} instNET = ({0})obj;", type.FullName.Replace('+', '.'))); CodeWriter codeWriter19 = codeWriter13.AddChild(string.Concat("public static explicit operator IntPtr(", this.codeClassName, " obj)")); codeWriter19.Line("return obj.instWbemObjectAccessIP;"); codeWriter14.Line("public ManagementObject GetInstance() {return instance;}"); PropertyDataCollection properties = this.newClass.Properties; InstrumentationType instrumentationType = this.instrumentationType; switch (instrumentationType) { case InstrumentationType.Instance: { properties.Add("ProcessId", CimType.String, false); properties.Add("InstanceId", CimType.String, false); properties["ProcessId"].Qualifiers.Add("key", true); properties["InstanceId"].Qualifiers.Add("key", true); this.newClass.Qualifiers.Add("dynamic", true, false, false, false, true); this.newClass.Qualifiers.Add("provider", naming.DecoupledProviderInstanceName, false, false, false, true); num = 0; flag = false; members = type.GetMembers(); for (i = 0; i < (int)members.Length; i++) { memberInfo = members[i]; if ((memberInfo as FieldInfo != null || memberInfo as PropertyInfo != null) && (int)memberInfo.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length <= 0) { if (memberInfo as FieldInfo == null) { if (memberInfo as PropertyInfo != null) { propertyInfo = memberInfo as PropertyInfo; if (!propertyInfo.CanRead) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } getMethod = propertyInfo.GetGetMethod(); if (null == getMethod || getMethod.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } if ((int)getMethod.GetParameters().Length > 0) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } } else { fieldInfo = memberInfo as FieldInfo; if (fieldInfo.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } memberName = ManagedNameAttribute.GetMemberName(memberInfo); if (memberInfo as FieldInfo == null) { propertyType = (memberInfo as PropertyInfo).PropertyType; } else { propertyType = (memberInfo as FieldInfo).FieldType; } flag1 = false; if (propertyType.IsArray) { if (propertyType.GetArrayRank() != 1) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } flag1 = true; propertyType = propertyType.GetElementType(); } str = null; item = null; if (mapTypeToConverterClassName.Contains(propertyType)) { item = (string)mapTypeToConverterClassName[propertyType]; str = ManagedNameAttribute.GetMemberName(propertyType); } flag2 = false; if (propertyType == typeof(object)) { flag2 = true; if (!flag4) { flag4 = true; codeWriter14.Line("static Hashtable mapTypeToConverter = new Hashtable();"); foreach (DictionaryEntry dictionaryEntry1 in mapTypeToConverterClassName) { codeWriter15.Line(string.Format("mapTypeToConverter[typeof({0})] = typeof({1});", ((Type)dictionaryEntry1.Key).FullName.Replace('+', '.'), (string)dictionaryEntry1.Value)); } } } str1 = string.Concat("prop_", (object)num); num1 = num; num = num1 + 1; str2 = string.Concat("handle_", (object)num1); codeWriter14.Line(string.Concat("static int ", str2, ";")); codeWriter15.Line(string.Format("IWOA.GetPropertyHandle_f27(27, wbemObjectAccessIP, \"{0}\", out cimType, out {1});", memberName, str2)); codeWriter14.Line(string.Concat("PropertyData ", str1, ";")); codeWriter16.Line(string.Format("{0} = instance.Properties[\"{1}\"];", str1, memberName)); if (!flag2) { if (str == null) { if (flag1) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.AddChild(string.Format("if(null == instNET.{0})", memberInfo.Name)).Line(string.Format("{0}.Value = null;", str1)); codeWriter18.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.WMITimeArrayToStringArray(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { if (propertyType == typeof(byte) || propertyType == typeof(sbyte)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 1, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(short) || propertyType == typeof(ushort) || propertyType == typeof(char)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(uint) || propertyType == typeof(int) || propertyType == typeof(float)) { codeWriter18.Line(string.Format("IWOA.WriteDWORD_f31(31, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(ulong) || propertyType == typeof(long) || propertyType == typeof(double)) { codeWriter18.Line(string.Format("IWOA.WriteQWORD_f33(33, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 52, SafeAssign.WMITimeToString(instNET.{1}));", str2, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { codeWriter12 = codeWriter18.AddChild(string.Format("if(null != instNET.{0})", memberInfo.Name)); codeWriter12.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, (instNET.{1}.Length+1)*2, instNET.{1});", str2, memberInfo.Name)); codeWriter18.AddChild("else").Line(string.Format("IWOA.Put_f5(5, instWbemObjectAccessIP, \"{0}\", 0, ref nullObj, 8);", memberName)); if (!flag) { flag = true; codeWriter14.Line("object nullObj = DBNull.Value;"); } } } else { codeWriter18.Line(string.Format("if(instNET.{0})", memberInfo.Name)); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolTrue);", str2)); codeWriter18.Line("else"); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolFalse);", str2)); } } } } } } } else { if (!propertyType.IsValueType) { codeWriter5 = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter6 = codeWriter18.AddChild("else"); codeWriter6.Line(string.Format("{0}.Value = null;", str1)); } else { codeWriter5 = codeWriter18; } if (!flag1) { codeWriter14.Line(string.Format("{0} lazy_embeddedConverter_{1} = null;", item, str1)); codeWriter9 = codeWriter13.AddChild(string.Format("{0} embeddedConverter_{1}", item, str1)); codeWriter10 = codeWriter9.AddChild("get"); codeWriter11 = codeWriter10.AddChild(string.Format("if(null == lazy_embeddedConverter_{0})", str1)); codeWriter11.Line(string.Format("lazy_embeddedConverter_{0} = new {1}();", str1, item)); codeWriter10.Line(string.Format("return lazy_embeddedConverter_{0};", str1)); codeWriter5.Line(string.Format("embeddedConverter_{0}.ToWMI(instNET.{1});", str1, memberInfo.Name)); codeWriter5.Line(string.Format("{0}.Value = embeddedConverter_{0}.instance;", str1)); } else { codeWriter5.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter5.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter5.Line(string.Format("{0}[] embeddedConverters = new {0}[len];", item)); codeWriter7 = codeWriter5.AddChild("for(int i=0;i<len;i++)"); codeWriter7.Line(string.Format("embeddedConverters[i] = new {0}();", item)); if (!propertyType.IsValueType) { codeWriter8 = codeWriter7.AddChild(string.Format("if(instNET.{0}[i] != null)", memberInfo.Name)); codeWriter8.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } else { codeWriter7.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } codeWriter7.Line("embeddedObjects[i] = embeddedConverters[i].instance;"); codeWriter5.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } } else { codeWriter = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter1 = codeWriter18.AddChild("else"); codeWriter1.Line(string.Format("{0}.Value = null;", str1)); if (!flag1) { codeWriter4 = codeWriter.AddChild(string.Format("if(mapTypeToConverter.Contains(instNET.{0}.GetType()))", memberInfo.Name)); codeWriter4.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}.GetType()];", memberInfo.Name)); codeWriter4.Line("IWmiConverter converter = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter4.Line(string.Format("converter.ToWMI(instNET.{0});", memberInfo.Name)); codeWriter4.Line(string.Format("{0}.Value = converter.GetInstance();", str1)); codeWriter.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.GetInstance(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter.Line("IWmiConverter[] embeddedConverters = new IWmiConverter[len];"); codeWriter2 = codeWriter.AddChild("for(int i=0;i<len;i++)"); codeWriter3 = codeWriter2.AddChild(string.Format("if((instNET.{0}[i] != null) && mapTypeToConverter.Contains(instNET.{0}[i].GetType()))", memberInfo.Name)); codeWriter3.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}[i].GetType()];", memberInfo.Name)); codeWriter3.Line("embeddedConverters[i] = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter3.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); codeWriter3.Line("embeddedObjects[i] = embeddedConverters[i].GetInstance();"); codeWriter2.AddChild("else").Line(string.Format("embeddedObjects[i] = SafeAssign.GetManagementObject(instNET.{0}[i]);", memberInfo.Name)); codeWriter.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } cimType = CimType.String; if (memberInfo.DeclaringType == type) { flag3 = true; try { propertyDatum = this.newClass.Properties[memberName]; CimType type1 = propertyDatum.Type; if (propertyDatum.IsLocal) { throw new ArgumentException(string.Format(RC.GetString("MEMBERCONFLILCT_EXCEPT"), memberInfo.Name), memberInfo.Name); } } catch (ManagementException managementException3) { ManagementException managementException2 = managementException3; if (managementException2.ErrorCode == ManagementStatus.NotFound) { flag3 = false; } else { throw; } } if (!flag3) { if (str == null) { if (!flag2) { if (propertyType != typeof(ManagementObject)) { if (propertyType != typeof(sbyte)) { if (propertyType != typeof(byte)) { if (propertyType != typeof(short)) { if (propertyType != typeof(ushort)) { if (propertyType != typeof(int)) { if (propertyType != typeof(uint)) { if (propertyType != typeof(long)) { if (propertyType != typeof(ulong)) { if (propertyType != typeof(float)) { if (propertyType != typeof(double)) { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType != typeof(char)) { if (propertyType != typeof(DateTime)) { if (propertyType != typeof(TimeSpan)) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } else { cimType = CimType.DateTime; } } else { cimType = CimType.DateTime; } } else { cimType = CimType.Char16; } } else { cimType = CimType.String; } } else { cimType = CimType.Boolean; } } else { cimType = CimType.Real64; } } else { cimType = CimType.Real32; } } else { cimType = CimType.UInt64; } } else { cimType = CimType.SInt64; } } else { cimType = CimType.UInt32; } } else { cimType = CimType.SInt32; } } else { cimType = CimType.UInt16; } } else { cimType = CimType.SInt16; } } else { cimType = CimType.UInt8; } } else { cimType = CimType.SInt8; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } try { properties.Add(memberName, cimType, flag1); } catch (ManagementException managementException5) { ManagementException managementException4 = managementException5; SchemaMapping.ThrowUnsupportedMember(memberInfo, managementException4); } if (propertyType == typeof(TimeSpan)) { item1 = properties[memberName]; item1.Qualifiers.Add("SubType", "interval", false, true, true, true); } if (str != null) { propertyDatum1 = properties[memberName]; propertyDatum1.Qualifiers["CIMTYPE"].Value = string.Concat("object:", str); } } } } } codeWriter15.Line("Marshal.Release(wbemObjectAccessIP);"); return; } case InstrumentationType.Event: { num = 0; flag = false; members = type.GetMembers(); for (i = 0; i < (int)members.Length; i++) { memberInfo = members[i]; if ((memberInfo as FieldInfo != null || memberInfo as PropertyInfo != null) && (int)memberInfo.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length <= 0) { if (memberInfo as FieldInfo == null) { if (memberInfo as PropertyInfo != null) { propertyInfo = memberInfo as PropertyInfo; if (!propertyInfo.CanRead) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } getMethod = propertyInfo.GetGetMethod(); if (null == getMethod || getMethod.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } if ((int)getMethod.GetParameters().Length > 0) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } } else { fieldInfo = memberInfo as FieldInfo; if (fieldInfo.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } memberName = ManagedNameAttribute.GetMemberName(memberInfo); if (memberInfo as FieldInfo == null) { propertyType = (memberInfo as PropertyInfo).PropertyType; } else { propertyType = (memberInfo as FieldInfo).FieldType; } flag1 = false; if (propertyType.IsArray) { if (propertyType.GetArrayRank() != 1) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } flag1 = true; propertyType = propertyType.GetElementType(); } str = null; item = null; if (mapTypeToConverterClassName.Contains(propertyType)) { item = (string)mapTypeToConverterClassName[propertyType]; str = ManagedNameAttribute.GetMemberName(propertyType); } flag2 = false; if (propertyType == typeof(object)) { flag2 = true; if (!flag4) { flag4 = true; codeWriter14.Line("static Hashtable mapTypeToConverter = new Hashtable();"); foreach (DictionaryEntry dictionaryEntry2 in mapTypeToConverterClassName) { codeWriter15.Line(string.Format("mapTypeToConverter[typeof({0})] = typeof({1});", ((Type)dictionaryEntry2.Key).FullName.Replace('+', '.'), (string)dictionaryEntry2.Value)); } } } str1 = string.Concat("prop_", num); num1 = num; num = num1 + 1; str2 = string.Concat("handle_", num1); codeWriter14.Line(string.Concat("static int ", str2, ";")); codeWriter15.Line(string.Format("IWOA.GetPropertyHandle_f27(27, wbemObjectAccessIP, \"{0}\", out cimType, out {1});", memberName, str2)); codeWriter14.Line(string.Concat("PropertyData ", str1, ";")); codeWriter16.Line(string.Format("{0} = instance.Properties[\"{1}\"];", str1, memberName)); if (!flag2) { if (str == null) { if (flag1) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.AddChild(string.Format("if(null == instNET.{0})", memberInfo.Name)).Line(string.Format("{0}.Value = null;", str1)); codeWriter18.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.WMITimeArrayToStringArray(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { if (propertyType == typeof(byte) || propertyType == typeof(sbyte)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 1, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(short) || propertyType == typeof(ushort) || propertyType == typeof(char)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(uint) || propertyType == typeof(int) || propertyType == typeof(float)) { codeWriter18.Line(string.Format("IWOA.WriteDWORD_f31(31, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(ulong) || propertyType == typeof(long) || propertyType == typeof(double)) { codeWriter18.Line(string.Format("IWOA.WriteQWORD_f33(33, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 52, SafeAssign.WMITimeToString(instNET.{1}));", str2, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { codeWriter12 = codeWriter18.AddChild(string.Format("if(null != instNET.{0})", memberInfo.Name)); codeWriter12.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, (instNET.{1}.Length+1)*2, instNET.{1});", str2, memberInfo.Name)); codeWriter18.AddChild("else").Line(string.Format("IWOA.Put_f5(5, instWbemObjectAccessIP, \"{0}\", 0, ref nullObj, 8);", memberName)); if (!flag) { flag = true; codeWriter14.Line("object nullObj = DBNull.Value;"); } } } else { codeWriter18.Line(string.Format("if(instNET.{0})", memberInfo.Name)); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolTrue);", str2)); codeWriter18.Line("else"); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolFalse);", str2)); } } } } } } } else { if (!propertyType.IsValueType) { codeWriter5 = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter6 = codeWriter18.AddChild("else"); codeWriter6.Line(string.Format("{0}.Value = null;", str1)); } else { codeWriter5 = codeWriter18; } if (!flag1) { codeWriter14.Line(string.Format("{0} lazy_embeddedConverter_{1} = null;", item, str1)); codeWriter9 = codeWriter13.AddChild(string.Format("{0} embeddedConverter_{1}", item, str1)); codeWriter10 = codeWriter9.AddChild("get"); codeWriter11 = codeWriter10.AddChild(string.Format("if(null == lazy_embeddedConverter_{0})", str1)); codeWriter11.Line(string.Format("lazy_embeddedConverter_{0} = new {1}();", str1, item)); codeWriter10.Line(string.Format("return lazy_embeddedConverter_{0};", str1)); codeWriter5.Line(string.Format("embeddedConverter_{0}.ToWMI(instNET.{1});", str1, memberInfo.Name)); codeWriter5.Line(string.Format("{0}.Value = embeddedConverter_{0}.instance;", str1)); } else { codeWriter5.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter5.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter5.Line(string.Format("{0}[] embeddedConverters = new {0}[len];", item)); codeWriter7 = codeWriter5.AddChild("for(int i=0;i<len;i++)"); codeWriter7.Line(string.Format("embeddedConverters[i] = new {0}();", item)); if (!propertyType.IsValueType) { codeWriter8 = codeWriter7.AddChild(string.Format("if(instNET.{0}[i] != null)", memberInfo.Name)); codeWriter8.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } else { codeWriter7.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } codeWriter7.Line("embeddedObjects[i] = embeddedConverters[i].instance;"); codeWriter5.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } } else { codeWriter = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter1 = codeWriter18.AddChild("else"); codeWriter1.Line(string.Format("{0}.Value = null;", str1)); if (!flag1) { codeWriter4 = codeWriter.AddChild(string.Format("if(mapTypeToConverter.Contains(instNET.{0}.GetType()))", memberInfo.Name)); codeWriter4.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}.GetType()];", memberInfo.Name)); codeWriter4.Line("IWmiConverter converter = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter4.Line(string.Format("converter.ToWMI(instNET.{0});", memberInfo.Name)); codeWriter4.Line(string.Format("{0}.Value = converter.GetInstance();", str1)); codeWriter.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.GetInstance(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter.Line("IWmiConverter[] embeddedConverters = new IWmiConverter[len];"); codeWriter2 = codeWriter.AddChild("for(int i=0;i<len;i++)"); codeWriter3 = codeWriter2.AddChild(string.Format("if((instNET.{0}[i] != null) && mapTypeToConverter.Contains(instNET.{0}[i].GetType()))", memberInfo.Name)); codeWriter3.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}[i].GetType()];", memberInfo.Name)); codeWriter3.Line("embeddedConverters[i] = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter3.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); codeWriter3.Line("embeddedObjects[i] = embeddedConverters[i].GetInstance();"); codeWriter2.AddChild("else").Line(string.Format("embeddedObjects[i] = SafeAssign.GetManagementObject(instNET.{0}[i]);", memberInfo.Name)); codeWriter.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } cimType = CimType.String; if (memberInfo.DeclaringType == type) { flag3 = true; try { propertyDatum = this.newClass.Properties[memberName]; CimType type1 = propertyDatum.Type; if (propertyDatum.IsLocal) { throw new ArgumentException(string.Format(RC.GetString("MEMBERCONFLILCT_EXCEPT"), memberInfo.Name), memberInfo.Name); } } catch (ManagementException managementException3) { ManagementException managementException2 = managementException3; if (managementException2.ErrorCode == ManagementStatus.NotFound) { flag3 = false; } else { throw; } } if (!flag3) { if (str == null) { if (!flag2) { if (propertyType != typeof(ManagementObject)) { if (propertyType != typeof(sbyte)) { if (propertyType != typeof(byte)) { if (propertyType != typeof(short)) { if (propertyType != typeof(ushort)) { if (propertyType != typeof(int)) { if (propertyType != typeof(uint)) { if (propertyType != typeof(long)) { if (propertyType != typeof(ulong)) { if (propertyType != typeof(float)) { if (propertyType != typeof(double)) { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType != typeof(char)) { if (propertyType != typeof(DateTime)) { if (propertyType != typeof(TimeSpan)) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } else { cimType = CimType.DateTime; } } else { cimType = CimType.DateTime; } } else { cimType = CimType.Char16; } } else { cimType = CimType.String; } } else { cimType = CimType.Boolean; } } else { cimType = CimType.Real64; } } else { cimType = CimType.Real32; } } else { cimType = CimType.UInt64; } } else { cimType = CimType.SInt64; } } else { cimType = CimType.UInt32; } } else { cimType = CimType.SInt32; } } else { cimType = CimType.UInt16; } } else { cimType = CimType.SInt16; } } else { cimType = CimType.UInt8; } } else { cimType = CimType.SInt8; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } try { properties.Add(memberName, cimType, flag1); } catch (ManagementException managementException5) { ManagementException managementException4 = managementException5; SchemaMapping.ThrowUnsupportedMember(memberInfo, managementException4); } if (propertyType == typeof(TimeSpan)) { item1 = properties[memberName]; item1.Qualifiers.Add("SubType", "interval", false, true, true, true); } if (str != null) { propertyDatum1 = properties[memberName]; propertyDatum1.Qualifiers["CIMTYPE"].Value = string.Concat("object:", str); } } } } } codeWriter15.Line("Marshal.Release(wbemObjectAccessIP);"); return; } case InstrumentationType.Abstract: { this.newClass.Qualifiers.Add("abstract", true, false, false, false, true); num = 0; flag = false; members = type.GetMembers(); for (i = 0; i < (int)members.Length; i++) { memberInfo = members[i]; if ((memberInfo as FieldInfo != null || memberInfo as PropertyInfo != null) && (int)memberInfo.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length <= 0) { if (memberInfo as FieldInfo == null) { if (memberInfo as PropertyInfo != null) { propertyInfo = memberInfo as PropertyInfo; if (!propertyInfo.CanRead) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } getMethod = propertyInfo.GetGetMethod(); if (null == getMethod || getMethod.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } if ((int)getMethod.GetParameters().Length > 0) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } } else { fieldInfo = memberInfo as FieldInfo; if (fieldInfo.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } memberName = ManagedNameAttribute.GetMemberName(memberInfo); if (memberInfo as FieldInfo == null) { propertyType = (memberInfo as PropertyInfo).PropertyType; } else { propertyType = (memberInfo as FieldInfo).FieldType; } flag1 = false; if (propertyType.IsArray) { if (propertyType.GetArrayRank() != 1) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } flag1 = true; propertyType = propertyType.GetElementType(); } str = null; item = null; if (mapTypeToConverterClassName.Contains(propertyType)) { item = (string)mapTypeToConverterClassName[propertyType]; str = ManagedNameAttribute.GetMemberName(propertyType); } flag2 = false; if (propertyType == typeof(object)) { flag2 = true; if (!flag4) { flag4 = true; codeWriter14.Line("static Hashtable mapTypeToConverter = new Hashtable();"); foreach (DictionaryEntry dictionaryEntry3 in mapTypeToConverterClassName) { codeWriter15.Line(string.Format("mapTypeToConverter[typeof({0})] = typeof({1});", ((Type)dictionaryEntry3.Key).FullName.Replace('+', '.'), (string)dictionaryEntry3.Value)); } } } str1 = string.Concat("prop_", (object)num); num1 = num; num = num1 + 1; str2 = string.Concat("handle_", (object)num1); codeWriter14.Line(string.Concat("static int ", str2, ";")); codeWriter15.Line(string.Format("IWOA.GetPropertyHandle_f27(27, wbemObjectAccessIP, \"{0}\", out cimType, out {1});", memberName, str2)); codeWriter14.Line(string.Concat("PropertyData ", str1, ";")); codeWriter16.Line(string.Format("{0} = instance.Properties[\"{1}\"];", str1, memberName)); if (!flag2) { if (str == null) { if (flag1) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.AddChild(string.Format("if(null == instNET.{0})", memberInfo.Name)).Line(string.Format("{0}.Value = null;", str1)); codeWriter18.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.WMITimeArrayToStringArray(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { if (propertyType == typeof(byte) || propertyType == typeof(sbyte)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 1, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(short) || propertyType == typeof(ushort) || propertyType == typeof(char)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(uint) || propertyType == typeof(int) || propertyType == typeof(float)) { codeWriter18.Line(string.Format("IWOA.WriteDWORD_f31(31, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(ulong) || propertyType == typeof(long) || propertyType == typeof(double)) { codeWriter18.Line(string.Format("IWOA.WriteQWORD_f33(33, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 52, SafeAssign.WMITimeToString(instNET.{1}));", str2, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { codeWriter12 = codeWriter18.AddChild(string.Format("if(null != instNET.{0})", memberInfo.Name)); codeWriter12.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, (instNET.{1}.Length+1)*2, instNET.{1});", str2, memberInfo.Name)); codeWriter18.AddChild("else").Line(string.Format("IWOA.Put_f5(5, instWbemObjectAccessIP, \"{0}\", 0, ref nullObj, 8);", memberName)); if (!flag) { flag = true; codeWriter14.Line("object nullObj = DBNull.Value;"); } } } else { codeWriter18.Line(string.Format("if(instNET.{0})", memberInfo.Name)); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolTrue);", str2)); codeWriter18.Line("else"); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolFalse);", str2)); } } } } } } } else { if (!propertyType.IsValueType) { codeWriter5 = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter6 = codeWriter18.AddChild("else"); codeWriter6.Line(string.Format("{0}.Value = null;", str1)); } else { codeWriter5 = codeWriter18; } if (!flag1) { codeWriter14.Line(string.Format("{0} lazy_embeddedConverter_{1} = null;", item, str1)); codeWriter9 = codeWriter13.AddChild(string.Format("{0} embeddedConverter_{1}", item, str1)); codeWriter10 = codeWriter9.AddChild("get"); codeWriter11 = codeWriter10.AddChild(string.Format("if(null == lazy_embeddedConverter_{0})", str1)); codeWriter11.Line(string.Format("lazy_embeddedConverter_{0} = new {1}();", str1, item)); codeWriter10.Line(string.Format("return lazy_embeddedConverter_{0};", str1)); codeWriter5.Line(string.Format("embeddedConverter_{0}.ToWMI(instNET.{1});", str1, memberInfo.Name)); codeWriter5.Line(string.Format("{0}.Value = embeddedConverter_{0}.instance;", str1)); } else { codeWriter5.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter5.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter5.Line(string.Format("{0}[] embeddedConverters = new {0}[len];", item)); codeWriter7 = codeWriter5.AddChild("for(int i=0;i<len;i++)"); codeWriter7.Line(string.Format("embeddedConverters[i] = new {0}();", item)); if (!propertyType.IsValueType) { codeWriter8 = codeWriter7.AddChild(string.Format("if(instNET.{0}[i] != null)", memberInfo.Name)); codeWriter8.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } else { codeWriter7.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } codeWriter7.Line("embeddedObjects[i] = embeddedConverters[i].instance;"); codeWriter5.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } } else { codeWriter = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter1 = codeWriter18.AddChild("else"); codeWriter1.Line(string.Format("{0}.Value = null;", str1)); if (!flag1) { codeWriter4 = codeWriter.AddChild(string.Format("if(mapTypeToConverter.Contains(instNET.{0}.GetType()))", memberInfo.Name)); codeWriter4.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}.GetType()];", memberInfo.Name)); codeWriter4.Line("IWmiConverter converter = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter4.Line(string.Format("converter.ToWMI(instNET.{0});", memberInfo.Name)); codeWriter4.Line(string.Format("{0}.Value = converter.GetInstance();", str1)); codeWriter.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.GetInstance(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter.Line("IWmiConverter[] embeddedConverters = new IWmiConverter[len];"); codeWriter2 = codeWriter.AddChild("for(int i=0;i<len;i++)"); codeWriter3 = codeWriter2.AddChild(string.Format("if((instNET.{0}[i] != null) && mapTypeToConverter.Contains(instNET.{0}[i].GetType()))", memberInfo.Name)); codeWriter3.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}[i].GetType()];", memberInfo.Name)); codeWriter3.Line("embeddedConverters[i] = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter3.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); codeWriter3.Line("embeddedObjects[i] = embeddedConverters[i].GetInstance();"); codeWriter2.AddChild("else").Line(string.Format("embeddedObjects[i] = SafeAssign.GetManagementObject(instNET.{0}[i]);", memberInfo.Name)); codeWriter.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } cimType = CimType.String; if (memberInfo.DeclaringType == type) { flag3 = true; try { propertyDatum = this.newClass.Properties[memberName]; CimType type1 = propertyDatum.Type; if (propertyDatum.IsLocal) { throw new ArgumentException(string.Format(RC.GetString("MEMBERCONFLILCT_EXCEPT"), memberInfo.Name), memberInfo.Name); } } catch (ManagementException managementException3) { ManagementException managementException2 = managementException3; if (managementException2.ErrorCode == ManagementStatus.NotFound) { flag3 = false; } else { throw; } } if (!flag3) { if (str == null) { if (!flag2) { if (propertyType != typeof(ManagementObject)) { if (propertyType != typeof(sbyte)) { if (propertyType != typeof(byte)) { if (propertyType != typeof(short)) { if (propertyType != typeof(ushort)) { if (propertyType != typeof(int)) { if (propertyType != typeof(uint)) { if (propertyType != typeof(long)) { if (propertyType != typeof(ulong)) { if (propertyType != typeof(float)) { if (propertyType != typeof(double)) { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType != typeof(char)) { if (propertyType != typeof(DateTime)) { if (propertyType != typeof(TimeSpan)) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } else { cimType = CimType.DateTime; } } else { cimType = CimType.DateTime; } } else { cimType = CimType.Char16; } } else { cimType = CimType.String; } } else { cimType = CimType.Boolean; } } else { cimType = CimType.Real64; } } else { cimType = CimType.Real32; } } else { cimType = CimType.UInt64; } } else { cimType = CimType.SInt64; } } else { cimType = CimType.UInt32; } } else { cimType = CimType.SInt32; } } else { cimType = CimType.UInt16; } } else { cimType = CimType.SInt16; } } else { cimType = CimType.UInt8; } } else { cimType = CimType.SInt8; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } try { properties.Add(memberName, cimType, flag1); } catch (ManagementException managementException5) { ManagementException managementException4 = managementException5; SchemaMapping.ThrowUnsupportedMember(memberInfo, managementException4); } if (propertyType == typeof(TimeSpan)) { item1 = properties[memberName]; item1.Qualifiers.Add("SubType", "interval", false, true, true, true); } if (str != null) { propertyDatum1 = properties[memberName]; propertyDatum1.Qualifiers["CIMTYPE"].Value = string.Concat("object:", str); } } } } } codeWriter15.Line("Marshal.Release(wbemObjectAccessIP);"); return; } default: { num = 0; flag = false; members = type.GetMembers(); for (i = 0; i < (int)members.Length; i++) { memberInfo = members[i]; if ((memberInfo as FieldInfo != null || memberInfo as PropertyInfo != null) && (int)memberInfo.GetCustomAttributes(typeof(IgnoreMemberAttribute), false).Length <= 0) { if (memberInfo as FieldInfo == null) { if (memberInfo as PropertyInfo != null) { propertyInfo = memberInfo as PropertyInfo; if (!propertyInfo.CanRead) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } getMethod = propertyInfo.GetGetMethod(); if (null == getMethod || getMethod.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } if ((int)getMethod.GetParameters().Length > 0) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } } else { fieldInfo = memberInfo as FieldInfo; if (fieldInfo.IsStatic) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } } memberName = ManagedNameAttribute.GetMemberName(memberInfo); if (memberInfo as FieldInfo == null) { propertyType = (memberInfo as PropertyInfo).PropertyType; } else { propertyType = (memberInfo as FieldInfo).FieldType; } flag1 = false; if (propertyType.IsArray) { if (propertyType.GetArrayRank() != 1) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } flag1 = true; propertyType = propertyType.GetElementType(); } str = null; item = null; if (mapTypeToConverterClassName.Contains(propertyType)) { item = (string)mapTypeToConverterClassName[propertyType]; str = ManagedNameAttribute.GetMemberName(propertyType); } flag2 = false; if (propertyType == typeof(object)) { flag2 = true; if (!flag4) { flag4 = true; codeWriter14.Line("static Hashtable mapTypeToConverter = new Hashtable();"); foreach (DictionaryEntry dictionaryEntry4 in mapTypeToConverterClassName) { codeWriter15.Line(string.Format("mapTypeToConverter[typeof({0})] = typeof({1});", ((Type)dictionaryEntry4.Key).FullName.Replace('+', '.'), (string)dictionaryEntry4.Value)); } } } str1 = string.Concat("prop_", (object)num); num1 = num; num = num1 + 1; str2 = string.Concat("handle_", (object)num1); codeWriter14.Line(string.Concat("static int ", str2, ";")); codeWriter15.Line(string.Format("IWOA.GetPropertyHandle_f27(27, wbemObjectAccessIP, \"{0}\", out cimType, out {1});", memberName, str2)); codeWriter14.Line(string.Concat("PropertyData ", str1, ";")); codeWriter16.Line(string.Format("{0} = instance.Properties[\"{1}\"];", str1, memberName)); if (!flag2) { if (str == null) { if (flag1) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.AddChild(string.Format("if(null == instNET.{0})", memberInfo.Name)).Line(string.Format("{0}.Value = null;", str1)); codeWriter18.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.WMITimeArrayToStringArray(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { if (propertyType == typeof(byte) || propertyType == typeof(sbyte)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 1, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(short) || propertyType == typeof(ushort) || propertyType == typeof(char)) { codeWriter18.Line(string.Format("{0} instNET_{1} = instNET.{1} ;", propertyType, memberInfo.Name)); codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref instNET_{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(uint) || propertyType == typeof(int) || propertyType == typeof(float)) { codeWriter18.Line(string.Format("IWOA.WriteDWORD_f31(31, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType == typeof(ulong) || propertyType == typeof(long) || propertyType == typeof(double)) { codeWriter18.Line(string.Format("IWOA.WriteQWORD_f33(33, instWbemObjectAccessIP, {0}, instNET.{1});", str2, memberInfo.Name)); } else { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType == typeof(DateTime) || propertyType == typeof(TimeSpan)) { codeWriter18.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 52, SafeAssign.WMITimeToString(instNET.{1}));", str2, memberInfo.Name)); } else { codeWriter18.Line(string.Format("{0}.Value = instNET.{1};", str1, memberInfo.Name)); } } else { codeWriter12 = codeWriter18.AddChild(string.Format("if(null != instNET.{0})", memberInfo.Name)); codeWriter12.Line(string.Format("IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, (instNET.{1}.Length+1)*2, instNET.{1});", str2, memberInfo.Name)); codeWriter18.AddChild("else").Line(string.Format("IWOA.Put_f5(5, instWbemObjectAccessIP, \"{0}\", 0, ref nullObj, 8);", memberName)); if (!flag) { flag = true; codeWriter14.Line("object nullObj = DBNull.Value;"); } } } else { codeWriter18.Line(string.Format("if(instNET.{0})", memberInfo.Name)); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolTrue);", str2)); codeWriter18.Line("else"); codeWriter18.Line(string.Format(" IWOA.WritePropertyValue_f28(28, instWbemObjectAccessIP, {0}, 2, ref SafeAssign.boolFalse);", str2)); } } } } } } } else { if (!propertyType.IsValueType) { codeWriter5 = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter6 = codeWriter18.AddChild("else"); codeWriter6.Line(string.Format("{0}.Value = null;", str1)); } else { codeWriter5 = codeWriter18; } if (!flag1) { codeWriter14.Line(string.Format("{0} lazy_embeddedConverter_{1} = null;", item, str1)); codeWriter9 = codeWriter13.AddChild(string.Format("{0} embeddedConverter_{1}", item, str1)); codeWriter10 = codeWriter9.AddChild("get"); codeWriter11 = codeWriter10.AddChild(string.Format("if(null == lazy_embeddedConverter_{0})", str1)); codeWriter11.Line(string.Format("lazy_embeddedConverter_{0} = new {1}();", str1, item)); codeWriter10.Line(string.Format("return lazy_embeddedConverter_{0};", str1)); codeWriter5.Line(string.Format("embeddedConverter_{0}.ToWMI(instNET.{1});", str1, memberInfo.Name)); codeWriter5.Line(string.Format("{0}.Value = embeddedConverter_{0}.instance;", str1)); } else { codeWriter5.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter5.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter5.Line(string.Format("{0}[] embeddedConverters = new {0}[len];", item)); codeWriter7 = codeWriter5.AddChild("for(int i=0;i<len;i++)"); codeWriter7.Line(string.Format("embeddedConverters[i] = new {0}();", item)); if (!propertyType.IsValueType) { codeWriter8 = codeWriter7.AddChild(string.Format("if(instNET.{0}[i] != null)", memberInfo.Name)); codeWriter8.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } else { codeWriter7.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); } codeWriter7.Line("embeddedObjects[i] = embeddedConverters[i].instance;"); codeWriter5.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } } else { codeWriter = codeWriter18.AddChild(string.Format("if(instNET.{0} != null)", memberInfo.Name)); codeWriter1 = codeWriter18.AddChild("else"); codeWriter1.Line(string.Format("{0}.Value = null;", str1)); if (!flag1) { codeWriter4 = codeWriter.AddChild(string.Format("if(mapTypeToConverter.Contains(instNET.{0}.GetType()))", memberInfo.Name)); codeWriter4.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}.GetType()];", memberInfo.Name)); codeWriter4.Line("IWmiConverter converter = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter4.Line(string.Format("converter.ToWMI(instNET.{0});", memberInfo.Name)); codeWriter4.Line(string.Format("{0}.Value = converter.GetInstance();", str1)); codeWriter.AddChild("else").Line(string.Format("{0}.Value = SafeAssign.GetInstance(instNET.{1});", str1, memberInfo.Name)); } else { codeWriter.Line(string.Format("int len = instNET.{0}.Length;", memberInfo.Name)); codeWriter.Line("ManagementObject[] embeddedObjects = new ManagementObject[len];"); codeWriter.Line("IWmiConverter[] embeddedConverters = new IWmiConverter[len];"); codeWriter2 = codeWriter.AddChild("for(int i=0;i<len;i++)"); codeWriter3 = codeWriter2.AddChild(string.Format("if((instNET.{0}[i] != null) && mapTypeToConverter.Contains(instNET.{0}[i].GetType()))", memberInfo.Name)); codeWriter3.Line(string.Format("Type type = (Type)mapTypeToConverter[instNET.{0}[i].GetType()];", memberInfo.Name)); codeWriter3.Line("embeddedConverters[i] = (IWmiConverter)Activator.CreateInstance(type);"); codeWriter3.Line(string.Format("embeddedConverters[i].ToWMI(instNET.{0}[i]);", memberInfo.Name)); codeWriter3.Line("embeddedObjects[i] = embeddedConverters[i].GetInstance();"); codeWriter2.AddChild("else").Line(string.Format("embeddedObjects[i] = SafeAssign.GetManagementObject(instNET.{0}[i]);", memberInfo.Name)); codeWriter.Line(string.Format("{0}.Value = embeddedObjects;", str1)); } } cimType = CimType.String; if (memberInfo.DeclaringType == type) { flag3 = true; try { propertyDatum = this.newClass.Properties[memberName]; CimType type1 = propertyDatum.Type; if (propertyDatum.IsLocal) { throw new ArgumentException(string.Format(RC.GetString("MEMBERCONFLILCT_EXCEPT"), memberInfo.Name), memberInfo.Name); } } catch (ManagementException managementException3) { ManagementException managementException2 = managementException3; if (managementException2.ErrorCode == ManagementStatus.NotFound) { flag3 = false; } else { throw; } } if (!flag3) { if (str == null) { if (!flag2) { if (propertyType != typeof(ManagementObject)) { if (propertyType != typeof(sbyte)) { if (propertyType != typeof(byte)) { if (propertyType != typeof(short)) { if (propertyType != typeof(ushort)) { if (propertyType != typeof(int)) { if (propertyType != typeof(uint)) { if (propertyType != typeof(long)) { if (propertyType != typeof(ulong)) { if (propertyType != typeof(float)) { if (propertyType != typeof(double)) { if (propertyType != typeof(bool)) { if (propertyType != typeof(string)) { if (propertyType != typeof(char)) { if (propertyType != typeof(DateTime)) { if (propertyType != typeof(TimeSpan)) { SchemaMapping.ThrowUnsupportedMember(memberInfo); } else { cimType = CimType.DateTime; } } else { cimType = CimType.DateTime; } } else { cimType = CimType.Char16; } } else { cimType = CimType.String; } } else { cimType = CimType.Boolean; } } else { cimType = CimType.Real64; } } else { cimType = CimType.Real32; } } else { cimType = CimType.UInt64; } } else { cimType = CimType.SInt64; } } else { cimType = CimType.UInt32; } } else { cimType = CimType.SInt32; } } else { cimType = CimType.UInt16; } } else { cimType = CimType.SInt16; } } else { cimType = CimType.UInt8; } } else { cimType = CimType.SInt8; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } } else { cimType = CimType.Object; } try { properties.Add(memberName, cimType, flag1); } catch (ManagementException managementException5) { ManagementException managementException4 = managementException5; SchemaMapping.ThrowUnsupportedMember(memberInfo, managementException4); } if (propertyType == typeof(TimeSpan)) { item1 = properties[memberName]; item1.Qualifiers.Add("SubType", "interval", false, true, true, true); } if (str != null) { propertyDatum1 = properties[memberName]; propertyDatum1.Qualifiers["CIMTYPE"].Value = string.Concat("object:", str); } } } } } codeWriter15.Line("Marshal.Release(wbemObjectAccessIP);"); return; } } }