private object DataReaderToObject(SqlCeDataReader reader, EntityType entity) { object entityObject = null; switch (entity) { case EntityType.Processor: entityObject = new EntProcessor(); break; case EntityType.OS: entityObject = new EntOS(); break; case EntityType.Bios: entityObject = new EntBios(); break; case EntityType.MotherBoard: entityObject = new EntMotherBoard(); break; case EntityType.Disk: entityObject = new EntDisk(); break; case EntityType.Memory: entityObject = new EntMemory(); break; case EntityType.LogicalDrive: entityObject = new EntLogicalDrive(); break; case EntityType.CDRom: entityObject = new EntCDRom(); break; case EntityType.Video: entityObject = new EntVideo(); break; case EntityType.Multimedia: entityObject = new EntMultimedia(); break; case EntityType.Monitor: entityObject = new EntMonitor(); break; case EntityType.Share: entityObject = new EntShare(); break; case EntityType.StartUp: entityObject = new EntStartUp(); break; case EntityType.Hotfix: entityObject = new EntHotfixes(); break; case EntityType.Processes: entityObject = new EntProcesses(); break; case EntityType.Softwares: entityObject = new EntSoftwares(); break; case EntityType.Services: entityObject = new EntServices(); break; case EntityType.IPRoutes: entityObject = new EntIPRoutes(); break; case EntityType.EnvironmentVar: entityObject = new EntEnvironmentVars(); break; case EntityType.Computer: entityObject = new EntComputer(); break; case EntityType.Printer: entityObject = new EntPrinter(); break; case EntityType.UserGroup: entityObject = new EntUserGroups(); break; case EntityType.NetworkAdapter: entityObject = new EntNetworkAdapter(); break; } Type t = entityObject.GetType(); PropertyInfo[] pi = t.GetProperties(); foreach (PropertyInfo prop in pi) { if (prop.Name == "ClassName" || prop.Name == "Icon" || prop.Name == "NodeName") continue; switch (prop.PropertyType.Name) { case "String": string strValue = reader.GetString(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, strValue, null); break; case "Int32": int intValue = reader.GetInt32(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, intValue, null); break; case "Double": double dValue = reader.GetDouble(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, dValue, null); break; case "DateTime": DateTime dtValue = DateTime.MinValue; if ( reader.GetValue(reader.GetOrdinal(prop.Name))== DBNull.Value) { dtValue = DateTime.MinValue; } else { dtValue = reader.GetDateTime(reader.GetOrdinal(prop.Name)); } prop.SetValue(entityObject, dtValue, null); break; case "Boolean": bool bValue = reader.GetBoolean(reader.GetOrdinal(prop.Name)); prop.SetValue(entityObject, bValue, null); break; } } return entityObject; }
private static EntComputer FillDetails(ManagementBaseObject obj) { EntComputer objEntComp = new EntComputer(); try { objEntComp.BootupState = WMIUtil.ToString(obj["BootupState"]); } catch (Exception) { objEntComp.BootupState = ""; } try { objEntComp.Caption = WMIUtil.ToString(obj["Caption"]); } catch (Exception) { objEntComp.Caption = ""; } try { int timeZone = WMIUtil.ToInteger(obj["CurrentTimeZone"]); if ( timeZone < 0 ) { objEntComp.CurrentTimeZone = "GMT -" + timeZone.ToString()+" minutes"; } else { objEntComp.CurrentTimeZone = "GMT +" + timeZone.ToString()+" minutes"; } } catch (Exception) { objEntComp.CurrentTimeZone = ""; } try { objEntComp.DaylightInEffect = (bool)obj["DaylightInEffect"]; } catch (Exception) { objEntComp.DaylightInEffect= false; } try { objEntComp.Description = WMIUtil.ToString(obj["Description"]); } catch (Exception) { objEntComp.Description = ""; } try { objEntComp.DNSHostName = WMIUtil.ToString(obj["DNSHostName"]); } catch (Exception) { objEntComp.DNSHostName = "N/A"; } try { objEntComp.Domain = WMIUtil.ToString(obj["Domain"]); } catch (Exception) { objEntComp.Domain = ""; } try { DomainRoleValues domainRoles = (DomainRoleValues)WMIUtil.ToInteger(obj["DomainRole"]); objEntComp.DomainRole = WMIUtil.SplitCamelCase(domainRoles.ToString()); } catch (Exception) { objEntComp.DomainRole = ""; } try { objEntComp.EnableDaylightSavingsTime = (bool)obj["EnableDaylightSavingsTime"]; } catch (Exception) { objEntComp.EnableDaylightSavingsTime = false; } try { objEntComp.Manufacturer = WMIUtil.ToString(obj["Manufacturer"]); } catch (Exception) { objEntComp.Manufacturer = ""; } try { objEntComp.Model = WMIUtil.ToString(obj["Model"]); } catch (Exception) { objEntComp.Model = ""; } try { objEntComp.Name = WMIUtil.ToString(obj["Name"]); } catch (Exception) { objEntComp.Name = ""; } try { objEntComp.NetworkServerModeEnabled = (bool)(obj["NetworkServerModeEnabled"]); } catch (Exception) { objEntComp.NetworkServerModeEnabled = false; } try { objEntComp.PartOfDomain = (bool)(obj["PartOfDomain"]); } catch (Exception) { objEntComp.PartOfDomain = false; } try { PCSystemTypeValues pcTypeValues = (PCSystemTypeValues)WMIUtil.ToInteger(obj["PCSystemType"]); objEntComp.PCSystemType = WMIUtil.SplitCamelCase(pcTypeValues.ToString()); } catch (Exception) { objEntComp.PCSystemType = "Unknown"; } try { PowerStateValues powerStateValues = (PowerStateValues)WMIUtil.ToInteger(obj["PowerState"]); objEntComp.PowerState = WMIUtil.SplitCamelCase(powerStateValues.ToString()); } catch (Exception) { objEntComp.PowerState = ""; } try { StateValues powerSupplyStateValues = (StateValues)WMIUtil.ToInteger(obj["PowerState"]); objEntComp.PowerSupplyState= WMIUtil.SplitCamelCase(powerSupplyStateValues.ToString()); } catch (Exception) { objEntComp.PowerSupplyState = ""; } try { objEntComp.PrimaryOwnerContact = WMIUtil.ToString(obj["PrimaryOwnerContact"]); } catch (Exception) { objEntComp.PrimaryOwnerContact = ""; } try { objEntComp.PrimaryOwnerName = WMIUtil.ToString(obj["PrimaryOwnerName"]); } catch (Exception) { objEntComp.PrimaryOwnerName = ""; } try { objEntComp.Roles = WMIUtil.StringArrayToString(obj["Roles"]); } catch (Exception) { objEntComp.Roles = ""; } try { objEntComp.Status = WMIUtil.ToString(obj["Status"]); } catch (Exception) { objEntComp.Status = ""; } try { objEntComp.SupportContactDescription = WMIUtil.ToString(obj["SupportContactDescription"]); } catch (Exception) { objEntComp.SupportContactDescription = ""; } try { objEntComp.SystemStartupDelay = WMIUtil.ToInteger(obj["SystemStartupDelay"]); } catch (Exception) { objEntComp.SystemStartupDelay = -1; } try { objEntComp.SystemStartupOptions = WMIUtil.StringArrayToString(obj["SystemStartupOptions"]); } catch (Exception) { objEntComp.SystemStartupOptions = ""; } try { objEntComp.SystemType = WMIUtil.ToString(obj["SystemType"]); } catch (Exception) { objEntComp.SystemType = ""; } try { StateValues thermalStateValues = (StateValues)WMIUtil.ToInteger(obj["PowerState"]); objEntComp.ThermalState = WMIUtil.SplitCamelCase(thermalStateValues.ToString()); } catch (Exception) { objEntComp.ThermalState = ""; } try { objEntComp.UserName = WMIUtil.ToString(obj["UserName"]); } catch (Exception) { objEntComp.UserName = ""; } try { WakeupTypeValues wakeUpValues = (WakeupTypeValues)WMIUtil.ToInteger(obj["WakeUpType"]); objEntComp.WakeUpType = WMIUtil.SplitCamelCase(wakeUpValues.ToString()); } catch (Exception) { objEntComp.WakeUpType = ""; } try { objEntComp.Workgroup = WMIUtil.ToString(obj["Workgroup"]); } catch (Exception) { objEntComp.Workgroup = ""; } return objEntComp; }