예제 #1
0
        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;
        }
예제 #2
0
파일: Printer.cs 프로젝트: 5dollartools/NAM
        private static EntPrinter FillDetails(ManagementBaseObject obj)
        {
            EntPrinter objEntPrinter = new EntPrinter();
            try
            {
                objEntPrinter.Attributes = GetPrinterAttributes((uint)obj["Attributes"]);
            }
            catch (Exception)
            {
                objEntPrinter.Attributes = "";
            }

            try
            {
                AvailabilityValues availability = (AvailabilityValues)WMIUtil.ToInteger(obj["Availability"]);
                objEntPrinter.Availability = WMIUtil.SplitCamelCase(availability.ToString());
            }
            catch (Exception)
            {
                objEntPrinter.Availability = "";
            }

            try
            {
                objEntPrinter.AveragePagesPerMinute = WMIUtil.ToString(obj["AveragePagesPerMinute"]) + " pages per minute";
            }
            catch (Exception)
            {
                objEntPrinter.Availability = "";
            }

            try
            {
                objEntPrinter.Caption = WMIUtil.ToString(obj["Caption"]);
            }
            catch (Exception)
            {
                objEntPrinter.Caption = "";
            }

            try
            {
                objEntPrinter.HorizontalResolution = WMIUtil.ToInteger(obj["HorizontalResolution"]);
            }
            catch (Exception)
            {
                objEntPrinter.HorizontalResolution = 0;
            }

            try
            {
                objEntPrinter.VerticalResolution = WMIUtil.ToInteger(obj["VerticalResolution"]);
            }
            catch (Exception)
            {
                objEntPrinter.VerticalResolution = 0;
            }

            try
            {
                objEntPrinter.Local = (bool)obj["Local"];
            }
            catch (Exception)
            {
                objEntPrinter.Local = false;
            }

            try
            {
                objEntPrinter.Network = (bool)obj["Network"];
            }
            catch (Exception)
            {
                objEntPrinter.Network= false;
            }
            try
            {
                objEntPrinter.Shared = (bool)obj["Shared"];
            }
            catch (Exception)
            {
                objEntPrinter.Shared = false;
            }

            try
            {
                objEntPrinter.Location = WMIUtil.ToString(obj["Location"]);
            }
            catch (Exception)
            {
                objEntPrinter.Location = "";
            }

            try
            {
                objEntPrinter.PortName = WMIUtil.ToString(obj["PortName"]);
            }
            catch (Exception)
            {
                objEntPrinter.PortName = "";
            }

            try
            {
                PrinterState priState = (PrinterState)WMIUtil.ToInteger(obj["PrinterState"]);
                objEntPrinter.PrinterState = WMIUtil.SplitCamelCase(priState.ToString());
            }
            catch (Exception)
            {
                objEntPrinter.PrinterState = "";
            }

            try
            {
                PrinterStatus priStatus = (PrinterStatus)WMIUtil.ToInteger(obj["PrinterStatus"]);
                objEntPrinter.PrinterStatus = WMIUtil.SplitCamelCase(priStatus.ToString());
            }
            catch (Exception)
            {
                objEntPrinter.PrinterStatus = "";
            }

            try
            {
                objEntPrinter.ServerName = WMIUtil.ToString(obj["ServerName"]);
            }
            catch (Exception)
            {
                objEntPrinter.ServerName = "";
            }

            try
            {
                objEntPrinter.ShareName = WMIUtil.ToString(obj["ShareName"]);
            }
            catch (Exception)
            {
                objEntPrinter.ShareName= "";
            }

            return objEntPrinter;
        }