public override void OnLoad(ConfigNode node) { // KSP Seems to want to make an instance of my partModule during initial load if (vessel == null) { return; } foreach (var hdNode in node.GetNodes("harddisk")) { var newDisk = new Harddisk(hdNode); HardDisk = newDisk; } UnityEngine.Debug.Log("******************************* ON LOAD "); InitCpu(); UnityEngine.Debug.Log("******************************* CPU Inited "); if (cpu != null) { cpu.OnLoad(node); } base.OnLoad(node); }
public override void OnLoad(ConfigNode node) { try { // KSP Seems to want to make an instance of my partModule during initial load if (vessel == null) { return; } if (node.HasNode("harddisk")) { var newDisk = node.GetNode("harddisk").ToHardDisk(); HardDisk = newDisk; } InitObjects(); if (shared != null && shared.Cpu != null) { ((CPU)shared.Cpu).OnLoad(node); } base.OnLoad(node); } catch (Exception ex) //Intentional Pokemon, if exceptions get out of here it can kill the craft { SafeHouse.Logger.Log("ONLOAD Exception: " + ex.TargetSite); SafeHouse.Logger.LogException(ex); } }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(shared); shared.Cpu = new Execution.CPU(shared); // initialize the file system shared.VolumeMgr.Add(shared.Factory.CreateArchive()); if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); } shared.VolumeMgr.Add(HardDisk); if (!Config.GetInstance().StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } }
public ArchiveAndHarddiskCopyAndMoveTest() { archivePath = Path.Combine(Path.GetTempPath(), KosTestDirectory); archive = PrepareArchive(archivePath); harddisk = new Harddisk(1000); }
public void InitObjects() { Debug.LogWarning("kOS: InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new Compilation.KS.KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new VolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.Cpu = new Execution.CPU(shared); // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(kOS.Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (kOS.Screen.TermWindow)gObj.GetComponent(typeof(kOS.Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null && archive.CheckRange(vessel)) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = "boot" }; HardDisk.Add(boot); } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } shared.Cpu.Boot(); }
public static Harddisk ToHardDisk(this ConfigNode configNode) { var capacity = 10000; if (configNode.HasValue("capacity")) capacity = int.Parse(configNode.GetValue("capacity")); var toReturn = new Harddisk(capacity); if (configNode.HasValue("volumeName")) toReturn.Name = configNode.GetValue("volumeName"); foreach (ConfigNode fileNode in configNode.GetNodes("file")) { toReturn.Add(fileNode.ToProgramFile()); } return toReturn; }
public override void OnLoad(ConfigNode node) { // KSP Seems to want to make an instance of my partModule during initial load if (vessel == null) { return; } if (node.HasNode("harddisk")) { var newDisk = new Harddisk(node.GetNode("harddisk")); HardDisk = newDisk; } InitObjects(); if (shared != null && shared.Cpu != null) { shared.Cpu.OnLoad(node); } base.OnLoad(node); }
public override void OnLoad(ConfigNode node) { try { // KSP Seems to want to make an instance of my partModule during initial load if (vessel == null) return; if (node.HasNode("harddisk")) { var newDisk = node.GetNode("harddisk").ToHardDisk(); HardDisk = newDisk; } InitObjects(); if (shared != null && shared.Cpu != null) { ((CPU)shared.Cpu).OnLoad(node); } base.OnLoad(node); } catch (Exception ex) //Intentional Pokemon, if exceptions get out of here it can kill the craft { SafeHouse.Logger.Log("ONLOAD Exception: " + ex.TargetSite); SafeHouse.Logger.LogException(ex); } }
public void InitObjects() { if (objectsInitialized) { SafeHouse.Logger.SuperVerbose("kOSProcessor.InitObjects() - objects already initialized"); return; } objectsInitialized = true; CalcConstsFromKSP(); shared = new SharedObjects(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = new Screen.ConnectivityInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new ConnectivityVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.AddonManager = new AddOns.AddonManager(shared); shared.GameEventDispatchManager = new GameEventDispatchManager(shared); // Make the window that is going to correspond to this kOS part: shared.Window = gameObject.AddComponent <Screen.TermWindow>(); shared.Window.AttachTo(shared); shared.SoundMaker = shared.Window.GetSoundMaker(); // initialize archive Archive = new Archive(SafeHouse.ArchiveFolder); shared.VolumeMgr.Add(Archive); Messages = new MessageQueue(); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(diskSpace); if (!string.IsNullOrEmpty(Tag)) { HardDisk.Name = Tag; } var path = BootFilePath; // populate it with the boot file, but only if using a new disk: if (path != null && !SafeHouse.Config.StartOnArchive) { var bootVolumeFile = Archive.Open(BootFilePath) as VolumeFile; if (bootVolumeFile != null) { if (HardDisk.SaveFile(BootFilePath, bootVolumeFile.ReadAll()) == null) { // Throwing an exception during InitObjects will break the initialization and won't show // the error to the user. So we just log the error instead. At some point in the future // it would be nice to queue up these init errors and display them to the user somewhere. SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space."); } } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!SafeHouse.Config.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } // initialize processor mode if different than READY if (ProcessorMode != ProcessorModes.READY) { ProcessorModeChanged(); } InitProcessorTracking(); }
public Server GetServer(string hostname) { Server server = new Server(); SqlConnection myConnection = ConnectDB(); // Provide the query string with a parameter placeholder. try { string queryString = "SELECT * from dbo.server WHERE Name = '" + hostname + "'"; SqlCommand command = new SqlCommand(queryString, myConnection); myConnection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { server.Name = reader[0].ToString(); server.Status = reader[1].ToString(); server.Ram = Convert.ToInt64(reader[2]); server.OsVer = reader[3].ToString(); } myConnection.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string queryString = "SELECT * from dbo.netcard WHERE SFK_ID = '" + hostname + "'"; SqlCommand command = new SqlCommand(queryString, myConnection); myConnection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { NetWorkCard Card = new NetWorkCard(); Card.IpAddress = reader[1].ToString(); Card.MacAddress = reader[2].ToString(); server.NetWorkCard.Add(Card); } myConnection.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } try { string queryString = "SELECT * from dbo.Hdd WHERE SFK_ID = '" + hostname + "'"; SqlCommand command = new SqlCommand(queryString, myConnection); myConnection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Harddisk Disk = new Harddisk(); Disk.DriveLetter = reader[1].ToString(); Disk.MbSize = Convert.ToInt64(reader[2]); server.Hdd.Add(Disk); } myConnection.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(server); }
//returns a list of all servers public ObservableCollection <Server> GetAllServers() { string queryString_getServes = "SELECT * FROM dbo.Server"; SqlConnection sqlCon = ConnectDB(); SqlCommand command_getServes = new SqlCommand(queryString_getServes, sqlCon); ObservableCollection <Server> servers = new ObservableCollection <Server>(); sqlCon.Open(); try { //get servers SqlDataReader reader = command_getServes.ExecuteReader(); while (reader.Read()) { Server server = new Server(); server.Name = reader[0].ToString(); server.Status = reader[1].ToString(); server.Ram = Convert.ToInt64(reader[2]); server.OsVer = reader[3].ToString(); servers.Add(server); } //get networks cards for (int i = 0; i < servers.Count; i++) { //find all netcards related to the current server string queryString_getNetCards = "SELECT * from dbo.netcard WHERE SFK_ID = '" + servers[i].Name + "'"; SqlCommand command_getNetCards = new SqlCommand(queryString_getNetCards, sqlCon); reader = command_getNetCards.ExecuteReader(); while (reader.Read()) { //create a new netcard and add it to the server NetWorkCard Card = new NetWorkCard(); Card.IpAddress = reader[1].ToString(); Card.MacAddress = reader[2].ToString(); servers[i].NetWorkCard.Add(Card); } } //get hdd's for (int i = 0; i < servers.Count; i++) { //find all hdd's related to the current server string queryString_getHDDs = "SELECT * from dbo.hdd WHERE SFK_ID = '" + servers[i].Name + "'"; SqlCommand command_getHDDs = new SqlCommand(queryString_getHDDs, sqlCon); reader = command_getHDDs.ExecuteReader(); while (reader.Read()) { //create a new hdd and add it to the server Harddisk hdd = new Harddisk(); hdd.DriveLetter = reader[1].ToString(); hdd.MbSize = (int)reader[2]; servers[i].Hdd.Add(hdd); } reader.Close(); } } catch (Exception ex) { Console.WriteLine(ex); } finally { sqlCon.Close(); } return(servers); }
public static Harddisk ToHardDisk(this ConfigNode configNode) { var capacity = 10000; if (configNode.HasValue("capacity")) capacity = int.Parse(configNode.GetValue("capacity")); var toReturn = new Harddisk(capacity); if (configNode.HasValue("volumeName")) toReturn.Name = configNode.GetValue("volumeName"); toReturn.RootHarddiskDirectory = configNode.ToHarddiskDirectory(toReturn, VolumePath.EMPTY); return toReturn; }
public void InitObjects() { SafeHouse.Logger.LogWarning("InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = shared.Factory.CreateVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.SoundMaker = Sound.SoundMaker.Instance; // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && bootFile != "None" && !Config.Instance.StartOnArchive) { var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = bootFile }; HardDisk.Add(boot); } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } InitProcessorTracking(); }
public void InitObjects() { SafeHouse.Logger.LogWarning("InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = shared.Factory.CreateVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.SoundMaker = Sound.SoundMaker.Instance; // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); if (!string.IsNullOrEmpty(Tag)) { HardDisk.Name = Tag; } // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && bootFile != "None" && !SafeHouse.Config.StartOnArchive) { var bootVolumeFile = archive.Open(bootFile); if (bootVolumeFile != null) { FileContent content = bootVolumeFile.ReadAll(); if (HardDisk.IsRoomFor(bootFile, content)) { HardDisk.Save(bootFile, content); } else { // Throwing an exception during InitObjects will break the initialization and won't show // the error to the user. So we just log the error instead. At some point in the future // it would be nice to queue up these init errors and display them to the user somewhere. SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space."); } } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!SafeHouse.Config.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } // initialize processor mode if different than READY if (ProcessorMode != ProcessorModes.READY) { ProcessorModeChanged(); } InitProcessorTracking(); }
public static HarddiskFile ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk) { var filename = configNode.GetValue(FILENAME_VALUE_STRING); FileContent fileContent = Decode(configNode.GetValue("line")); harddisk.Save(filename, fileContent); return new HarddiskFile(harddisk, filename); }
public void Setup() { TestVolume = new Harddisk(ExpectedCapacity); }
public HarddiskToHarddiskCopyAndMoveTest() { harddisk1 = new Harddisk(1000); harddisk2 = new Harddisk(1000); }
public void InitObjects() { SafeHouse.Logger.LogWarning("InitObjects: " + (shared == null)); shared = new SharedObjects(); CreateFactory(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = shared.Factory.CreateInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = shared.Factory.CreateVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.SoundMaker = Sound.SoundMaker.Instance; // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); // initialize archive var archive = shared.Factory.CreateArchive(); shared.VolumeMgr.Add(archive); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP)); if (!String.IsNullOrEmpty(Tag)) { HardDisk.Name = Tag; } // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && bootFile != "None" && !Config.Instance.StartOnArchive) { var bootProgramFile = archive.GetByName(bootFile); if (bootProgramFile != null) { // Copy to HardDisk as "boot". var boot = new ProgramFile(bootProgramFile) { Filename = bootFile }; HardDisk.Add(boot); } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!Config.Instance.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } InitProcessorTracking(); }
public HarddiskFile(Harddisk harddisk, string name) : base(name) { this.harddisk = harddisk; }
public static FileContent ToHarddiskFile(this ConfigNode configNode, Harddisk harddisk, HarddiskDirectory directory) { try { string content = null; if (configNode.TryGetValue("ascii", ref content)) // ASCII files just get decoded from the ConfigNode safe representation { return new FileContent(PersistenceUtilities.DecodeLine(content)); } if (configNode.TryGetValue("binary", ref content)) // binary files get decoded from Base64 and gzip { return new FileContent(PersistenceUtilities.DecodeBase64ToBinary(content)); } if (configNode.TryGetValue("line", ref content)) // fall back to legacy logic { return Decode(content); } } catch (Exception ex) { SafeHouse.Logger.LogError(string.Format("Exception caught loading file information: {0}\n\nStack Trace:\n{1}", ex.Message, ex.StackTrace)); } SafeHouse.Logger.LogError(string.Format("Error loading file information from ConfigNode at path {0} on hard disk {1}", directory.Path, harddisk.Name)); return new FileContent(""); // if there was an error, just return a blank file. }
private static HarddiskDirectory ToHarddiskDirectory(this ConfigNode configNode, Harddisk harddisk, VolumePath path) { HarddiskDirectory directory = new HarddiskDirectory(harddisk, path); foreach (ConfigNode fileNode in configNode.GetNodes("file")) { directory.CreateFile(fileNode.GetValue(FilenameValueString), fileNode.ToHarddiskFile(harddisk, directory)); } foreach (ConfigNode dirNode in configNode.GetNodes("directory")) { string dirName = dirNode.GetValue(DirnameValueString); directory.CreateDirectory(dirName, dirNode.ToHarddiskDirectory(harddisk, VolumePath.FromString(dirName, path))); } return directory; }
public void InitObjects() { shared = new SharedObjects(); shared.Vessel = vessel; shared.Processor = this; shared.KSPPart = part; shared.UpdateHandler = new UpdateHandler(); shared.BindingMgr = new BindingManager(shared); shared.Interpreter = new Screen.ConnectivityInterpreter(shared); shared.Screen = shared.Interpreter; shared.ScriptHandler = new KSScript(); shared.Logger = new KSPLogger(shared); shared.VolumeMgr = new ConnectivityVolumeManager(shared); shared.ProcessorMgr = new ProcessorManager(); shared.FunctionManager = new FunctionManager(shared); shared.TransferManager = new TransferManager(shared); shared.Cpu = new CPU(shared); shared.AddonManager = new AddOns.AddonManager(shared); // Make the window that is going to correspond to this kOS part: var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow)); DontDestroyOnLoad(gObj); shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow)); shared.Window.AttachTo(shared); shared.SoundMaker = shared.Window.GetSoundMaker(); // initialize archive Archive = new Archive(SafeHouse.ArchiveFolder); shared.VolumeMgr.Add(Archive); Messages = new MessageQueue(); // initialize harddisk if (HardDisk == null) { HardDisk = new Harddisk(diskSpace); if (!string.IsNullOrEmpty(Tag)) { HardDisk.Name = Tag; } var path = BootFilePath; // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation: if (vessel.situation == Vessel.Situations.PRELAUNCH && path != null && !SafeHouse.Config.StartOnArchive) { var bootVolumeFile = Archive.Open(BootFilePath) as VolumeFile; if (bootVolumeFile != null) { if (HardDisk.SaveFile(BootFilePath, bootVolumeFile.ReadAll()) == null) { // Throwing an exception during InitObjects will break the initialization and won't show // the error to the user. So we just log the error instead. At some point in the future // it would be nice to queue up these init errors and display them to the user somewhere. SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space."); } } } } shared.VolumeMgr.Add(HardDisk); // process setting if (!SafeHouse.Config.StartOnArchive) { shared.VolumeMgr.SwitchTo(HardDisk); } // initialize processor mode if different than READY if (ProcessorMode != ProcessorModes.READY) { ProcessorModeChanged(); } InitProcessorTracking(); }
public Server WMICall(string servername) { // Create Server obj. Server server = new Server(); ConnectionOptions options = new ConnectionOptions(); // bruger den konto som programmet bliver kørt af. options.Impersonation = System.Management.ImpersonationLevel.Impersonate; // Viser hvor vi vil søge henne, dette er WMI root på servern ManagementScope scope = new ManagementScope("\\\\" + servername + "\\root\\cimv2", options); // Forbinder til server try { scope.Connect(); //Query system for Operating System information ObjectQuery OSquery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher OSsearcher = new ManagementObjectSearcher(scope, OSquery); ManagementObjectCollection OSqueryCollection = OSsearcher.Get(); foreach (ManagementObject OS in OSqueryCollection) { server.Name = OS.GetPropertyValue("csname").ToString(); server.OsVer = OS.GetPropertyValue("Caption").ToString(); } //Query system for Computer System information ObjectQuery CSquery = new ObjectQuery("SELECT * FROM Win32_ComputerSystem"); ManagementObjectSearcher CSsearcher = new ManagementObjectSearcher(scope, CSquery); ManagementObjectCollection CSqueryCollection = CSsearcher.Get(); foreach (ManagementObject CS in CSqueryCollection) { server.Ram = (Convert.ToInt64(CS.GetPropertyValue("TotalPhysicalMemory"))) / 1048576; } //Query system for DiskDrive information ObjectQuery LDquery = new ObjectQuery("SELECT * FROM Win32_LogicalDisk"); ManagementObjectSearcher LDsearcher = new ManagementObjectSearcher(scope, LDquery); ManagementObjectCollection LDqueryCollection = LDsearcher.Get(); foreach (ManagementObject LD in LDqueryCollection) { Harddisk harddisk = new Harddisk(); harddisk.DriveLetter = LD["DeviceID"].ToString(); harddisk.MbSize = (Convert.ToInt64(LD["Size"])) / 1048576; server.Hdd.Add(harddisk); } //Query system for network information ObjectQuery NCquery = new ObjectQuery("SELECT MacAddress,IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'"); ManagementObjectSearcher NCsearcher = new ManagementObjectSearcher(scope, NCquery); ManagementObjectCollection NCqueryCollection = NCsearcher.Get(); foreach (ManagementObject NC in NCqueryCollection) { NetWorkCard netWorkCard = new NetWorkCard(); int nrIP = ((System.Array)(NC["IPAddress"])).Length; for (int c = 0; c < nrIP; c++) { netWorkCard.IpAddress = ((Array)(NC["IPAddress"])).GetValue(c).ToString(); netWorkCard.MacAddress = NC["MacAddress"].ToString(); } server.NetWorkCard.Add(netWorkCard); } // Return Server obj. return(server); } catch { Debug.WriteLine("WMI Error"); return(null); } }