Beispiel #1
0
        public static void Main(string[] args)
        {
            Detector d = new Detector();

            Console.WriteLine("Detected CPUs:");
            foreach (ProcessorDTOResponse item in d.GetProcessorsInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected memory:");
            foreach (MemoryDTOResponse item in d.GetMemoryInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected OS:");
            OperatingSystemDTOResponse os = d.GetOperatingSystemInfo();

            PropertiesPrinter.Print(os);

            Console.WriteLine("\nDetected storage:");
            foreach (StorageDTOResponse item in d.GetStorageInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected ethernets:");
            foreach (EthernetDTOResponse item in d.GetEthernetInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected fc cards:");
            foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected shares:");
            foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected software:");
            foreach (SoftwareDTOResponse item in d.GetSoftwareInfo())
            {
                PropertiesPrinter.Print(item);
            }

            Console.WriteLine("\nDetected device:");
            DeviceDTOResponse dev = d.GetDeviceInfo();

            PropertiesPrinter.Print(dev);

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Beispiel #2
0
        public OperatingSystemDTOResponse GetOperatingSystemInfo()
        {
            OperatingSystemDTOResponse os = new OperatingSystemDTOResponse();

            try
            {
                SelectQuery query = new SelectQuery("select Caption, TotalVisibleMemorySize from Win32_OperatingSystem");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject obj in searcher.Get())
                {
                    os.Label = GetValueAsString(obj, "Caption");
                    try
                    {
                        os.Memory = ConvertSizeToMiB(Int64.Parse(obj["TotalVisibleMemorySize"].ToString()), SizeUnits.KB).ToString();
                    }
                    catch (Exception e)
                    {
                        Logger.Instance.LogError(e.ToString());
                    }
                    break;
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            int totalCoresCount = 0;

            foreach (ProcessorDTOResponse cpu in GetProcessorsInfo())
            {
                int coresCount;
                if (int.TryParse(cpu.Cores, out coresCount))
                {
                    totalCoresCount += coresCount;
                }
            }
            os.CoresCount = totalCoresCount.ToString();

            Int64 totalDisksSize = 0;

            foreach (StorageDTOResponse storage in GetStorageInfo())
            {
                Int64 storageSize;
                if (Int64.TryParse(storage.Size, out storageSize))
                {
                    totalDisksSize += storageSize;
                }
            }
            os.Storage = totalDisksSize.ToString();

            return(os);
        }
Beispiel #3
0
        public string GetAllComponentsJSON()
        {
            string json = "{\"data\":{";

            json += "\"status\":\"success\",";
            json += "\"date\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\",";
            json += "\"plugin\":\"donpedro\",";
            json += "\"messages\":[],";
            json += "\"device\":{";
            DeviceDTOResponse deviceInfo = GetDeviceInfo();

            json += "\"model_name\":\"" + deviceInfo.ModelName + "\",";
            json += "\"serial_number\":\"" + deviceInfo.SerialNumber + "\",";
            json += "\"system_ip_addresses\":[" + string.Join(",", GetIPAddressInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"mac_addresses\":[" + string.Join(",", GetMacAddressInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"disks\":[" + string.Join(",", GetStorageInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"fibrechannel_cards\":[" + string.Join(",", GetFibreChannelInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"disk_shares\":[" + string.Join(",", GetDiskShareMountInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"memory\":[" + string.Join(",", GetMemoryInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"processors\":[" + string.Join(",", GetProcessorsInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            json += "\"installed_software\":[" + string.Join(",", GetSoftwareInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],";
            OperatingSystemDTOResponse operatingSystem = GetOperatingSystemInfo();

            json += "\"system_memory\":\"" + operatingSystem.SystemMemory + "\",";
            json += "\"system_storage\":\"" + operatingSystem.SystemStorage + "\",";
            json += "\"system_cores_count\":\"" + operatingSystem.SystemCoresCount + "\"";
            json += "},";
            json += "\"results_priority\":{";
            json += "\"model_name\":25,";
            json += "\"serial_number\":20,";
            json += "\"system_ip_addresses\":60,";
            json += "\"mac_addresses\":50,";
            json += "\"disks\":30,";
            json += "\"fibrechannel_cards\":60,";
            json += "\"disk_shares\":30,";
            json += "\"memory\":60,";
            json += "\"processors\":60,";
            json += "\"installed_software\":60,";
            json += "\"system_memory\":60,";
            json += "\"system_storage\":30,";
            json += "\"system_cores_count\":60";
            return(json + "}}}");
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            Detector d = new Detector();

            Console.WriteLine("Detected CPUs:");
            foreach (ProcessorDTOResponse item in d.GetProcessorsInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected memory:");
            foreach (MemoryDTOResponse item in d.GetMemoryInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected OS:");
            OperatingSystemDTOResponse os = d.GetOperatingSystemInfo();

            foreach (var prop in os.GetType().GetProperties())
            {
                Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(os, null));
            }
            Console.WriteLine();

            Console.WriteLine("\nDetected storage:");
            foreach (StorageDTOResponse item in d.GetStorageInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected ethernets:");
            foreach (EthernetDTOResponse item in d.GetEthernetInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected fc cards:");
            foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected shares:");
            foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo())
            {
                foreach (var prop in item.GetType().GetProperties())
                {
                    Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null));
                }
                Console.WriteLine();
            }

            Console.WriteLine("\nDetected device:");
            DeviceDTOResponse dev = d.GetDeviceInfo();

            foreach (var prop in dev.GetType().GetProperties())
            {
                Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(dev, null));
            }
            Console.WriteLine();

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Beispiel #5
0
        public void Print(Detector d, bool jsonOnly)
        {
            if (jsonOnly)
            {
                Console.WriteLine(d.GetAllComponentsJSON());
            }
            else
            {
                Console.WriteLine("Detected CPUs:");
                foreach (ProcessorDTOResponse item in d.GetProcessorsInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected memory:");
                foreach (MemoryDTOResponse item in d.GetMemoryInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected OS:");
                OperatingSystemDTOResponse os = d.GetOperatingSystemInfo();
                PropertiesPrinter.Print(os);

                Console.WriteLine("\nDetected storage:");
                foreach (StorageDTOResponse item in d.GetStorageInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected IP addresses:");
                foreach (IPAddressDTOResponse item in d.GetIPAddressInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected MAC addresses:");
                foreach (MacAddressDTOResponse item in d.GetMacAddressInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected fc cards:");
                foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected shares:");
                foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected software:");
                foreach (SoftwareDTOResponse item in d.GetSoftwareInfo())
                {
                    PropertiesPrinter.Print(item);
                }

                Console.WriteLine("\nDetected device:");
                DeviceDTOResponse dev = d.GetDeviceInfo();
                PropertiesPrinter.Print(dev);
            }
        }